Skip to content

Commit

Permalink
Use the ert plugin system for installing everest forward models
Browse files Browse the repository at this point in the history
  • Loading branch information
verveerpj committed Nov 7, 2024
1 parent 721f3c6 commit 07f44e8
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 43 deletions.
2 changes: 0 additions & 2 deletions src/everest/config/everest_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
validate_forward_model_configs,
)
from everest.jobs import script_names
from everest.util.forward_models import collect_forward_models

from ..config_file_loader import yaml_file_to_substituted_config_dict
from ..strings import (
Expand Down Expand Up @@ -297,7 +296,6 @@ def validate_forward_model_job_name_installed(self): # pylint: disable=E0213
installed_jobs_name = [job.name for job in install_jobs]
installed_jobs_name += list(script_names) # default jobs
installed_jobs_name += get_system_installed_jobs() # system jobs
installed_jobs_name += [job["name"] for job in collect_forward_models()]

errors = []
for fm_job in forward_model_jobs:
Expand Down
2 changes: 0 additions & 2 deletions src/everest/plugins/hook_specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ def flow_config_path():
def get_forward_models():
"""
Return a list of dicts detailing the names and paths to forward models.
Example [{"name": "job1", "path":"path1"}, {"name": "job2", "path":"path2"}]
"""


Expand Down
3 changes: 0 additions & 3 deletions src/everest/simulator/everest_to_ert.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
from everest.config_keys import ConfigKeys
from everest.queue_driver.queue_driver import _extract_queue_system
from everest.strings import EVEREST, SIMULATION_DIR, STORAGE_DIR
from everest.util.forward_models import collect_forward_models


def _get_datafiles(ever_config: EverestConfig):
Expand Down Expand Up @@ -209,8 +208,6 @@ def _fetch_everest_jobs(ever_config: EverestConfig):
f.write("EXECUTABLE %s" % script)

ever_jobs.append(Job(name=default_job, source=job_spec_file))
for job in collect_forward_models():
ever_jobs.append(Job(name=job["name"], source=job["path"]))

return ever_jobs

Expand Down
6 changes: 3 additions & 3 deletions tests/everest/test_everlint.py
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ def test_lint_everest_models_jobs():
def test_overloading_everest_models_names():
config = yaml_file_to_substituted_config_dict(SNAKE_OIL_CONFIG)
for job in collect_forward_models():
config["install_jobs"][2]["name"] = job["name"]
config["forward_model"][1] = job["name"]
config["install_jobs"][2]["name"] = job
config["forward_model"][1] = job
errors = EverestConfig.lint_config_dict(config)
assert len(errors) == 0, f"Failed for job {job['name']}"
assert len(errors) == 0, f"Failed for job {job}"
33 changes: 16 additions & 17 deletions tests/everest/test_fm_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@
import pytest
from pydantic import BaseModel

from ert import ForwardModelStepPlugin
from everest.config import EverestConfig
from everest.plugins import hook_impl, hook_specs, hookimpl
from everest.simulator.everest_to_ert import everest_to_ert_config
from everest.strings import EVEREST
from everest.util.forward_models import collect_forward_models
from tests.everest.utils import relpath

SNAKE_CONFIG_PATH = relpath("test_data/snake_oil/everest/model/snake_oil.yml")


class MockPluginManager(pluggy.PluginManager):
Expand All @@ -35,26 +41,19 @@ def register_plugin_hooks(*plugins) -> MockPluginManager:
yield register_plugin_hooks


def test_jobs():
for job in collect_forward_models():
assert "name" in job
assert "path" in job


def test_everest_models_jobs(plugin_manager):
def test_everest_models_jobs():
pytest.importorskip("everest_models")
pm = plugin_manager()
assert any(
hook.plugin_name.startswith(EVEREST)
for hook in pm.hook.get_forward_models.get_hookimpls()
)
ert_config = everest_to_ert_config(EverestConfig.load_file(SNAKE_CONFIG_PATH))
jobs = collect_forward_models()
assert bool(jobs)
for job in jobs:
job_class = ert_config.installed_forward_model_steps.get(job)
assert job_class is not None
assert isinstance(job_class, ForwardModelStepPlugin)


def test_multiple_plugins(plugin_manager):
_JOBS = [
{"name": "job1", "path": "/some/path1"},
{"name": "job2", "path": "/some/path2"},
]
_JOBS = ["job1", "job2"]

class Plugin1:
@hookimpl
Expand All @@ -68,7 +67,7 @@ def get_forward_models(self):

pm = plugin_manager(Plugin1(), Plugin2())

jobs = list(chain.from_iterable(pm.hook.get_forward_models()))
jobs = set(chain.from_iterable(pm.hook.get_forward_models()))
for value in _JOBS:
assert value in jobs

Expand Down
14 changes: 0 additions & 14 deletions tests/everest/test_res_initialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
_everest_to_ert_config_dict,
everest_to_ert_config,
)
from everest.util.forward_models import collect_forward_models
from tests.everest.utils import (
everest_default_jobs,
hide_opm,
Expand Down Expand Up @@ -577,19 +576,6 @@ def test_strip_date_job_insertion(copy_test_data_to_tmp):
assert snake_dict == ert_config_dict


def test_forward_model_job_insertion(copy_test_data_to_tmp):
# Load config file
ever_config = EverestConfig.load_file(SNAKE_CONFIG_PATH)

# Transform to res dict
ert_config_dict = _everest_to_ert_config_dict(ever_config)

jobs = ert_config_dict[ErtConfigKeys.INSTALL_JOB]
for job in collect_forward_models():
res_job = (job["name"], job["path"])
assert res_job in jobs


def test_workflow_job(copy_test_data_to_tmp):
workflow_jobs = [{"name": "test", "source": "jobs/TEST"}]
ever_config = EverestConfig.load_file(SNAKE_CONFIG_PATH)
Expand Down
3 changes: 1 addition & 2 deletions tests/everest/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from everest.detached import ServerStatus, everserver_status
from everest.jobs import script_names
from everest.util import has_opm
from everest.util.forward_models import collect_forward_models


def skipif_no_opm(function):
Expand Down Expand Up @@ -124,7 +123,7 @@ def everest_default_jobs(output_dir):
os.path.join(output_dir, ".jobs", "_%s" % script_name),
)
for script_name in script_names
] + [(job["name"], job["path"]) for job in collect_forward_models()]
]


def create_cached_mocked_test_case(request, monkeypatch) -> pathlib.Path:
Expand Down

0 comments on commit 07f44e8

Please sign in to comment.