Skip to content

Commit ab5c86a

Browse files
committed
Fix smoother_update runmodels not using active realizations
This commit fixes the issue where all the run models using smoother_update would ignore the specified active realizations. (cherry picked from commit f361ca3)
1 parent 8972d42 commit ab5c86a

5 files changed

Lines changed: 15 additions & 1 deletion

File tree

src/ert/analysis/_es_update.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,13 +419,16 @@ def smoother_update(
419419
rng: np.random.Generator | None = None,
420420
progress_callback: Callable[[AnalysisEvent], None] | None = None,
421421
global_scaling: float = 1.0,
422+
active_realizations: list[bool] | None = None,
422423
) -> SmootherSnapshot:
423424
if not progress_callback:
424425
progress_callback = noop_progress_callback
425426
if rng is None:
426427
rng = np.random.default_rng()
427428

428429
ens_mask = prior_storage.get_realization_mask_with_responses()
430+
if active_realizations:
431+
ens_mask &= active_realizations
429432

430433
smoother_snapshot = SmootherSnapshot(
431434
source_ensemble_name=prior_storage.name,

src/ert/run_models/ensemble_smoother.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ def update_ensemble_parameters(
7878
prior.iteration,
7979
prior.id,
8080
),
81+
active_realizations=self.active_realizations,
8182
)
8283

8384
@classmethod

src/ert/run_models/manual_update.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ def update_ensemble_parameters(
5959
prior.iteration,
6060
prior.id,
6161
),
62+
active_realizations=self.active_realizations,
6263
)
6364

6465
@classmethod

src/ert/run_models/multiple_data_assimilation.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ def update_ensemble_parameters(
143143
prior.iteration,
144144
prior.id,
145145
),
146+
active_realizations=self.active_realizations,
146147
)
147148

148149
@staticmethod

tests/ert/unit_tests/analysis/test_es_update.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1175,6 +1175,8 @@ def test_gen_data_missing(storage, uniform_parameter, obs):
11751175

11761176
@pytest.mark.usefixtures("use_tmpdir")
11771177
def test_update_subset_parameters(storage, uniform_parameter, obs):
1178+
ensemble_size = 12 # We only want to update 0-9
1179+
active_realizations = [True] * 10 + [False] * 2
11781180
no_update_param = GenKwConfig(
11791181
name="EXTRA_PARAMETER",
11801182
forward_init=False,
@@ -1193,7 +1195,7 @@ def test_update_subset_parameters(storage, uniform_parameter, obs):
11931195
)
11941196
prior = storage.create_ensemble(
11951197
experiment,
1196-
ensemble_size=10,
1198+
ensemble_size=ensemble_size,
11971199
iteration=0,
11981200
name="prior",
11991201
)
@@ -1248,6 +1250,7 @@ def test_update_subset_parameters(storage, uniform_parameter, obs):
12481250
["PARAMETER"],
12491251
ObservationSettings(),
12501252
ESSettings(),
1253+
active_realizations=active_realizations,
12511254
)
12521255

12531256
assert (
@@ -1258,3 +1261,8 @@ def test_update_subset_parameters(storage, uniform_parameter, obs):
12581261
prior.load_parameters("PARAMETER", 0).rows()
12591262
!= posterior_ens.load_parameters("PARAMETER", 0).rows()
12601263
)
1264+
assert prior.ensemble_size == posterior_ens.ensemble_size
1265+
assert len(prior.load_parameters("PARAMETER")["realization"]) == ensemble_size
1266+
assert len(
1267+
posterior_ens.load_parameters("PARAMETER")["realization"]
1268+
) == active_realizations.count(True)

0 commit comments

Comments
 (0)