Skip to content

Commit

Permalink
Remove SIMULATION_JOB keyword
Browse files Browse the repository at this point in the history
  • Loading branch information
DanSava committed Dec 20, 2024
1 parent 2e9c71a commit 177cbb0
Show file tree
Hide file tree
Showing 15 changed files with 73 additions and 192 deletions.
4 changes: 0 additions & 4 deletions docs/ert/reference/configuration/forward_model.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ To add a job to the forward model, use the :code:`FORWARD_MODEL` keyword.
Each :code:`FORWARD_MODEL` keyword instructs ERT to run a specific executable.
You can build a series of jobs by listing multiple :code:`FORWARD_MODEL` keywords.

An alternative to :code:`FORWARD_MODEL` is the :code:`SIMULATION_JOB` keyword,
which can also configure the forward model.
The difference lies in how these keywords pass command-line arguments to the final executable.

You can find all pre-configured jobs to define your forward models :ref:`here <Pre-configured jobs>`.
These jobs form the building blocks for your custom forward models in ERT.

Expand Down
10 changes: 0 additions & 10 deletions docs/ert/reference/configuration/keywords.rst
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ Keyword name Required
:ref:`RUNPATH_FILE <runpath_file>` NO .ert_runpath_list Name of file with path for all forward models that ERT has run. To be used by user defined scripts to find the realizations
:ref:`RUN_TEMPLATE <run_template>` NO Install arbitrary files in the runpath directory
:ref:`SETENV <setenv>` NO You can modify the UNIX environment with SETENV calls
:ref:`SIMULATION_JOB <simulation_job>` NO Lightweight alternative FORWARD_MODEL
:ref:`STOP_LONG_RUNNING <stop_long_running>` NO FALSE Stop long running realizations after minimum number of realizations (MIN_REALIZATIONS) have run
:ref:`SUBMIT_SLEEP <submit_sleep>` NO 0.0 Determines for how long the system will sleep between submitting jobs.
:ref:`SUMMARY <summary>` NO Add summary variables for internalization
Expand Down Expand Up @@ -1759,15 +1758,6 @@ FORWARD_MODEL

In available jobs in ERT you can see a list of the jobs which are available.

SIMULATION_JOB
--------------
.. _simulation_job:

``SIMULATION_JOB`` is a lightweight version of ``FORWARD_MODEL`` that allows passing
raw command line arguments to executable.
It is heavily used in Everest as the Everest configuration transpiles all jobs
into ``SIMULATION_JOB``.

JOB_SCRIPT
----------
.. _job_script:
Expand Down
23 changes: 6 additions & 17 deletions src/ert/config/ert_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -760,8 +760,12 @@ def _create_list_of_forward_model_steps_to_run(
)
continue
fm_step.private_args = Substitutions()
for key, val in args:
fm_step.private_args[key] = val
for arg in args:
match arg:
case key, val:
fm_step.private_args[key] = val
case val:
fm_step.arglist.append(val)

should_add_step = True

Expand All @@ -779,21 +783,6 @@ def _create_list_of_forward_model_steps_to_run(
if should_add_step:
fm_steps.append(fm_step)

for fm_step_description in config_dict.get(ConfigKeys.SIMULATION_JOB, []):
try:
fm_step = copy.deepcopy(installed_steps[fm_step_description[0]])
except KeyError:
errors.append(
ConfigValidationError.with_context(
f"Could not find forward model step {fm_step_description[0]!r} "
f"in list of installed forward model steps: {installed_steps}",
fm_step_description[0],
)
)
continue
fm_step.arglist = fm_step_description[1:]
fm_steps.append(fm_step)

for fm_step in fm_steps:
if fm_step.name in cls.PREINSTALLED_FORWARD_MODEL_STEPS:
try:
Expand Down
1 change: 0 additions & 1 deletion src/ert/config/parsing/config_keywords.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ class ConfigKeys(StrEnum):
RUN_TEMPLATE = "RUN_TEMPLATE"
SCHEDULE_PREDICTION_FILE = "SCHEDULE_PREDICTION_FILE"
SETENV = "SETENV"
SIMULATION_JOB = "SIMULATION_JOB"
STD_CUTOFF = "STD_CUTOFF"
SUMMARY = "SUMMARY"
SURFACE = "SURFACE"
Expand Down
9 changes: 0 additions & 9 deletions src/ert/config/parsing/config_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,6 @@ def forward_model_keyword() -> SchemaItem:
)


def simulation_job_keyword() -> SchemaItem:
return SchemaItem(
kw=ConfigKeys.SIMULATION_JOB,
argc_max=None,
multi_occurrence=True,
)


