From 7b5264cd04f07d56f514496c7b91abd09d5bde9a Mon Sep 17 00:00:00 2001 From: DanSava Date: Mon, 9 Sep 2024 12:23:29 +0300 Subject: [PATCH] Generate Ert manifest file using ensemble Experiment content --- src/ert/config/ert_config.py | 26 +++++++++ tests/unit_tests/config/test_ert_config.py | 62 ++++++++++++++++++++++ 2 files changed, 88 insertions(+) diff --git a/src/ert/config/ert_config.py b/src/ert/config/ert_config.py index a294ba5ce9f..7127e2eb064 100644 --- a/src/ert/config/ert_config.py +++ b/src/ert/config/ert_config.py @@ -63,6 +63,7 @@ parse, ) from .queue_config import QueueConfig +from .summary_config import SummaryConfig from .workflow import Workflow from .workflow_job import ErtScriptLoadFailure, WorkflowJob @@ -272,6 +273,31 @@ def from_dict(cls, config_dict) -> Self: for key, val in config_dict.get("SETENV", []): env_vars[key] = val + forward_model_steps = cls._create_list_of_forward_model_steps_to_run( + installed_forward_model_steps, + substitution_list, + config_dict, + ) + + simulation_step_exists = False + for step in forward_model_steps: + for name in ["eclipse", "flow"]: + if name in step.name.lower(): + simulation_step_exists = True + break + if simulation_step_exists: + break + + has_summary_config = any( + isinstance(config, SummaryConfig) + for config in ensemble_config.response_configuration + ) + + if has_summary_config and not simulation_step_exists: + ConfigWarning.warn( + "Config contians a SUMMARY key but no simulation job known to generate a summary file detected in the forward model" + ) + return cls( substitution_list=substitution_list, ensemble_config=ensemble_config, diff --git a/tests/unit_tests/config/test_ert_config.py b/tests/unit_tests/config/test_ert_config.py index a2215f45f38..9561dffa1e7 100644 --- a/tests/unit_tests/config/test_ert_config.py +++ b/tests/unit_tests/config/test_ert_config.py @@ -1644,3 +1644,65 @@ def test_that_empty_params_file_gives_reasonable_error(tmpdir, param_config): with pytest.raises(ConfigValidationError, match="No parameters specified in"): ErtConfig.from_file("config.ert") + + +@pytest.mark.usefixtures("use_tmpdir") +def test_warning_raised_when_summary_key_and_no_simulation_job_present(caplog, recwarn): + caplog.set_level(logging.WARNING) + + with open("job_file", "w", encoding="utf-8") as fout: + fout.write("EXECUTABLE echo\nARGLIST \n") + + with open("config_file.ert", "w", encoding="utf-8") as fout: + # Write a minimal config file + fout.write("NUM_REALIZATIONS 1\n") + fout.write("SUMMARY *\n") + fout.write("ECLBASE RESULT_SUMMARY\n") + + fout.write("INSTALL_JOB job_name job_file\n") + fout.write( + "FORWARD_MODEL job_name(=A/, =/x)\n" + ) + + ErtConfig.from_file("config_file.ert") + + # Check no warning is logged when config contains + # forward model step with and as arguments + assert not caplog.text + assert len(recwarn) == 1 + assert issubclass(recwarn[0].category, ConfigWarning) + assert ( + recwarn[0].message.info.message + == "Config contians a SUMMARY key but no simulation job known to generate a summary file detected in the forward model" + ) + + +@pytest.mark.parametrize( + "job_name", ["eclipse", "eclipse100", "flow", "FLOW", "ECLIPSE100"] +) +@pytest.mark.usefixtures("use_tmpdir") +def test_no_warning_when_summary_key_and_simulation_job_present( + caplog, recwarn, job_name +): + caplog.set_level(logging.WARNING) + + with open("job_file", "w", encoding="utf-8") as fout: + fout.write("EXECUTABLE echo\nARGLIST \n") + + with open("config_file.ert", "w", encoding="utf-8") as fout: + # Write a minimal config file + fout.write("NUM_REALIZATIONS 1\n") + fout.write("SUMMARY *\n") + fout.write("ECLBASE RESULT_SUMMARY\n") + + fout.write(f"INSTALL_JOB {job_name} job_file\n") + fout.write( + f"FORWARD_MODEL {job_name}(=A/, =/x)\n" + ) + + ErtConfig.from_file("config_file.ert") + + # Check no warning is logged when config contains + # forward model step with and as arguments + assert not caplog.text + assert len(recwarn) == 0