Skip to content

Make restart on ES_MDA work with changed ensamble size#12909

Open
erlenlh wants to merge 1 commit intomainfrom
Fix_restart_ESMDA_when_size_change
Open

Make restart on ES_MDA work with changed ensamble size#12909
erlenlh wants to merge 1 commit intomainfrom
Fix_restart_ESMDA_when_size_change

Conversation

@erlenlh
Copy link
Contributor

@erlenlh erlenlh commented Feb 17, 2026

Issue
Resolves #12180

Approach
Created a function for re-mapping lists into sets, finding common indices and converting back to list for further processing. Comparing sets eliminates the problem of different length lists.

(Screenshot of new behavior in GUI if applicable)

  • PR title captures the intent of the changes, and is fitting for release notes.
  • Added appropriate release note label
  • Commit history is consistent and clean, in line with the contribution guidelines.
  • Make sure unit tests pass locally after every commit (git rebase -i main --exec 'just rapid-tests')

When applicable

  • When there are user facing changes: Updated documentation
  • New behavior or changes to existing untested code: Ensured that unit tests are added (See Ground Rules).
  • Large PR: Prepare changes in small commits for more convenient review
  • Bug fix: Add regression test for the bug
  • Bug fix: Add backport label to latest release (format: 'backport release-branch-name')

@codecov-commenter
Copy link

codecov-commenter commented Feb 17, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.15%. Comparing base (3cbbcc9) to head (af2c778).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #12909      +/-   ##
==========================================
- Coverage   90.16%   90.15%   -0.01%     
==========================================
  Files         447      447              
  Lines       31057    31071      +14     
==========================================
+ Hits        28002    28012      +10     
- Misses       3055     3059       +4     
Flag Coverage Δ
cli-tests 36.86% <75.00%> (+0.01%) ⬆️
gui-tests 67.54% <68.75%> (-0.04%) ⬇️
performance-and-unit-tests 76.84% <100.00%> (-0.01%) ⬇️
test 45.98% <6.25%> (-0.02%) ⬇️

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.

@erlenlh erlenlh force-pushed the Fix_restart_ESMDA_when_size_change branch from 0799376 to 02132c9 Compare February 18, 2026 10:56
@codspeed-hq
Copy link

codspeed-hq bot commented Feb 18, 2026

Merging this PR will not alter performance

✅ 35 untouched benchmarks


Comparing Fix_restart_ESMDA_when_size_change (af2c778) with main (3cbbcc9)

Open in CodSpeed

@erlenlh erlenlh force-pushed the Fix_restart_ESMDA_when_size_change branch from 02132c9 to 3f3d66d Compare February 19, 2026 08:00
@jonathan-eq
Copy link
Contributor

Does this solve the issue? I think we need a larger gui test where we run ert with design_matrix realization 0-9, close ert and remove realization 8 and 9 from design matrix, open ert and try "Restart run" from the previous run.
I thought the issue was that the validator uses the ensemble_size from config/design_matrix on "restart from", instead of what was actually used in the run that we are restarting from 🤔

@jonathan-eq
Copy link
Contributor

There should already be an integration test that you can backpack off, otherwise I can help you get started :)

@xjules
Copy link
Contributor

xjules commented Feb 19, 2026

Does this solve the issue? I think we need a larger gui test where we run ert with design_matrix realization 0-9, close ert and remove realization 8 and 9 from design matrix, open ert and try "Restart run" from the previous run. I thought the issue was that the validator uses the ensemble_size from config/design_matrix on "restart from", instead of what was actually used in the run that we are restarting from 🤔

I'd say in this case, it should be enough to test it manually. The complexity of such a test (ie. restart esmda) would be much higher than the frequency of the actual cases that could have this issue.

@jonathan-eq
Copy link
Contributor

Does this solve the issue? I think we need a larger gui test where we run ert with design_matrix realization 0-9, close ert and remove realization 8 and 9 from design matrix, open ert and try "Restart run" from the previous run. I thought the issue was that the validator uses the ensemble_size from config/design_matrix on "restart from", instead of what was actually used in the run that we are restarting from 🤔

I'd say in this case, it should be enough to test it manually. The complexity of such a test (ie. restart esmda) would be much higher than the frequency of the actual cases that could have this issue.

I am sure we have other tests that just create some mock storage of some kind. We only need to test this one panel or even just the validator.

@erlenlh
Copy link
Contributor Author

erlenlh commented Feb 19, 2026

Does this solve the issue? I think we need a larger gui test where we run ert with design_matrix realization 0-9, close ert and remove realization 8 and 9 from design matrix, open ert and try "Restart run" from the previous run. I thought the issue was that the validator uses the ensemble_size from config/design_matrix on "restart from", instead of what was actually used in the run that we are restarting from 🤔

How I read the issue, its not about realizations from design matrix. Its about changing num_realizations in config to a lower value. Since ens_mask is loaded from prior_storage is has the old length. Could also be issues if we tamper with design matrix, I havent considered that since I didnt interpret the issue that way 🤷

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a bug where restarting an ES_MDA run would fail when the ensemble size in the configuration was changed to a different value than the original run. The issue occurred because the code attempted to use bitwise AND (&=) on boolean arrays of different lengths, which is not supported.

Changes:

  • Introduced _create_combined_ensemble_mask function that handles mask intersection using set operations on indices instead of array operations, allowing masks of different lengths to be properly combined
  • Updated smoother_update to use the new function instead of in-place bitwise AND
  • Added comprehensive unit tests covering various scenarios including different-length masks

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/ert/analysis/_es_update.py Added _create_combined_ensemble_mask function to safely intersect ensemble masks of different lengths; refactored smoother_update to use the new function
tests/ert/unit_tests/analysis/test_es_update.py Added import for the new function and parametrized unit tests covering None case, same-length intersection, different-length intersection, and no-intersection scenarios

@erlenlh erlenlh force-pushed the Fix_restart_ESMDA_when_size_change branch 3 times, most recently from 5363dfb to 25f4704 Compare February 24, 2026 11:13
@frode-aarstad
Copy link
Contributor

Looks good. Only comment is the testcase suggested by copilot. The failing codspeed test is probably just flaky

@erlenlh erlenlh force-pushed the Fix_restart_ESMDA_when_size_change branch from 25f4704 to af2c778 Compare February 26, 2026 08:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unable to use "Restart run" in ES_MDA if number of realizations (size) have shrunk

7 participants