Skip to content

Commit

Permalink
todo: give the injected plugin env into the json for fm validateion
Browse files Browse the repository at this point in the history
  • Loading branch information
berland committed Dec 11, 2024
1 parent d4a47f5 commit 40c8946
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
15 changes: 14 additions & 1 deletion src/ert/config/ert_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ def create_forward_model_json(
env_vars = {}
if env_pr_fm_step is None:
env_pr_fm_step = {}
import pprint

print("** env pr fm step")
pprint.pprint(env_pr_fm_step)

class Substituter:
def __init__(self, fm_step):
Expand Down Expand Up @@ -344,6 +348,12 @@ class ErtConfigWithPlugins(ErtConfig):
ENV_PR_FM_STEP: ClassVar[dict[str, dict[str, Any]]] = env_pr_fm_step
ACTIVATE_SCRIPT = ErtPluginManager().activate_script()

import pprint

print("\n*******")
print("in with_plugins()")
pprint.pprint(env_pr_fm_step)

assert issubclass(ErtConfigWithPlugins, ErtConfig)
return ErtConfigWithPlugins

Expand Down Expand Up @@ -834,7 +844,10 @@ def _create_list_of_forward_model_steps_to_run(
skip_pre_experiment_validation=True,
)
job_json = substituted_json["jobList"][0]
fm_step.validate_pre_experiment(job_json, env_vars)
fm_step.validate_pre_experiment(
job_json,
{**cls.ENV_PR_FM_STEP.get(fm_step.name, {}), **env_vars},
)
except ForwardModelStepValidationError as err:
errors.append(
ConfigValidationError.with_context(
Expand Down
12 changes: 6 additions & 6 deletions src/ert/plugins/hook_implementations/forward_model_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,16 +216,14 @@ def __init__(self) -> None:
default_mapping={"<NUM_CPU>": 1, "<OPTS>": ""},
)

def validate_pre_experiment(
self, _: ForwardModelStepJSON, env_vars: dict[str, str]
) -> None:
def validate_pre_experiment(self, fm_json: ForwardModelStepJSON) -> None:

Check failure on line 219 in src/ert/plugins/hook_implementations/forward_model_steps.py

View workflow job for this annotation

GitHub Actions / type-checking (3.12)

Signature of "validate_pre_experiment" incompatible with supertype "ForwardModelStep"
if "<VERSION>" not in self.private_args:
raise ForwardModelStepValidationError(
"Forward model step ECLIPSE100 must be given a VERSION argument"
)
version = self.private_args["<VERSION>"]
available_versions = _available_eclrun_versions(
simulator="eclipse", env_vars=env_vars
simulator="eclipse", env_vars=fm_json["environment"]
)

if available_versions and version not in available_versions:
Expand Down Expand Up @@ -279,15 +277,16 @@ def __init__(self) -> None:
)

def validate_pre_experiment(

Check failure on line 279 in src/ert/plugins/hook_implementations/forward_model_steps.py

View workflow job for this annotation

GitHub Actions / type-checking (3.12)

Signature of "validate_pre_experiment" incompatible with supertype "ForwardModelStep"
self, _: ForwardModelStepJSON, env_vars: dict[str, str]
self,
fm_step_json: ForwardModelStepJSON,
) -> None:
if "<VERSION>" not in self.private_args:
raise ForwardModelStepValidationError(
"Forward model step ECLIPSE300 must be given a VERSION argument"
)
version = self.private_args["<VERSION>"]
available_versions = _available_eclrun_versions(
simulator="e300", env_vars=env_vars
simulator="e300", env_vars=fm_step_json["environment"]
)
if available_versions and version not in available_versions:
raise ForwardModelStepValidationError(
Expand Down Expand Up @@ -647,6 +646,7 @@ def _available_eclrun_versions(
simulator,
"--report-versions",
],
env=env_vars,
)
.decode("utf-8")
.strip()
Expand Down
10 changes: 4 additions & 6 deletions tests/ert/unit_tests/config/test_forward_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,14 +583,12 @@ def test_that_eclipse_fm_step_check_version_availability(eclipse_v):
ConfigValidationError,
match=rf".*Unavailable {eclipse_v} version dummy. Available versions: \[\'20.*",
):
_ = ErtConfig.with_plugins().from_file(config_file_name)
ErtConfig.with_plugins().from_file(config_file_name)


@pytest.mark.parametrize("eclipse_v", ["ECLIPSE100", "ECLIPSE300"])
@pytest.mark.usefixtures("use_tmpdir")
def test_that_we_can_point_to_a_custom_eclrun_when_checking_versions(
eclipse_v, tmp_path
):
def test_that_we_can_point_to_a_custom_eclrun_when_checking_versions(eclipse_v):
eclrun_bin = Path("bin/eclrun")
eclrun_bin.parent.mkdir()
eclrun_bin.write_text("#!/bin/sh\necho 2036.1 2036.2 2037.1", encoding="utf-8")
Expand All @@ -609,7 +607,7 @@ def test_that_we_can_point_to_a_custom_eclrun_when_checking_versions(
ConfigValidationError,
match=rf".*Unavailable {eclipse_v} version 2034.1. Available versions: \[\'2036.1.*",
):
_ = ErtConfig.with_plugins().from_file(config_file_name)
ErtConfig.with_plugins().from_file(config_file_name)


@pytest.mark.skipif(shutil.which("eclrun") is not None, reason="eclrun is present")
Expand Down Expand Up @@ -869,7 +867,7 @@ def test_that_plugin_forward_model_raises_pre_experiment_validation_error_early(
):
(tmp_path / "test.ert").write_text(
"""
NUM_REALIZATIONS 1
NUM_REALIZATIONS 1
FORWARD_MODEL FM1(<arg1>=never,<arg2>=world,<arg3>=derpyderp)
FORWARD_MODEL FM2
"""
Expand Down

0 comments on commit 40c8946

Please sign in to comment.