Skip to content

Commit

Permalink
test: alias permutation mechanics
Browse files Browse the repository at this point in the history
  • Loading branch information
hellkite500 committed Aug 28, 2024
1 parent ebd1b6e commit ba07a38
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
10 changes: 10 additions & 0 deletions python/ngen_cal/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
18 changes: 18 additions & 0 deletions python/ngen_cal/tests/test_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit ba07a38

Please sign in to comment.