Skip to content

Commit

Permalink
WIP: add support for multiple occurences of design matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
xjules committed Dec 18, 2024
1 parent 01156bb commit c03d719
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 41 deletions.
6 changes: 2 additions & 4 deletions src/ert/config/analysis_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def from_dict(cls, config_dict: ConfigDict) -> AnalysisConfig:

min_realization = min(min_realization, num_realization)

design_matrix_config_list = config_dict.get(ConfigKeys.DESIGN_MATRIX, None)
design_matrix_config_list = config_dict.get(ConfigKeys.DESIGN_MATRIX, [])

options: dict[str, dict[str, Any]] = {"STD_ENKF": {}, "IES_ENKF": {}}
observation_settings: dict[str, Any] = {
Expand Down Expand Up @@ -194,9 +194,7 @@ def from_dict(cls, config_dict: ConfigDict) -> AnalysisConfig:
observation_settings=obs_settings,
es_module=es_settings,
ies_module=ies_settings,
design_matrix=DesignMatrix.from_config_list(design_matrix_config_list)
if design_matrix_config_list is not None
else None,
design_matrix=DesignMatrix.from_config_list(design_matrix_config_list),
)
return config

Expand Down
79 changes: 42 additions & 37 deletions src/ert/config/design_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,44 +39,49 @@ def __post_init__(self) -> None:
) from exc

@classmethod
def from_config_list(cls, config_list: list[str]) -> DesignMatrix:
filename = Path(config_list[0])
options = option_dict(config_list, 1)
design_sheet = options.get("DESIGN_SHEET")
default_sheet = options.get("DEFAULT_SHEET")
errors = []
if filename.suffix not in {
".xlsx",
".xls",
}:
errors.append(
ErrorInfo(
f"DESIGN_MATRIX must be of format .xls or .xlsx; is '{filename}'"
).set_context(config_list)
)
if design_sheet is None:
errors.append(
ErrorInfo("Missing required DESIGN_SHEET").set_context(config_list)
)
if default_sheet is None:
errors.append(
ErrorInfo("Missing required DEFAULT_SHEET").set_context(config_list)
)
if design_sheet is not None and design_sheet == default_sheet:
errors.append(
ErrorInfo(
"DESIGN_SHEET and DEFAULT_SHEET can not point to the same sheet."
).set_context(config_list)
def from_config_list(cls, config_lists: list[list[str]]) -> list[DesignMatrix]:
design_matrix_list: list[DesignMatrix] = []
for config_list in config_lists:
filename = Path(config_list[0])
options = option_dict(config_list, 1)
design_sheet = options.get("DESIGN_SHEET")
default_sheet = options.get("DEFAULT_SHEET")
errors = []
if filename.suffix not in {
".xlsx",
".xls",
}:
errors.append(
ErrorInfo(
f"DESIGN_MATRIX must be of format .xls or .xlsx; is '{filename}'"
).set_context(config_list)
)
if design_sheet is None:
errors.append(
ErrorInfo("Missing required DESIGN_SHEET").set_context(config_list)
)
if default_sheet is None:
errors.append(
ErrorInfo("Missing required DEFAULT_SHEET").set_context(config_list)
)
if design_sheet is not None and design_sheet == default_sheet:
errors.append(
ErrorInfo(
"DESIGN_SHEET and DEFAULT_SHEET can not point to the same sheet."
).set_context(config_list)
)
if errors:
raise ConfigValidationError.from_collected(errors)
assert design_sheet is not None
assert default_sheet is not None
design_matrix_list.append(
cls(
xls_filename=filename,
design_sheet=design_sheet,
default_sheet=default_sheet,
)
)
if errors:
raise ConfigValidationError.from_collected(errors)
assert design_sheet is not None
assert default_sheet is not None
return cls(
xls_filename=filename,
design_sheet=design_sheet,
default_sheet=default_sheet,
)
return design_matrix_list

def merge_with_existing_parameters(
self, existing_parameters: list[ParameterConfig]
Expand Down

0 comments on commit c03d719

Please sign in to comment.