Skip to content

Commit

Permalink
Generate Ert manifest file using ensemble Experiment content
Browse files Browse the repository at this point in the history
  • Loading branch information
DanSava committed Sep 9, 2024
1 parent ee02327 commit 7b5264c
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/ert/config/ert_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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,
Expand Down
62 changes: 62 additions & 0 deletions tests/unit_tests/config/test_ert_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <ECLBASE> <RUNPATH>\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(<ECLBASE>=A/<ECLBASE>, <RUNPATH>=<RUNPATH>/x)\n"
)

ErtConfig.from_file("config_file.ert")

# Check no warning is logged when config contains
# forward model step with <ECLBASE> and <RUNPATH> 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 <ECLBASE> <RUNPATH>\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}(<ECLBASE>=A/<ECLBASE>, <RUNPATH>=<RUNPATH>/x)\n"
)

ErtConfig.from_file("config_file.ert")

# Check no warning is logged when config contains
# forward model step with <ECLBASE> and <RUNPATH> as arguments
assert not caplog.text
assert len(recwarn) == 0

0 comments on commit 7b5264c

Please sign in to comment.