Skip to content

Commit

Permalink
Add forward model output functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
DanSava committed Oct 31, 2024
1 parent 974266c commit cb8a768
Show file tree
Hide file tree
Showing 19 changed files with 120 additions and 56 deletions.
8 changes: 5 additions & 3 deletions docs/contribute/fm_ops_remover/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@


@bootstrap_parser
def build_argument_parser():
def build_argument_parser(skip_type=False):
parser, required_group = get_parser(
description="Given everest generated wells.json file"
"and a list of well names. remove the intersecting names' operations."
)
add_wells_input_argument(required_group, help="Everest generated wells.json file")
add_output_argument(required_group, help="Output File")
add_wells_input_argument(
required_group, help="Everest generated wells.json file", skip_type=skip_type
)
add_output_argument(required_group, help="Output File", skip_type=skip_type)
required_group.add_argument(
"-w", "--wells", required=True, help="wells to modified.", nargs="+", type=str
)
Expand Down
21 changes: 20 additions & 1 deletion src/everest_models/everest_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import pathlib
import sys
from importlib import import_module, resources
from typing import Any, Dict, List, Sequence, Type
from typing import Any, Dict, List, Sequence, Set, Type

from pydantic import BaseModel

Expand Down Expand Up @@ -129,3 +129,22 @@ def get_forward_model_documentations() -> Dict[str, Any]:
"full_job_name": full_job_name,
}
return docs


@hookimpl
def custom_forward_model_outputs(forward_model_steps: List[str]) -> Set[str]:
forward_models = [step["name"] for step in get_forward_models()]
outputs = set()
for step in forward_model_steps:
step_name, *args = step.split()
if step_name in forward_models:
try:
parser = import_module(
f"{JOBS}.fm_{step_name}.parser"
).build_argument_parser(skip_type=True)
options = parser.parse_args(args)
if options.output:
outputs.add(options.output)
except SystemExit:
pass
return outputs
7 changes: 4 additions & 3 deletions src/everest_models/jobs/fm_add_templates/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@


@bootstrap_parser
def build_argument_parser():
def build_argument_parser(skip_type=False):
SchemaAction.register_models(SCHEMAS)
parser, required_group = get_parser(
description="Inserts template file paths for all well operations in the "
Expand All @@ -29,11 +29,12 @@ def build_argument_parser():
required_group,
schema=Wells,
help="Input file that requires template paths. Json file expected ex: wells.json",
skip_type=skip_type,
)
add_output_argument(required_group, help="Output file")
add_output_argument(required_group, help="Output file", skip_type=skip_type)
required_group.add_argument(
*_CONFIG_ARGUMENT.split("/"),
type=partial(parse_file, schema=TemplateConfig),
type=partial(parse_file, schema=TemplateConfig) if not skip_type else str,
required=True,
help="Config file containing list of template file paths to be injected.",
)
Expand Down
7 changes: 5 additions & 2 deletions src/everest_models/jobs/fm_compute_economics/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@


