From 59285b0d2440a162b6020d2726c98a31d29f55f9 Mon Sep 17 00:00:00 2001 From: Brinton Eldridge Date: Tue, 27 Aug 2024 14:31:22 -0500 Subject: [PATCH 01/10] changes to _eval_step_func --- python/simulation.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/python/simulation.py b/python/simulation.py index 60538271d..54f969b21 100644 --- a/python/simulation.py +++ b/python/simulation.py @@ -4996,14 +4996,13 @@ def _combine(sim, todo): def _eval_step_func(sim, func, todo): num_args = get_num_args(func) + name_args = func.__code__.co_varnames + self_count = int("self" in name_args) - 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) + if num_args not in {1 + self_count, 2 + self_count}: + raise ValueError(f"Step function '{func.__name__}' requires 1 or 2 arguments") + + func(sim, todo) if num_args == 2 + self_count else func(sim) def _when_true_funcs(cond, *step_funcs): From bb09612cf2d5e0df70535dd72cdca6189d19745d Mon Sep 17 00:00:00 2001 From: Brinton Eldridge <90061933+kombatEldridge@users.noreply.github.com> Date: Thu, 29 Aug 2024 12:59:49 -0500 Subject: [PATCH 02/10] Update simulation.py --- python/simulation.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/python/simulation.py b/python/simulation.py index 54f969b21..8d1439c59 100644 --- a/python/simulation.py +++ b/python/simulation.py @@ -99,6 +99,12 @@ def get_num_args(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: @@ -4996,7 +5002,7 @@ def _combine(sim, todo): def _eval_step_func(sim, func, todo): num_args = get_num_args(func) - name_args = func.__code__.co_varnames + name_args = get_name_args(func) self_count = int("self" in name_args) if num_args not in {1 + self_count, 2 + self_count}: From 3552f8f28b896909381e9fb2ec36f4f5021fea1b Mon Sep 17 00:00:00 2001 From: Brinton Eldridge Date: Thu, 29 Aug 2024 13:11:17 -0500 Subject: [PATCH 03/10] double to single quotes --- python/simulation.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/python/simulation.py b/python/simulation.py index 8d1439c59..339c3a217 100644 --- a/python/simulation.py +++ b/python/simulation.py @@ -99,6 +99,7 @@ def get_num_args(func): else func.__code__.co_argcount ) + def get_name_args(func): return ( ("sim", "todo") @@ -106,6 +107,7 @@ def get_name_args(func): else func.__code__.co_varnames[: func.__code__.co_argcount] ) + def vec(*args): try: # Check for vec(x, [y, [z]]) From 5ff7e373ee1a395118dbc7cdd570efb492077b16 Mon Sep 17 00:00:00 2001 From: Brinton Eldridge Date: Tue, 3 Sep 2024 07:35:52 -0500 Subject: [PATCH 04/10] incorrect if statement --- python/simulation.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/python/simulation.py b/python/simulation.py index 339c3a217..2ed0c475c 100644 --- a/python/simulation.py +++ b/python/simulation.py @@ -5009,8 +5009,11 @@ def _eval_step_func(sim, func, todo): if num_args not in {1 + self_count, 2 + self_count}: raise ValueError(f"Step function '{func.__name__}' requires 1 or 2 arguments") - - func(sim, todo) if num_args == 2 + self_count else func(sim) + elif num_args == 2 + self_count: + func(sim, todo) + elif num_args == 1 + self_count: + if todo == "step": + func(sim) def _when_true_funcs(cond, *step_funcs): From 84585e4da751bc5942cdaf25c2414c5d5d850e27 Mon Sep 17 00:00:00 2001 From: Brinton Eldridge Date: Tue, 3 Sep 2024 08:38:59 -0500 Subject: [PATCH 05/10] reverted _eval_step_func, rm get_name_args, edited get_num_args --- python/simulation.py | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/python/simulation.py b/python/simulation.py index 2ed0c475c..013cc0ccb 100644 --- a/python/simulation.py +++ b/python/simulation.py @@ -3,6 +3,7 @@ """ import functools +import inspect import math import numbers import os @@ -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]]) @@ -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): From 8f684051b55f0d0ddea1096b71d231b0dd9dd88c Mon Sep 17 00:00:00 2001 From: "Steven G. Johnson" Date: Tue, 3 Sep 2024 11:47:52 -0400 Subject: [PATCH 06/10] Update python/simulation.py --- python/simulation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/simulation.py b/python/simulation.py index 013cc0ccb..cee62fd02 100644 --- a/python/simulation.py +++ b/python/simulation.py @@ -97,7 +97,7 @@ def get_num_args(func): return ( 2 if isinstance(func, Harminv) or isinstance(func, PadeDFT) - else func.__code__.co_argcount - 1 + else func.__code__.co_argcount - 1 # first argument is "self", passed implicitly for bound methods if inspect.ismethod(func) else func.__code__.co_argcount ) From 0babfee3ca8e338c1b22c85c24c0fe60ba96f016 Mon Sep 17 00:00:00 2001 From: "Steven G. Johnson" Date: Tue, 3 Sep 2024 12:16:21 -0400 Subject: [PATCH 07/10] Update python/simulation.py --- python/simulation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/simulation.py b/python/simulation.py index cee62fd02..aa0ee373f 100644 --- a/python/simulation.py +++ b/python/simulation.py @@ -97,7 +97,7 @@ def get_num_args(func): return ( 2 if isinstance(func, Harminv) or isinstance(func, PadeDFT) - else func.__code__.co_argcount - 1 # first argument is "self", passed implicitly for bound methods + else func.__code__.co_argcount - 1 # first argument is "self" if inspect.ismethod(func) else func.__code__.co_argcount ) From 66134796574e8a8cec33354c4fdbfb4f3f6d1d2f Mon Sep 17 00:00:00 2001 From: "Steven G. Johnson" Date: Tue, 3 Sep 2024 12:52:16 -0400 Subject: [PATCH 08/10] Update python/simulation.py --- python/simulation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/simulation.py b/python/simulation.py index aa0ee373f..2521a3780 100644 --- a/python/simulation.py +++ b/python/simulation.py @@ -97,7 +97,7 @@ def get_num_args(func): return ( 2 if isinstance(func, Harminv) or isinstance(func, PadeDFT) - else func.__code__.co_argcount - 1 # first argument is "self" + else func.__code__.co_argcount - 1 # first argument is "self" if inspect.ismethod(func) else func.__code__.co_argcount ) From 2ac635fdd0750b1d93e6832e1256172b549f785c Mon Sep 17 00:00:00 2001 From: Brinton Eldridge Date: Wed, 4 Sep 2024 06:35:14 -0500 Subject: [PATCH 09/10] if statement readability update --- python/simulation.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/python/simulation.py b/python/simulation.py index 2521a3780..726fb4ebf 100644 --- a/python/simulation.py +++ b/python/simulation.py @@ -94,13 +94,12 @@ def fix_dft_args(args, i): def get_num_args(func): - return ( - 2 - if isinstance(func, Harminv) or isinstance(func, PadeDFT) - else func.__code__.co_argcount - 1 # first argument is "self" - if inspect.ismethod(func) - else func.__code__.co_argcount - ) + if isinstance(func, Harminv) or isinstance(func, PadeDFT): + return 2 + elif inspect.ismethod(func): + return func.__code__.co_argcount - 1 # remove 'self' from count + else: + return func.__code__.co_argcount def vec(*args): From 566c47db63de8ee218c7dd9d1429172c082c80cf Mon Sep 17 00:00:00 2001 From: Brinton Eldridge Date: Wed, 4 Sep 2024 06:36:11 -0500 Subject: [PATCH 10/10] added space from pre-check --- python/simulation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/simulation.py b/python/simulation.py index 726fb4ebf..3bf01a092 100644 --- a/python/simulation.py +++ b/python/simulation.py @@ -97,7 +97,7 @@ def get_num_args(func): if isinstance(func, Harminv) or isinstance(func, PadeDFT): return 2 elif inspect.ismethod(func): - return func.__code__.co_argcount - 1 # remove 'self' from count + return func.__code__.co_argcount - 1 # remove 'self' from count else: return func.__code__.co_argcount