From dec3eea5f5d563092a33821dea85fc9a3ebba00f Mon Sep 17 00:00:00 2001 From: Feda Curic Date: Fri, 10 Mar 2023 10:50:41 +0100 Subject: [PATCH] Add temporary test --- src/ert/analysis/_es_update.py | 14 ++++++------- test-data/poly_example/poly_loc.ert | 22 ++++++++++++++++++++ test-data/poly_example/poly_loc_1.ert | 23 +++++++++++++++++++++ test-data/poly_example/poly_no_loc.ert | 20 ++++++++++++++++++ test-data/poly_example/poly_zero_loc.ert | 23 +++++++++++++++++++++ test-data/poly_example/test_localization.sh | 9 ++++++++ 6 files changed, 103 insertions(+), 8 deletions(-) create mode 100644 test-data/poly_example/poly_loc.ert create mode 100644 test-data/poly_example/poly_loc_1.ert create mode 100644 test-data/poly_example/poly_no_loc.ert create mode 100644 test-data/poly_example/poly_zero_loc.ert create mode 100644 test-data/poly_example/test_localization.sh diff --git a/src/ert/analysis/_es_update.py b/src/ert/analysis/_es_update.py index 4e1f8665b11..4d72c885246 100644 --- a/src/ert/analysis/_es_update.py +++ b/src/ert/analysis/_es_update.py @@ -423,7 +423,7 @@ def analysis_ES( Sigma_Y = np.diag(np.sqrt(np.diag(C_YY))) batch_size = 1000 for parameter in update_step.parameters: - num_params = len(parameter) + num_params = temp_storage[parameter.name].shape[0] correlation_threshold = module.localization_correlation_threshold( ensemble_size ) @@ -438,14 +438,9 @@ def analysis_ES( for param_batch_idx in tqdm(batches): X_local = temp_storage[parameter.name][param_batch_idx, :] A = X_local - X_local.mean(axis=1, keepdims=True) - # A_prime = A[param_batch_idx, :] - A[param_batch_idx, :].mean( - # axis=1, keepdims=True - # ) - # C_AA = A_prime @ A_prime.T / (ensemble_size - 1) C_AA = A @ A.T / (ensemble_size - 1) # State-measurement covariance matrix - # C_AY = A_prime @ Y_prime.T / (ensemble_size - 1) C_AY = A @ Y_prime.T / (ensemble_size - 1) Sigma_A = np.diag(np.sqrt(np.diag(C_AA))) @@ -454,6 +449,10 @@ 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 cann 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) for grp in param_groups: @@ -475,10 +474,9 @@ def analysis_ES( inversion=ies.InversionType(module.inversion), param_ensemble=param_ensemble, ) - # A[param_batch_idx[param_idx], :] = smoother.update(A_chunk) temp_storage[parameter.name][ param_batch_idx[param_idx], : - ] = smoother.udpate(X_chunk) + ] = smoother.update(X_chunk) else: for parameter in update_step.parameters: smoother.fit( diff --git a/test-data/poly_example/poly_loc.ert b/test-data/poly_example/poly_loc.ert new file mode 100644 index 00000000000..d0348521e89 --- /dev/null +++ b/test-data/poly_example/poly_loc.ert @@ -0,0 +1,22 @@ +JOBNAME poly_%d + +RANDOM_SEED 1234 + +QUEUE_SYSTEM LOCAL +QUEUE_OPTION LOCAL MAX_RUNNING 50 + +RUNPATH runpath/es_loc/realization-/iter- + +ANALYSIS_SET_VAR STD_ENKF LOCALIZATION True + +OBS_CONFIG observations +TIME_MAP time_map + +NUM_REALIZATIONS 100 +MIN_REALIZATIONS 1 + +GEN_KW COEFFS coeff.tmpl coeffs.json coeff_priors +GEN_DATA POLY_RES RESULT_FILE:poly_%d.out REPORT_STEPS:0 INPUT_FORMAT:ASCII + +INSTALL_JOB poly_eval POLY_EVAL +SIMULATION_JOB poly_eval diff --git a/test-data/poly_example/poly_loc_1.ert b/test-data/poly_example/poly_loc_1.ert new file mode 100644 index 00000000000..6936037b73b --- /dev/null +++ b/test-data/poly_example/poly_loc_1.ert @@ -0,0 +1,23 @@ +JOBNAME poly_%d + +RANDOM_SEED 1234 + +QUEUE_SYSTEM LOCAL +QUEUE_OPTION LOCAL MAX_RUNNING 50 + +RUNPATH runpath/es_loc_1/realization-/iter- + +ANALYSIS_SET_VAR STD_ENKF LOCALIZATION True +ANALYSIS_SET_VAR STD_ENKF LOCALIZATION_CORRELATION_THRESHOLD 1.0 + +OBS_CONFIG observations +TIME_MAP time_map + +NUM_REALIZATIONS 100 +MIN_REALIZATIONS 1 + +GEN_KW COEFFS coeff.tmpl coeffs.json coeff_priors +GEN_DATA POLY_RES RESULT_FILE:poly_%d.out REPORT_STEPS:0 INPUT_FORMAT:ASCII + +INSTALL_JOB poly_eval POLY_EVAL +SIMULATION_JOB poly_eval diff --git a/test-data/poly_example/poly_no_loc.ert b/test-data/poly_example/poly_no_loc.ert new file mode 100644 index 00000000000..884adfdaccf --- /dev/null +++ b/test-data/poly_example/poly_no_loc.ert @@ -0,0 +1,20 @@ +JOBNAME poly_%d + +RANDOM_SEED 1234 + +QUEUE_SYSTEM LOCAL +QUEUE_OPTION LOCAL MAX_RUNNING 50 + +RUNPATH runpath/es_no_loc/realization-/iter- + +OBS_CONFIG observations +TIME_MAP time_map + +NUM_REALIZATIONS 100 +MIN_REALIZATIONS 1 + +GEN_KW COEFFS coeff.tmpl coeffs.json coeff_priors +GEN_DATA POLY_RES RESULT_FILE:poly_%d.out REPORT_STEPS:0 INPUT_FORMAT:ASCII + +INSTALL_JOB poly_eval POLY_EVAL +SIMULATION_JOB poly_eval diff --git a/test-data/poly_example/poly_zero_loc.ert b/test-data/poly_example/poly_zero_loc.ert new file mode 100644 index 00000000000..9dcd57ddf70 --- /dev/null +++ b/test-data/poly_example/poly_zero_loc.ert @@ -0,0 +1,23 @@ +JOBNAME poly_%d + +RANDOM_SEED 1234 + +QUEUE_SYSTEM LOCAL +QUEUE_OPTION LOCAL MAX_RUNNING 50 + +RUNPATH runpath/es_zero_loc/realization-/iter- + +ANALYSIS_SET_VAR STD_ENKF LOCALIZATION True +ANALYSIS_SET_VAR STD_ENKF LOCALIZATION_CORRELATION_THRESHOLD 0.0 + +OBS_CONFIG observations +TIME_MAP time_map + +NUM_REALIZATIONS 100 +MIN_REALIZATIONS 1 + +GEN_KW COEFFS coeff.tmpl coeffs.json coeff_priors +GEN_DATA POLY_RES RESULT_FILE:poly_%d.out REPORT_STEPS:0 INPUT_FORMAT:ASCII + +INSTALL_JOB poly_eval POLY_EVAL +SIMULATION_JOB poly_eval diff --git a/test-data/poly_example/test_localization.sh b/test-data/poly_example/test_localization.sh new file mode 100644 index 00000000000..3f04a258692 --- /dev/null +++ b/test-data/poly_example/test_localization.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +ert ensemble_smoother poly_no_loc.ert --target ES_no_loc + +ert ensemble_smoother poly_zero_loc.ert --target ES_zero_loc + +ert ensemble_smoother poly_loc.ert --target ES_loc + +ert ensemble_smoother poly_loc_1.ert --target ES_loc_1