@bootstrap_parser
def build_argument_parser():
def build_argument_parser(skip_type=False):
SchemaAction.register_models(SCHEMAS)
parser, required_group = get_parser(
description="Module to calculate economical indicators based on an eclipse simulation. "
Expand All @@ -33,14 +33,17 @@ def build_argument_parser():
required_group.add_argument(
*CONFIG_ARGUMENT.split("/"),
required=True,
type=partial(parse_file, schema=EconomicIndicatorConfig),
type=partial(parse_file, schema=EconomicIndicatorConfig)
if not skip_type
else str,
help="Path to config file containing at least prices",
)
add_output_argument(
parser,
required=False,
default=None,
help="Path to output-file where the economical indicators result is written to.",
skip_type=skip_type,
)
parser.add_argument(
"--output-currency",
Expand Down
6 changes: 4 additions & 2 deletions src/everest_models/jobs/fm_drill_date_planner/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,25 @@


@bootstrap_parser
def build_argument_parser():
def build_argument_parser(skip_type=False):
parser, required_group = get_parser(
description="Calculate and write drill times from scaled controls.",
)
add_wells_input_argument(
required_group,
help="Wells file generated by Everest (wells.json).",
skip_type=skip_type,
)
add_output_argument(
required_group,
help="Output file: input for drill planner job.",
skip_type=skip_type,
)
required_group.add_argument(
"-opt",
"--optimizer",
required=True,
type=valid_input_file,
type=valid_input_file if not skip_type else str,
help="File containing information related to wells. The format is "
"consistent with the wells.json file when running everest and can "
"be used directly.",
Expand Down
8 changes: 5 additions & 3 deletions src/everest_models/jobs/fm_drill_planner/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@


@bootstrap_parser
def build_argument_parser():
def build_argument_parser(skip_type=False):
SchemaAction.register_models(SCHEMAS)
parser, required_group = get_parser(
description="A module that given a well priority list and a set of "
Expand All @@ -35,6 +35,7 @@ def build_argument_parser():
"consistent with the wells.json file when running everest and can "
"be used directly.",
schema=Wells,
skip_type=skip_type,
)
add_output_argument(
required_group,
Expand All @@ -43,11 +44,12 @@ def build_argument_parser():
"drill_planner. Please note that it is highly recommended to not use the "
"same filename as the input-file. In cases where the same workflow is run "
"twice, it is generally advised that the input-file for each job is consistent",
skip_type=skip_type,
)
required_group.add_argument(
*_CONFIG_ARGUMENT.split("/"),
required=True,
type=partial(parse_file, schema=DrillPlanConfig),
type=partial(parse_file, schema=DrillPlanConfig) if not skip_type else str,
help="Configuration file in yaml format describing the constraints of the "
"field development. The file must contain information about rigs and slots "
"that the wells can be drilled through. Additional information, such as "
Expand All @@ -56,7 +58,7 @@ def build_argument_parser():
required_group.add_argument(
*_OPTIMIZER_ARGUMENT.split("/"),
required=True,
type=valid_input_file,
type=valid_input_file if not skip_type else str,
help="The optimizer file is generated from everest it "
"contains the well priority values - a float for each well.",
)
Expand Down
5 changes: 3 additions & 2 deletions src/everest_models/jobs/fm_extract_summary_data/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
from everest_models.jobs.shared.validators import valid_iso_date


def build_argument_parser():
def build_argument_parser(skip_type=False):
description = "Module to extract Eclipse Summary keyword data for single date or date interval"
parser, requird_group = get_parser(description=description)

add_summary_argument(requird_group)
add_summary_argument(requird_group, skip_type=skip_type)
add_output_argument(
requird_group,
help="Output file",
skip_type=skip_type,
)
add_lint_argument(parser)
parser.add_argument(
Expand Down
4 changes: 3 additions & 1 deletion src/everest_models/jobs/fm_interpret_well_drill/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
)


def build_argument_parser():
def build_argument_parser(skip_type=False):
description = (
"This module transforms dakota well_drill output to a json object."
"This object contains a list of well names to keep."
Expand All @@ -19,11 +19,13 @@ def build_argument_parser():
"Yaml file that contains optimizer output, this should consist "
"of a list of well names, with their associated value between 0 and 1"
),
skip_type=skip_type,
)
add_lint_argument(parser)
add_output_argument(
required_group,
help="File path to write the resulting json file to.",
skip_type=skip_type,
)

return parser
Expand Down
8 changes: 5 additions & 3 deletions src/everest_models/jobs/fm_npv/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,33 @@


@bootstrap_parser
def build_argument_parser():
def build_argument_parser(skip_type=False):
SchemaAction.register_models(SCHEMAS)
parser, required_group = get_parser(
description="Module to calculate the NPV based on an eclipse simulation. "
"All optional args, except: lint, schemas, input and output, is also configurable through the config file."
)
add_summary_argument(required_group)
add_summary_argument(required_group, skip_type=skip_type)
add_wells_input_argument(
parser,
required=False,
help="Path to input file containing information related to wells. "
"The format is consistent with the wells.json file when running "
"everest. It must contain a 'readydate' key for each well for when "
"it is considered completed and ready for production.",
skip_type=skip_type,
)
add_output_argument(
parser,
required=False,
default="npv",
help="Path to output-file where the NPV result is written to.",
skip_type=skip_type,
)
required_group.add_argument(
*CONFIG_ARGUMENT.split("/"),
required=True,
type=partial(parse_file, schema=NPVConfig),
type=partial(parse_file, schema=NPVConfig) if not skip_type else str,
help="Path to config file containing at least prices",
)
parser.add_argument(
Expand Down
11 changes: 8 additions & 3 deletions src/everest_models/jobs/fm_rf/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,22 @@
from everest_models.jobs.shared.validators import valid_iso_date


def build_argument_parser():
def build_argument_parser(skip_type=False):
parser, required_group = get_parser(
description="Calculates the recovery factor given summary keys and dates.\n"
"Requires a Summary instance to retrieve the volumes from. The summary "
"keys requested must be in the Summary instance. If the dates are outside "
"the simulation range, they will be clamped to nearest. Will throw an "
"error if the entire date range is outside the simulation range."
)
add_summary_argument(required_group)
add_summary_argument(required_group, skip_type=skip_type)
add_lint_argument(parser)
add_output_argument(parser, required=False, help="Filename of the output file. ")
add_output_argument(
parser,
required=False,
help="Filename of the output file. ",
skip_type=skip_type,
)
parser.add_argument(
"-pk",
"--production_key",
Expand Down
6 changes: 4 additions & 2 deletions src/everest_models/jobs/fm_schmerge/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


@bootstrap_parser
def build_argument_parser():
def build_argument_parser(skip_type=False):
parser, required_group = get_parser(
description="This module works on a schedule file intended for reservoir simulation"
"(e.g. eclipse or flow), and injects templates at given dates. If the report"
Expand All @@ -21,7 +21,7 @@ def build_argument_parser():
"-s",
"--schedule",
required=True,
type=valid_schedule_template,
type=valid_schedule_template if not skip_type else str,
help="Schedule file to inject templates into. The only currently"
" accepted date format is the following: one line consisting of the"
" DATES keyword, followed by a date in the format of '1 JAN 2000'"
Expand All @@ -37,9 +37,11 @@ def build_argument_parser():
" and the ops is a list of operations to be performed on the well."
" The operations are defined within a dict with the required keys template,"
" date and any parameter values that are to be injected into the given template",
skip_type=skip_type,
)
add_output_argument(
required_group,
help="File path to write the resulting schedule file to.",
skip_type=skip_type,
)
return parser
6 changes: 4 additions & 2 deletions src/everest_models/jobs/fm_select_wells/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def scaled_well_number(value: str) -> float:


@bootstrap_parser
def build_argument_parser():
def build_argument_parser(skip_type=False):
SchemaAction.register_models({"file": WellNumber})
parser, required_named_arguments = get_parser(
description="Select the first wells from a drill planner output file."
Expand All @@ -34,10 +34,12 @@ def build_argument_parser():
add_wells_input_argument(
required_named_arguments,
help="Input file: a drill planner output file.",
skip_type=skip_type,
)
add_output_argument(
required_named_arguments,
help="Output file: updated drill planner output file",
skip_type=skip_type,
)
parser.add_argument(
"-m",
Expand All @@ -60,7 +62,7 @@ def build_argument_parser():
)
well_number_file.add_argument(
"file_path",
type=scaled_well_number,
type=scaled_well_number if not skip_type else str,
)
sub_required_named_args.add_argument(
"-r",
Expand Down
4 changes: 2 additions & 2 deletions src/everest_models/jobs/fm_stea/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from everest_models.jobs.shared.arguments import add_lint_argument, get_parser


def build_argument_parser():
def build_argument_parser(skip_type=False):
description = (
"STEA is a powerful economic analysis tool used for complex economic "
"analysis and portfolio optimization. STEA helps you analyze single "
Expand All @@ -19,7 +19,7 @@ def build_argument_parser():
required_group.add_argument(
"-c",
"--config",
type=lambda value: stea.SteaInput(Path(value)),
type=lambda value: stea.SteaInput(Path(value)) if not skip_type else str,
help="STEA (yaml) config file",
required=True,
)
Expand Down
4 changes: 2 additions & 2 deletions src/everest_models/jobs/fm_strip_dates/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ def _valid_ecl_file(value: str):
return valid_ecl_summary(value), value


def build_argument_parser():
def build_argument_parser(skip_type=False):
description = (
"Makes sure a given summary file contains only report steps at the "
"list of dates given as an argument"
)
parser, required_group = get_parser(description=description)

add_summary_argument(required_group, func=_valid_ecl_file)
add_summary_argument(required_group, func=_valid_ecl_file, skip_type=skip_type)
add_lint_argument(parser)
parser.add_argument(
"-d",
Expand Down
Loading

0 comments on commit cb8a768

Please sign in to comment.