Skip to content

Commit

Permalink
Implement lazy-loading at top level
Browse files Browse the repository at this point in the history
  • Loading branch information
edan-bainglass committed Sep 5, 2024
1 parent 55ee885 commit 70c7539
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 109 deletions.
27 changes: 13 additions & 14 deletions src/aiidalab_qe/app/configuration/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,8 @@
import traitlets as tl

from aiida import orm
from aiidalab_qe.app.utils import get_entry_items
from aiidalab_widgets_base import WizardAppWidgetStep

from .advanced import AdvancedSettings
from .workflow import WorkChainSettings


class ConfigureQeAppWorkChainStep(ipw.VBox, WizardAppWidgetStep):
confirmed = tl.Bool()
Expand All @@ -24,7 +20,12 @@ class ConfigureQeAppWorkChainStep(ipw.VBox, WizardAppWidgetStep):
# output dictionary
configuration_parameters = tl.Dict()

def __init__(self, **kwargs):
def render(self):
from aiidalab_qe.app.utils import get_entry_items

from .advanced import AdvancedSettings
from .workflow import WorkChainSettings

self.workchain_settings = WorkChainSettings()
self.advanced_settings = AdvancedSettings()

Expand Down Expand Up @@ -100,22 +101,20 @@ def __init__(self, **kwargs):

self.confirm_button.on_click(self.confirm)

super().__init__(
children=[
self.tab,
self._submission_blocker_messages,
self.confirm_button,
],
**kwargs,
)
self.children = [
self.tab,
self._submission_blocker_messages,
self.confirm_button,
]

@tl.observe("previous_step_state")
def _observe_previous_step_state(self, _change):
self._update_state()

def get_configuration_parameters(self):
"""Get the parameters of the configuration step."""

if not hasattr(self, "tab"):
return {}
return {s.identifier: s.get_panel_value() for s in self.tab.children}

def set_configuration_parameters(self, parameters):
Expand Down
20 changes: 12 additions & 8 deletions src/aiidalab_qe/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,18 @@

import ipywidgets as ipw

from aiida.orm import load_node
from aiidalab_qe.app.configuration import ConfigureQeAppWorkChainStep
from aiidalab_qe.app.result import ViewQeAppWorkChainStatusAndResultsStep
from aiidalab_qe.app.structure import StructureSelectionStep
from aiidalab_qe.app.submission import SubmitQeAppWorkChainStep
from aiidalab_qe.common import QeAppWorkChainSelector
from aiidalab_widgets_base import WizardAppWidget, WizardAppWidgetStep


class App(ipw.VBox):
"""The main widget that combines all the application steps together."""

def __init__(self, qe_auto_setup=True):
from aiidalab_qe.app.configuration import ConfigureQeAppWorkChainStep
from aiidalab_qe.app.result import ViewQeAppWorkChainStatusAndResultsStep
from aiidalab_qe.app.structure import StructureSelectionStep
from aiidalab_qe.app.submission import SubmitQeAppWorkChainStep
from aiidalab_qe.common import QeAppWorkChainSelector
from aiidalab_widgets_base import WizardAppWidget

# Create the application steps
self.structure_step = StructureSelectionStep(auto_advance=True)
self.structure_step.observe(self._observe_structure_selection, "structure")
Expand Down Expand Up @@ -85,6 +84,8 @@ def __init__(self, qe_auto_setup=True):
]
)

self._wizard_app_widget.selected_index = None

@property
def steps(self):
return self._wizard_app_widget.steps
Expand All @@ -100,6 +101,8 @@ def _observe_structure_selection(self, change):

def _observe_selected_index(self, change):
"""Check unsaved change in the step when leaving the step."""
from aiidalab_widgets_base import WizardAppWidgetStep

# no accordion tab is selected
if not change["new"]:
return
Expand All @@ -120,6 +123,7 @@ def _observe_selected_index(self, change):
self.submit_step.external_submission_blockers = blockers

def _observe_process_selection(self, change):
from aiida.orm import load_node
from aiida.orm.utils.serialize import deserialize_unsafe

if change["old"] == change["new"]:
Expand Down
34 changes: 17 additions & 17 deletions src/aiidalab_qe/app/result/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,7 @@
import traitlets as tl

from aiida import orm
from aiida.engine import ProcessState
from aiida.engine.processes import control
from aiidalab_widgets_base import (
AiidaNodeViewWidget,
ProcessMonitor,
ProcessNodesTreeWidget,
WizardAppWidgetStep,
)
from aiidalab_widgets_base import WizardAppWidgetStep

# trigger registration of the viewer widget:
from .workchain_viewer import WorkChainViewer # noqa: F401
Expand All @@ -22,7 +15,13 @@
class ViewQeAppWorkChainStatusAndResultsStep(ipw.VBox, WizardAppWidgetStep):
process = tl.Unicode(allow_none=True)

def __init__(self, **kwargs):
def render(self):
from aiidalab_widgets_base import (
AiidaNodeViewWidget,
ProcessMonitor,
ProcessNodesTreeWidget,
)

