-
Notifications
You must be signed in to change notification settings - Fork 140
Add controls for configuring localization update strategies #14316
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
Open
frode-aarstad
wants to merge
17
commits into
equinor:main
Choose a base branch
from
frode-aarstad:update-edit-settings-with-update-strategies
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
14baeed
First draft
frode-aarstad b4cb9b4
Add save / cancel
frode-aarstad ce88f26
Second draft
frode-aarstad 066760d
3rd
frode-aarstad add26aa
Fix tests
frode-aarstad ee838c3
Add tests for analysis module panel
frode-aarstad 1145f31
Add tests for analysis model edit
frode-aarstad cff1a9e
Remove deprected test
frode-aarstad de1e142
fixup
frode-aarstad fdc1d10
Remove redundant test
frode-aarstad 499690e
Fix correlation threshold
frode-aarstad 2988dcd
Address review comments
frode-aarstad 95a41ef
Address review comments
frode-aarstad 8906a2a
Fix manual update
frode-aarstad 218c572
Fix esmda
frode-aarstad 8cdb41a
Fix tests
frode-aarstad d0ab84e
Small fix
frode-aarstad File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,49 +1,120 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from typing import TYPE_CHECKING | ||
| from collections import defaultdict | ||
|
|
||
| from PyQt6.QtCore import QMargins, Qt | ||
| from PyQt6.QtWidgets import QHBoxLayout, QPushButton, QWidget | ||
| from PyQt6.QtWidgets import ( | ||
| QDialog, | ||
| QDialogButtonBox, | ||
| QHBoxLayout, | ||
| QPushButton, | ||
| QVBoxLayout, | ||
| QWidget, | ||
| ) | ||
|
|
||
| from ert.config import ESSettings, LocalizationType, ParameterConfig | ||
| from ert.gui.icon_utils import load_icon | ||
|
|
||
| from .analysismodulevariablespanel import AnalysisModuleVariablesPanel | ||
| from .closabledialog import ClosableDialog | ||
|
|
||
| if TYPE_CHECKING: | ||
| from ert.config import AnalysisModule | ||
|
|
||
|
|
||
| class AnalysisModuleEdit(QWidget): | ||
| def __init__( | ||
| self, | ||
| analysis_module: AnalysisModule, | ||
| es_settings: ESSettings, | ||
| parameter_config: list[ParameterConfig], | ||
| ensemble_size: int, | ||
| ) -> None: | ||
| self.analysis_module = analysis_module | ||
| self.ensemble_size = ensemble_size | ||
| QWidget.__init__(self) | ||
|
|
||
| self._es_settings: ESSettings = es_settings | ||
| self._parameter_config: list[ParameterConfig] = parameter_config | ||
| self._ensemble_size: int = ensemble_size | ||
|
|
||
| layout = QHBoxLayout() | ||
|
|
||
| variables_popup_button = QPushButton("Edit") | ||
| variables_popup_button.setObjectName("analysis_variables_popup_button") | ||
| variables_popup_button.setIcon(load_icon("edit.svg")) | ||
| variables_popup_button.clicked.connect(self.showVariablesPopup) | ||
| variables_popup_button.clicked.connect(self._show_update_settings_dialog) | ||
|
|
||
| layout.addWidget(variables_popup_button, 0, Qt.AlignmentFlag.AlignLeft) | ||
| layout.setContentsMargins(QMargins(0, 0, 0, 0)) | ||
| layout.addStretch() | ||
|
|
||
| self.setLayout(layout) | ||
|
|
||
| def showVariablesPopup(self) -> None: | ||
| variable_dialog = AnalysisModuleVariablesPanel( | ||
| self.analysis_module, self.ensemble_size | ||
| @property | ||
| def parameter_config(self) -> list[ParameterConfig]: | ||
| return self._parameter_config | ||
|
|
||
| @parameter_config.setter | ||
| def parameter_config(self, value: list[ParameterConfig]) -> None: | ||
| self._parameter_config = value | ||
|
|
||
| def _show_update_settings_dialog(self) -> None: | ||
| dialog = QDialog(self.parent()) # type: ignore | ||
| dialog.setWindowTitle("Update settings") | ||
| dialog.setModal(True) | ||
| dialog.setWindowFlag(Qt.WindowType.CustomizeWindowHint, True) | ||
| dialog.setWindowFlag(Qt.WindowType.WindowContextHelpButtonHint, False) | ||
| dialog.setWindowFlag(Qt.WindowType.WindowCloseButtonHint, False) | ||
|
|
||
| layout = QVBoxLayout() | ||
|
|
||
| update_strategies: dict[str, LocalizationType] = defaultdict( | ||
| lambda: LocalizationType.GLOBAL | ||
| ) | ||
| for parameter_config in self._parameter_config: | ||
| if parameter_config.update_strategy: | ||
| update_strategies[parameter_config.type.upper()] = ( | ||
| parameter_config.update_strategy | ||
| ) | ||
|
|
||
| correlation_threshold = 1.0 | ||
| if self._ensemble_size != 0: | ||
| correlation_threshold = self._es_settings.correlation_threshold( | ||
| self._ensemble_size | ||
| ) | ||
|
|
||
| update_settings_dialog = AnalysisModuleVariablesPanel( | ||
| update_strategies=update_strategies, | ||
| correlation_threshold=correlation_threshold, | ||
| enkf_truncation=self._es_settings.enkf_truncation, | ||
| ) | ||
| dialog = ClosableDialog( | ||
| "Edit variables", | ||
| variable_dialog, | ||
| self.parent(), # type: ignore | ||
|
|
||
| layout.addWidget(update_settings_dialog, stretch=1) | ||
|
|
||
| button_box = QDialogButtonBox( | ||
| QDialogButtonBox.StandardButton.Save | ||
| | QDialogButtonBox.StandardButton.Cancel | ||
| ) | ||
| dialog.exec() | ||
| save_button = button_box.button(QDialogButtonBox.StandardButton.Save) | ||
| assert save_button is not None | ||
| save_button.setAutoDefault(False) | ||
| cancel_button = button_box.button(QDialogButtonBox.StandardButton.Cancel) | ||
| assert cancel_button is not None | ||
| cancel_button.setAutoDefault(False) | ||
| button_box.accepted.connect(dialog.accept) | ||
| button_box.rejected.connect(dialog.reject) | ||
|
|
||
| button_layout = QHBoxLayout() | ||
| button_layout.addStretch() | ||
| button_layout.addWidget(button_box) | ||
| layout.addLayout(button_layout) | ||
|
|
||
| dialog.setLayout(layout) | ||
| dialog.setFixedSize(450, 300) | ||
|
|
||
| if dialog.exec() == QDialog.DialogCode.Accepted: | ||
| self._es_settings.localization_correlation_threshold = ( | ||
| update_settings_dialog.correlation_threshold | ||
| ) | ||
| self._es_settings.enkf_truncation = update_settings_dialog.enkf_truncation | ||
| for name, strategy in update_settings_dialog.update_strategies.items(): | ||
| for parameter_config in self._parameter_config: | ||
| if ( | ||
| parameter_config.type.upper() == name | ||
| and parameter_config.update_strategy is not None | ||
| ): | ||
| parameter_config.update_strategy = strategy | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.