Skip to content

Remove LocalEnsemble.load_all_gen_kw_data() - #12015

Merged
jonathan-eq merged 1 commit into
equinor:mainfrom
jonathan-eq:improve-plotter
Oct 10, 2025
Merged

Remove LocalEnsemble.load_all_gen_kw_data()#12015
jonathan-eq merged 1 commit into
equinor:mainfrom
jonathan-eq:improve-plotter

Conversation

@jonathan-eq

@jonathan-eq jonathan-eq commented Oct 7, 2025

Copy link
Copy Markdown
Contributor

Issue
Resolves #11939

Approach
This commit removes the function, and replaces it with LocalEnsemble.load_scalars() as it gradually moves from pandas towards polars.

(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')

Comment on lines +93 to +96
ensemble_data = ensemble.load_scalars().to_pandas().set_index("realization")
ensemble_data.columns.name = None
ensemble_data.index.name = "Realization"
ensemble_data = ensemble_data.sort_index(axis=1)

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.

This is more or less the same as what was in load_all_gen_kw_data(), but it will be removed as we rewrite csv_export to use polars instead of pandas. We should do this gradually and in increments.

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.

@xjules
I will create an issue for this rewrite pandas -> polars, but it won't be done in this PR.

@codecov-commenter

codecov-commenter commented Oct 7, 2025

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.72%. Comparing base (1e382c8) to head (56a1a39).
⚠️ Report is 962 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #12015      +/-   ##
==========================================
- Coverage   90.73%   90.72%   -0.01%     
==========================================
  Files         432      432              
  Lines       28911    28902       -9     
==========================================
- Hits        26231    26222       -9     
  Misses       2680     2680              
Flag Coverage Δ
cli-tests 38.85% <0.00%> (-0.08%) ⬇️
gui-tests 69.07% <100.00%> (-0.01%) ⬇️
performance-and-unit-tests 74.02% <100.00%> (-0.01%) ⬇️
test 40.04% <0.00%> (+<0.01%) ⬆️

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.

@jonathan-eq
jonathan-eq force-pushed the improve-plotter branch 2 times, most recently from 59fb512 to 0acac2f Compare October 7, 2025 13:48
@jonathan-eq jonathan-eq self-assigned this Oct 7, 2025
@jonathan-eq jonathan-eq added the release-notes:maintenance Automatically categorise as maintenance change in release notes label Oct 7, 2025
@codspeed-hq

codspeed-hq Bot commented Oct 7, 2025

Copy link
Copy Markdown

CodSpeed Performance Report

Merging #12015 will not alter performance

Comparing jonathan-eq:improve-plotter (56a1a39) with main (1e382c8)

Summary

✅ 22 untouched

for iter_nr in range(2):
ensemble = experiment.get_ensemble_by_name(f"iter-{iter_nr}")
data.append(ensemble.load_all_gen_kw_data())
ensemble_data = ensemble.load_scalars().to_pandas().set_index("realization")

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.

do we need to have pandas here? Ie. maybe just update snapshot?

Comment thread tests/ert/ui_tests/cli/test_update.py Outdated
assert (
np.linalg.det(posterior.cov().to_numpy())
<= np.linalg.det(prior.cov().to_numpy()) + 0.001
np.linalg.det(posterior.to_pandas().cov().to_numpy())

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.

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.

Yes, but not for all columns.

@xjules xjules Oct 8, 2025

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.

posterior.cov().to_numpy()
cov_matrix = np.cov(posterior.to_numpy(), rowvar=False)


for i in range(ensemble.ensemble_size):
assert (
f",{name},{gen_kw_data.iloc[i]['COEFFS:a']:.6f},{gen_kw_data.iloc[i]['COEFFS:b']:.6f},{gen_kw_data.iloc[i]['COEFFS:c']:.6f},{misfit_data.iloc[i]['MISFIT:POLY_OBS']:.6f},{misfit_data.iloc[i]['MISFIT:TOTAL']:.6f}"

@xjules xjules Oct 8, 2025

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.

you can do directly row in pl.Dataframe

row_gen = gen_kw_data.row(i, named=True)
{row_gen['COEFFS:a']:.6f}

# generalized variance for the parameters.
assert (
0
< np.linalg.det(df_posterior.cov().to_numpy())

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.

the same as above pl.cov ....

data = ensemble.load_scalars().to_pandas().set_index("realization")
data.columns.name = None
data.index.name = "Realization"
data = data.sort_index(axis=1)

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.

Can we update snapshot instead?

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.

That will change behavior. I don't think we want to do that in this PR.

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.

Not sure that I understand. What do you mean by behaviour?

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 we have to update the snapshot, the behavior/format has been altered. I don't think that should be done in this refactor-pr

This commit removes the function, and replaces it with
`LocalEnsemble.load_scalars()` as it gradually moves from pandas towards
polars.

@xjules xjules 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.

Nice job @jonathan-eq ! Can you create an issue to remove pandas from the tests further on?

@jonathan-eq

Copy link
Copy Markdown
Contributor Author

#12043

@jonathan-eq

Copy link
Copy Markdown
Contributor Author

Blocked by equinor/semeio#772

@jonathan-eq
jonathan-eq merged commit 3a7b4e4 into equinor:main Oct 10, 2025
34 of 35 checks passed
@jonathan-eq
jonathan-eq deleted the improve-plotter branch February 25, 2026 07:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-notes:maintenance Automatically categorise as maintenance change in release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove local_ensemble.load_all_gen_kw_data and make use of scalar endpoint instead

3 participants