From 5e30d3b5dd2f3071ff8dadc30e638d5647275541 Mon Sep 17 00:00:00 2001 From: Remco de Boer <29308176+redeboer@users.noreply.github.com> Date: Tue, 16 May 2023 15:40:51 +0200 Subject: [PATCH 1/2] ENH: move data arguments to front for `partial` This is required for defining a gradient over the parameters --- src/tensorwaves/function/sympy/__init__.py | 5 ++++- tests/function/test_function.py | 3 ++- tests/test_estimator.py | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/tensorwaves/function/sympy/__init__.py b/src/tensorwaves/function/sympy/__init__.py index b8c8f327..ffd5c34a 100644 --- a/src/tensorwaves/function/sympy/__init__.py +++ b/src/tensorwaves/function/sympy/__init__.py @@ -109,7 +109,10 @@ def create_parametrized_function( [0.0, 0.0, 0.0, 0.0, 0.0] """ free_symbols = _get_free_symbols(expression) - sorted_symbols = sorted(free_symbols, key=lambda s: s.name) + parameter_set = set(parameters) + parameter_symbols = sorted(free_symbols & parameter_set, key=lambda s: s.name) + data_symbols = sorted(free_symbols - parameter_set, key=lambda s: s.name) + sorted_symbols = tuple(data_symbols + parameter_symbols) # for partial+gradient lambdified_function = _lambdify_normal_or_fast( expression=expression, symbols=sorted_symbols, diff --git a/tests/function/test_function.py b/tests/function/test_function.py index 412a2281..90635197 100644 --- a/tests/function/test_function.py +++ b/tests/function/test_function.py @@ -35,7 +35,8 @@ def function(self) -> ParametrizedBackendFunction: return create_parametrized_function(expression, parameters, backend="numpy") def test_argument_order(self, function: ParametrizedBackendFunction): - assert function.argument_order == ("c_1", "c_2", "c_3", "c_4", "x") + """Test whether data arguments come before parameters.""" + assert function.argument_order == ("x", "c_1", "c_2", "c_3", "c_4") @pytest.mark.parametrize( ("test_data", "expected_results"), diff --git a/tests/test_estimator.py b/tests/test_estimator.py index 935be3bd..fae4e1ef 100644 --- a/tests/test_estimator.py +++ b/tests/test_estimator.py @@ -111,7 +111,7 @@ def test_create_cached_function(backend): assert isinstance(cached_function, ParametrizedBackendFunction) assert isinstance(cache_transformer, SympyDataTransformer) - assert cached_function.argument_order == ("a", "c", "f0", "x") + assert cached_function.argument_order == ("f0", "x", "a", "c") # data args first assert set(cached_function.parameters) == {"a", "c"} assert set(cache_transformer.functions) == {"f0", "x"} From 028de06c2e963f2e430ef7af980dc9215d412bb0 Mon Sep 17 00:00:00 2001 From: Remco de Boer <29308176+redeboer@users.noreply.github.com> Date: Tue, 30 May 2023 11:11:09 +0200 Subject: [PATCH 2/2] DOC: use Wiki link for Minuit2 The official webpages of Minuit2 appear to be unstable --- src/tensorwaves/optimizer/minuit.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tensorwaves/optimizer/minuit.py b/src/tensorwaves/optimizer/minuit.py index 23ec90fd..230728da 100644 --- a/src/tensorwaves/optimizer/minuit.py +++ b/src/tensorwaves/optimizer/minuit.py @@ -18,7 +18,7 @@ class Minuit2(Optimizer): - """Adapter to `Minuit2 `_. + """Adapter to `Minuit2 `_. Implements the `~.interface.Optimizer` interface using `iminuit.Minuit`.