Skip to content

Commit

Permalink
Avoid forward model crash after MPI NOSIM E100 run
Browse files Browse the repository at this point in the history
This fixes a regression from 2453a2c.
  • Loading branch information
berland committed Nov 21, 2024
1 parent b5f9caa commit e764083
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/ert/resources/forward_models/res/script/ecl_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from contextlib import contextmanager
from pathlib import Path
from random import random
from typing import List
from typing import List, Optional

import resfo
from ecl_config import EclConfig, EclrunConfig, Simulator
Expand Down Expand Up @@ -157,7 +157,7 @@ def pushd(run_path):
os.chdir(starting_directory)


def find_unsmry(basepath: Path) -> Path:
def find_unsmry(basepath: Path) -> Optional[Path]:
def _is_unsmry(base: str, path: str) -> bool:
if "." not in path:
return False
Expand All @@ -173,7 +173,7 @@ def _is_unsmry(base: str, path: str) -> bool:
filter(lambda x: _is_unsmry(base, x), os.listdir(dir or "."))
)
if not candidates:
raise ValueError(f"Could not find any unsmry matching case path {basepath}")
return None
if len(candidates) > 1:
raise ValueError(
f"Ambiguous reference to unsmry in {basepath}, could be any of {candidates}"
Expand Down
47 changes: 47 additions & 0 deletions tests/ert/unit_tests/resources/test_ecl_run_new_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,53 @@ def test_forward_model_cmd_line_api_works(source_root):
assert Path("SPE1.OK").exists()


@pytest.mark.integration_test
@pytest.mark.requires_eclipse
@pytest.mark.usefixtures("use_tmpdir", "init_eclrun_config")
def test_ecl_run_on_parallel_deck(source_root):
deck = (source_root / "test-data/ert/eclipse/SPE1.DATA").read_text(encoding="utf-8")
deck = deck.replace("TITLE", "PARALLEL\n 2 /\n\nTITLE")
Path("SPE1.DATA").write_text(deck, encoding="utf-8")
ecl_run.run(
ecl_config.Ecl100Config(), ["SPE1.DATA", "--version=2019.3", "--num-cpu=2"]
)
assert Path("SPE1.OK").exists()


@pytest.mark.integration_test
@pytest.mark.requires_eclipse
@pytest.mark.usefixtures("use_tmpdir", "init_eclrun_config")
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")
ecl_run.run(ecl_config.Ecl100Config(), ["SPE1.DATA", "--version=2019.3"])
assert Path("SPE1.OK").exists()
assert not Path("SPE1.UNSMRY").exists()


@pytest.mark.integration_test
@pytest.mark.requires_eclipse
@pytest.mark.usefixtures("use_tmpdir", "init_eclrun_config")
def test_await_completed_summary_file_times_out_on_nosim_with_mpi(source_root):
minimum_duration = 15 # This is max_wait in the await function tested
deck = (source_root / "test-data/ert/eclipse/SPE1.DATA").read_text(encoding="utf-8")
deck = deck.replace("TITLE", "NOSIM\n\nPARALLEL\n 2 /\n\nTITLE")
Path("SPE1.DATA").write_text(deck, encoding="utf-8")
start_time = time.time()
ecl_run.run(
ecl_config.Ecl100Config(), ["SPE1.DATA", "--version=2019.3", "--num-cpu=2"]
)
end_time = time.time()
assert Path("SPE1.OK").exists()
assert not Path(
"SPE1.UNSMRY"
).exists(), "A nosim run should not produce an unsmry file"
assert (
end_time - start_time > minimum_duration
), "timeout in await_completed not triggered"


@pytest.mark.integration_test
@pytest.mark.requires_eclipse
@pytest.mark.usefixtures("use_tmpdir", "init_eclrun_config")
Expand Down

0 comments on commit e764083

Please sign in to comment.