Skip to content

Commit

Permalink
Raise warning when summary key and no simulator job present in ert co…
Browse files Browse the repository at this point in the history
…nfig
  • Loading branch information
DanSava committed Sep 20, 2024
1 parent ce4149b commit d3f000a
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 2 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
4 changes: 2 additions & 2 deletions test-data/snake_oil_field/snake_oil_surface.ert
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ REFCASE refcase/SNAKE_OIL_FIELD
TIME_MAP refcase/time_map.txt
OBS_CONFIG observations/observations.txt

INSTALL_JOB SNAKE_OIL_SIMULATOR jobs/SNAKE_OIL_SIMULATOR
INSTALL_JOB SNAKE_OIL_ECLIPSE_SIMULATOR jobs/SNAKE_OIL_SIMULATOR
INSTALL_JOB SNAKE_OIL_NPV jobs/SNAKE_OIL_NPV
INSTALL_JOB SNAKE_OIL_DIFF jobs/SNAKE_OIL_DIFF

FORWARD_MODEL SNAKE_OIL_SIMULATOR
FORWARD_MODEL SNAKE_OIL_ECLIPSE_SIMULATOR
FORWARD_MODEL SNAKE_OIL_NPV
FORWARD_MODEL SNAKE_OIL_DIFF

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 @@ -1743,3 +1743,65 @@ def test_general_option_in_local_config_has_priority_over_site_config(
assert config.queue_config.max_running == 13
assert config.queue_config.submit_sleep == 14
assert config.queue_config.queue_system == QueueSystem.TORQUE


@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 d3f000a

Please sign in to comment.