From e7640838cac5784f9d40fefcd3d8caa74c9b5548 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5vard=20Berland?= Date: Thu, 21 Nov 2024 09:38:47 +0100 Subject: [PATCH] Avoid forward model crash after MPI NOSIM E100 run This fixes a regression from 2453a2c. --- .../forward_models/res/script/ecl_run.py | 6 +-- .../resources/test_ecl_run_new_config.py | 47 +++++++++++++++++++ 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/src/ert/resources/forward_models/res/script/ecl_run.py b/src/ert/resources/forward_models/res/script/ecl_run.py index 92e34f7c477..a5313fba2d9 100644 --- a/src/ert/resources/forward_models/res/script/ecl_run.py +++ b/src/ert/resources/forward_models/res/script/ecl_run.py @@ -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 @@ -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 @@ -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}" diff --git a/tests/ert/unit_tests/resources/test_ecl_run_new_config.py b/tests/ert/unit_tests/resources/test_ecl_run_new_config.py index cf068d098d4..7322d82c060 100644 --- a/tests/ert/unit_tests/resources/test_ecl_run_new_config.py +++ b/tests/ert/unit_tests/resources/test_ecl_run_new_config.py @@ -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")