Skip to content

Commit

Permalink
Discard FINISHED process status notification on next monitor round
Browse files Browse the repository at this point in the history
  • Loading branch information
edan-bainglass committed Dec 27, 2024
1 parent 284eed4 commit 5b7034d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 15 deletions.
29 changes: 16 additions & 13 deletions src/aiidalab_qe/common/panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,7 @@ class ResultsModel(PanelModel, HasProcess):
_this_process_uuid = None

auto_render = False
_completed_process = False

CSS_MAP = {
"finished": "success",
Expand All @@ -533,7 +534,13 @@ def update(self):
self.auto_render = True

def update_process_status_notification(self):
self.process_status_notification = self._get_child_process_status()
if self._completed_process:
self.process_status_notification = ""
return
status = self._get_child_process_status()
self.process_status_notification = status
if "success" in status:
self._completed_process = True

def fetch_child_process_node(self, child="this") -> orm.ProcessNode | None:
if not self.process_uuid:
Expand Down Expand Up @@ -602,12 +609,10 @@ class ResultsPanel(Panel[RM]):
It has a update method to update the result in the panel.
"""

has_controls = False
loading_message = "Loading {identifier} results"

def __init__(self, model: RM, **kwargs):
super().__init__(model=model, **kwargs)

self._model.observe(
self._on_process_change,
"process_uuid",
Expand All @@ -617,19 +622,23 @@ def __init__(self, model: RM, **kwargs):
"monitor_counter",
)

self.links = []

def render(self):
if self.rendered:
if self._model.identifier == "structure":
self._render()
return
if self.has_controls or not self._model.has_process:

if not self._model.has_process:
return

self.results_container = ipw.VBox()

if self._model.auto_render:
self.children = [self.results_container]
self._load_results()
else:
self._render_controls()
self.children += (self.results_container,)

def _on_process_change(self, _):
self._model.update()
Expand All @@ -638,15 +647,14 @@ def _on_monitor_counter_change(self, _):
self._model.update_process_status_notification()

def _on_load_results_click(self, _):
self.load_controls.children = []
self._load_results()

def _load_results(self):
self.load_controls.children = []
self.results_container.children = [self.loading_message]
self._render()
self.rendered = True
self._post_render()
self.has_controls = False

def _render_controls(self):
self.process_status_notification = ipw.HTML()
Expand All @@ -668,8 +676,6 @@ def _render_controls(self):
)
self.load_results_button.on_click(self._on_load_results_click)

self.results_container = ipw.VBox()

self.load_controls = ipw.HBox(
children=[]
if self._model.auto_render
Expand All @@ -687,11 +693,8 @@ def _render_controls(self):
self.children = [
self.process_status_notification,
self.load_controls,
self.results_container,
]

self.has_controls = True

def _render(self):
raise NotImplementedError()

Expand Down
15 changes: 13 additions & 2 deletions src/aiidalab_qe/plugins/electronic_structure/result/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ class ElectronicStructureResultsModel(ResultsModel):
"pdos": "PDOS",
}

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._completed_processes = set()

@property
def include(self):
return any(identifier in self.properties for identifier in self.identifiers)
Expand All @@ -40,8 +44,15 @@ def update(self):
self.title = f"Electronic {' + '.join(parts)}"

def update_process_status_notification(self):
statuses = [self._get_child_process_status(child) for child in self.identifiers]
self.process_status_notification = "\n".join(statuses)
self._status_notifications = []
for identifier in self.identifiers:
if identifier in self._completed_processes:
continue
status = self._get_child_process_status(identifier)
self._status_notifications.append(status)
if "success" in status:
self._completed_processes.add(identifier)
self.process_status_notification = "\n".join(self._status_notifications)

def has_partial_results(self, identifier):
if identifier == "bands":
Expand Down

0 comments on commit 5b7034d

Please sign in to comment.