From 4b8c54725b10d2e5cecad56bfbb841f7026d3265 Mon Sep 17 00:00:00 2001 From: "Yngve S. Kristiansen" Date: Tue, 3 Sep 2024 10:22:31 +0200 Subject: [PATCH] Move manifest logic to response configs --- src/ert/config/gen_data_config.py | 12 ++++++++++++ src/ert/config/response_config.py | 5 +++++ src/ert/config/summary_config.py | 5 +++++ src/ert/enkf_main.py | 18 ++++-------------- 4 files changed, 26 insertions(+), 14 deletions(-) diff --git a/src/ert/config/gen_data_config.py b/src/ert/config/gen_data_config.py index 8a579527dfc..98b4d576b53 100644 --- a/src/ert/config/gen_data_config.py +++ b/src/ert/config/gen_data_config.py @@ -31,6 +31,18 @@ def __post_init__(self) -> None: if report_steps is not None: report_steps.sort() + @property + def expected_input_files(self) -> List[str]: + expected_files = [] + for input_file, report_steps in zip(self.input_files, self.report_steps_list): + if report_steps is None: + expected_files.append(input_file) + else: + for report_step in report_steps: + expected_files.append(input_file.replace("%d", str(report_step))) + + return expected_files + @classmethod def from_config_dict(cls, config_dict: ConfigDict) -> Optional[Self]: gen_data_list = config_dict.get("GEN_DATA", []) # type: ignore diff --git a/src/ert/config/response_config.py b/src/ert/config/response_config.py index 8d23b4dea1a..d40f899ed87 100644 --- a/src/ert/config/response_config.py +++ b/src/ert/config/response_config.py @@ -23,6 +23,11 @@ def to_dict(self) -> Dict[str, Any]: data["_ert_kind"] = self.__class__.__name__ return data + @property + @abstractmethod + def expected_input_files(self) -> List[str]: + """Returns a list of filenames expected to be produced by the forward model""" + @property @abstractmethod def response_type(self) -> str: diff --git a/src/ert/config/summary_config.py b/src/ert/config/summary_config.py index c0e507de208..49d1b46a302 100644 --- a/src/ert/config/summary_config.py +++ b/src/ert/config/summary_config.py @@ -32,6 +32,11 @@ def __post_init__(self) -> None: if len(self.keys) < 1: raise ValueError("SummaryConfig must be given at least one key") + @property + def expected_input_files(self) -> List[str]: + base = self.input_files[0] + return [f"{base}.UNSMRY", f"{base}.SMSPEC"] + def read_from_file(self, run_path: str, iens: int) -> xr.Dataset: filename = self.input_files[0].replace("", str(iens)) _, keys, time_map, data = read_summary(f"{run_path}/{filename}", self.keys) diff --git a/src/ert/enkf_main.py b/src/ert/enkf_main.py index 536af0bfafc..b139c294146 100644 --- a/src/ert/enkf_main.py +++ b/src/ert/enkf_main.py @@ -14,10 +14,8 @@ from .config import ( ExtParamConfig, Field, - GenDataConfig, GenKwConfig, ParameterConfig, - SummaryConfig, SurfaceConfig, ) from .run_arg import RunArg @@ -128,18 +126,10 @@ def _manifest_to_json(ensemble: Ensemble, iens: int = 0) -> Dict[str, Any]: elif param_config.output_file is not None and not param_config.forward_init: manifest[param_config.name] = str(param_config.output_file) # Add expected response files to manifest - for name, respons_config in ensemble.experiment.response_configuration.items(): - if isinstance(respons_config, SummaryConfig): - input_file = respons_config.input_file.replace("", str(iens)) - manifest[f"{name}_UNSMRY"] = f"{input_file}.UNSMRY" - manifest[f"{name}_SMSPEC"] = f"{input_file}.SMSPEC" - if isinstance(respons_config, GenDataConfig): - input_file = respons_config.input_file - if respons_config.report_steps: - for step in respons_config.report_steps: - manifest[f"{name}_{step}"] = input_file.replace("%d", str(step)) - elif "%d" not in input_file: - manifest[name] = input_file + for respons_config in ensemble.experiment.response_configuration.values(): + for input_file in respons_config.expected_input_files: + manifest[f"{respons_config.response_type}_{input_file}"] = input_file + return manifest