Skip to content

Commit

Permalink
Move manifest logic to response configs
Browse files Browse the repository at this point in the history
  • Loading branch information
Yngve S. Kristiansen committed Sep 9, 2024
1 parent b914b77 commit 4b8c547
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 14 deletions.
12 changes: 12 additions & 0 deletions src/ert/config/gen_data_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions src/ert/config/response_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 5 additions & 0 deletions src/ert/config/summary_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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("<IENS>", str(iens))
_, keys, time_map, data = read_summary(f"{run_path}/{filename}", self.keys)
Expand Down
18 changes: 4 additions & 14 deletions src/ert/enkf_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@
from .config import (
ExtParamConfig,
Field,
GenDataConfig,
GenKwConfig,
ParameterConfig,
SummaryConfig,
SurfaceConfig,
)
from .run_arg import RunArg
Expand Down Expand Up @@ -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("<IENS>", 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


Expand Down

0 comments on commit 4b8c547

Please sign in to comment.