Skip to content

Commit

Permalink
Pass label to WorkChainSelector (#473)
Browse files Browse the repository at this point in the history
The workchain selector is very slow since it loads workchain node to retrieve information from it. This is not necessary since we can store the workchain-related information in the submission step and pass it to workchain selector. It accelerates the loading time of workchain selector in QeApp and makes the loading of the app much faster.
  • Loading branch information
superstar54 authored Sep 19, 2023
1 parent b4b5a72 commit 855b08f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 43 deletions.
20 changes: 20 additions & 0 deletions src/aiidalab_qe/app/submission/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,11 +383,31 @@ def submit(self, _=None):
builder_parameters = self._extract_report_parameters(
builder, extra_parameters
)
process.label = self._generate_label()
process.base.extras.set("builder_parameters", builder_parameters)
self.process = process

self._update_state()

def _generate_label(self) -> dict:
"""Generate a label for the work chain based on the input parameters."""
formula = self.input_structure.get_formula()
properties = [
p for p in self.input_parameters["workchain"]["properties"] if p != "realx"
]
relax_type = self.input_parameters["workchain"].get("relax_type")
if relax_type != "none":
relax_info = "structure is relaxed"
else:
relax_info = "structure is not relaxed"
if not properties:
properties_info = ""
else:
properties_info = f"properties on {', '.join(properties)}"

label = "{} {} {}".format(formula, relax_info, properties_info)
return label

def _create_builder(self) -> ProcessBuilderNamespace:
"""Create the builder for the `QeAppWorkChain` submit."""
from copy import deepcopy
Expand Down
49 changes: 6 additions & 43 deletions src/aiidalab_qe/common/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import ipywidgets as ipw
import traitlets as tl
from aiida import orm
from aiida.tools.query.calculation import CalculationQueryBuilder


Expand All @@ -29,9 +28,10 @@ class WorkChainSelector(ipw.HBox):
# use `None` as setting the widget's value to None will lead to "no selection".
_NO_PROCESS = object()

BASE_FMT_WORKCHAIN = "{wc.pk:6}{wc.ctime:>10}\t{wc.state:<16}"
BASE_FMT_WORKCHAIN = "{wc.pk:6}{wc.ctime:>10}\t{wc.state:<16}\t{wc.label:<16}"

BASE_FIELDS = [("pk", int), ("ctime", str), ("state", str)]
projections = ["pk", "ctime", "state", "label"]
BASE_FIELDS = [("pk", int), ("ctime", str), ("state", str), ("label", str)]
extra_fields = None

def __init__(self, process_label, **kwargs):
Expand Down Expand Up @@ -82,14 +82,13 @@ def find_work_chains(self):
filters=filters,
order_by={"ctime": "desc"},
)
projections = ["pk", "ctime", "state"]
projected = builder.get_projected(
query_set,
projections=projections,
projections=self.projections,
)

for result in projected[1:]:
process_info = dict(zip(projections, result))
process_info = dict(zip(self.projections, result))

if self.extra_fields is not None:
pk = process_info["pk"]
Expand Down Expand Up @@ -145,43 +144,7 @@ def _observe_value(self, change):


class QeAppWorkChainSelector(WorkChainSelector):
extra_fields = [("formula", str), ("relax_info", str), ("properties_info", str)]
# extra_fields = [("formula", str), ("relax_info", str), ("properties_info", str)]

def __init__(self, **kwargs):
super().__init__(process_label="QeAppWorkChain", **kwargs)

def parse_extra_info(self, pk: int) -> dict:
"""Parse extra information about the work chain.
:param pk: the UUID of the work chain to parse
:return: the parsed extra information"""
workchain = orm.load_node(pk)
formula = workchain.inputs.structure.get_formula()

properties = []
if "pdos" in workchain.inputs:
properties.append("pdos")
if "bands" in workchain.inputs:
properties.append("bands")

if "relax" in workchain.inputs:
builder_parameters = workchain.get_extra("builder_parameters", {})
relax_type = builder_parameters.get("relax_type")

if relax_type != "none":
relax_info = "structure is relaxed"
else:
relax_info = "static SCF calculation on structure"
else:
relax_info = "structure is not relaxed"

if not properties:
properties_info = ""
else:
properties_info = f"properties on {', '.join(properties)}"

return {
"formula": formula,
"relax_info": relax_info,
"properties_info": properties_info,
}

0 comments on commit 855b08f

Please sign in to comment.