From ba07a3824cfe636cc6a6aef10d73cf9f85473b66 Mon Sep 17 00:00:00 2001 From: Nels Frazier Date: Wed, 28 Aug 2024 08:21:27 -0600 Subject: [PATCH] test: alias permutation mechanics --- python/ngen_cal/tests/conftest.py | 10 ++++++++++ python/ngen_cal/tests/test_params.py | 18 ++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/python/ngen_cal/tests/conftest.py b/python/ngen_cal/tests/conftest.py index e3af5da5..0c786b9e 100644 --- a/python/ngen_cal/tests/conftest.py +++ b/python/ngen_cal/tests/conftest.py @@ -241,3 +241,13 @@ def multi_model_shared_params2() -> Mapping[str, list[Parameter]]: params = {'A':[p1, p3], 'B':[p2]} return params + +@pytest.fixture +def multi_model_alias_params() -> Mapping[str, list[Parameter]]: + p1 = Parameter(name='a', alias='c', min=0, max=1, init=0) + p2 = Parameter(name='b', alias='c', min=0, max=1, init=0) + p3 = Parameter(name='d', min=0, max=1, init=0) + + params = {'A':[p1,p3], 'B':[p2, p3], 'C':[p3]} + + return params diff --git a/python/ngen_cal/tests/test_params.py b/python/ngen_cal/tests/test_params.py index bb483c9d..223ce577 100644 --- a/python/ngen_cal/tests/test_params.py +++ b/python/ngen_cal/tests/test_params.py @@ -40,3 +40,21 @@ def test_multi_params2(multi_model_shared_params2: Mapping[str, list[Parameter]] pa = params[ params['model'] == 'A' ].drop('model', axis=1).loc['a'] pb = params[ params['model'] == 'B' ].drop('model', axis=1).loc['a'] assert pa.equals( pb ) + +def test_alias_params(multi_model_alias_params: Mapping[str, list[Parameter]]): + # This is essentially the path the params go through from + # creation in model.py to update in search.py + assert multi_model_alias_params['C'][0].alias == multi_model_alias_params['C'][0].name + params = _params_as_df(multi_model_alias_params) + params = pd.DataFrame(params).rename(columns={'init':'0'}) + # create new iteration from old + params['1'] = params['0'] + #update the parameters by index + + params.loc['c', '1'] = 0.5 + pa = params[ params['model'] == 'A' ] + pb = params[ params['model'] == 'B' ] + + assert pa.drop(['model', 'param'], axis=1).equals( pb.drop(['model', 'param'], axis=1) ) + +# TODO test/document case where params have same name but different min/max/init values