Skip to content

Commit

Permalink
f
Browse files Browse the repository at this point in the history
  • Loading branch information
verveerpj committed Dec 18, 2024
1 parent 9d69516 commit 9ed17dc
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions src/ert/run_models/everest_run_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@
from .base_run_model import BaseRunModel, StatusEvents

if TYPE_CHECKING:
import numpy.typing as npt

from ert.storage import Ensemble, Experiment


Expand Down Expand Up @@ -105,7 +103,6 @@ def __init__(
everest_config: EverestConfig,
simulation_callback: SimulationCallback,
optimization_callback: OptimizerCallback,
display_all_jobs: bool = True,
):
Path(everest_config.log_dir).mkdir(parents=True, exist_ok=True)
Path(everest_config.optimization_output_dir).mkdir(parents=True, exist_ok=True)
Expand All @@ -126,7 +123,6 @@ def __init__(
self._sim_callback = simulation_callback
self._opt_callback = optimization_callback
self._fm_errors: dict[int, dict[str, Any]] = {}
self._display_all_jobs = display_all_jobs
self._result: OptimalResult | None = None
self._exit_code: EverestExitCode | None = None
self._evaluator_cache: _EvaluatorCache | None = (
Expand All @@ -152,8 +148,6 @@ def __init__(
active_realizations=[], # Set dynamically in run_forward_model()
)

self.num_retries_per_iter = 0 # OK?

@classmethod
def create(
cls,
Expand Down Expand Up @@ -232,7 +226,7 @@ def run_experiment(
)

if self._exit_code is None:
self._exit_code = self._get_exit_code(optimizer_exit_code)
self._exit_code = self._get_everest_exit_code(optimizer_exit_code)

def _create_optimizer(self) -> BasicOptimizer:
RESULT_COLUMNS = {
Expand Down Expand Up @@ -334,7 +328,9 @@ def _create_optimizer(self) -> BasicOptimizer:

return optimizer

def _get_exit_code(self, optimizer_exit_code: OptimizerExitCode) -> EverestExitCode:
def _get_everest_exit_code(
self, optimizer_exit_code: OptimizerExitCode
) -> EverestExitCode:
match optimizer_exit_code:
case OptimizerExitCode.MAX_FUNCTIONS_REACHED:
return EverestExitCode.MAX_FUNCTIONS_REACHED
Expand Down Expand Up @@ -610,8 +606,8 @@ def onerror(

def _gather_results(
self, ensemble: Ensemble
) -> list[dict[str, npt.NDArray[np.float64]]]:
results: list[dict[str, npt.NDArray[np.float64]]] = []
) -> list[dict[str, NDArray[np.float64]]]:
results: list[dict[str, NDArray[np.float64]]] = []
for sim_id, successful in enumerate(self.active_realizations):
if not successful:
logger.error(f"Simulation {sim_id} failed.")
Expand All @@ -632,7 +628,7 @@ def _get_evaluator_result(
control_values: NDArray[np.float64],
evaluator_context: EvaluatorContext,
case_data: dict[int, Any],
results: list[dict[str, npt.NDArray[np.float64]]],
results: list[dict[str, NDArray[np.float64]]],
cached_results: dict[int, Any],
) -> EvaluatorResult:
# We minimize the negative of the objectives:
Expand Down Expand Up @@ -800,7 +796,7 @@ def add(

def get(
self, realization_id: int, controls: NDArray[np.float64]
) -> tuple[Any, ...] | None:
) -> tuple[NDArray[np.float64], NDArray[np.float64] | None] | None:
for control_values, objectives, constraints in self._data.get(
realization_id, []
):
Expand Down

0 comments on commit 9ed17dc

Please sign in to comment.