Skip to content

Commit

Permalink
Make design_matrix parameter_configuration a single GenKw element
Browse files Browse the repository at this point in the history
The dictionary introduced in parameter configuration in design matrix config seems to be not necessary
and thus removing it.
  • Loading branch information
xjules committed Jan 22, 2025
1 parent 2839ae7 commit 3442885
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
11 changes: 5 additions & 6 deletions src/ert/config/design_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ def merge_with_other(self, dm_other: DesignMatrix) -> None:
except ValueError as exc:
errors.append(ErrorInfo(f"Error when merging design matrices {exc}!"))

pc_other = dm_other.parameter_configuration[DESIGN_MATRIX_GROUP]
pc_self = self.parameter_configuration[DESIGN_MATRIX_GROUP]
pc_other = dm_other.parameter_configuration
pc_self = self.parameter_configuration
assert isinstance(pc_other, GenKwConfig)
assert isinstance(pc_self, GenKwConfig)
for tfd in pc_other.transform_function_definitions:
Expand Down Expand Up @@ -131,7 +131,7 @@ def merge_with_existing_parameters(

new_param_config: list[ParameterConfig] = []

design_parameter_group = self.parameter_configuration[DESIGN_MATRIX_GROUP]
design_parameter_group = self.parameter_configuration
design_keys = []
if isinstance(design_parameter_group, GenKwConfig):
design_keys = [e.name for e in design_parameter_group.transform_functions]
Expand Down Expand Up @@ -163,7 +163,7 @@ def merge_with_existing_parameters(

def read_design_matrix(
self,
) -> tuple[list[bool], pd.DataFrame, dict[str, ParameterConfig]]:
) -> tuple[list[bool], pd.DataFrame, ParameterConfig]:
# Read the parameter names (first row) as strings to prevent pandas from modifying them.
# This ensures that duplicate or empty column names are preserved exactly as they appear in the Excel sheet.
# By doing this, we can properly validate variable names, including detecting duplicates or missing names.
Expand Down Expand Up @@ -204,7 +204,6 @@ def read_design_matrix(
)
design_matrix_df = design_matrix_df.assign(**defaults_to_use)

parameter_configuration: dict[str, ParameterConfig] = {}
transform_function_definitions: list[TransformFunctionDefinition] = []
for parameter in design_matrix_df.columns:
transform_function_definitions.append(
Expand All @@ -214,7 +213,7 @@ def read_design_matrix(
values=[],
)
)
parameter_configuration[DESIGN_MATRIX_GROUP] = GenKwConfig(
parameter_configuration = GenKwConfig(
name=DESIGN_MATRIX_GROUP,
forward_init=False,
template_file=None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def test_merge_multiple_occurrences(
design_matrix_1.merge_with_other(design_matrix_2)
else:
design_matrix_1.merge_with_other(design_matrix_2)
design_params = design_matrix_1.parameter_configuration.get("DESIGN_MATRIX", [])
design_params = design_matrix_1.parameter_configuration
assert all(param in design_params for param in ("a", "b", "c", "d"))
assert design_matrix_1.active_realizations == [True, True, True]
df = design_matrix_1.design_matrix_df
Expand Down Expand Up @@ -181,7 +181,7 @@ def test_reading_design_matrix(tmp_path):
xl_write, index=False, sheet_name="DefaultValues", header=False
)
design_matrix = DesignMatrix(design_path, "DesignSheet01", "DefaultValues")
design_params = design_matrix.parameter_configuration.get(DESIGN_MATRIX_GROUP, [])
design_params = design_matrix.parameter_configuration
assert all(param in design_params for param in ("a", "b", "c", "one", "d"))
assert design_matrix.active_realizations == [True, True, False, False, True]

Expand Down
2 changes: 1 addition & 1 deletion tests/ert/unit_tests/test_libres_facade.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ def test_save_parameters_to_storage_from_design_dataframe(
design_matrix = DesignMatrix(design_path, "DesignSheet01", "DefaultValues")
with open_storage(tmp_path / "storage", mode="w") as storage:
experiment_id = storage.create_experiment(
parameters=[design_matrix.parameter_configuration[DESIGN_MATRIX_GROUP]]
parameters=[design_matrix.parameter_configuration]
)
ensemble = storage.create_ensemble(
experiment_id, name="default", ensemble_size=ensemble_size
Expand Down

0 comments on commit 3442885

Please sign in to comment.