Skip to content

Add design matrix panel for parameters preview #8910

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 11, 2024
Merged

Conversation

xjules
Copy link
Contributor

@xjules xjules commented Oct 8, 2024

Issue
Resolves #8825

NB! This PR is based on #8800
The relevant files are:
-- src/ert/gui/simulation/ensemble_experiment_panel.py
-- src/ert/gui/simulation/experiment_panel.py
-- src/ert/gui/tools/design_matrix/design_matrix_panel.py
-- tests/ert/unit_tests/gui/simulation/test_run_dialog.py

Merging is blocked as it requires the PR above to be merged.

Now it's rebased

Approach
Add a QDialog that shows pd.DataFrame as QTableView

(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 'pytest tests/ert/unit_tests -n logical -m "not integration_test"')

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: Create Backport PR to latest release

@xjules xjules self-assigned this Oct 8, 2024
@xjules xjules force-pushed the dm_panel branch 3 times, most recently from b47bd57 to 25111b6 Compare October 9, 2024 07:17
@codecov-commenter
Copy link

codecov-commenter commented Oct 9, 2024

Codecov Report

Attention: Patch coverage is 45.45455% with 30 lines in your changes missing coverage. Please review.

Project coverage is 91.59%. Comparing base (072decc) to head (a2a8018).
Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
...ert/gui/tools/design_matrix/design_matrix_panel.py 27.58% 21 Missing ⚠️
...rc/ert/gui/simulation/ensemble_experiment_panel.py 64.00% 9 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8910      +/-   ##
==========================================
- Coverage   91.70%   91.59%   -0.11%     
==========================================
  Files         343      344       +1     
  Lines       21235    21294      +59     
==========================================
+ Hits        19473    19504      +31     
- Misses       1762     1790      +28     
Flag Coverage Δ
cli-tests 39.73% <0.00%> (-0.04%) ⬇️
gui-tests 73.55% <30.90%> (-0.12%) ⬇️
performance-tests 50.29% <25.45%> (-0.05%) ⬇️
unit-tests 80.33% <45.45%> (-0.04%) ⬇️

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 force-pushed the dm_panel branch 2 times, most recently from 65b1a97 to 372aaab Compare October 9, 2024 08:21
@xjules
Copy link
Contributor Author

xjules commented Oct 9, 2024

Preview screenshot:

image

@xjules xjules marked this pull request as ready for review October 9, 2024 09:54
@jonathan-eq jonathan-eq self-requested a review October 10, 2024 06:21
def __init__(self, ensemble_size: int, run_path: str, notifier: ErtNotifier):
def __init__(
self,
analysis_config: AnalysisConfig,
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need the entire analysisconfig, or only designmatrix?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good question and I have thought about it and decided on using the entire config:

  • other panels get the entire analysisconfig too and thus it makes the api more uniform
  • when doing the validation ( not there yet), we might to access more of the configs

@@ -78,6 +83,23 @@ def __init__(self, ensemble_size: int, run_path: str, notifier: ErtNotifier):
)
layout.addRow("Active realizations", self._active_realizations_field)

design_matrix = analysis_config.design_matrix
dm_param_button = QPushButton("Show parameters")
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we rename dm_param_button to show_dm_param_button?

Comment on lines 118 to 133
if design_matrix is not None:
if design_matrix.design_matrix_df is None:
design_matrix.read_design_matrix()
if (
design_matrix.design_matrix_df is not None
and not design_matrix.design_matrix_df.empty
):
viewer = DesignMatrixPanel(design_matrix.design_matrix_df)
viewer.setMinimumHeight(500)
viewer.setMinimumWidth(1000)
viewer.adjustSize()
viewer.exec_()

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add

if design_matrix is None:
      return

and remove the indentation?

) -> None:
super().__init__(parent)

self.setWindowTitle("Design matrix parameters viewer")
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we have the title as viewer or preview?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you mean by title?

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we change:
self.setWindowTitle("Design matrix parameters viewer") to
self.setWindowTitle("Design matrix parameters preview")

Copy link
Contributor Author

@xjules xjules Oct 11, 2024

Choose a reason for hiding this comment

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

Right, from this it sounds you are fine with both 😄

Should we have the title as viewer or preview?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, we can keep it as viewer 👌

Copy link
Contributor Author

@xjules xjules Oct 11, 2024

Choose a reason for hiding this comment

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

Just change it to: f"Design matrix parameters from {filename}"

Copy link
Contributor

Choose a reason for hiding this comment

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

Even better :)

"design_matrix_entry",
(True, False),
)
def test_that_design_matrix_show_parameters_button_is_enabled(
Copy link
Contributor

Choose a reason for hiding this comment

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

Here we are also testing that the button should be disabled, but I cannot think of a better name.
Maybe we can add to the test that when you push the button, the design matrix param viewer should pop up?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hm, like in another test or inside this one?

Copy link
Contributor

Choose a reason for hiding this comment

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

We should really keep the unit tests at a unit level, but here I would test it in the same one. Then we would get to test the button visibility and the click functionality. We could call the test test_design_matrix_show_parameters_button

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd need to create a pandas frame and it'd become integration I think. But maybe it's still fine to have as unit though 🤷

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, you are right. Let's keep it as is.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, you are right. Let's keep it as is.

I'll give it a go 😸

Copy link
Contributor

@jonathan-eq jonathan-eq left a comment

Choose a reason for hiding this comment

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

Looks very good! See minor nitpicking 🚠

button_layout.addStretch() # Add stretch to push the button to the left

layout.addRow("Design Matrix", button_layout)
if design_matrix is not None:
Copy link
Collaborator

@larsevj larsevj Oct 11, 2024

Choose a reason for hiding this comment

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

I propose to only make the button if design_matrix exist, then it will be less confusion what this new but disabled thing is. And so only people that have actually set DESIGN_MATRIX will see this option at all.
But can of course be up for discussion.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree^

Copy link
Contributor Author

@xjules xjules Oct 11, 2024

Choose a reason for hiding this comment

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

Hm, I made it on purpose mainly due to testing. But could be done though.

) -> None:
super().__init__(parent)

self.setWindowTitle("Design matrix parameters viewer")
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would propose to include the xlsx filename in the title, for instance Parameters from some_file.xlsx.

with patch.object(
DesignMatrix, "design_matrix_df", design_matrix_df
), patch.object(DesignMatrix, "xls_filename", Path(xls_filename)):
qtbot.mouseClick(show_dm_parameters, Qt.LeftButton)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we also assert the new component is showing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have removed it

- Button to show the parameters is shown when design_matrix is present
- Add test for design matrix show parameters button
Copy link
Contributor

@jonathan-eq jonathan-eq left a comment

Choose a reason for hiding this comment

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

LGTM!

@xjules xjules added release-notes:new-feature Automatically categorise as new feature in release notes sensitivity labels Oct 11, 2024
@xjules xjules enabled auto-merge (rebase) October 11, 2024 13:34
@xjules xjules merged commit 391a25f into equinor:main Oct 11, 2024
56 checks passed
@xjules xjules deleted the dm_panel branch October 11, 2024 14:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-notes:new-feature Automatically categorise as new feature in release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Show preview of design matrix parameters
4 participants