Skip to content

Commit

Permalink
reverted _eval_step_func, rm get_name_args, edited get_num_args
Browse files Browse the repository at this point in the history
  • Loading branch information
kombatEldridge committed Sep 3, 2024
1 parent 5ff7e37 commit 84585e4
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions python/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""

import functools
import inspect
import math
import numbers
import os
Expand Down Expand Up @@ -96,18 +97,12 @@ def get_num_args(func):
return (
2
if isinstance(func, Harminv) or isinstance(func, PadeDFT)
else func.__code__.co_argcount - 1
if inspect.ismethod(func)
else func.__code__.co_argcount
)


def get_name_args(func):
return (
("sim", "todo")
if isinstance(func, Harminv) or isinstance(func, PadeDFT)
else func.__code__.co_varnames[: func.__code__.co_argcount]
)


def vec(*args):
try:
# Check for vec(x, [y, [z]])
Expand Down Expand Up @@ -5004,16 +4999,14 @@ def _combine(sim, todo):

def _eval_step_func(sim, func, todo):
num_args = get_num_args(func)
name_args = get_name_args(func)
self_count = int("self" in name_args)

if num_args not in {1 + self_count, 2 + self_count}:
raise ValueError(f"Step function '{func.__name__}' requires 1 or 2 arguments")
elif num_args == 2 + self_count:
func(sim, todo)
elif num_args == 1 + self_count:
if num_args != 1 and num_args != 2:
raise ValueError(f"Step function '{func.__name__}'' requires 1 or 2 arguments")
elif num_args == 1:
if todo == "step":
func(sim)
elif num_args == 2:
func(sim, todo)


def _when_true_funcs(cond, *step_funcs):
Expand Down

0 comments on commit 84585e4

Please sign in to comment.