Skip to content

Make restart on ES_MDA work with changed ensamble size#12909

Merged
erlenlh merged 1 commit intomainfrom
Fix_restart_ESMDA_when_size_change
Mar 2, 2026
Merged

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

Conversation

@erlenlh
Copy link
Copy Markdown
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
Copy Markdown

codecov-commenter commented Feb 17, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.35%. Comparing base (3b015c8) to head (327bb52).
⚠️ Report is 1 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #12909      +/-   ##
==========================================
- Coverage   90.36%   90.35%   -0.01%     
==========================================
  Files         453      453              
  Lines       31153    31167      +14     
==========================================
+ Hits        28150    28161      +11     
- Misses       3003     3006       +3     
Flag Coverage Δ
cli-tests 37.23% <75.00%> (+0.01%) ⬆️
gui-tests 67.81% <68.75%> (-0.01%) ⬇️
performance-and-unit-tests 77.03% <100.00%> (+<0.01%) ⬆️
test 46.16% <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.

Comment thread tests/ert/unit_tests/analysis/test_es_update.py Outdated
@erlenlh erlenlh force-pushed the Fix_restart_ESMDA_when_size_change branch from 0799376 to 02132c9 Compare February 18, 2026 10:56
Comment thread src/ert/analysis/_es_update.py Outdated
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Feb 18, 2026

Merging this PR will not alter performance

✅ 35 untouched benchmarks


Comparing Fix_restart_ESMDA_when_size_change (327bb52) with main (3b015c8)

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
Comment thread tests/ert/unit_tests/analysis/test_es_update.py Outdated
@jonathan-eq
Copy link
Copy Markdown
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
Copy Markdown
Contributor

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

@xjules
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor

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

Comment thread tests/ert/unit_tests/analysis/test_es_update.py Outdated
Comment thread tests/ert/unit_tests/analysis/test_es_update.py
@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
Copy Markdown
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
Copy link
Copy Markdown
Contributor

@xjules xjules left a comment

Choose a reason for hiding this comment

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

I think it should be ready now. 🚀

@erlenlh erlenlh force-pushed the Fix_restart_ESMDA_when_size_change branch from af2c778 to 327bb52 Compare March 2, 2026 08:33
@erlenlh erlenlh enabled auto-merge (squash) March 2, 2026 08:38
@erlenlh erlenlh merged commit 79cb853 into main Mar 2, 2026
33 checks passed
@erlenlh erlenlh deleted the Fix_restart_ESMDA_when_size_change branch March 2, 2026 08:48
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