Skip to content

Commit

Permalink
Write eclbase to runpath_list if present
Browse files Browse the repository at this point in the history
  • Loading branch information
eivindjahren committed Aug 20, 2024
1 parent 02f996b commit b00cf8e
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/ert/libres_facade.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ def load_from_forward_model(
runpath_format=self.config.model_config.runpath_format_string,
filename=str(self.config.runpath_file),
substitution_list=self.config.substitution_list,
eclbase=self.config.ensemble_config.eclbase,
),
realisations,
ensemble=ensemble,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def run(self, ert_config: ErtConfig, workflow_args: List[Any]) -> None:
runpath_format=ert_config.model_config.runpath_format_string,
filename=str(ert_config.runpath_file),
substitution_list=ert_config.substitution_list,
eclbase=ert_config.ensemble_config.eclbase,
)
run_paths.write_runpath_list(
*self.get_ranges(
Expand Down
1 change: 1 addition & 0 deletions src/ert/run_models/base_run_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ def __init__(
runpath_format=config.model_config.runpath_format_string,
filename=str(config.runpath_file),
substitution_list=self.substitution_list,
eclbase=config.ensemble_config.eclbase,
)
self._iter_snapshot: Dict[int, Snapshot] = {}
self._status_queue = status_queue
Expand Down
13 changes: 11 additions & 2 deletions src/ert/runpaths.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ def __init__(
runpath_format: str,
filename: Union[str, Path] = ".ert_runpath_list",
substitution_list: Optional[SubstitutionList] = None,
eclbase: Optional[str] = None,
):
self._jobname_format = jobname_format
self.runpath_list_filename = Path(filename)
self._runpath_format = str(Path(runpath_format).resolve())
self._substitution_list = substitution_list or SubstitutionList()
self._eclbase = eclbase

def set_ert_ensemble(self, ensemble_name: str) -> None:
self._substitution_list["<ERT-CASE>"] = ensemble_name
Expand Down Expand Up @@ -88,12 +90,19 @@ def write_runpath_list(
with open(self.runpath_list_filename, "w", encoding="utf-8") as filehandle:
for iteration in iteration_numbers:
for realization in realization_numbers:
job_name = self._substitution_list.substitute_real_iter(
job_name_or_eclbase = self._substitution_list.substitute_real_iter(
self._jobname_format, realization, iteration
)
runpath = self._substitution_list.substitute_real_iter(
self._runpath_format, realization, iteration
)
if self._eclbase is not None:
job_name_or_eclbase = (
self._substitution_list.substitute_real_iter(
self._eclbase, realization, iteration
)
)

filehandle.write(
f"{realization:03d} {runpath} {job_name} {iteration:03d}\n"
f"{realization:03d} {runpath} {job_name_or_eclbase} {iteration:03d}\n"
)
1 change: 1 addition & 0 deletions src/ert/simulator/batch_simulator_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ def __post_init__(self) -> None:
runpath_format=ert_config.model_config.runpath_format_string,
filename=str(ert_config.runpath_file),
substitution_list=global_substitutions,
eclbase=ert_config.ensemble_config.eclbase,
)
self.run_args = create_run_arguments(
run_paths,
Expand Down
27 changes: 18 additions & 9 deletions tests/unit_tests/test_runpaths.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,22 @@ def test_runpath_file_writer_substitution(tmp_path):
)


def render_dynamic_values(s, itr, iens, geo_id):
dynamic_magic_strings = {
"<GEO_ID>": geo_id,
"<ITER>": itr,
"<IENS>": iens,
}
for key, val in dynamic_magic_strings.items():
s = s.replace(key, str(val))
def test_runpath_file_writes_eclbase_when_present(tmp_path):
runpath_file = tmp_path / "runpath_file"

return s
context = SubstitutionList()
context["<casename>"] = "my_case"
runpaths = Runpaths(
"<casename>_job",
"/path/<casename>/ensemble-<IENS>/iteration<ITER>",
runpath_file,
context,
"path/to/eclbase",
)

runpaths.write_runpath_list([1], [1])

assert (
runpath_file.read_text()
== "001 /path/my_case/ensemble-1/iteration1 path/to/eclbase 001\n"
)

0 comments on commit b00cf8e

Please sign in to comment.