Skip to content

Conversation

@oddvarlia
Copy link
Collaborator

@oddvarlia oddvarlia commented Dec 6, 2025

Function to update 3D field parameters with the method implemented in DistanceESMDA for ensemble smoother with
distance-based localization

Linked to: #12406

Approach
A 3D field parameter can often not be update in one go due to large memory requirements due to the Kalman gain matrix K and the localization matrix RHO. To handle this the field parameter can be split into subsets or batches. Each batch should be a set of layers of field parameter values defined in the field parameter grid (ertbox grid). Each batch must consists of a complete set of layers, not subset of layers of field parameters. The main reason for processing the update by batches of layers of field parameters is that the calculation of scaling factors (elements in the RHO matrix) can be done layer by layer due to the assumption that only lateral distance is of importance in the definition of influence of an observation, hence the calculation of RHO is done for one layer and then copied to all the other layers of the ertbox grid.

@oddvarlia oddvarlia marked this pull request as draft December 6, 2025 10:16
@oddvarlia oddvarlia changed the title Added function to update 3D field parameter with ensemble smoother wi… Update 3D field parameter with ensemble smoother with distance-based localization Dec 6, 2025
@oddvarlia oddvarlia force-pushed the distance_based_batch_update branch 2 times, most recently from 1554bb7 to 36554db Compare December 6, 2025 19:50
@codecov-commenter
Copy link

codecov-commenter commented Dec 6, 2025

Codecov Report

❌ Patch coverage is 94.11765% with 16 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.67%. Comparing base (c528c39) to head (0587269).

Files with missing lines Patch % Lines
src/ert/analysis/_es_update.py 93.49% 16 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #12469      +/-   ##
==========================================
- Coverage   90.67%   90.67%   -0.01%     
==========================================
  Files         429      429              
  Lines       29803    30073     +270     
==========================================
+ Hits        27025    27268     +243     
- Misses       2778     2805      +27     
Flag Coverage Δ
cli-tests 37.24% <6.98%> (-0.33%) ⬇️
gui-tests 68.70% <6.98%> (-0.71%) ⬇️
performance-and-unit-tests 74.09% <94.11%> (+0.16%) ⬆️
test 37.79% <6.98%> (-0.29%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@xjules xjules added this to SCOUT Dec 8, 2025
@xjules xjules moved this to In Progress in SCOUT Dec 8, 2025
@oddvarlia oddvarlia force-pushed the distance_based_batch_update branch 9 times, most recently from b52aa01 to a9c9709 Compare December 12, 2025 10:10
@oddvarlia oddvarlia force-pushed the distance_based_batch_update branch 4 times, most recently from 568900f to 3d044e4 Compare December 20, 2025 09:49
@oddvarlia oddvarlia force-pushed the distance_based_batch_update branch 7 times, most recently from e4b0c6f to 8f14437 Compare January 6, 2026 18:46
@oddvarlia oddvarlia removed the status in SCOUT Jan 7, 2026
@oddvarlia oddvarlia moved this to In Progress in SCOUT Jan 7, 2026
@oddvarlia oddvarlia force-pushed the distance_based_batch_update branch from 8f14437 to 9f42875 Compare January 7, 2026 12:26
@oddvarlia oddvarlia force-pushed the distance_based_batch_update branch 4 times, most recently from 872cdac to fa9fee8 Compare January 11, 2026 21:33
@xjules
Copy link
Contributor

xjules commented Jan 12, 2026

Let's have a meeting on the snapshots since this might be cumbersome to maintain. We should get to use hypothesis library instead and implement property based testing instead.

@oddvarlia oddvarlia force-pushed the distance_based_batch_update branch 14 times, most recently from 799157d to 5471426 Compare January 16, 2026 09:45
@codspeed-hq
Copy link

codspeed-hq bot commented Jan 16, 2026

Merging this PR will not alter performance

✅ 22 untouched benchmarks


Comparing oddvarlia:distance_based_batch_update (0587269) with main (c528c39)

Open in CodSpeed

@oddvarlia oddvarlia force-pushed the distance_based_batch_update branch 2 times, most recently from 0587269 to 0bd1029 Compare January 19, 2026 10:05
… 3D fields

Added functions:
- update_3D_field_with_distance_esmda
- update_2D_field_with_distance_esmda
- _calc_max_number_of_layers_per_batch_for_distance_localization
- adjust_inactive_field_values_to_match_average_of_active_field_values
- define_active_matrix_for_initial_ensemble

The function 'update_3D_field_with_distance_esmda' will update one 3D field parameter using the algorithm
implemented in class DistanceESMDA in repo iterative_ensemble_smoother. This function requires that
an object of DistanceESMDA is input. It will split the field parameter in batches when necessary due to memory
constraints. The function 'update_2D_field_with_distance_esmda' will update a 2D field (surface parameter),
but in this case no split into batches. Failure will be thrown if 2D field is too large to be updated.

The function '_calc_max_number_of_layers_per_batch_for_distance_localization' calculates the max
size of a batch of field parameter values within the limit of available memory.

The function ' adjust_inactive_field_values_to_match_average_of_active_field_values' is used to
ensure that ensemble average is not influenced by extrapolated values of inactive field parameters.
Is used to set field parameter values equal to ensemble average if they corresponds to realizations
where the geomodel grid cell is inactive.

The function define_active_matrix_for_initial_ensemble will create a (nparam, nreal) sized matrix
with bool variables to defined which realization for which field parameters are used (active) and which one
are not used in the prior ensemble since it does not exist in the geomodel from which the field parameter
originate.

update pyproject.toml  to include gaussianfft to be used in tests
@oddvarlia oddvarlia force-pushed the distance_based_batch_update branch from 0bd1029 to a464ab2 Compare January 19, 2026 11:06
@oddvarlia oddvarlia moved this from In Progress to Ready for Review in SCOUT Jan 19, 2026
@oddvarlia oddvarlia requested a review from xjules January 19, 2026 11:54
@oddvarlia oddvarlia force-pushed the distance_based_batch_update branch from 999445a to 01ed347 Compare January 19, 2026 12:00
# The output here is for visual inspection of the result
# and is not output in automatic test runs, but can be
# used in manual inspection of the results from the update.
write_mean_stdev_to_files(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's remove this output functions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Ready for Review

Development

Successfully merging this pull request may close these issues.

3 participants