Skip to content

Commit

Permalink
Time loading and writing during update
Browse files Browse the repository at this point in the history
  • Loading branch information
Feda Curic authored and dafeda committed Jun 13, 2023
1 parent b2b3dc5 commit 14baf1a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/ert/_c_wrappers/analysis/analysis_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,8 @@ def set_var(self, var_name: str, value: Union[float, int, bool, str]):

except ValueError:
raise ConfigValidationError(
f"Variable {var_name!r} with value {value!r} has incorrect type."
f"Variable {var_name!r} with value {value!r} has "
f"incorrect type."
f" Expected type {var['type'].__name__!r} but received"
f" value {value!r} of type {type(value).__name__!r}"
)
Expand Down
27 changes: 21 additions & 6 deletions src/ert/analysis/_es_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from dataclasses import dataclass, field
from math import sqrt
from pathlib import Path
from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Tuple
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Tuple, Callable

import iterative_ensemble_smoother as ies
import numpy as np
Expand Down Expand Up @@ -369,9 +369,13 @@ def analysis_ES(
iens_active_index = [i for i in range(len(ens_mask)) if ens_mask[i]]

progress_callback(Progress(Task("Loading data", 1, 3), None))
start = time.time()
temp_storage = _create_temporary_parameter_storage(
source_fs, ensemble_config, iens_active_index
)
end = time.time()
elapsed = end - start
print(f"Time to run _create_temporary_parameter_storage: {elapsed}")

ensemble_size = sum(ens_mask)
param_ensemble = _param_ensemble_for_projection(
Expand All @@ -383,8 +387,9 @@ def analysis_ES(
truncation = module.get_truncation()
# Looping over local analysis update_step
for update_step in updatestep:
print("Loading responses and observations...")
start = time.time()
try:
print("Loading responses and observations...")
Y, (
observation_values,
observation_errors,
Expand All @@ -400,6 +405,9 @@ def analysis_ES(
)
except IndexError as e:
raise ErtAnalysisError(e) from e
end = time.time()
elapsed = end - start
print(f"Time to run _load_observations_and_responses: {elapsed}")

# pylint: disable=unsupported-assignment-operation
smoother_snapshot.update_step_snapshots[update_step.name] = update_snapshot
Expand Down Expand Up @@ -446,14 +454,17 @@ def analysis_ES(
np.linalg.inv(Sigma_A) @ C_AY @ np.linalg.inv(Sigma_Y)
)
c_bool = c_AY > correlation_threshold
# Some parameters might be significantly correlated to the exact same
# responses, making up what we call a `parameter group``.
# Some parameters might be significantly correlated
# to the exact same responses,
# making up what we call a `parameter group``.
# We want to call the update only once per such parameter group
# to speed up computation.
param_groups = np.unique(c_bool, axis=0)

# Drop the parameter group that does not correlate to any responses.
row_with_all_false = np.all(param_groups == False, axis=1)
row_with_all_false = np.all(
param_groups == False, axis=1
) # noqa: E712, E501
param_groups = param_groups[~row_with_all_false]

for grp in param_groups:
Expand Down Expand Up @@ -519,9 +530,13 @@ def analysis_ES(
_save_to_temporary_storage(temp_storage, [parameter], A)

progress_callback(Progress(Task("Storing data", 3, 3), None))
start = time.time()
_save_temporary_storage_to_disk(
target_fs, ensemble_config, temp_storage, iens_active_index
)
end = time.time()
elapsed = end - start
print(f"Time to run _save_temporary_storage_to_disk: {elapsed}")


def analysis_IES(
Expand Down Expand Up @@ -581,7 +596,7 @@ def analysis_IES(
f"No active observations for update step: {update_step.name}."
)

noise = rng.standard_normal(size=(len(observation_values), S.shape[1]))
noise = rng.standard_normal(size=(len(observation_values), Y.shape[1]))
for parameter in update_step.parameters:
iterative_ensemble_smoother.fit(
Y,
Expand Down

0 comments on commit 14baf1a

Please sign in to comment.