From 7d23c4835eed46445c80676d7a4f3f3aa3024fe4 Mon Sep 17 00:00:00 2001 From: Nels Frazier Date: Mon, 9 Sep 2024 15:04:56 -0600 Subject: [PATCH 1/2] feat(ngen): allow for multi-model parameter space to be created, using params as index --- python/ngen_cal/src/ngen/cal/ngen.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/python/ngen_cal/src/ngen/cal/ngen.py b/python/ngen_cal/src/ngen/cal/ngen.py index 9d2cd498..88ba181b 100644 --- a/python/ngen_cal/src/ngen/cal/ngen.py +++ b/python/ngen_cal/src/ngen/cal/ngen.py @@ -46,13 +46,22 @@ 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) + df = pd.concat(dfs) + # Copy the parameter column and use it as the index + # The param -> model relation has to be maintained for writing back + # to specific model components later + df['p'] = df['param'] + return df.set_index('p') 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 + if p: + df['p'] = df['param'] + return df.set_index('p') + else: + return df def _map_params_to_realization(params: Mapping[str, Parameters], realization: Realization): # don't even think about calibration multiple formulations at once just yet.. From e8824de95893cd4ade1e0b19408578efa87b28b6 Mon Sep 17 00:00:00 2001 From: Nels Frazier Date: Mon, 9 Sep 2024 15:08:04 -0600 Subject: [PATCH 2/2] chore(ngen): update note to self on multi-model calibration mechanics --- python/ngen_cal/src/ngen/cal/ngen.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/python/ngen_cal/src/ngen/cal/ngen.py b/python/ngen_cal/src/ngen/cal/ngen.py index 88ba181b..30efba2e 100644 --- a/python/ngen_cal/src/ngen/cal/ngen.py +++ b/python/ngen_cal/src/ngen/cal/ngen.py @@ -64,7 +64,12 @@ def _params_as_df(params: Mapping[str, Parameters], name: str = None): return df def _map_params_to_realization(params: Mapping[str, Parameters], realization: Realization): - # don't even think about calibration multiple formulations at once just yet.. + # Since params are mapped by model name, we can track the model/param relationship + # in the dataframe to reconstruct each models parameters indepndently + # with a unique parameter index build in _params_as_df, this supports multi-model + # parameters with a key distinction -- + # WARNING parameters with the _exact_ same name between two models will be exposed + # as two parameters in the parameter space, but will always share the same value module = realization.formulations[0].params if isinstance(module, MultiBMI):