Skip to content

Commit

Permalink
Implement lazy loading in configuration step
Browse files Browse the repository at this point in the history
  • Loading branch information
edan-bainglass committed Sep 10, 2024
1 parent 3efcfb6 commit 1d107d9
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 82 deletions.
19 changes: 4 additions & 15 deletions src/aiidalab_qe/app/configuration/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,13 @@ def render(self):
layout=ipw.Layout(min_height="250px"),
selected_index=None,
)
self.tab.observe(self._on_tab_change, "selected_index")

self.tab.set_title(0, "Basic settings")
self.tab.set_title(1, "Advanced settings")

self.tab.observe(self._on_tab_change, "selected_index")

self.tab.selected_index = 0

# store the property identifier and setting panel for all plugins
# only show the setting panel when the corresponding property is selected
# first add the built-in settings
Expand All @@ -65,12 +67,6 @@ def render(self):
"advanced": self.advanced_settings,
}

# list of trailets to link
# if new trailets are added to the settings, they need to be added here
trailets_list = ["input_structure", "protocol", "electronic_type", "spin_type"]

self.tab.selected_index = 0

# then add plugin specific settings
entries = get_entry_items("aiidalab_qe.properties", "setting")
for identifier, entry_point in entries.items():
Expand All @@ -81,13 +77,6 @@ def render(self):
self.workchain_settings.properties[identifier].run.observe(
self._update_panel, "value"
)
# link the trailets if they exist in the plugin specific settings
for trailet in trailets_list:
if hasattr(self.settings[identifier], trailet):
ipw.dlink(
(self.advanced_settings, trailet),
(self.settings[identifier], trailet),
)

self._submission_blocker_messages = ipw.HTML()

Expand Down
2 changes: 1 addition & 1 deletion src/aiidalab_qe/app/configuration/advanced.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ def render(self):
]

ipw.dlink(
(config_model, "workchain_protocol"),
(config_model, "protocol"),
(self, "protocol"),
)
ipw.dlink(
Expand Down
2 changes: 1 addition & 1 deletion src/aiidalab_qe/app/configuration/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class ConfigurationModel(traitlets.HasTraits):

input_structure = traitlets.Instance(orm.StructureData, allow_none=True)
configuration_parameters = traitlets.Dict()
workchain_protocol = traitlets.Unicode()
protocol = traitlets.Unicode()
spin_type = traitlets.Unicode()
electronic_type = traitlets.Unicode()

Expand Down
2 changes: 1 addition & 1 deletion src/aiidalab_qe/app/configuration/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def update_reminder_info(change, name=name):

ipw.dlink(
(self.workchain_protocol, "value"),
(config_model, "workchain_protocol"),
(config_model, "protocol"),
)
ipw.dlink(
(self.spin_type, "value"),
Expand Down
18 changes: 16 additions & 2 deletions src/aiidalab_qe/common/panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ def __init__(self, parent=None, identifier=None, **kwargs):
:param kwargs: keyword arguments to pass to the ipw.VBox constructor.
"""
self.parent = parent
if identifier:
self.identifier = identifier
self.identifier = identifier or getattr(self, "identifier", "plugin")
super().__init__(
children=kwargs.pop("children", []),
**kwargs,
Expand Down Expand Up @@ -61,6 +60,21 @@ def _update_state(self):
"""Update the state of the panel."""


class SettingPanel(Panel):
title = "Settings"
description = ""

def __init__(self, **kwargs):
from aiidalab_qe.common.widgets import LoadingWidget

super().__init__(
children=[LoadingWidget(f"Loading {self.identifier} settings")],
**kwargs,
)

self.rendered = False


class OutlinePanel(Panel):
title = "Outline"
description = ""
Expand Down
25 changes: 14 additions & 11 deletions src/aiidalab_qe/plugins/bands/setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@

import ipywidgets as ipw

from aiidalab_qe.common.panel import Panel
from aiidalab_qe.common.panel import SettingPanel


class Setting(Panel):
class Setting(SettingPanel):
title = "Bands Structure"
identifier = "bands"

def __init__(self, **kwargs):
def render(self):
if self.rendered:
return

self.settings_title = ipw.HTML(
"""<div style="padding-top: 0px; padding-bottom: 0px">
<h4>Settings</h4></div>"""
Expand All @@ -34,14 +37,14 @@ def __init__(self, **kwargs):
],
value="hexagonal",
)
super().__init__(
children=[
self.settings_title,
self.kpath_2d_help,
self.kpath_2d,
],
**kwargs,
)

self.children = [
self.settings_title,
self.kpath_2d_help,
self.kpath_2d,
]

self.rendered = True

def get_panel_value(self):
"""Return a dictionary with the input parameters for the plugin."""
Expand Down
32 changes: 23 additions & 9 deletions src/aiidalab_qe/plugins/pdos/setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,21 @@
create_kpoints_from_distance,
)
from aiida_quantumespresso.workflows.pdos import PdosWorkChain
from aiidalab_qe.common.panel import Panel
from aiidalab_qe.common.panel import SettingPanel


class Setting(Panel):
class Setting(SettingPanel):
title = "PDOS"
identifier = "pdos"
input_structure = tl.Instance(orm.StructureData, allow_none=True)
protocol = tl.Unicode(allow_none=True)

def __init__(self, **kwargs):
def render(self):
if self.rendered:
return

from aiidalab_qe.app.configuration.model import config_model

self.settings_title = ipw.HTML(
"""<div style="padding-top: 0px; padding-bottom: 0px">
<h4>Settings</h4></div>"""
Expand All @@ -34,14 +39,23 @@ def __init__(self, **kwargs):
self.mesh_grid = ipw.HTML()
self.nscf_kpoints_distance.observe(self._display_mesh, "value")
self.nscf_kpoints_distance.observe(self._procotol_changed, "change")
super().__init__(
children=[
self.settings_title,
ipw.HBox([self.nscf_kpoints_distance, self.mesh_grid]),
],
**kwargs,

self.children = [
self.settings_title,
ipw.HBox([self.nscf_kpoints_distance, self.mesh_grid]),
]

ipw.dlink(
(config_model, "protocol"),
(self, "protocol"),
)
ipw.dlink(
(config_model, "input_structure"),
(self, "input_structure"),
)

self.rendered = True

@tl.observe("protocol")
def _procotol_changed(self, change):
self.nscf_kpoints_distance.value = PdosWorkChain.get_protocol_inputs(
Expand Down
51 changes: 29 additions & 22 deletions src/aiidalab_qe/plugins/xas/setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import yaml

from aiida import orm
from aiidalab_qe.common.panel import Panel
from aiidalab_qe.common.panel import SettingPanel
from aiidalab_qe.plugins import xas as xas_folder

PSEUDO_TOC = yaml.safe_load(resources.read_text(xas_folder, "pseudo_toc.yaml"))
Expand Down Expand Up @@ -112,7 +112,7 @@ def _download_extract_pseudo_archive(func):
)


class Setting(Panel):
class Setting(SettingPanel):
title = "XAS Settings"
identifier = "xas"
input_structure = tl.Instance(orm.StructureData, allow_none=True)
Expand Down Expand Up @@ -169,7 +169,12 @@ class Setting(Panel):
</div>"""
)

def __init__(self, **kwargs):
def render(self):
if self.rendered:
return

from aiidalab_qe.app.configuration.model import config_model

self.gipaw_pseudos = pseudo_data_dict["pbe"]["gipaw_pseudos"]
self.core_hole_pseudos = pseudo_data_dict["pbe"]["core_hole_pseudos"]["1s"]
self.core_wfc_data_dict = pseudo_data_dict["pbe"]["core_wavefunction_data"]
Expand All @@ -190,27 +195,29 @@ def __init__(self, **kwargs):
style={"description_width": "initial"},
)

