Skip to content

Commit

Permalink
Ignore erroneous auto-scale configuration, but warn
Browse files Browse the repository at this point in the history
  • Loading branch information
berland committed Nov 28, 2024
1 parent 55793cd commit fac0dd6
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 5 deletions.
16 changes: 12 additions & 4 deletions src/ert/analysis/_es_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,11 +349,19 @@ def _load_observations_and_responses(
)
)

scaling_factors_df = polars.concat(scaling_factors_dfs)
ensemble.save_observation_scaling_factors(scaling_factors_df)
if len(scaling_factors_dfs):
scaling_factors_df = polars.concat(scaling_factors_dfs)
ensemble.save_observation_scaling_factors(scaling_factors_df)

# Recompute with updated scales
scaled_errors = errors * scaling
# Recompute with updated scales
scaled_errors = errors * scaling
else:
msg = (
f"WARNING: Could not auto-scale the observations {auto_scale_observations}. "
f"No match with existing active observations {obs_keys}"
)
logger.warning(msg)
print(msg)

update_snapshot = []
for (
Expand Down
4 changes: 3 additions & 1 deletion test-data/ert/poly_example/poly.ert
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ RUNPATH poly_out/realization-<IENS>/iter-<ITER>
OBS_CONFIG observations
REALIZATION_MEMORY 50mb

NUM_REALIZATIONS 100
NUM_REALIZATIONS 10
MIN_REALIZATIONS 1

ANALYSIS_SET_VAR OBSERVATIONS AUTO_SCALE *_OBs

GEN_KW COEFFS coeff_priors
GEN_DATA POLY_RES RESULT_FILE:poly.out

Expand Down
29 changes: 29 additions & 0 deletions tests/ert/unit_tests/analysis/test_es_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,35 @@ def test_that_autoscaling_applies_to_scaled_errors(storage):
assert scaled_errors_without_autoscale.tolist() == [1, 2]


def test_that_autoscaling_ignores_typos_in_observation_names(storage, caplog):
observations_and_responses = polars.DataFrame(
{
"response_key": ["RESPONSE", "RESPONSE", "RESPONSE", "RESPONSE"],
"index": ["rs00", "rs0", "rs0", "rs1"],
"observation_key": ["obs1_1", "obs1_2", "obs2", "obs2"],
"observations": polars.Series([2, 4, 3, 3], dtype=polars.Float32),
"std": polars.Series([1, 2, 1, 1], dtype=polars.Float32),
"1": polars.Series([1, 4, 7, 8], dtype=polars.Float32),
}
)

experiment = storage.create_experiment(name="dummyexp")
ensemble = experiment.create_ensemble(name="dummy", ensemble_size=10)
_mock_load_observations_and_responses(
observations_and_responses,
alpha=1,
std_cutoff=0.05,
global_std_scaling=1,
auto_scale_observations=[["OOOPS1*"]],
progress_callback=lambda _: None,
ensemble=ensemble,
)
logged_messages = str(caplog.messages) # NB: The code also prints to the terminal
assert "Could not auto-scale the observations" in logged_messages
assert "OOPS" in logged_messages
assert "obs1_1" in logged_messages


@pytest.mark.integration_test
def test_gen_data_obs_data_mismatch(storage, uniform_parameter):
resp = GenDataConfig(keys=["RESPONSE"])
Expand Down

0 comments on commit fac0dd6

Please sign in to comment.