Skip to content

Commit

Permalink
validate eclrun-version with no eclconfig, untested
Browse files Browse the repository at this point in the history
wip: simplified EclRun

wip: can run eclipse on flow_example

wip: eclipse maybe works, flowrun missing

Renamed files, merging eclrun and flowrun now

Merged runner script for flowrun and eclrun

more opm flowrun tests in place

Allow usage of direct flow installation if no flowrun

No MPI run without flowrun

fixup, test_await needs to u se tmp_dir fixture

Can't test eclipse version when no elcrun. UNTESTED

wip: dedicated test_run_reservoirsimultor

Get path to eclrun from environment

fix eclipse integration tests, using paths from ert-configurations

reinstate flow.ert

clean up and rewrite config/forward_model tests

fixup test_run_reservoirsimulator

use tmpdir

commitin --- problems with eclrun_path and SETENV

Try again, fixes for env passing to validate_pre_experiment

solve ruf062
  • Loading branch information
berland committed Dec 13, 2024
1 parent 1af592d commit a5663d5
Show file tree
Hide file tree
Showing 16 changed files with 970 additions and 1,762 deletions.
17 changes: 14 additions & 3 deletions src/ert/config/ert_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -759,10 +759,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 @@ -827,9 +832,15 @@ def _create_list_of_forward_model_steps_to_run(
context=substitutions,
forward_model_steps=[fm_step],
skip_pre_experiment_validation=True,
env_vars=env_vars,
)
job_json = substituted_json["jobList"][0]
fm_step.validate_pre_experiment(job_json)
fm_json = substituted_json["jobList"][0]
fm_json["environment"] = {
**cls.ENV_PR_FM_STEP.get(fm_step.name, {}), # plugins
**fm_json["environment"], # setenv
**substituted_json["global_environment"],
}
fm_step.validate_pre_experiment(fm_json)
except ForwardModelStepValidationError as err:
errors.append(
ConfigValidationError.with_context(
Expand Down
80 changes: 36 additions & 44 deletions src/ert/plugins/hook_implementations/forward_model_steps.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
import os
import shutil
import subprocess
from pathlib import Path
from textwrap import dedent
from typing import Literal

import yaml

from ert import (
ForwardModelStepDocumentation,
ForwardModelStepJSON,
ForwardModelStepPlugin,
ForwardModelStepValidationError,
plugin,
)
from ert.plugins import ErtPluginManager


class CarefulCopyFile(ForwardModelStepPlugin):
Expand Down Expand Up @@ -207,31 +203,33 @@ def __init__(self) -> None:
str(
(
Path(__file__)
/ "../../../resources/forward_models/res/script/ecl100.py"
/ "../../../resources/forward_models/run_reservoirsimulator.py"
).resolve()
),
"<ECLBASE>",
"-v",
"eclipse",
"<VERSION>",
"<ECLBASE>",
"-n",
"<NUM_CPU>",
"<OPTS>",
],
default_mapping={"<NUM_CPU>": 1, "<OPTS>": ""},
)

def validate_pre_experiment(self, _: ForwardModelStepJSON) -> None:
def validate_pre_experiment(self, fm_json: ForwardModelStepJSON) -> 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=fm_json["environment"]
)

if available_versions and version not in available_versions:
raise ForwardModelStepValidationError(
f"Unavailable ECLIPSE100 version {version} current supported "
f"versions {available_versions}"
f"Unavailable ECLIPSE100 version {version}. "
f"Available versions: {available_versions}"
)

@staticmethod
Expand Down Expand Up @@ -265,30 +263,35 @@ def __init__(self) -> None:
str(
(
Path(__file__)
/ "../../../resources/forward_models/res/script/ecl300.py"
/ "../../../resources/forward_models/run_reservoirsimulator.py"
).resolve()
),
"<ECLBASE>",
"-v",
"e300",
"<VERSION>",
"<ECLBASE>",
"-n",
"<NUM_CPU>",
"<OPTS>",
],
default_mapping={"<NUM_CPU>": 1, "<OPTS>": "", "<VERSION>": "version"},
)

def validate_pre_experiment(self, _: ForwardModelStepJSON) -> None:
def validate_pre_experiment(
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")
available_versions = _available_eclrun_versions(
simulator="e300", env_vars=fm_step_json["environment"]
)
if available_versions and version not in available_versions:
raise ForwardModelStepValidationError(
f"Unavailable ECLIPSE300 version {version} current supported "
f"versions {available_versions}"
f"Unavailable ECLIPSE300 version {version}. "
f"Available versions: {available_versions}"
)

@staticmethod
Expand Down Expand Up @@ -317,11 +320,11 @@ def __init__(self) -> None:
str(
(
Path(__file__)
/ "../../../resources/forward_models/res/script/flow.py"
/ "../../../resources/forward_models/run_reservoirsimulator.py"
).resolve()
),
"flow",
"<ECLBASE>",
"-v",
"<VERSION>",
"-n",
"<NUM_CPU>",
Expand Down Expand Up @@ -628,33 +631,22 @@ def installable_forward_model_steps() -> list[type[ForwardModelStepPlugin]]:
return [*_UpperCaseFMSteps, *_LowerCaseFMSteps]


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

if not ecl_config_path:
return []
eclrun_env = {"PATH": os.getenv("PATH", "")}

with open(ecl_config_path, encoding="utf-8") as f:
try:
config = yaml.safe_load(f)
except yaml.YAMLError as e:
raise ValueError(f"Failed parse: {ecl_config_path} as yaml") from e
ecl_install_path = config.get("eclrun_env", {}).get("PATH", "")
eclrun_env["PATH"] = eclrun_env["PATH"] + os.pathsep + ecl_install_path

def _available_eclrun_versions(
simulator: Literal["eclipse", "e300"], env_vars: dict[str, str]
) -> list[str]:
eclrun_path = env_vars.get("ECLRUN_PATH", "")
try:
eclrun_abspath = shutil.which(Path(eclrun_path) / "eclrun")
if eclrun_abspath is None:
return []
return (
subprocess.check_output(
["eclrun", "--report-versions", simulator],
env=eclrun_env,
[
eclrun_abspath,
simulator,
"--report-versions",
],
env=env_vars,
)
.decode("utf-8")
.strip()
Expand Down
9 changes: 0 additions & 9 deletions src/ert/resources/forward_models/res/script/ecl100.py

This file was deleted.

14 changes: 0 additions & 14 deletions src/ert/resources/forward_models/res/script/ecl100_config.yml

This file was deleted.

9 changes: 0 additions & 9 deletions src/ert/resources/forward_models/res/script/ecl300.py

This file was deleted.

8 changes: 0 additions & 8 deletions src/ert/resources/forward_models/res/script/ecl300_config.yml

This file was deleted.

Loading

0 comments on commit a5663d5

Please sign in to comment.