Skip to content

Commit

Permalink
Update the workchain viewer by the process monitor
Browse files Browse the repository at this point in the history
  • Loading branch information
superstar54 committed Oct 8, 2024
1 parent 14e5009 commit f8c7338
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
31 changes: 17 additions & 14 deletions src/aiidalab_qe/app/result/workchain_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@
@register_viewer_widget("process.workflow.workchain.WorkChainNode.")
class WorkChainViewer(ipw.VBox):
_results_shown = tl.Set()
process_uuid = tl.Unicode(allow_none=True)

def __init__(self, node, **kwargs):
if node.process_label != "QeAppWorkChain":
super().__init__()
return

self.node = node
self.process_uuid = node.uuid
# In the new version of the plugin, the ui_parameters are stored as a yaml string
# which is then converted to a dictionary
ui_parameters = node.base.extras.get("ui_parameters", {})
Expand All @@ -41,12 +42,12 @@ def __init__(self, node, **kwargs):
self.title = ipw.HTML(
f"""
<hr style="height:2px;background-color:#2097F3;">
<h4>QE App Workflow (pk: {self.node.pk}) &mdash;
{self.node.inputs.structure.get_formula()}
<h4>QE App Workflow (pk: {node.pk}) &mdash;
{node.inputs.structure.get_formula()}
</h4>
"""
)
self.workflows_summary = SummaryView(self.node)
self.workflows_summary = SummaryView(node)

self.summary_tab = ipw.VBox(children=[self.workflows_summary])
# Only the summary tab is shown by default
Expand All @@ -59,7 +60,7 @@ def __init__(self, node, **kwargs):
self.results = {}
entries = get_entry_items("aiidalab_qe.properties", "result")
for identifier, entry_point in entries.items():
result = entry_point(self.node)
result = entry_point(node)
self.results[identifier] = result
self.results[identifier].identifier = identifier

Expand All @@ -83,29 +84,31 @@ def toggle_camera():
toggle_camera()

self.result_tabs.observe(on_selected_index_change, "selected_index")
self._update_view()

super().__init__(
children=[self.title, self.result_tabs],
**kwargs,
)
self._process_monitor = ProcessMonitor(
process=self.node,
self.process_monitor = ProcessMonitor(
timeout=1.0,
callbacks=[
self._update_view,
],
)
ipw.dlink((self, "process_uuid"), (self.process_monitor, "value"))

@property
def node(self):
return orm.load_node(self.process_uuid)

def _update_view(self):
with self.hold_trait_notifications():
if self.node.is_finished:
node = self.node
if node.is_finished:
self._show_workflow_output()
# if the structure is present in the workchain,
# the structure tab will be added.
if (
"structure" not in self._results_shown
and "structure" in self.node.outputs
):
if "structure" not in self._results_shown and "structure" in node.outputs:
self._show_structure()
self.result_tabs.children += (self.structure_tab,)
# index of the last tab
Expand All @@ -119,7 +122,7 @@ def _update_view(self):
if result.identifier not in self._results_shown:
# check if the all required results are in the outputs
results_ready = [
label in self.node.outputs for label in result.workchain_labels
label in node.outputs for label in result.workchain_labels
]
if all(results_ready):
result._update_view()
Expand Down
4 changes: 4 additions & 0 deletions tests/test_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,14 @@ def test_kill_and_clean_buttons(app_to_submit, generate_qeapp_workchain):
@pytest.mark.usefixtures("sssp")
def test_workchainview(generate_qeapp_workchain):
"""Test the result tabs are properly updated"""
import time

from aiidalab_qe.app.result.workchain_viewer import WorkChainViewer

wkchain = generate_qeapp_workchain()
wcv = WorkChainViewer(wkchain.node)
# wait for the tabs to be updated by the process monitor
time.sleep(2)
assert len(wcv.result_tabs.children) == 5
assert wcv.result_tabs._titles["0"] == "Workflow Summary"
assert wcv.result_tabs._titles["1"] == "Final Geometry"
Expand Down

0 comments on commit f8c7338

Please sign in to comment.