Skip to content

Commit

Permalink
Adapt new eclrun-code to work with Everest
Browse files Browse the repository at this point in the history
Remove --enable-tuning, we don't allow arbitrary arguments yet to flow FM

Print stderr from everest run

Allow defaulting version for flow

typing and actionlinting
  • Loading branch information
berland committed Dec 20, 2024
1 parent 6b8e360 commit 8a627e1
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 57 deletions.
28 changes: 23 additions & 5 deletions .github/workflows/test_ert_with_flow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ jobs:
- name: Install uv
uses: astral-sh/setup-uv@v4

- name: Install ert
run:
uv pip install ".[dev]"
- name: Install ert and everest
run: |
uv pip install ".[everest,dev]"
uv pip install git+https://github.com/equinor/everest-models
- name: Install flow
run: |
Expand All @@ -47,6 +48,23 @@ jobs:
set -e
pytest tests/ert/unit_tests/resources/test_run_flow_simulator.py
cd test-data/ert/flow_example
- name: Run Ert on an example configuration with flow
run: |
pushd test-data/ert/flow_example
perl -p -i -e 's/NUM_REALIZATIONS\s*12/NUM_REALIZATIONS 2/g' flow.ert
ert ensemble_experiment flow.ert --disable-monitor
ert ensemble_experiment flow.ert
popd
- name: Run Everest on an example configuration with flow
run: |
set -e
pushd test-data/everest/egg/everest/model
everest lint config_flow.yml
everest run config_flow.yml || (
find .
find . -name "ERROR"
find . -name "ERROR" -exec cat {} \;
find . -name "./*stderr*"
find . -name "./*stderr*" -exec cat {} \;
)
popd
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
4 changes: 2 additions & 2 deletions src/ert/gui/tools/plot/plottery/plots/histogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ def plotHistogram(
else:
current_min = data[ensemble.name].min()
current_max = data[ensemble.name].max()
minimum = current_min if minimum is None else min(minimum, current_min) # type: ignore
maximum = current_max if maximum is None else max(maximum, current_max) # type: ignore
minimum = current_min if minimum is None else min(minimum, current_min)
maximum = current_max if maximum is None else max(maximum, current_max)
max_element_count = max(max_element_count, len(data[ensemble.name].index))

bin_count = ceil(sqrt(max_element_count))
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
12 changes: 8 additions & 4 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 @@ -205,13 +205,13 @@ def flowrun_command(self) -> list[str]:
if self.bypass_flowrun:
return [
self.runner_abspath,
self.data_file,
str(self.run_path / self.data_file),
]
return [
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 options.simulator != "flow" and 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
7 changes: 1 addition & 6 deletions test-data/everest/egg/everest/model/config_flow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,6 @@ simulator:
queue_system: local
cores: 3

install_jobs:
-
name: myflow
source: r{{ configpath }}/jobs/flow

install_data:
-
source: r{{ configpath }}/../../eclipse/include/realizations/realization-r{{ realization }}/eclipse
Expand All @@ -116,5 +111,5 @@ forward_model:
- well_constraints -i files/well_readydate.json -c files/wc_config.yml -rc well_rate.json -o wc_wells.json
- add_templates -i wc_wells.json -c files/at_config.yml -o at_wells.json
- schmerge -s eclipse/include/schedule/schedule.tmpl -i at_wells.json -o eclipse/include/schedule/schedule.sch
- myflow r{{ eclbase }} --enable-tuning
- flow r{{ eclbase }}
- rf -s r{{ eclbase }} -o rf
6 changes: 0 additions & 6 deletions test-data/everest/egg/everest/model/jobs/flow

This file was deleted.

18 changes: 0 additions & 18 deletions test-data/everest/egg/everest/model/jobs/flow.py

This file was deleted.

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 8a627e1

Please sign in to comment.