Skip to content

Commit

Permalink
Register ProcessNodeViewer for all process types (#348)
Browse files Browse the repository at this point in the history
Extend the existing `WorkChainNodeViewe` to all AiiDA process types.
  • Loading branch information
danielhollas authored Sep 13, 2022
1 parent 20194a8 commit f4c3e3e
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 8 deletions.
25 changes: 18 additions & 7 deletions aiidalab_widgets_base/viewers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import spglib
import traitlets
from aiida.cmdline.utils.common import get_workchain_report
from aiida.cmdline.utils.query import formatting
from aiida.orm import Node
from ase import Atoms, neighborlist
from ase.cell import Cell
Expand Down Expand Up @@ -1164,18 +1165,28 @@ def __init__(self, bands, **kwargs):
super().__init__(children, **kwargs)


@register_viewer_widget("process.calculation.calcfunction.CalcFunctionNode.")
@register_viewer_widget("process.calculation.calcjob.CalcJobNode.")
@register_viewer_widget("process.workflow.workfunction.WorkFunctionNode.")
@register_viewer_widget("process.workflow.workchain.WorkChainNode.")
class WorkChainNodeViewerWidget(ipw.HTML):
def __init__(self, workchain, **kwargs):
self.workchain = workchain
class ProcessNodeViewerWidget(ipw.HTML):
def __init__(self, process, **kwargs):
self.process = process

# Displaying reports only from the selected workchain,
# NOT from its descendants
report = get_workchain_report(self.workchain, "REPORT", max_depth=1)
# Displaying reports only from the selected process,
# NOT from its descendants.
report = get_workchain_report(self.process, "REPORT", max_depth=1)
# Filter out the first column with dates
filtered_report = re.sub(
r"^[0-9]{4}.*\| ([A-Z]+)\]", r"\1", report, flags=re.MULTILINE
)
self.value = f"<pre>{filtered_report}</pre>"
header = f"""
Process {process.process_label},
State: {formatting.format_process_state(process.process_state.value)},
UUID: {process.uuid} (pk: {process.pk})<br>
Started {formatting.format_relative_time(process.ctime)},
Last modified {formatting.format_relative_time(process.mtime)}<br>
"""
self.value = f"{header}<pre>{filtered_report}</pre>"

super().__init__(**kwargs)
40 changes: 39 additions & 1 deletion notebooks/aiida_datatypes_viewers.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,44 @@
"vwr = viewer(fd.store(), downloadable=True)\n",
"display(vwr)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Workfunctions and Calcfunctions"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from aiida.workflows.arithmetic.add_multiply import add, add_multiply\n",
"from aiida.engine import run_get_node\n",
"from aiida.orm import Int"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"result, workfunction = run_get_node(add_multiply, Int(3), Int(4), Int(5))\n",
"display(viewer(workfunction))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"result, calcfunction = run_get_node(add, Int(3), Int(4))\n",
"display(viewer(calcfunction))"
]
}
],
"metadata": {
Expand All @@ -187,7 +225,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.7"
"version": "3.7.9"
}
},
"nbformat": 4,
Expand Down

0 comments on commit f4c3e3e

Please sign in to comment.