Skip to content

Commit

Permalink
Improve the implementation of submission blocker
Browse files Browse the repository at this point in the history
  • Loading branch information
unkcpz committed Oct 28, 2023
1 parent e2a625f commit 5a775ea
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 35 deletions.
27 changes: 10 additions & 17 deletions src/aiidalab_qe/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
Authors: AiiDAlab team
"""

import copy

import ipywidgets as ipw
import traitlets as tl
from aiida.orm import load_node
from aiidalab_widgets_base import WizardAppWidget, WizardAppWidgetStep

Expand All @@ -19,9 +20,6 @@
class App(ipw.VBox):
"""The main widget that combines all the application steps together."""

# use to store the blocker messages for each step
_submission_blockers = tl.Dict()

def __init__(self, qe_auto_setup=True):
# Create the application steps
self.structure_step = StructureSelectionStep(auto_advance=True)
Expand Down Expand Up @@ -54,10 +52,6 @@ def __init__(self, qe_auto_setup=True):
(self.configure_step, "configuration_parameters"),
(self.submit_step, "input_parameters"),
)
ipw.dlink(
(self, "_submission_blockers"),
(self.submit_step, "_outside_submission_blockers"),
)

ipw.dlink(
(self.submit_step, "process"),
Expand All @@ -74,10 +68,6 @@ def __init__(self, qe_auto_setup=True):
("Status & Results", self.results_step),
]
)
# init the blocker messages
self._submission_blockers = {
i: [] for i in range(len(self._wizard_app_widget.steps))
}
self._wizard_app_widget.observe(self._observe_selected_index, "selected_index")

# Add process selection header
Expand Down Expand Up @@ -117,22 +107,25 @@ def _observe_selected_index(self, change):
with self.submit_step.hold_sync():
new_idx = change["new"]
# if entering the submit step, udpate the blocker messages
blockers = self._submission_blockers.copy()
if new_idx == 2:
# check the structure step is saved
for i in range(2):
# check if the step is saved
blockers = copy.deepcopy(
self.submit_step.external_submission_blockers
)
if not self.steps[i][1].is_saved():
self.steps[i][1].state = WizardAppWidgetStep.State.CONFIGURED
blockers[i] = [
blockers.append(
f"There are unsaved changes in the Step {i+1}: {self.steps[i][0]}"
]
)
# update the blocker message, this will trigger the observer
# to update the blocker message of the submit step
else:
# remove the blocker message if the step has all changes confirmed
blockers[i] = []
self._submission_blockers = blockers
blockers = []

self.submit_step.external_submission_blockers = blockers

def _observe_process_selection(self, change):
from aiida.orm.utils.serialize import deserialize_unsafe
Expand Down
24 changes: 6 additions & 18 deletions src/aiidalab_qe/app/submission/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ class SubmitQeAppWorkChainStep(ipw.VBox, WizardAppWidgetStep):
process = tl.Instance(orm.WorkChainNode, allow_none=True)
previous_step_state = tl.UseEnum(WizardAppWidgetStep.State)
input_parameters = tl.Dict()
_submission_blockers = tl.List(tl.Unicode())
_outside_submission_blockers = tl.Dict()
internal_submission_blockers = tl.List(tl.Unicode())
external_submission_blockers = tl.List(tl.Unicode())

def __init__(self, qe_auto_setup=True, **kwargs):
self.message_area = ipw.Output()
Expand Down Expand Up @@ -139,13 +139,7 @@ def __init__(self, qe_auto_setup=True, **kwargs):
]
)

@tl.observe("_outside_submission_blockers")
def _observe_outside_submission_blockers(self, _=None):
"""Observe the submission blockers from the app, and update the
submission blockers of the submit step."""
self._submission_blockers = list(self._identify_submission_blockers())

@tl.observe("_submission_blockers")
@tl.observe("internal_submission_blockers", "external_submission_blockers")
def _observe_submission_blockers(self, change):
"""Observe the submission blockers and update the message area."""
if change["new"]:
Expand All @@ -158,13 +152,7 @@ def _observe_submission_blockers(self, change):
self._submission_blocker_messages.value = ""

def _identify_submission_blockers(self):
"""Identify the blockers for the submission.
Include the blockers from the app and the blockers from the submit step itself.
"""
# blocker messages from the app
for msgs in self._outside_submission_blockers.values():
for msg in msgs:
yield msg
"""Validate the inputs and identify blockers for the submission."""
# Do not submit while any of the background setup processes are running.
if self.qe_setup_status.busy or self.sssp_installation_status.busy:
yield "Background setup processes must finish."
Expand Down Expand Up @@ -199,11 +187,11 @@ def _update_state(self, _=None):

blockers = list(self._identify_submission_blockers())
if any(blockers):
self._submission_blockers = blockers
self.internal_submission_blockers = blockers
self.state = self.State.READY
return

self._submission_blockers = []
self.internal_submission_blockers = []
self.state = self.state.CONFIGURED

def _toggle_install_widgets(self, change):
Expand Down

0 comments on commit 5a775ea

Please sign in to comment.