Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shared param test #180

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions python/ngen_cal/src/ngen/cal/ngen.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ def _params_as_df(params: Mapping[str, Parameters], name: str = None):
df['model'] = k
df.rename(columns={'name':'param'}, inplace=True)
dfs.append(df)
return pd.concat(dfs)
return pd.concat(dfs).set_index('param')
else:
p = params.get(name, [])
df = pd.DataFrame([s.__dict__ for s in p])
df['model'] = name
df.rename(columns={'name':'param'}, inplace=True)
return df
return df.set_index('param')
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh. It is actually possible for this dataframe to be empty if called from _map_params_to_realization and there is a module in the realization which doesn't have any params from the config to map to it, in this case, the set_index here will fail

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I think this breaks search, since param is no longer a column when subset to update_config

search.py", line 168, in dds_set


def _map_params_to_realization(params: Mapping[str, Parameters], realization: Realization):
# don't even think about calibration multiple formulations at once just yet..
Expand Down
4 changes: 2 additions & 2 deletions python/ngen_cal/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def explicit_catchments(nexus, fabric, workdir) -> Generator[ List[ CalibrationC
def multi_model_shared_params() -> Mapping[str, list[Parameter]]:
p1 = Parameter(name='a', min=0, max=1, init=0)
p2 = Parameter(name='a', min=0, max=1, init=0)

params = {'A':[p1], 'B':[p2]}
p3 = Parameter(name='c', min=0, max=1, init=0)
params = {'A':[p1], 'B':[p2], 'C':[p3]}

return params
8 changes: 4 additions & 4 deletions python/ngen_cal/tests/test_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ def test_multi_params(multi_model_shared_params: Mapping[str, list[Parameter]]):
# create new iteration from old
params['1'] = params['0']
#update the parameters by index
params.loc[0, '1'] = 0.5
params.loc['a', '1'] = 0.5
pa = params[ params['model'] == 'A' ]
pb = params[ params['model'] == 'B' ]

pc = params[ params['model'] == 'C' ]
assert pa.drop('model', axis=1).equals( pb.drop('model', axis=1) )

# TODO test/document case where params have same name but different min/max/init values
# ensure unique params/alias are not modifed by selection
assert pa.loc['a', '1'] != pc.loc['c', '1']