Skip to content

Commit

Permalink
WIP: Adapt new eclrun-code to work with Everest
Browse files Browse the repository at this point in the history
  • Loading branch information
berland committed Dec 19, 2024
1 parent 87124b2 commit fde4fee
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 19 deletions.
14 changes: 14 additions & 0 deletions src/ert/config/ert_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 6 additions & 3 deletions src/ert/plugins/hook_implementations/forward_model_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,9 @@ def __init__(self) -> None:
).resolve()
),
"eclipse",
"<VERSION>",
"<ECLBASE>",
"--version",
"<VERSION>",
"-n",
"<NUM_CPU>",
"<OPTS>",
Expand Down Expand Up @@ -267,8 +268,9 @@ def __init__(self) -> None:
).resolve()
),
"e300",
"<VERSION>",
"<ECLBASE>",
"--version",
"<VERSION>",
"-n",
"<NUM_CPU>",
"<OPTS>",
Expand Down Expand Up @@ -324,8 +326,9 @@ def __init__(self) -> None:
).resolve()
),
"flow",
"<VERSION>",
"<ECLBASE>",
"--version",
"<VERSION>",
"-n",
"<NUM_CPU>",
"<OPTS>",
Expand Down
10 changes: 7 additions & 3 deletions src/ert/resources/forward_models/run_reservoirsimulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
Expand All @@ -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),
]
Expand Down Expand Up @@ -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"
Expand All @@ -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")

Expand Down
34 changes: 21 additions & 13 deletions tests/ert/unit_tests/resources/test_run_eclipse_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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()


Expand All @@ -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()

Expand All @@ -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()

Expand All @@ -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()

Expand All @@ -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()


Expand All @@ -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(
Expand All @@ -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.
Expand All @@ -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()
Expand All @@ -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
Expand All @@ -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"]
)


Expand All @@ -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()

Expand All @@ -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"
Expand Down

0 comments on commit fde4fee

Please sign in to comment.