Skip to content

Commit 36250ff

Browse files
authored
Remove EverestDataAPI and is_improvement flag from everest storage (#14084)
* Remove unused EverestDataApi * Remove is_improvement flag from everest storage * Move utilities to utils.py
1 parent 62af0fd commit 36250ff

9 files changed

Lines changed: 41 additions & 650 deletions

File tree

src/ert/dark_storage/endpoints/responses.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
serialize_dataframe_to_response,
2020
)
2121
from ert.storage import Ensemble, Storage
22+
from everest.config.utils import CONSTRAINT_TOLERANCE, constraint_violation_check
2223

2324
router = APIRouter(tags=["responses"])
2425
logger = logging.getLogger(__name__)
@@ -160,12 +161,6 @@ def data_for_response(
160161
if ensemble.batch_objectives is None:
161162
return pd.DataFrame()
162163

163-
def constraint_violation_check(violation: pl.DataFrame | None) -> float:
164-
if violation is None:
165-
return 0.0
166-
return violation.drop("batch_id").to_numpy().max().item()
167-
168-
CONSTRAINT_TOL = 1e-6
169164
accepted_batches: list[tuple[Ensemble, float]] = []
170165
rejected_batches_with_value_and_reason: list[
171166
tuple[Ensemble, float, RejectionReason]
@@ -196,7 +191,7 @@ def constraint_violation_check(violation: pl.DataFrame | None) -> float:
196191
input_violation,
197192
output_violation,
198193
)
199-
< CONSTRAINT_TOL
194+
< CONSTRAINT_TOLERANCE
200195
and total_objective < max_total_objective
201196
):
202197
accepted_batches.append(

src/ert/run_models/everest_run_model.py

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,6 @@ def _handle_optimizer_results(self, results: tuple[Results, ...]) -> None:
624624
for batch_id, batch_dict in batch_dataframes.items():
625625
target_ensemble = self._experiment.get_ensemble_by_name(f"batch_{batch_id}")
626626
target_ensemble.save_batch_dataframes(dataframes=batch_dict)
627-
target_ensemble.update_improvement_flag(is_improvement=False)
628627

629628
for r in results:
630629
batches = (
@@ -753,59 +752,6 @@ def objectives_config(self) -> EverestObjectivesConfig:
753752
assert isinstance(obj_config, EverestObjectivesConfig)
754753
return obj_config
755754

756-
def _update_ensemble_improvement_flags(self) -> None:
757-
assert self._experiment is not None
758-
759-
# This a somewhat arbitrary threshold, this should be a user choice
760-
# during visualization:
761-
CONSTRAINT_TOL = 1e-6
762-
763-
max_total_objective = np.inf
764-
for ensemble in self._experiment.ensembles_with_function_results:
765-
assert ensemble.batch_objectives is not None
766-
total_objective = ensemble.batch_objectives["total_objective_value"].item()
767-
bound_constraint_violation = (
768-
0.0
769-
if ensemble.batch_bound_constraint_violations is None
770-
else (
771-
ensemble.batch_bound_constraint_violations.drop("batch_id")
772-
.to_numpy()
773-
.max()
774-
.item()
775-
)
776-
)
777-
input_constraint_violation = (
778-
0.0
779-
if ensemble.batch_input_constraint_violations is None
780-
else (
781-
ensemble.batch_input_constraint_violations.drop("batch_id")
782-
.to_numpy()
783-
.max()
784-
.item()
785-
)
786-
)
787-
output_constraint_violation = (
788-
0.0
789-
if ensemble.batch_output_constraint_violations is None
790-
else (
791-
ensemble.batch_output_constraint_violations.drop("batch_id")
792-
.to_numpy()
793-
.max()
794-
.item()
795-
)
796-
)
797-
if (
798-
max(
799-
bound_constraint_violation,
800-
input_constraint_violation,
801-
output_constraint_violation,
802-
)
803-
< CONSTRAINT_TOL
804-
and total_objective < max_total_objective
805-
):
806-
ensemble.update_improvement_flag(is_improvement=True)
807-
max_total_objective = total_objective
808-
809755
def _create_experiment_storage(self) -> LocalExperiment:
810756
return self._storage.create_experiment(
811757
name=self.experiment_name, experiment_config=self.to_experiment_config()
@@ -836,8 +782,6 @@ def run_experiment(
836782
# Run the optimization:
837783
optimizer_exit_code = optimizer.run(initial_guesses)
838784

839-
# Store some final results.
840-
self._update_ensemble_improvement_flags()
841785
if (
842786
optimizer_exit_code is not RoptExitCode.UNKNOWN
843787
and optimizer_exit_code is not RoptExitCode.TOO_FEW_REALIZATIONS

src/ert/storage/local_ensemble.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ class _Index(BaseModel, extra="forbid"):
101101
prior_ensemble_id: UUID | None
102102
started_at: datetime
103103
everest_realization_info: dict[int, EverestRealizationInfo] | None = None
104-
is_improvement: bool | None = None
105104

106105

107106
class _Failure(BaseModel, extra="forbid"):
@@ -1727,17 +1726,6 @@ def perturbation_constraints(self) -> pl.DataFrame | None:
17271726
)
17281727
)
17291728

1730-
@property
1731-
def is_improvement(self) -> bool:
1732-
return bool(self._index.is_improvement)
1733-
1734-
def update_improvement_flag(self, is_improvement: bool) -> None:
1735-
self._index.is_improvement = is_improvement
1736-
self._storage._write_transaction(
1737-
self._path / "index.json",
1738-
self._index.model_dump_json(indent=2).encode("utf-8"),
1739-
)
1740-
17411729
def load_all_misfit_data(self) -> pl.DataFrame:
17421730
"""Loads all misfit data for a given ensemble.
17431731

src/everest/api/__init__.py

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)