From fde4feecbbd7d06a52579150b655eb210f584273 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5vard=20Berland?= Date: Thu, 19 Dec 2024 15:56:35 +0100 Subject: [PATCH] WIP: Adapt new eclrun-code to work with Everest --- src/ert/config/ert_config.py | 14 ++++++++ .../forward_model_steps.py | 9 +++-- .../forward_models/run_reservoirsimulator.py | 10 ++++-- .../resources/test_run_eclipse_simulator.py | 34 ++++++++++++------- 4 files changed, 48 insertions(+), 19 deletions(-) diff --git a/src/ert/config/ert_config.py b/src/ert/config/ert_config.py index e7663b3d86f..ead115a2fca 100644 --- a/src/ert/config/ert_config.py +++ b/src/ert/config/ert_config.py @@ -797,6 +797,20 @@ def _create_list_of_forward_model_steps_to_run( ) continue fm_step.arglist = fm_step_description[1:] + + fm_step.environment = { + **cls.ENV_PR_FM_STEP.get(fm_step.name.upper(), {}), + **fm_step.environment, + } + + # Special casing for run_reservoirsimulator.py + if fm_step.name == "eclipse100": + fm_step.arglist = ("eclipse", *fm_step.arglist) + if fm_step.name == "eclipse300": + fm_step.arglist = ("eclipse300", *fm_step.arglist) + if fm_step.name == "flow": + fm_step.arglist = ("flow", *fm_step.arglist) + fm_steps.append(fm_step) for fm_step in fm_steps: diff --git a/src/ert/plugins/hook_implementations/forward_model_steps.py b/src/ert/plugins/hook_implementations/forward_model_steps.py index 02f2421d1c0..622e9395669 100644 --- a/src/ert/plugins/hook_implementations/forward_model_steps.py +++ b/src/ert/plugins/hook_implementations/forward_model_steps.py @@ -207,8 +207,9 @@ def __init__(self) -> None: ).resolve() ), "eclipse", - "", "", + "--version", + "", "-n", "", "", @@ -267,8 +268,9 @@ def __init__(self) -> None: ).resolve() ), "e300", - "", "", + "--version", + "", "-n", "", "", @@ -324,8 +326,9 @@ def __init__(self) -> None: ).resolve() ), "flow", - "", "", + "--version", + "", "-n", "", "", diff --git a/src/ert/resources/forward_models/run_reservoirsimulator.py b/src/ert/resources/forward_models/run_reservoirsimulator.py index e920da80a33..dda93dd5df9 100755 --- a/src/ert/resources/forward_models/run_reservoirsimulator.py +++ b/src/ert/resources/forward_models/run_reservoirsimulator.py @@ -195,7 +195,7 @@ def eclrun_command(self) -> list[str]: self.simulator, "--version", str(self.version), - self.data_file, + str(self.run_path / self.data_file), "--summary-conversion", "yes" if self.summary_conversion else "no", ] @@ -211,7 +211,7 @@ def flowrun_command(self) -> list[str]: self.runner_abspath, "--version", str(self.version), - self.data_file, + str(self.run_path / self.data_file), "--np", str(self.num_cpu), ] @@ -377,8 +377,8 @@ def tail_textfile(file_path: Path, num_chars: int) -> str: def run_reservoirsimulator(args: list[str]) -> None: parser = ArgumentParser() parser.add_argument("simulator", type=str, choices=["flow", "eclipse", "e300"]) - parser.add_argument("version", type=str) parser.add_argument("ecl_case", type=str) + parser.add_argument("--version", type=str, default="") parser.add_argument("-n", "--num-cpu", dest="num_cpu", type=int, default=1) parser.add_argument( "-i", "--ignore-errors", dest="ignore_errors", action="store_true" @@ -389,6 +389,10 @@ def run_reservoirsimulator(args: list[str]) -> None: options = parser.parse_args(args) + if not options.version: + raise RuntimeError( + f"The version to {options.simulator} must be explicitly passed" + ) if options.summary_conversion and options.simulator == "flow": raise RuntimeError("--summary-conversion is not available with simulator flow") diff --git a/tests/ert/unit_tests/resources/test_run_eclipse_simulator.py b/tests/ert/unit_tests/resources/test_run_eclipse_simulator.py index a093ca1bb1d..6bd07c7e6e3 100644 --- a/tests/ert/unit_tests/resources/test_run_eclipse_simulator.py +++ b/tests/ert/unit_tests/resources/test_run_eclipse_simulator.py @@ -100,7 +100,9 @@ def test_runeclrun_argparse_api(source_root): source_root / "test-data/ert/eclipse/SPE1.DATA", "SPE1.DATA", ) - run_reservoirsimulator.run_reservoirsimulator(["eclipse", "2019.3", "SPE1.DATA"]) + run_reservoirsimulator.run_reservoirsimulator( + ["eclipse", "SPE1.DATA", "--version", "2019.3"] + ) assert Path("SPE1.OK").exists() @@ -116,7 +118,9 @@ def test_eclrun_when_unsmry_is_ambiguous(source_root): # Mock files from another existing run Path("PREVIOUS_SPE1.SMSPEC").touch() Path("PREVIOUS_SPE1.UNSMRY").touch() - run_reservoirsimulator.run_reservoirsimulator(["eclipse", "2019.3", "SPE1.DATA"]) + run_reservoirsimulator.run_reservoirsimulator( + ["eclipse", "SPE1.DATA", "--version", "2019.3"] + ) assert Path("SPE1.OK").exists() @@ -131,7 +135,7 @@ def test_eclrun_when_unsmry_is_ambiguous_with_mpi(source_root): Path("PREVIOUS_SPE1.SMSPEC").touch() Path("PREVIOUS_SPE1.UNSMRY").touch() run_reservoirsimulator.run_reservoirsimulator( - ["eclipse", "2019.3", "SPE1.DATA", "--num-cpu=2"] + ["eclipse", "SPE1.DATA", "--version", "2019.3", "--num-cpu=2"] ) assert Path("SPE1.OK").exists() @@ -144,7 +148,7 @@ def test_ecl_run_on_parallel_deck(source_root): deck = deck.replace("TITLE", "PARALLEL\n 2 /\n\nTITLE") Path("SPE1.DATA").write_text(deck, encoding="utf-8") run_reservoirsimulator.run_reservoirsimulator( - ["eclipse", "2019.3", "SPE1.DATA", "--num-cpu=2"] + ["eclipse", "SPE1.DATA", "--version", "2019.3", "--num-cpu=2"] ) assert Path("SPE1.OK").exists() @@ -156,7 +160,9 @@ def test_eclrun_on_nosim(source_root): deck = (source_root / "test-data/ert/eclipse/SPE1.DATA").read_text(encoding="utf-8") deck = deck.replace("TITLE", "NOSIM\n\nTITLE") Path("SPE1.DATA").write_text(deck, encoding="utf-8") - run_reservoirsimulator.run_reservoirsimulator(["eclipse", "2019.3", "SPE1.DATA"]) + run_reservoirsimulator.run_reservoirsimulator( + ["eclipse", "SPE1.DATA", "--version", "2019.3"] + ) assert Path("SPE1.OK").exists() assert not Path("SPE1.UNSMRY").exists() @@ -170,7 +176,9 @@ def test_eclrun_on_nosim_with_existing_unsmry_file(source_root): deck = deck.replace("TITLE", "NOSIM\n\nTITLE") Path("SPE1.UNSMRY").write_text("", encoding="utf-8") Path("SPE1.DATA").write_text(deck, encoding="utf-8") - run_reservoirsimulator.run_reservoirsimulator(["eclipse", "2019.3", "SPE1.DATA"]) + run_reservoirsimulator.run_reservoirsimulator( + ["eclipse", "SPE1.DATA", "--version", "2019.3"] + ) assert Path("SPE1.OK").exists() @@ -181,7 +189,7 @@ def test_await_completed_summary_file_does_not_time_out_on_nosim_with_mpi(source deck = deck.replace("TITLE", "NOSIM\n\nPARALLEL\n 2 /\n\nTITLE") Path("SPE1.DATA").write_text(deck, encoding="utf-8") run_reservoirsimulator.run_reservoirsimulator( - ["eclipse", "2019.3", "SPE1.DATA", "--num-cpu=2"] + ["eclipse", "SPE1.DATA", "--version", "2019.3", "--num-cpu=2"] ) assert Path("SPE1.OK").exists() assert not Path( @@ -207,7 +215,7 @@ def test_eclrun_on_nosim_with_mpi_and_existing_unsmry_file(source_root): Path("SPE1.UNSMRY").write_text("", encoding="utf-8") Path("SPE1.DATA").write_text(deck, encoding="utf-8") run_reservoirsimulator.run_reservoirsimulator( - ["eclipse", "2019.3", "SPE1.DATA", "--num-cpu=2"] + ["eclipse", "SPE1.DATA", "--version", "2019.3", "--num-cpu=2"] ) # There is no assert on runtime because we cannot predict how long the Eclipse license # checkout takes, otherwise we should assert that there is no await for unsmry completion. @@ -223,7 +231,7 @@ def test_eclrun_will_raise_on_deck_errors(source_root): "SPE1_ERROR.DATA", ) erun = run_reservoirsimulator.RunReservoirSimulator( - "eclipse", "2019.3", "SPE1_ERROR" + "eclipse", "SPE1_ERROR", "--version", "2019.3" ) with pytest.raises(Exception, match="ERROR"): erun.run_eclipseX00() @@ -236,7 +244,7 @@ def test_failed_run_gives_nonzero_returncode_and_exception(monkeypatch): deck = Path("MOCKED_DECK.DATA") deck.touch() erun = run_reservoirsimulator.RunReservoirSimulator( - "eclipse", "dummy_version", deck.name + "eclipse", deck.name, "--version", "dummy_version" ) return_value_with_code = mock.MagicMock() return_value_with_code.returncode = 1 @@ -260,7 +268,7 @@ def test_deck_errors_can_be_ignored(source_root): "SPE1_ERROR.DATA", ) run_reservoirsimulator.run_reservoirsimulator( - ["eclipse", "2019.3", "SPE1_ERROR.DATA", "--ignore-errors"] + ["eclipse", "SPE1_ERROR.DATA", "--version", "2019.3", "--ignore-errors"] ) @@ -273,7 +281,7 @@ def test_flag_needed_to_produce_hdf5_output_with_ecl100(source_root): "SPE1.DATA", ) run_reservoirsimulator.run_reservoirsimulator( - ["eclipse", "2019.3", "SPE1.DATA", "--summary-conversion"] + ["eclipse", "SPE1.DATA", "--version", "2019.3", "--summary-conversion"] ) assert Path("SPE1.h5").exists() @@ -290,7 +298,7 @@ def test_mpi_run_is_managed_by_system_tool(source_root): r"PARALLEL\s+2", Path("SPE1_PARALLEL.DATA").read_text(encoding="utf-8") ), "Test requires a deck needing 2 CPUs" run_reservoirsimulator.run_reservoirsimulator( - ["eclipse", "2019.3", "SPE1_PARALLEL.DATA"] + ["eclipse", "SPE1_PARALLEL.DATA", "--version", "2019.3"] ) assert Path("SPE1_PARALLEL.PRT").stat().st_size > 0, "Eclipse did not run at all"