Skip to content

Commit

Permalink
Add missing features in resource settings tabs (#946)
Browse files Browse the repository at this point in the history
This PR looks to clean up the recently implemented plugin-based tab system in the resources/submission step (#939).
The idea is to leverage the newly developed abstraction in #945 to encapsulate the behavior of ANY resource settings panel, leaving the global resource settings panel to override based on its unique added features.

A few added items addressed in this PR:

- PW code parallelization widget syncing between tabs
- Support for syncing newly setup codes
- Warning notification for overridden plugin resources
- Syncing back with global resources on un-override
  • Loading branch information
edan-bainglass authored Dec 9, 2024
1 parent 7bb67ae commit 9a814ac
Show file tree
Hide file tree
Showing 23 changed files with 657 additions and 599 deletions.
2 changes: 1 addition & 1 deletion src/aiidalab_qe/app/configuration/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def __init__(self, model: ConfigurationStepModel, **kwargs):
lambda structure: ""
if structure
else """
<div class="alert alert-info">
<div class="alert alert-danger">
<b>Please set the input structure first.</b>
</div>
""",
Expand Down
5 changes: 2 additions & 3 deletions src/aiidalab_qe/app/configuration/advanced/subsettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@


class AdvancedCalculationSubSettingsModel(Model):
identifier = "sub"
dependencies = []

loaded_from_process = tl.Bool(False)
Expand All @@ -33,12 +34,10 @@ def reset(self):


class AdvancedConfigurationSubSettingsPanel(ipw.VBox, t.Generic[M]):
identifier = "sub"

def __init__(self, model: M, **kwargs):
from aiidalab_qe.common.widgets import LoadingWidget

self.loading_message = LoadingWidget(f"Loading {self.identifier} settings")
self.loading_message = LoadingWidget(f"Loading {model.identifier} settings")

super().__init__(
layout={"justify_content": "space-between", **kwargs.get("layout", {})},
Expand Down
8 changes: 4 additions & 4 deletions src/aiidalab_qe/app/configuration/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def update(self):
def get_model_state(self):
parameters = {
identifier: model.get_model_state()
for identifier, model in self._models.items()
for identifier, model in self.get_models()
if model.include
}
parameters["workchain"] |= {
Expand All @@ -100,7 +100,7 @@ def set_model_state(self, parameters):
workchain_parameters: dict = parameters.get("workchain", {})
self.relax_type = workchain_parameters.get("relax_type")
properties = set(workchain_parameters.get("properties", []))
for identifier, model in self._models.items():
for identifier, model in self.get_models():
model.include = identifier in self._default_models | properties
if parameters.get(identifier):
model.set_model_state(parameters[identifier])
Expand All @@ -111,7 +111,7 @@ def reset(self):
self.relax_type_help = self._get_default_relax_type_help()
self.relax_type_options = self._get_default_relax_type_options()
self.relax_type = self._get_default_relax_type()
for identifier, model in self._models.items():
for identifier, model in self.get_models():
if identifier not in self._default_models:
model.include = False

Expand All @@ -135,7 +135,7 @@ def _link_model(self, model: ConfigurationSettingsModel):

def _get_properties(self):
properties = []
for identifier, model in self._models.items():
for identifier, model in self.get_models():
if identifier in self._default_models:
continue
if model.include:
Expand Down
82 changes: 43 additions & 39 deletions src/aiidalab_qe/app/submission/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

from aiidalab_qe.app.parameters import DEFAULT_PARAMETERS
from aiidalab_qe.app.utils import get_entry_items
from aiidalab_qe.common.panel import ResourceSettingsModel, ResourceSettingsPanel
from aiidalab_qe.common.code import PluginCodes, PwCodeModel
from aiidalab_qe.common.panel import PluginResourceSettingsModel, ResourceSettingsPanel
from aiidalab_qe.common.setup_codes import QESetupWidget
from aiidalab_qe.common.setup_pseudos import PseudosInstallWidget
from aiidalab_widgets_base import WizardAppWidgetStep
Expand Down Expand Up @@ -39,10 +40,6 @@ def __init__(self, model: SubmissionStepModel, qe_auto_setup=True, **kwargs):
self._on_submission,
"confirmed",
)
self._model.observe(
self._on_input_structure_change,
"input_structure",
)
self._model.observe(
self._on_input_parameters_change,
"input_parameters",
Expand Down Expand Up @@ -77,22 +74,28 @@ def __init__(self, model: SubmissionStepModel, qe_auto_setup=True, **kwargs):

self.rendered = False

global_code_model = GlobalResourceSettingsModel()
self.global_code_settings = GlobalResourceSettingsPanel(model=global_code_model)
self._model.add_model("global", global_code_model)
global_code_model.observe(
global_resources_model = GlobalResourceSettingsModel()
self.global_resources = GlobalResourceSettingsPanel(
model=global_resources_model
)
self._model.add_model("global", global_resources_model)
ipw.dlink(
(self._model, "plugin_overrides"),
(global_resources_model, "plugin_overrides"),
)
global_resources_model.observe(
self._on_plugin_submission_blockers_change,
["submission_blockers"],
)
global_code_model.observe(
global_resources_model.observe(
self._on_plugin_submission_warning_messages_change,
["submission_warning_messages"],
)

self.settings = {
"global": self.global_code_settings,
"global": self.global_resources,
}
self._fetch_plugin_settings()
self._fetch_plugin_resource_settings()

self._install_sssp(qe_auto_setup)
self._set_up_qe(qe_auto_setup)
Expand Down Expand Up @@ -197,9 +200,7 @@ def submit(self, _=None):
self._model.confirm()

def reset(self):
with self.hold_trait_notifications():
self._model.reset()
self._model.set_selected_codes()
self._model.reset()

@tl.observe("previous_step_state")
def _on_previous_step_state_change(self, _):
Expand All @@ -211,14 +212,15 @@ def _on_tab_change(self, change):
tab: ResourceSettingsPanel = self.tabs.children[tab_index] # type: ignore
tab.render()

def _on_input_structure_change(self, _):
""""""

def _on_input_parameters_change(self, _):
self._model.update_active_models()
self._update_tabs()
self._model.update_process_label()
self._model.update_plugin_inclusion()
self._model.update_plugin_overrides()
self._model.update_submission_blockers()
self._update_tabs()

def _on_plugin_overrides_change(self, _):
self._model.update_plugin_overrides()

def _on_plugin_submission_blockers_change(self, _):
self._model.update_submission_blockers()
Expand All @@ -237,16 +239,13 @@ def _on_submission_blockers_change(self, _):
self._model.update_submission_blocker_message()
self._update_state()

def _on_submission_warning_change(self, _):
self._model.update_submission_warning_message()

def _on_installation_change(self, _):
self._model.update_submission_blockers()

def _on_qe_installed(self, _):
self._toggle_qe_installation_widget()
if self._model.qe_installed:
self._model.refresh_codes()
self._model.update()

def _on_sssp_installed(self, _):
self._toggle_sssp_installation_widget()
Expand Down Expand Up @@ -325,14 +324,24 @@ def _update_state(self, _=None):
else:
self.state = self.state.CONFIGURED

def _fetch_plugin_settings(self):
eps = get_entry_items("aiidalab_qe.properties", "code")
for identifier, data in eps.items():
def _fetch_plugin_resource_settings(self):
entries = get_entry_items("aiidalab_qe.properties", "resources")
codes: PluginCodes = {
"dft": {
"pw": PwCodeModel(),
},
}
for identifier, resources in entries.items():
for key in ("panel", "model"):
if key not in data:
if key not in resources:
raise ValueError(f"Entry {identifier} is missing the '{key}' key")
panel = data["panel"]
model: ResourceSettingsModel = data["model"]()

panel = resources["panel"]
model: PluginResourceSettingsModel = resources["model"]()
model.observe(
self._on_plugin_overrides_change,
"override",
)
model.observe(
self._on_plugin_submission_blockers_change,
["submission_blockers"],
Expand All @@ -343,16 +352,11 @@ def _fetch_plugin_settings(self):
)
self._model.add_model(identifier, model)

def toggle_plugin(_, model=model):
model.update()
self._update_tabs()

model.observe(
toggle_plugin,
"include",
)

self.settings[identifier] = panel(
identifier=identifier,
model=model,
)

codes[identifier] = dict(model.get_models())

self.global_resources.set_up_codes(codes)
Loading

0 comments on commit 9a814ac

Please sign in to comment.