Skip to content

Commit f09754c

Browse files
committed
Consolidate ert parameters precision to 32bits
- Give a precision interval in test - update snapshots
1 parent 3a7b4e4 commit f09754c

File tree

20 files changed

+282
-272
lines changed

20 files changed

+282
-272
lines changed

src/ert/analysis/_es_update.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,8 @@ def adaptive_localization_progress_callback(
299299
np.fill_diagonal(T, T.diagonal() + 1)
300300

301301
def correlation_callback(
302-
cross_correlations_of_batch: npt.NDArray[np.float64],
303-
cross_correlations_accumulator: list[npt.NDArray[np.float64]],
302+
cross_correlations_of_batch: npt.NDArray[np.float32],
303+
cross_correlations_accumulator: list[npt.NDArray[np.float32]],
304304
) -> None:
305305
cross_correlations_accumulator.append(cross_correlations_of_batch)
306306

@@ -350,7 +350,7 @@ def correlation_callback(
350350
progress_callback(AnalysisStatusEvent(msg=log_msg))
351351

352352
start = time.time()
353-
cross_correlations: list[npt.NDArray[np.float64]] = []
353+
cross_correlations: list[npt.NDArray[np.float32]] = []
354354
for param_batch_idx in batches:
355355
update_idx = param_batch_idx[non_zero_variance_mask[param_batch_idx]]
356356
X_local = param_ensemble_array[update_idx, :]

src/ert/analysis/_update_commons.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def _auto_scale_observations(
9696
obs_mask: npt.NDArray[np.bool_],
9797
active_realizations: list[str],
9898
progress_callback: Callable[[AnalysisEvent], None],
99-
) -> tuple[npt.NDArray[np.float64], pl.DataFrame] | tuple[None, None]:
99+
) -> tuple[npt.NDArray[np.float32], pl.DataFrame] | tuple[None, None]:
100100
"""
101101
Performs 'Auto Scaling' to mitigate issues with correlated observations,
102102
and saves computed scaling factors across input groups to ERT storage.
@@ -328,7 +328,7 @@ class _OutlierColumns(StrEnum):
328328
def _all_parameters(
329329
ensemble: Ensemble,
330330
iens_active_index: npt.NDArray[np.int_],
331-
) -> npt.NDArray[np.float64]:
331+
) -> npt.NDArray[np.float32]:
332332
"""Return all parameters in assimilation problem"""
333333

334334
param_groups = list(ensemble.experiment.parameter_configuration.keys())

src/ert/analysis/misfit_preprocessor.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def get_scaling_factor(nr_observations: int, nr_components: int) -> float:
2929

3030

3131
def get_nr_primary_components(
32-
responses: npt.NDArray[np.float64], threshold: float
32+
responses: npt.NDArray[np.float32], threshold: float
3333
) -> int:
3434
"""
3535
Calculate the number of principal components required
@@ -61,7 +61,7 @@ def get_nr_primary_components(
6161

6262

6363
def cluster_responses(
64-
responses: npt.NDArray[np.float64],
64+
responses: npt.NDArray[np.float32],
6565
nr_clusters: int,
6666
) -> npt.NDArray[np.int_]:
6767
"""
@@ -70,7 +70,7 @@ def cluster_responses(
7070
be clustered together.
7171
"""
7272
correlation = spearmanr(responses).statistic
73-
if isinstance(correlation, np.float64):
73+
if isinstance(correlation, np.floating):
7474
correlation = np.array([[1, correlation], [correlation, 1]])
7575
# Take absolute value to cluster based on correlation strength rather
7676
# than direction.
@@ -84,9 +84,9 @@ def cluster_responses(
8484

8585

8686
def main(
87-
responses: npt.NDArray[np.float64],
88-
obs_errors: npt.NDArray[np.float64],
89-
) -> tuple[npt.NDArray[np.float64], npt.NDArray[np.int_], npt.NDArray[np.int_]]:
87+
responses: npt.NDArray[np.floating],
88+
obs_errors: npt.NDArray[np.floating],
89+
) -> tuple[npt.NDArray[np.floating], npt.NDArray[np.int_], npt.NDArray[np.int_]]:
9090
"""
9191
Perform 'Auto Scaling' to mitigate issues with correlated observations in ensemble
9292
smoothers.

src/ert/config/design_matrix.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,14 +391,14 @@ def convert_numeric_string_columns(df: pl.DataFrame) -> pl.DataFrame:
391391
for col, dtype in zip(df.columns, df.dtypes, strict=False):
392392
if dtype == pl.String:
393393
try:
394-
df = df.with_columns(pl.col(col).cast(pl.Int64, strict=True).alias(col))
394+
df = df.with_columns(pl.col(col).cast(pl.Int32, strict=True).alias(col))
395395
continue
396396
except InvalidOperationError:
397397
pass
398398

399399
try: # noqa: SIM105
400400
df = df.with_columns(
401-
pl.col(col).cast(pl.Float64, strict=True).alias(col)
401+
pl.col(col).cast(pl.Float32, strict=True).alias(col)
402402
)
403403
except InvalidOperationError:
404404
pass

src/ert/config/ext_param_config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def write_to_runpath(
7878

7979
def create_storage_datasets(
8080
self,
81-
from_data: npt.NDArray[np.float64],
81+
from_data: npt.NDArray[np.float32],
8282
iens_active_index: npt.NDArray[np.int_],
8383
) -> Iterator[tuple[int, xr.Dataset]]:
8484
for i, realization in enumerate(iens_active_index):
@@ -97,7 +97,7 @@ def create_storage_datasets(
9797

9898
def load_parameters(
9999
self, ensemble: Ensemble, realizations: npt.NDArray[np.int_]
100-
) -> npt.NDArray[np.float64]:
100+
) -> npt.NDArray[np.float32]:
101101
raise NotImplementedError
102102

103103
def load_parameter_graph(self) -> nx.Graph[int]:

src/ert/config/field.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ def write_to_runpath(
319319

320320
def create_storage_datasets(
321321
self,
322-
from_data: npt.NDArray[np.float64],
322+
from_data: npt.NDArray[np.float32],
323323
iens_active_index: npt.NDArray[np.int_],
324324
) -> Iterator[tuple[int, xr.Dataset]]:
325325
for i, realization in enumerate(iens_active_index):
@@ -336,7 +336,7 @@ def create_storage_datasets(
336336

337337
def load_parameters(
338338
self, ensemble: Ensemble, realizations: npt.NDArray[np.int_]
339-
) -> npt.NDArray[np.float64]:
339+
) -> npt.NDArray[np.float32]:
340340
ds = ensemble.load_parameters(self.name, realizations)
341341
assert isinstance(ds, xr.Dataset)
342342
ensemble_size = len(ds.realizations)

src/ert/config/gen_kw_config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ def write_to_runpath(
232232

233233
def load_parameters(
234234
self, ensemble: Ensemble, realizations: npt.NDArray[np.int_]
235-
) -> npt.NDArray[np.float64]:
235+
) -> npt.NDArray[np.float32]:
236236
return (
237237
ensemble.load_parameters(self.name, realizations)
238238
.drop("realization")
@@ -242,7 +242,7 @@ def load_parameters(
242242

243243
def create_storage_datasets(
244244
self,
245-
from_data: npt.NDArray[np.float64],
245+
from_data: npt.NDArray[np.float32],
246246
iens_active_index: npt.NDArray[np.int_],
247247
) -> Iterator[tuple[int | None, pl.DataFrame]]:
248248
yield (

src/ert/config/parameter_config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def write_to_runpath(
100100
@abstractmethod
101101
def create_storage_datasets(
102102
self,
103-
from_data: npt.NDArray[np.float64],
103+
from_data: npt.NDArray[np.float32],
104104
iens_active_index: npt.NDArray[np.int_],
105105
) -> Iterator[tuple[int | None, pl.DataFrame | xr.Dataset]]:
106106
"""
@@ -128,7 +128,7 @@ def copy_parameters(
128128
@abstractmethod
129129
def load_parameters(
130130
self, ensemble: Ensemble, realizations: npt.NDArray[np.int_]
131-
) -> npt.NDArray[np.float64]:
131+
) -> npt.NDArray[np.float32]:
132132
"""
133133
Load the parameter from internal storage for the given ensemble.
134134
Must return array of shape (number of parameters, number of realizations).

src/ert/config/surface_config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ def write_to_runpath(
199199

200200
def create_storage_datasets(
201201
self,
202-
from_data: npt.NDArray[np.float64],
202+
from_data: npt.NDArray[np.float32],
203203
iens_active_index: npt.NDArray[np.int_],
204204
) -> Iterator[tuple[int, xr.Dataset]]:
205205
for i, realization in enumerate(iens_active_index):
@@ -229,7 +229,7 @@ def create_storage_datasets(
229229

230230
def load_parameters(
231231
self, ensemble: Ensemble, realizations: npt.NDArray[np.int_]
232-
) -> npt.NDArray[np.float64]:
232+
) -> npt.NDArray[np.float32]:
233233
ds = ensemble.load_parameters(self.name, realizations)
234234
assert isinstance(ds, xr.Dataset)
235235
ensemble_size = len(ds.realizations)

src/ert/dark_storage/compute/misfits.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77

88
def _calculate_misfit(
9-
obs_value: npt.NDArray[np.float64],
10-
response_value: npt.NDArray[np.float64],
11-
obs_std: npt.NDArray[np.float64],
9+
obs_value: npt.NDArray[np.float32],
10+
response_value: npt.NDArray[np.float32],
11+
obs_std: npt.NDArray[np.float32],
1212
) -> list[float]:
1313
difference = response_value - obs_value
1414
misfit = (difference / obs_std) ** 2

0 commit comments

Comments
 (0)