Skip to content

Add opt-in for deleting intermediate runpaths for es_mda - #14325

Open
eilskra wants to merge 3 commits into
equinor:mainfrom
eilskra:iteration-deletion
Open

Add opt-in for deleting intermediate runpaths for es_mda#14325
eilskra wants to merge 3 commits into
equinor:mainfrom
eilskra:iteration-deletion

Conversation

@eilskra

@eilskra eilskra commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Added the option to delete the intermediate runpaths for es_mda. Often not not used for prediction runs, QC should be able to be done with the data from storage. Will free up space on scratch.

delete_intermediate_runpaths image
  • 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 screenshots are changed: Review screenshot-PR in ert-testdata,
    merge screenshot-PR in ert-testdata before merging this PR.
  • 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')

@eilskra
eilskra marked this pull request as draft August 31, 2026 12:09
@eilskra
eilskra force-pushed the iteration-deletion branch 2 times, most recently from ce33ecd to eec41c3 Compare August 31, 2026 12:19
@eilskra
eilskra requested a balanced review from Copilot August 31, 2026 12:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Adds optional ES-MDA intermediate runpath cleanup to reduce scratch-space usage.

Changes:

  • Adds GUI and CLI controls for cleanup.
  • Deletes intermediate ES-MDA runpaths after evaluation.
  • Persists and tests the new configuration field.
File summaries
File Description
src/ert/__main__.py Adds the CLI cleanup flag.
src/ert/gui/experiments/multiple_data_assimilation_panel.py Adds the default-enabled GUI checkbox.
src/ert/run_models/model_factory.py Passes cleanup configuration to the model.
src/ert/run_models/multiple_data_assimilation.py Implements intermediate runpath deletion.
src/ert/run_models/run_model_configs.py Adds and serializes the cleanup setting.
src/ert/storage/local_experiment.py Extends stored experiment metadata.
tests/ert/unit_tests/run_models/test_multiple_data_assimilation.py Tests runpath deletion behavior.
tests/ert/unit_tests/run_models/test_model_factory.py Updates ES-MDA factory fixtures.
tests/ert/unit_tests/run_models/test_experiment_serialization.py Updates serialization input.
tests/.../snake_oil.json Updates the ES-MDA snapshot.
tests/.../poly.json Updates the ES-MDA snapshot.
tests/.../config.json Updates the ES-MDA snapshot.
Review details

Suppressed comments (2)

src/ert/run_models/multiple_data_assimilation.py:231

  • ignore_errors=True silently suppresses permission and filesystem failures, so the run can claim it is deleting paths while freeing no scratch space. Catch OSError and emit a warning (without failing the expensive experiment) so operators can detect cleanup failures.
            logger.info(f"Deleting runpath of intermediate iteration: {path}")
            shutil.rmtree(path, ignore_errors=True)

src/ert/gui/experiments/multiple_data_assimilation_panel.py:233

  • This is a new user-facing, default-enabled destructive behavior, but no .rst documentation is updated. Document what is removed, that storage results remain, how GUI users opt out, and that the CLI remains opt-in; the existing ES-MDA how-to at docs/ert/getting_started/howto/esmda_select_prior.rst is a natural location.
        layout.addRow(
            ("Only keep prior and\nposterior on disk:"),
            self._only_keep_first_and_last_iteration_box,
        )
  • Files reviewed: 12/12 changed files
  • Comments generated: 6
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/ert/run_models/model_factory.py Outdated
Comment thread src/ert/run_models/multiple_data_assimilation.py Outdated
Comment thread src/ert/gui/experiments/multiple_data_assimilation_panel.py Outdated
Comment thread src/ert/__main__.py Outdated
Comment thread src/ert/__main__.py Outdated
Comment thread src/ert/gui/experiments/multiple_data_assimilation_panel.py Outdated
@codecov-commenter

codecov-commenter commented Aug 31, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.54839% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.74%. Comparing base (67dc075) to head (fbaf347).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/ert/run_models/multiple_data_assimilation.py 89.47% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #14325      +/-   ##
==========================================
- Coverage   90.81%   90.74%   -0.07%     
==========================================
  Files         497      497              
  Lines       36062    36093      +31     