super().__init__(
children=[
# self.structure_title,
# self.structure_help,
# ipw.HBox(
# [self.structure_type],
# ),
self.element_selection_title,
self.element_selection_help,
ipw.HBox(
[self.element_and_ch_treatment], layout=ipw.Layout(width="95%")
),
self.supercell_title,
self.supercell_help,
ipw.HBox(
[self.supercell_min_parameter],
),
],
**kwargs,
self.children = [
# self.structure_title,
# self.structure_help,
# ipw.HBox(
# [self.structure_type],
# ),
self.element_selection_title,
self.element_selection_help,
ipw.HBox([self.element_and_ch_treatment], layout=ipw.Layout(width="95%")),
self.supercell_title,
self.supercell_help,
ipw.HBox(
[self.supercell_min_parameter],
),
]

ipw.dlink(
(config_model, "input_structure"),
(self, "input_structure"),
)

self.rendered = True

def get_panel_value(self):
elements_list = []
core_hole_treatments = {}
Expand Down
50 changes: 30 additions & 20 deletions src/aiidalab_qe/plugins/xps/setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import traitlets as tl

from aiida.orm import Group, QueryBuilder, StructureData
from aiidalab_qe.common.panel import Panel
from aiidalab_qe.common.panel import SettingPanel

base_url = "https://github.com/superstar54/xps-data/raw/main/pseudo_demo/"

Expand All @@ -25,7 +25,7 @@ def run_(*args, **kwargs):
run_(["verdi", "archive", "import", url, "--no-import-group"])


class Setting(Panel):
class Setting(SettingPanel):
title = "XPS Settings"
identifier = "xps"
input_structure = tl.Instance(StructureData, allow_none=True)
Expand Down Expand Up @@ -94,7 +94,12 @@ class Setting(Panel):
</div>"""
)

def __init__(self, **kwargs):
def render(self):
if self.rendered:
return

from aiidalab_qe.app.configuration.model import config_model

# Core hole treatment type
self.core_hole_treatment = ipw.ToggleButtons(
options=[
Expand Down Expand Up @@ -133,25 +138,30 @@ def __init__(self, **kwargs):
)

self.pseudo_group.observe(self._update_pseudo, names="value")
super().__init__(
children=[
self.structure_title,
self.structure_help,
ipw.HBox(
[self.structure_type],
),
self.pseudo_title,
self.pseudo_help,
self.pseudo_group,
self.core_level_title,
self.core_level_help,
ipw.HBox(
[self.core_level_list],
),
],
**kwargs,

self.children = [
self.structure_title,
self.structure_help,
ipw.HBox(
[self.structure_type],
),
self.pseudo_title,
self.pseudo_help,
self.pseudo_group,
self.core_level_title,
self.core_level_help,
ipw.HBox(
[self.core_level_list],
),
]

ipw.dlink(
(config_model, "input_structure"),
(self, "input_structure"),
)

self.rendered = True

def get_panel_value(self):
"""Return a dictionary with the input parameters for the plugin."""
core_level_list = [
Expand Down

0 comments on commit 1d107d9

Please sign in to comment.