55import traceback
66from functools import cached_property
77from pathlib import Path
8- from typing import Any , ClassVar , TypedDict
8+ from typing import Any , ClassVar , TypedDict , cast
99from uuid import UUID
1010
1111import numpy as np
1212import polars as pl
1313from ropt .results import FunctionResults , GradientResults , Results
1414
15- from ert .config import EverestConstraintsConfig , EverestObjectivesConfig
15+ from ert .config import EverestObjectivesConfig
1616from ert .storage import LocalEnsemble , LocalExperiment , LocalStorage , open_storage
1717from ert .storage .local_ensemble import BatchDataframes
1818from everest .strings import EVEREST
@@ -25,8 +25,6 @@ def try_read_df(path: Path) -> pl.DataFrame | None:
2525
2626
2727class OptimizationDataframes (TypedDict , total = False ):
28- objective_functions : pl .DataFrame | None
29- nonlinear_constraints : pl .DataFrame | None
3028 realization_weights : pl .DataFrame | None
3129
3230
@@ -260,8 +258,6 @@ class _GradientResults(TypedDict):
260258
261259class EverestStorage :
262260 EXPERIMENT_DATAFRAMES : ClassVar [list [str ]] = [
263- "objective_functions" ,
264- "nonlinear_constraints" ,
265261 "realization_weights" ,
266262 ]
267263
@@ -319,8 +315,12 @@ def control_names(self) -> list[str]:
319315 return self .experiment .parameter_keys
320316
321317 @property
322- def objective_functions (self ) -> pl .DataFrame | None :
323- return pl .read_parquet (self .experiment ._path / "objective_functions.parquet" )
318+ def objective_functions (self ) -> EverestObjectivesConfig :
319+ objectives_config = self .experiment .response_configuration .get (
320+ "everest_objectives"
321+ )
322+ assert objectives_config is not None
323+ return cast (EverestObjectivesConfig , objectives_config )
324324
325325 @property
326326 def nonlinear_constraints (self ) -> list [str ]:
@@ -483,38 +483,8 @@ def batches(self) -> list[BatchStorageData]:
483483
484484 def init (
485485 self ,
486- objective_functions : EverestObjectivesConfig ,
487- output_constraints : EverestConstraintsConfig | None ,
488486 realizations : list [int ],
489487 ) -> None :
490- weights = np .fromiter (
491- (
492- 1.0 if weight is None else weight
493- for weight in objective_functions .weights
494- ),
495- dtype = np .float64 ,
496- )
497-
498- objective_functions_dataframe = pl .DataFrame (
499- {
500- "objective_name" : objective_functions .keys ,
501- "weight" : pl .Series (weights / sum (weights ), dtype = pl .Float64 ),
502- "scale" : pl .Series (
503- [
504- 1.0 if scale is None else scale
505- for scale in objective_functions .scales
506- ],
507- dtype = pl .Float64 ,
508- ),
509- }
510- )
511-
512- nonlinear_constraints = (
513- pl .DataFrame ({"constraint_name" : output_constraints .keys })
514- if output_constraints
515- else None
516- )
517-
518488 realization_weights = pl .DataFrame (
519489 {
520490 "realization" : pl .Series (realizations , dtype = pl .UInt32 ),
@@ -523,15 +493,9 @@ def init(
523493
524494 self .save_experiment_dataframes (
525495 dataframes = {
526- "objective_functions" : objective_functions_dataframe ,
527- "nonlinear_constraints" : nonlinear_constraints ,
528496 "realization_weights" : realization_weights , # Store in metadata
529497 },
530498 experiment_path = self .experiment ._path ,
531- # Note: Write storage is held by ERT runmodel, hence we need to bypass
532- # the read/write, this should/could be synced better up between ERT /
533- # everest storage. Ideally Everest would have its own "write" priviliege
534- # for dumping optimization results.
535499 )
536500
537501 @classmethod
0 commit comments