==========================================
+ Hits        32748    32751       +3     
- Misses       3314     3342      +28     
Flag Coverage Δ
cli-tests 35.67% <41.93%> (+<0.01%) ⬆️
fuzz 43.84% <35.48%> (-0.01%) ⬇️
gui-tests 58.14% <64.51%> (+<0.01%) ⬆️
performance-and-unit-tests 80.92% <93.54%> (-0.13%) ⬇️
test 45.25% <29.03%> (-0.02%) ⬇️

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

Files with missing lines Coverage Δ
src/ert/__main__.py 88.47% <100.00%> (+0.08%) ⬆️
...ui/experiments/multiple_data_assimilation_panel.py 91.59% <100.00%> (+0.25%) ⬆️
src/ert/run_models/model_factory.py 97.69% <ø> (ø)
src/ert/run_models/run_model_configs.py 100.00% <100.00%> (ø)
src/ert/storage/local_experiment.py 96.35% <100.00%> (+<0.01%) ⬆️
src/ert/utils.py 96.77% <100.00%> (+0.05%) ⬆️
src/ert/run_models/multiple_data_assimilation.py 95.61% <89.47%> (-1.23%) ⬇️

... and 6 files with indirect coverage changes

@eilskra
eilskra force-pushed the iteration-deletion branch 3 times, most recently from 2897dfb to b11c74b Compare August 31, 2026 14:42
@codspeed-hq

codspeed-hq Bot commented Aug 31, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 36 untouched benchmarks


Comparing eilskra:iteration-deletion (a59a9ed) with main (67dc075)

Open in CodSpeed

@ertomatic

Copy link
Copy Markdown
Collaborator

Screenshots differ from baselines. A baseline update PR has been prepared: equinor/ert-testdata#112

@eilskra
eilskra marked this pull request as ready for review September 1, 2026 09:50
ertomatic pushed a commit to equinor/ert-testdata that referenced this pull request Sep 1, 2026
@eilskra eilskra changed the title Add intermediate iter deletion for es-mda Add opt-in for deleting intermediate runpaths for es_mda Sep 1, 2026
@eilskra eilskra added improvement Something nice to have, that will make life easier for developers or users or both. release-notes:improvement Automatically categorise as improvement in release notes and removed improvement Something nice to have, that will make life easier for developers or users or both. labels Sep 1, 2026
@eilskra eilskra added this to SCOUT Sep 1, 2026
@eilskra eilskra moved this to Ready for Review in SCOUT Sep 1, 2026
@eilskra
eilskra force-pushed the iteration-deletion branch 2 times, most recently from 77ad712 to d248a52 Compare September 1, 2026 10:02
@eilskra eilskra self-assigned this Sep 1, 2026
@eilskra
eilskra requested a balanced review from Copilot September 1, 2026 10:02
ertomatic pushed a commit to equinor/ert-testdata that referenced this pull request Sep 1, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details
  • Files reviewed: 16/17 changed files
  • Comments generated: 2
  • Review effort level: Balanced

Comment thread src/ert/run_models/multiple_data_assimilation.py Outdated
Comment on lines +239 to +243
for path in self._run_paths.get_paths(
realizations_stored_successfully, posterior.iteration
):
logger.info(f"Deleting runpath of intermediate iteration: {path}")
shutil.rmtree(path, ignore_errors=True)

@eilskra eilskra Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No? It will still create subfolders in the realization iteration, otherwise the realization iteration would overwrite itself for each realization?
Screenshot 2026-09-01 at 12 22 40

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Interesting comment from Copilot, it is absolutely possible to set
RUNPATH poly_out/realiation-<IENS>/iter-foo
and es-mda will actually run quite fine, reusing the the runpath for each realization over the iterations, and you have effectively implicitly deleted iter-0 to iter-2. In this case the deletion feature is superfluous (but it does represent a safety net as rerunning in an existing realization can have side-effects, just not for iter-1) but I don't see any big problems with it.

ertomatic pushed a commit to equinor/ert-testdata that referenced this pull request Sep 1, 2026
ertomatic pushed a commit to equinor/ert-testdata that referenced this pull request Sep 1, 2026
@berland