def data_kw_keyword() -> SchemaItem:
return SchemaItem(
kw=ConfigKeys.DATA_KW,
Expand Down Expand Up @@ -349,7 +341,6 @@ def init_user_config_schema() -> ConfigSchemaDict:
path_keyword(ConfigKeys.ENSPATH),
single_arg_keyword(ConfigKeys.JOBNAME),
forward_model_keyword(),
simulation_job_keyword(),
data_kw_keyword(),
define_keyword(),
existing_path_keyword(ConfigKeys.OBS_CONFIG),
Expand Down
3 changes: 1 addition & 2 deletions src/ert/config/summary_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ def from_config_dict(cls, config_dict: ConfigDict) -> SummaryConfig | None:
)
time_map = set(refcase.dates) if refcase is not None else None
fm_steps = config_dict.get(ConfigKeys.FORWARD_MODEL, [])
sim_steps = config_dict.get(ConfigKeys.SIMULATION_JOB, [])
names = [fm_step[0] for fm_step in fm_steps + sim_steps]
names = [fm_step[0] for fm_step in fm_steps]
simulation_step_exists = any(
any(sim in _name.lower() for sim in ["eclipse", "flow"])
for _name in names
Expand Down
8 changes: 4 additions & 4 deletions src/everest/simulator/everest_to_ert.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,12 +411,12 @@ def _extract_forward_model(ever_config: EverestConfig, ert_config):
forward_model += _extract_templating(ever_config)
forward_model += ever_config.forward_model or []

sim_job = ert_config.get(ErtConfigKeys.SIMULATION_JOB, [])
fm_steps = ert_config.get(ErtConfigKeys.FORWARD_MODEL, [])
for job in forward_model:
tmp = job.split()
sim_job.append(tuple(tmp))
job_name, *args = job.split()
fm_steps.append([job_name, args])

ert_config[ErtConfigKeys.SIMULATION_JOB] = sim_job
ert_config[ErtConfigKeys.FORWARD_MODEL] = fm_steps


def _extract_model(ever_config: EverestConfig, ert_config):
Expand Down
2 changes: 1 addition & 1 deletion test-data/ert/heat_equation/config.ert
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ FIELD COND PARAMETER cond.bgrdecl INIT_FILES:cond.bgrdecl FORWARD_INIT:True
GEN_DATA MY_RESPONSE RESULT_FILE:gen_data_%d.out REPORT_STEPS:10,71,132,193,255,316,377,438 INPUT_FORMAT:ASCII

INSTALL_JOB heat_equation HEAT_EQUATION
SIMULATION_JOB heat_equation <IENS> <ITER>
FORWARD_MODEL heat_equation <IENS> <ITER>
2 changes: 1 addition & 1 deletion test-data/ert/heat_equation/config_forward_init_false.ert
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ FIELD COND PARAMETER cond.bgrdecl INIT_FILES:cond_%d.bgrdecl FORWARD_INIT:False
GEN_DATA MY_RESPONSE RESULT_FILE:gen_data_%d.out REPORT_STEPS:10,71,132,193,255,316,377,438 INPUT_FORMAT:ASCII

INSTALL_JOB heat_equation HEAT_EQUATION
SIMULATION_JOB heat_equation <IENS> <ITER>
FORWARD_MODEL heat_equation <IENS> <ITER>
2 changes: 1 addition & 1 deletion tests/ert/ui_tests/cli/test_local_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def create_ert_config(path: Path):
NUM_REALIZATIONS 1
MIN_REALIZATIONS 1
INSTALL_JOB write_pid_to_file_and_sleep TEST_JOB
SIMULATION_JOB write_pid_to_file_and_sleep
FORWARD_MODEL write_pid_to_file_and_sleep
"""
),
encoding="utf-8",
Expand Down
9 changes: 0 additions & 9 deletions tests/ert/unit_tests/config/config_dict_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,6 @@ class ErtConfigValues:
min_realizations: str
define: list[tuple[str, str]]
forward_model: tuple[str, list[tuple[str, str]]]
simulation_job: list[list[str]]
stop_long_running: bool
data_kw_key: list[tuple[str, str]]
data_file: str
Expand Down Expand Up @@ -292,7 +291,6 @@ class ErtConfigValues:
def to_config_dict(self, config_file, cwd, all_defines=True):
result = {
ConfigKeys.FORWARD_MODEL: self.forward_model,
ConfigKeys.SIMULATION_JOB: self.simulation_job,
ConfigKeys.NUM_REALIZATIONS: self.num_realizations,
ConfigKeys.RUNPATH_FILE: self.runpath_file,
ConfigKeys.RUN_TEMPLATE: self.run_template,
Expand Down Expand Up @@ -387,7 +385,6 @@ def ert_config_values(draw, use_eclbase=booleans):
queue_system = draw(queue_systems)
install_jobs = draw(small_list(random_forward_model_names(words, file_names)))
forward_model = draw(small_list(job(install_jobs))) if install_jobs else []
simulation_job = draw(small_list(sim_job(install_jobs))) if install_jobs else []
gen_data = draw(
small_list(
st.tuples(
Expand Down Expand Up @@ -436,7 +433,6 @@ def ert_config_values(draw, use_eclbase=booleans):
st.builds(
ErtConfigValues,
forward_model=st.just(forward_model),
simulation_job=st.just(simulation_job),
num_realizations=positives,
eclbase=st.just(draw(words) + "%d") if use_eclbase else st.just(None),
runpath_file=st.just(draw(file_names) + "runpath"),
Expand Down Expand Up @@ -715,11 +711,6 @@ def to_config_file(filename, config_values):
if keyword in tuple_value_keywords:
for tuple_key, tuple_value in keyword_value:
config.write(f"{keyword} {tuple_key} {tuple_value}\n")
elif keyword == ConfigKeys.SIMULATION_JOB:
for job_config in keyword_value:
job_name = job_config[0]
job_args = " ".join(job_config[1:])
config.write(f"{keyword} {job_name} {job_args}\n")
elif keyword == ConfigKeys.FORWARD_MODEL:
for job_name, job_args in keyword_value:
config.write(
Expand Down
75 changes: 0 additions & 75 deletions tests/ert/unit_tests/config/test_create_forward_model_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -599,81 +599,6 @@ def test_that_config_path_is_the_directory_of_the_main_ert_config():
assert data["jobList"][0]["argList"] == [os.getcwd()]


@pytest.mark.usefixtures("use_tmpdir")
@pytest.mark.parametrize(
"job, forward_model, expected_args",
[
pytest.param(
dedent(
"""
EXECUTABLE echo
MIN_ARG 1
MAX_ARG 6
ARG_TYPE 0 STRING
ARG_TYPE 1 BOOL
ARG_TYPE 2 FLOAT
ARG_TYPE 3 INT
"""
),
"SIMULATION_JOB job_name Hello True 3.14 4",
["Hello", "True", "3.14", "4"],
id="Not all args",
),
pytest.param(
dedent(
"""
EXECUTABLE echo
MIN_ARG 1
MAX_ARG 2
ARG_TYPE 0 STRING
ARG_TYPE 0 STRING
"""
),
"SIMULATION_JOB job_name word <E42>",
["word", "<E42>"],
id="Some args",
),
pytest.param(
dedent(
"""
EXECUTABLE echo
MIN_ARG 1
MAX_ARG 2
ARG_TYPE 0 STRING
ARG_TYPE 0 STRING
ARGLIST <ARGUMENTA> <ARGUMENTB>
"""
),
"SIMULATION_JOB job_name arga argb",
["arga", "argb"],
id="simulation job with arglist",
),
],
)
def test_simulation_job(job, forward_model, expected_args):
with open("job_file", "w", encoding="utf-8") as fout:
fout.write(job)

with open("config_file.ert", "w", encoding="utf-8") as fout:
# Write a minimal config file
fout.write("NUM_REALIZATIONS 1\n")
fout.write("INSTALL_JOB job_name job_file\n")
fout.write(forward_model)

ert_config = ErtConfig.from_file("config_file.ert")
data = create_forward_model_json(
context=ert_config.substitutions,
forward_model_steps=ert_config.forward_model_steps,
env_vars=ert_config.env_vars,
user_config_file=ert_config.user_config_file,
run_id="",
)

assert len(ert_config.forward_model_steps) == 1
fm_data = data["jobList"][0]
assert fm_data["argList"] == expected_args


@pytest.mark.usefixtures("use_tmpdir")
def test_that_private_over_global_args_gives_logging_message(caplog):
caplog.set_level(logging.INFO)
Expand Down
12 changes: 3 additions & 9 deletions tests/ert/unit_tests/config/test_ert_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -775,17 +775,16 @@ def run(self, *args):
assert ert_config.workflows["workflow"].cmd_list[0][1] == ["0"]


@pytest.mark.parametrize("fm_keyword", ["FORWARD_MODEL", "SIMULATION_JOB"])
def test_that_unknown_job_gives_config_validation_error(fm_keyword):
def test_that_unknown_job_gives_config_validation_error():
with pytest.raises(
ConfigValidationError,
match="Could not find forward model step 'NO_SUCH_FORWARD_MODEL_STEP'",
):
_ = ErtConfig.from_file_contents(
dedent(
f"""
"""
NUM_REALIZATIONS 1
{fm_keyword} NO_SUCH_FORWARD_MODEL_STEP
FORWARD_MODEL NO_SUCH_FORWARD_MODEL_STEP
"""
)
)
Expand Down Expand Up @@ -1847,11 +1846,6 @@ def test_warning_raised_when_summary_key_and_no_simulation_job_present():
("flow", "FORWARD_MODEL"),
("FLOW", "FORWARD_MODEL"),
("ECLIPSE100", "FORWARD_MODEL"),
("eclipse", "SIMULATION_JOB"),
("eclipse100", "SIMULATION_JOB"),
("flow", "SIMULATION_JOB"),
("FLOW", "SIMULATION_JOB"),
("ECLIPSE100", "SIMULATION_JOB"),
],
)
@pytest.mark.usefixtures("use_tmpdir")
Expand Down
2 changes: 1 addition & 1 deletion tests/everest/test_detached.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def _get_reference_config():
DETACHED_NODE_DIR,
SIMULATION_DIR,
),
"SIMULATION_JOB": [
"FORWARD_MODEL": [
[
EVEREST_SERVER_CONFIG,
"--config-file",
Expand Down
Loading

0 comments on commit 177cbb0

Please sign in to comment.