Skip to content

Commit

Permalink
Use the ert plugin mechanism to install forward models
Browse files Browse the repository at this point in the history
  • Loading branch information
verveerpj committed Oct 31, 2024
1 parent 974266c commit 2ee51ed
Show file tree
Hide file tree
Showing 19 changed files with 43 additions and 35 deletions.
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ docs = [
[project.entry-points."everest"]
everest-models = "everest_models.everest_hooks"

[project.entry-points."ert"]
everest_models_forward_models = "everest_models.forward_models"

[project.scripts]
fm_add_templates = "everest_models.jobs.fm_add_templates.cli:main_entry_point"
fm_drill_date_planner = "everest_models.jobs.fm_drill_date_planner.cli:main_entry_point"
Expand Down
16 changes: 2 additions & 14 deletions src/everest_models/everest_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import logging
import pathlib
import sys
from importlib import import_module, resources
from typing import Any, Dict, List, Sequence, Type

Expand All @@ -24,9 +23,7 @@

logger = logging.getLogger(__name__)

FORWARD_MODEL_DIR = "forward_models"
PACKAGE = "everest_models"
JOBS = f"{PACKAGE}.jobs"
JOBS = "everest_models.jobs"


def _get_jobs():
Expand All @@ -42,16 +39,7 @@ def get_forward_models() -> List[Dict[str, str]]:
- {name: forward_model, path: /path/to/forward_model}
- ...
"""
if sys.version_info.minor >= 9:
jobs = resources.files(PACKAGE) / FORWARD_MODEL_DIR # type: ignore
else:
with resources.path(PACKAGE, FORWARD_MODEL_DIR) as fd:
jobs = fd

return [
{"name": (job_name := job.lstrip("fm_")), "path": str(jobs / job_name)}
for job in _get_jobs()
]
return []


@hookimpl
Expand Down
38 changes: 38 additions & 0 deletions src/everest_models/forward_models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from importlib import resources
from importlib.util import find_spec
from typing import Final

_HAVE_ERT: Final = find_spec("ert") is not None

if _HAVE_ERT:
import ert
from ert import ForwardModelStepDocumentation, ForwardModelStepPlugin

def build_forward_model_step_plugin(executable_name: str):
forward_model_name = executable_name.lstrip("fm_")
class_name = "".join(
x.capitalize() for x in forward_model_name.lower().split("_")
)
return type(
class_name,
(ForwardModelStepPlugin,),
{
"__init__": lambda x: ForwardModelStepPlugin.__init__(
x, name=forward_model_name, command=[executable_name]
),
"documentation": lambda: ForwardModelStepDocumentation(
category="everest.everest_models",
source_package="everest_models",
source_function_name=class_name,
description=f"The {forward_model_name} forward model.",
),
},
)

@ert.plugin(name="everest_models")
def installable_forward_model_steps():
return [
build_forward_model_step_plugin(job)
for job in resources.contents("everest_models.jobs")
if job.startswith("fm_")
]
1 change: 0 additions & 1 deletion src/everest_models/forward_models/add_templates

This file was deleted.

1 change: 0 additions & 1 deletion src/everest_models/forward_models/compute_economics

This file was deleted.

1 change: 0 additions & 1 deletion src/everest_models/forward_models/drill_date_planner

This file was deleted.

1 change: 0 additions & 1 deletion src/everest_models/forward_models/drill_planner

This file was deleted.

1 change: 0 additions & 1 deletion src/everest_models/forward_models/extract_summary_data

This file was deleted.

1 change: 0 additions & 1 deletion src/everest_models/forward_models/interpret_well_drill

This file was deleted.

1 change: 0 additions & 1 deletion src/everest_models/forward_models/npv

This file was deleted.

1 change: 0 additions & 1 deletion src/everest_models/forward_models/rf

This file was deleted.

1 change: 0 additions & 1 deletion src/everest_models/forward_models/schmerge

This file was deleted.

1 change: 0 additions & 1 deletion src/everest_models/forward_models/select_wells

This file was deleted.

4 changes: 0 additions & 4 deletions src/everest_models/forward_models/stea

This file was deleted.

3 changes: 0 additions & 3 deletions src/everest_models/forward_models/strip_dates

This file was deleted.

1 change: 0 additions & 1 deletion src/everest_models/forward_models/well_constraints

This file was deleted.

1 change: 0 additions & 1 deletion src/everest_models/forward_models/well_filter

This file was deleted.

1 change: 0 additions & 1 deletion src/everest_models/forward_models/well_swapping

This file was deleted.

1 change: 0 additions & 1 deletion src/everest_models/forward_models/well_trajectory

This file was deleted.

0 comments on commit 2ee51ed

Please sign in to comment.