11from __future__ import annotations
22
33import importlib
4- import json
54import logging
65from collections .abc import Iterator , Mapping , MutableMapping
7- from dataclasses import field
86from pathlib import Path
97from textwrap import dedent
108from typing import TYPE_CHECKING , Any , Literal , Self
1614from pydantic import BaseModel , ConfigDict , Field , model_validator
1715from ropt .workflow import find_sampler_plugin
1816
19- from ert .substitutions import substitute_runpath_name
20-
2117from .parameter_config import ParameterCardinality , ParameterConfig
2218
2319if TYPE_CHECKING :
@@ -144,37 +140,38 @@ def validate_backend_and_method(self) -> Self:
144140
145141
146142class EverestControl (ParameterConfig ):
147- """Create an EverestControl for @key with the given @input_keys
143+ """Create an EverestControl for a single control variable.
148144
149- @input_keys can be either a list of keys as strings or a dict with
150- keys as strings and a list of suffixes for each key.
151- If a list of strings is given, the order is preserved.
145+ Each EverestControl represents one scalar value. Multiple controls can
146+ share the same group name to indicate they belong to the same logical group.
152147 """
153148
154149 type : Literal ["everest_parameters" ] = "everest_parameters"
155- input_keys : list [str ] = field (default_factory = list )
150+ dimensionality : Literal [1 ] = 1
151+ input_key : str
156152 forward_init : bool = False
157153 output_file : str = ""
158154 forward_init_file : str = ""
159155 update : bool = False
160- types : list [Literal ["well_control" , "generic_control" ]]
161- initial_guesses : list [float ]
162- control_types : list [Literal ["real" , "integer" ]]
163- enabled : list [bool ]
164- min : list [float ]
165- max : list [float ]
166- perturbation_types : list [Literal ["absolute" , "relative" ]]
167- perturbation_magnitudes : list [float ]
168- scaled_ranges : list [tuple [float , float ]]
169- samplers : list [SamplerConfig | None ]
156+ control_type_ : Literal ["well_control" , "generic_control" ]
157+ initial_guess : float
158+ control_type : Literal ["real" , "integer" ]
159+ enabled : bool
160+ min : float
161+ max : float
162+ perturbation_type : Literal ["absolute" , "relative" ]
163+ perturbation_magnitude : float
164+ scaled_range : tuple [float , float ]
165+ sampler : SamplerConfig | None
166+ group : str
170167
171168 # Set up for deprecation, but has to live here until support for the
172169 # "dotdash" notation is removed for everest controls via everest config.
173- input_keys_dotdash : list [ str ] = field ( default_factory = list )
170+ input_key_dotdash : str = ""
174171
175172 @property
176173 def parameter_keys (self ) -> list [str ]:
177- return self .input_keys
174+ return [ self .input_key ]
178175
179176 @property
180177 def cardinality (self ) -> ParameterCardinality :
@@ -194,31 +191,12 @@ def load_parameter_graph(self) -> nx.Graph[int]:
194191 raise NotImplementedError
195192
196193 def __len__ (self ) -> int :
197- return len ( self . input_keys )
194+ return 1
198195
199196 def write_to_runpath (
200197 self , run_path : Path , real_nr : int , ensemble : Ensemble
201- ) -> None :
202- file_path : Path = run_path / substitute_runpath_name (
203- self .output_file , real_nr , ensemble .iteration
204- )
205- Path .mkdir (file_path .parent , exist_ok = True , parents = True )
206-
207- data : dict [str , Any ] = {}
208- df = ensemble .load_parameters (self .name , real_nr )
209- assert isinstance (df , pl .DataFrame )
210- df = df .drop ("realization" )
211- df = df .rename ({col : col .replace (f"{ self .name } ." , "" , 1 ) for col in df .columns })
212- for c in df .columns :
213- if "." in c :
214- top_key , sub_key = c .split ("." , 1 )
215- if top_key not in data :
216- data [top_key ] = {}
217- data [top_key ][sub_key ] = df [c ].item ()
218- else :
219- data [c ] = df [c ].item ()
220-
221- file_path .write_text (json .dumps (data ), encoding = "utf-8" )
198+ ) -> dict [str , dict [str , float | str ]] | None :
199+ raise NotImplementedError
222200
223201 def create_storage_datasets (
224202 self ,
@@ -228,7 +206,7 @@ def create_storage_datasets(
228206 df = pl .DataFrame (
229207 {
230208 "realization" : iens_active_index ,
231- ** { k : from_data [:, i ] for i , k in enumerate ( self . parameter_keys )} ,
209+ self . input_key : pl . Series ( from_data . flatten ()) ,
232210 },
233211 strict = False ,
234212 )
0 commit comments