Skip to content

Commit

Permalink
Lift app setup above wizard initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
edan-bainglass committed Feb 14, 2025
1 parent 09df961 commit 021ffe8
Show file tree
Hide file tree
Showing 12 changed files with 116 additions and 192 deletions.
9 changes: 0 additions & 9 deletions qe.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,6 @@
"\n",
"app = QeApp(process=pk)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"app.load()"
]
}
],
"metadata": {
Expand Down
65 changes: 7 additions & 58 deletions src/aiidalab_qe/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,10 @@

from pathlib import Path

import ipywidgets as ipw
from IPython.display import display

from aiidalab_qe.app.static import styles
from aiidalab_qe.app.wizard_app import WizardApp
from aiidalab_qe.app.wrapper import AppWrapperContoller, AppWrapperModel, AppWrapperView
from aiidalab_widgets_base.bug_report import (
install_create_github_issue_exception_handler,
)
from aiidalab_widgets_base.utils.loaders import load_css

DEFAULT_BUG_REPORT_URL = "https://github.com/aiidalab/aiidalab-qe/issues/new"
Expand All @@ -29,64 +24,18 @@ def __init__(
):
"""Initialize the AiiDAlab QE application with the necessary setup."""

self.process = process
self.qe_auto_setup = qe_auto_setup
self.log_widget = None

self._load_styles()

# Initialize MVC components
self.model = AppWrapperModel()
self.view = AppWrapperView()
display(self.view)

if show_log:
self.log_widget = ipw.Output(
layout=ipw.Layout(
border="solid 1px lightgray",
margin="2px",
padding="5px",
),
)
reset_button = ipw.Button(
description="Clear log",
button_style="primary",
icon="trash",
layout=ipw.Layout(width="fit-content"),
)
reset_button.on_click(lambda _: self.log_widget.clear_output())
display(
ipw.VBox(
children=[
reset_button,
self.log_widget,
],
)
)
model = AppWrapperModel()
model.process = process
model.show_log = show_log
model.qe_auto_setup = qe_auto_setup
view = AppWrapperView(show_log, bug_report_url)
_ = AppWrapperContoller(model, view)

# Set up bug report handling (if a URL is provided)
if bug_report_url:
install_create_github_issue_exception_handler(
self.log_widget if show_log else self.view.output,
url=bug_report_url,
labels=("bug", "automated-report"),
)

# setup UI controls
self.controller = AppWrapperContoller(self.model, self.view)
self.controller.enable_controls()
display(view)

def _load_styles(self):
"""Load CSS styles from the static directory."""
load_css(css_path=Path(styles.__file__).parent)

def load(self):
"""Initialize the WizardApp and integrate the app into the main view."""
self.app = WizardApp(
qe_auto_setup=self.qe_auto_setup,
log_widget=self.log_widget,
)
self.view.main.children = [self.app]
# load a previous calculation if it is provided
if self.process:
self.app.process = self.process
2 changes: 1 addition & 1 deletion src/aiidalab_qe/app/parameters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def recursive_merge(d1, d2):
DEFAULT_PARAMETERS = yaml.safe_load(resources.read_text(parameters, "qeapp.yaml"))


custom_config_file = Path.home() / ".aiidalab" / "quantumespresso" / "config.yml"
custom_config_file = Path.home() / ".aiidalab" / "quantum-espresso" / "config.yml"
if custom_config_file.exists():
custom_config = yaml.safe_load(custom_config_file.read_text())
DEFAULT_PARAMETERS = recursive_merge(DEFAULT_PARAMETERS, custom_config)
1 change: 1 addition & 0 deletions src/aiidalab_qe/app/result/components/summary/summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def _render_summary(self):
(self._model, "failed_calculation_report"),
(self.failed_calculation_report, "value"),
)
self._model.generate_failure_report()

self.children = [
container,
Expand Down
80 changes: 1 addition & 79 deletions src/aiidalab_qe/app/submission/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
PluginResourceSettingsPanel,
ResourceSettingsPanel,
)
from aiidalab_qe.common.setup_codes import QESetupWidget
from aiidalab_qe.common.setup_pseudos import PseudosInstallWidget
from aiidalab_qe.common.widgets import LinkButton, QeDependentWizardStep

from .global_settings import GlobalResourceSettingsModel, GlobalResourceSettingsPanel
Expand All @@ -30,7 +28,7 @@
class SubmitQeAppWorkChainStep(QeDependentWizardStep[SubmissionStepModel]):
missing_information_warning = "Missing input structure and/or configuration parameters. Please set them first."

def __init__(self, model: SubmissionStepModel, qe_auto_setup=True, **kwargs):
def __init__(self, model: SubmissionStepModel, **kwargs):
super().__init__(model=model, **kwargs)
self._model.observe(
self._on_submission,
Expand All @@ -47,22 +45,6 @@ def __init__(self, model: SubmissionStepModel, qe_auto_setup=True, **kwargs):
"external_submission_blockers",
],
)
self._model.observe(
self._on_installation_change,
["installing_sssp", "sssp_installed"],
)
self._model.observe(
self._on_sssp_installed,
"sssp_installed",
)
self._model.observe(
self._on_installation_change,
["installing_qe", "qe_installed"],
)
self._model.observe(
self._on_qe_installed,
"qe_installed",
)

global_resources_model = GlobalResourceSettingsModel()
self.global_resources = GlobalResourceSettingsPanel(
Expand All @@ -87,9 +69,6 @@ def __init__(self, model: SubmissionStepModel, qe_auto_setup=True, **kwargs):
}
self._fetch_plugin_resource_settings()

