Skip to content

Commit

Permalink
Propagate SETENV to forward model validation
Browse files Browse the repository at this point in the history
The settings implied through SETENV can affect how forward
model behave, and may also change how validation should be
performed.

This is in particular true for the Eclipse forward model steps
which try to validate the requested version. If a different
configuration of Eclipse is set through

  SETENV ECL100_SITE_CONFIG somefile.yml

(or for ECL300_SITE_CONFIG) this information must be conveyed
to the validation code.
  • Loading branch information
berland committed Dec 6, 2024
1 parent 0ba0626 commit dff8eb5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 14 deletions.
9 changes: 7 additions & 2 deletions src/ert/config/ert_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -762,10 +762,15 @@ def _create_list_of_forward_model_steps_to_run(
cls,
installed_steps: Dict[str, ForwardModelStep],
substitutions: Substitutions,
config_dict,
config_dict: dict,
) -> List[ForwardModelStep]:
errors = []
fm_steps = []

env_vars = {}
for key, val in config_dict.get("SETENV", []):
env_vars[key] = val

for fm_step_description in config_dict.get(ConfigKeys.FORWARD_MODEL, []):
if len(fm_step_description) > 1:
unsubstituted_step_name, args = fm_step_description
Expand Down Expand Up @@ -832,7 +837,7 @@ 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)
fm_step.validate_pre_experiment(job_json, env_vars)
except ForwardModelStepValidationError as err:
errors.append(
ConfigValidationError.with_context(
Expand Down
4 changes: 3 additions & 1 deletion src/ert/config/forward_model_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,9 @@ def convert_to_substitutions(cls, v: Dict[str, str]) -> Substitutions:
return v
return Substitutions(v)

def validate_pre_experiment(self, fm_step_json: ForwardModelStepJSON) -> None:
def validate_pre_experiment(
self, fm_step_json: ForwardModelStepJSON, env_vars: Dict[str, str]
) -> None:
"""
Raise errors pertaining to the environment not being
as the forward model step requires it to be. For example
Expand Down
30 changes: 19 additions & 11 deletions src/ert/plugins/hook_implementations/forward_model_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import subprocess
from pathlib import Path
from textwrap import dedent
from typing import List, Literal, Optional, Type
from typing import Dict, List, Literal, Optional, Type

import yaml

Expand All @@ -14,7 +14,6 @@
ForwardModelStepValidationError,
plugin,
)
from ert.plugins import ErtPluginManager


class CarefulCopyFile(ForwardModelStepPlugin):
Expand Down Expand Up @@ -220,13 +219,17 @@ def __init__(self) -> None:
default_mapping={"<NUM_CPU>": 1, "<OPTS>": ""},
)

def validate_pre_experiment(self, _: ForwardModelStepJSON) -> None:
def validate_pre_experiment(
self, _: ForwardModelStepJSON, env_vars: Dict[str, str]
) -> None:
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")
available_versions = _available_eclrun_versions(
simulator="eclipse", env_vars=env_vars
)

if available_versions and version not in available_versions:
raise ForwardModelStepValidationError(
Expand Down Expand Up @@ -278,13 +281,17 @@ def __init__(self) -> None:
default_mapping={"<NUM_CPU>": 1, "<OPTS>": "", "<VERSION>": "version"},
)

def validate_pre_experiment(self, _: ForwardModelStepJSON) -> None:
def validate_pre_experiment(
self, _: ForwardModelStepJSON, env_vars: Dict[str, str]
) -> 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")
available_versions = _available_eclrun_versions(
simulator="e300", env_vars=env_vars
)
if available_versions and version not in available_versions:
raise ForwardModelStepValidationError(
f"Unavailable ECLIPSE300 version {version} current supported "
Expand Down Expand Up @@ -628,14 +635,15 @@ def installable_forward_model_steps() -> List[Type[ForwardModelStepPlugin]]:
return [*_UpperCaseFMSteps, *_LowerCaseFMSteps]


def _available_eclrun_versions(simulator: Literal["eclipse", "e300"]) -> List[str]:
def _available_eclrun_versions(
simulator: Literal["eclipse", "e300"], env_vars: Dict[str, str]
) -> List[str]:
if shutil.which("eclrun") is None:
return []
pm = ErtPluginManager()
ecl_config_path = (
pm.get_ecl100_config_path()
env_vars.get("ECL100_SITE_CONFIG")
if simulator == "eclipse"
else pm.get_ecl300_config_path()
else env_vars.get("ECL300_SITE_CONFIG")
)

if not ecl_config_path:
Expand All @@ -661,4 +669,4 @@ def _available_eclrun_versions(simulator: Literal["eclipse", "e300"]) -> List[st
.split(" ")
)
except subprocess.CalledProcessError:
return []
return

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

View workflow job for this annotation

GitHub Actions / type-checking (3.12)

Return value expected

0 comments on commit dff8eb5

Please sign in to comment.