self.process_tree = ProcessNodesTreeWidget()
ipw.dlink(
(self, "process"),
Expand Down Expand Up @@ -57,15 +56,13 @@ def __init__(self, **kwargs):
self.kill_button.on_click(self._on_click_kill_button)
self.process_info = ipw.HTML()

super().__init__(
[
ipw.HBox(children=[self.kill_button, self.process_info]),
self.process_status,
],
**kwargs,
)
self.children = [
ipw.HBox(children=[self.kill_button, self.process_info]),
self.process_status,
]

self._update_kill_button_layout()
self.observe(self._observe_process, "process")

def can_reset(self):
"Do not allow reset while process is running."
Expand All @@ -76,6 +73,8 @@ def reset(self):

def _update_state(self):
"""Based on the process state, update the state of the step."""
from aiida.engine import ProcessState

if self.process is None:
self.state = self.State.INIT
else:
Expand Down Expand Up @@ -124,13 +123,14 @@ def _on_click_kill_button(self, _=None):
"""callback for the kill button.
First kill the process, then update the kill button layout.
"""
from aiida.engine.processes import control

workchain = [orm.load_node(self.process)]
control.kill_processes(workchain)

# update the kill button layout
self._update_kill_button_layout()

@tl.observe("process")
def _observe_process(self, _):
"""Callback for when the process is changed."""
# The order of the following calls matters,
Expand Down
79 changes: 40 additions & 39 deletions src/aiidalab_qe/app/structure/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,8 @@
import ipywidgets as ipw
import traitlets as tl

import aiida
from aiida_quantumespresso.data.hubbard_structure import HubbardStructureData
from aiidalab_qe.app.utils import get_entry_items
from aiidalab_qe.common import AddingTagsEditor
from aiidalab_widgets_base import (
BasicCellEditor,
BasicStructureEditor,
OptimadeQueryWidget,
StructureBrowserWidget,
StructureExamplesWidget,
StructureManagerWidget,
StructureUploadWidget,
WizardAppWidgetStep,
)
from aiida import orm
from aiidalab_widgets_base import WizardAppWidgetStep

# The Examples list of (name, file) tuple curretly passed to
# StructureExamplesWidget.
Expand All @@ -47,18 +35,45 @@ class StructureSelectionStep(ipw.VBox, WizardAppWidgetStep):
structure importers and the structure editors can be extended by plugins.
"""

structure = tl.Instance(aiida.orm.StructureData, allow_none=True)
confirmed_structure = tl.Instance(aiida.orm.StructureData, allow_none=True)
structure = tl.Instance(orm.StructureData, allow_none=True)
confirmed_structure = tl.Instance(orm.StructureData, allow_none=True)

def __init__(self, description=None, **kwargs):
if description is None:
description = ipw.HTML(
"""
<p>Select a structure from one of the following sources and then click
"Confirm" to go to the next step. </p><i class="fa fa-exclamation-circle"
aria-hidden="true"></i> Currently only three-dimensional structures are
supported.
"""
)
self.description = description
super().__init__(**kwargs)

def render(self):
"""docstring"""
from aiida_quantumespresso.data.hubbard_structure import HubbardStructureData
from aiidalab_qe.app.utils import get_entry_items
from aiidalab_qe.common import AddingTagsEditor
from aiidalab_widgets_base import (
BasicCellEditor,
BasicStructureEditor,
OptimadeQueryWidget,
StructureBrowserWidget,
StructureExamplesWidget,
StructureManagerWidget,
StructureUploadWidget,
)

importers = [
StructureUploadWidget(title="Upload file"),
OptimadeQueryWidget(embedded=False),
StructureBrowserWidget(
title="AiiDA database",
query_types=(
aiida.orm.StructureData,
aiida.orm.CifData,
orm.StructureData,
orm.CifData,
HubbardStructureData,
),
),
Expand All @@ -84,17 +99,6 @@ def __init__(self, description=None, **kwargs):
configuration_tabs=["Cell", "Selection", "Appearance", "Download"],
)

if description is None:
description = ipw.HTML(
"""
<p>Select a structure from one of the following sources and then click
"Confirm" to go to the next step. </p><i class="fa fa-exclamation-circle"
aria-hidden="true"></i> Currently only three-dimensional structures are
supported.
"""
)
self.description = description

self.structure_name_text = ipw.Text(
placeholder="[No structure selected]",
description="Selected:",
Expand All @@ -117,16 +121,13 @@ def __init__(self, description=None, **kwargs):
# structure manager to our 'structure' traitlet:
ipw.dlink((self.manager, "structure_node"), (self, "structure"))

super().__init__(
children=[
self.description,
self.manager,
self.structure_name_text,
self.message_area,
self.confirm_button,
],
**kwargs,
)
self.children = [
self.description,
self.manager,
self.structure_name_text,
self.message_area,
self.confirm_button,
]

@tl.default("state")
def _default_state(self):
Expand Down
Loading

0 comments on commit 70c7539

Please sign in to comment.