berland commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

I am not sure about the usage of "intermediate runpath" in the GUI text here - wondering if users will understand that concept, and if they are unsure of what it means, they will for sure not click it.

It may also be unclear to the user when this deletion is going to happen.

We can calculate what the intermediate iterations are, based on the input further up in the GUI element, and include "iter-1, iter-2" in the text somehow. On-prem users would also like to see the term "scratch" in the message, they might relate more to that than the term "runpath", but then "scratch" is a specific user group tribe-language and not Ert lingo.

@eilskra

eilskra commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

@berland

I am not sure about the usage of "intermediate runpath" in the GUI text here - wondering if users will understand that concept, and if they are unsure of what it means, they will for sure not click it.
It may also be unclear to the user when this deletion is going to happen.

I was thinking of wording the label in such a manner that it highlights that this is scratch disk optimization. However, my concern was that we could ruin runs for the users if we are not very explicit that this is a non-reversal deletion. The tooltip explains when the deletion happens, but I guess we could try to add this to the label too

We can calculate what the intermediate iterations are, based on the input further up in the GUI element, and include "iter-1, iter-2" in the text somehow. On-prem users would also like to see the term "scratch" in the message, they might relate more to that than the term "runpath", but then "scratch" is a specific user group tribe-language and not Ert lingo.

I tried to reduce the amount of tribe-language used (I am still not consistent, e.g restart vs prediction), but in the user documentation I highlight that this frees up scratch disk space (selling point of functionality).

I am not sure if we should accommodate wording or not, feel like we're currently in an awkward middle position:

  • If we don't use Ert lingo, it wont get picked up and will not be established
  • If we don't use tribe-language, feature might not get used due to users' uncertainties/confusions about the feature

Suggested labels:

  • "Delete intermediate realization iterations after completion"
  • "Minimize scratch-disk storage used
    (Delete intermediate realization iterations)"
  • "Only store initial prior and final posterior on scratch disk"

Comment thread src/ert/utils.py


ES_MDA_DELETE_RUNPATHS_HELP_TEXT = (
"Delete the runpath directories of intermediate iterations\n"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Instead of newlines, can't we have Qt or something wrap the text? The newlines make this text hard to maintain later.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Text also gets used for the CLI-arg helper, unsure if there are methods to wrap the text there?

Comment thread src/ert/utils.py
"so failures can still be investigated.\n"
"Results are still available in storage,\n"
"but the deleted intermediate iterations can no longer\n"
"be inspected or used as a prior for a restart."

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This last sentence is probably slightly incorrect. "Restart" is a very overloaded term (it is both an es-mda term, and an Eclipse term), and for some definitions (the Eclipse one), this statement is very correct. But since the parameters are in storage, es-mda can probably restart from intermediate iterations.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If it can be used as prior despite being removed from scratch, should we also add opt-in to remove initial prior (iter-0)?

@ertomatic

Copy link
Copy Markdown
Collaborator

Screenshot tests now pass. The baseline update PR equinor/ert-testdata#112 has been closed.

@berland

berland commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Another label suggestion: "Keep only prior and posteriors runpaths"

**self._update_experiment_config(),
**self._common_fields(),
"prior_ensemble_id": self.prior_ensemble_id,
"delete_intermediate_runpaths": (self.delete_intermediate_runpaths),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Does this belong here? Could see this belonging with the rest of the runpath configuration. While only needed in esmda at the moment, we do aim for this to be available and used for all run models down the line.

@eilskra eilskra Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If not added to the MultipleDataAssimilationConfig the experiment serialization test fails with:

AssertionError: Key delete_intermediate_runpaths not found in saved experiment. Expected value: False

Test added in this commit

Edit: Post discussion, will look into adding this to runpath config

Added a checkbox to run panel and cli arg for deleting
intermediate runpath iterations

Defaults to false, as the choice is irreversible

Failed realization does not get deleted as they
are removed from active realizations prior
to the deletion method-call
@eilskra eilskra moved this from Ready for Review to In Progress in SCOUT Sep 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-notes:improvement Automatically categorise as improvement in release notes

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

6 participants