self._install_sssp(qe_auto_setup)
self._set_up_qe(qe_auto_setup)

def _render(self):
self.process_label = ipw.Text(
description="Label:",
Expand Down Expand Up @@ -179,8 +158,6 @@ def _render(self):
layout=ipw.Layout(grid_gap="5px"),
),
self.tabs,
self.sssp_installation,
self.qe_setup,
self.submission_blocker_messages,
self.submission_warning_messages,
ipw.HTML("""
Expand Down Expand Up @@ -235,64 +212,9 @@ def _on_submission_blockers_change(self, _):
self._model.update_submission_blocker_message()
self._update_state()

def _on_installation_change(self, _):
self._model.update_submission_blockers()

def _on_qe_installed(self, _):
self._toggle_qe_installation_widget()
if self._model.qe_installed:
self._model.update()

def _on_sssp_installed(self, _):
self._toggle_sssp_installation_widget()

def _on_submission(self, _):
self._update_state()

def _install_sssp(self, qe_auto_setup):
self.sssp_installation = PseudosInstallWidget(auto_start=False)
ipw.dlink(
(self.sssp_installation, "busy"),
(self._model, "installing_sssp"),
)
ipw.dlink(
(self.sssp_installation, "installed"),
(self._model, "installing_sssp"),
lambda installed: not installed,
)
ipw.dlink(
(self.sssp_installation, "installed"),
(self._model, "sssp_installed"),
)
if qe_auto_setup:
self.sssp_installation.refresh()

def _set_up_qe(self, qe_auto_setup):
self.qe_setup = QESetupWidget(auto_start=False)
ipw.dlink(
(self.qe_setup, "busy"),
(self._model, "installing_qe"),
)
ipw.dlink(
(self.qe_setup, "installed"),
(self._model, "installing_qe"),
lambda installed: not installed,
)
ipw.dlink(
(self.qe_setup, "installed"),
(self._model, "qe_installed"),
)
if qe_auto_setup:
self.qe_setup.refresh()

def _toggle_sssp_installation_widget(self):
sssp_installation_display = "none" if self._model.sssp_installed else "block"
self.sssp_installation.layout.display = sssp_installation_display

def _toggle_qe_installation_widget(self):
qe_installation_display = "none" if self._model.qe_installed else "block"
self.qe_setup.layout.display = qe_installation_display

def _refresh_resources(self, _=None):
for _, model in self._model.get_models():
model.refresh_codes()
Expand Down
29 changes: 4 additions & 25 deletions src/aiidalab_qe/app/submission/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ class SubmissionStepModel(
submission_blocker_messages = tl.Unicode("")
submission_warning_messages = tl.Unicode("")

installing_qe = tl.Bool(False)
installing_sssp = tl.Bool(False)
qe_installed = tl.Bool(allow_none=True)
sssp_installed = tl.Bool(allow_none=True)

plugin_overrides = tl.List(tl.Unicode())

confirmation_exceptions = [
Expand All @@ -50,10 +45,6 @@ class SubmissionStepModel(
"external_submission_blockers",
"submission_blocker_messages",
"submission_warning_messages",
"installing_qe",
"installing_sssp",
"qe_installed",
"sssp_installed",
]

def __init__(self, *args, **kwargs):
Expand Down Expand Up @@ -153,16 +144,15 @@ def update_plugin_overrides(self):
]

def update_submission_blockers(self):
submission_blockers = list(self._check_submission_blockers())
submission_blockers = []
for _, model in self.get_models():
submission_blockers += model.submission_blockers
self.internal_submission_blockers = submission_blockers

def update_submission_warnings(self):
submission_warning_messages = self._check_submission_warnings()
for _, model in self.get_models():
submission_warning_messages += model.submission_warning_messages
self.submission_warning_messages = submission_warning_messages
self.submission_warning_messages = "".join(
model.submission_warning_messages for _, model in self.get_models()
) # type: ignore

def update_submission_blocker_message(self):
blockers = self.internal_submission_blockers + self.external_submission_blockers
Expand Down Expand Up @@ -292,14 +282,3 @@ def _create_builder(self, parameters) -> ProcessBuilderNamespace:
builder.relax.base.pw.parallelization = orm.Dict(dict=parallelization)

return builder

def _check_submission_blockers(self):
if self.installing_qe or self.installing_sssp:
yield "Background setup processes must finish."

if not self.sssp_installed:
yield "The SSSP library is not installed."

def _check_submission_warnings(self):
"""Check for any warnings that should be displayed to the user."""
return ""
3 changes: 1 addition & 2 deletions src/aiidalab_qe/app/wizard_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class WizardApp(ipw.VBox):
# The PK or UUID of the work chain node.
process = tl.Union([tl.Unicode(), tl.Int()], allow_none=True)

def __init__(self, qe_auto_setup=True, **kwargs):
def __init__(self, **kwargs):
# Initialize the models
self.structure_model = StructureStepModel()
self.configure_model = ConfigurationStepModel()
Expand All @@ -44,7 +44,6 @@ def __init__(self, qe_auto_setup=True, **kwargs):
self.submit_step = SubmitQeAppWorkChainStep(
model=self.submit_model,
auto_advance=True,
qe_auto_setup=qe_auto_setup,
)
self.results_step = ViewQeAppWorkChainStatusAndResultsStep(
model=self.results_model,
Expand Down
Loading

0 comments on commit 021ffe8

Please sign in to comment.