Skip to content

Commit

Permalink
Works
Browse files Browse the repository at this point in the history
  • Loading branch information
edan-bainglass committed Nov 25, 2024
1 parent 9eb4361 commit f0d57ee
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 35 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 @@ -154,6 +154,12 @@ def render(self):
"selected_index",
)

self.plugin_override_notification = ipw.HTML()
ipw.dlink(
(self._model, "plugin_override_notification"),
(self.plugin_override_notification, "value"),
)

self.children = [
ipw.HTML("""
<div style="padding-top: 0px; padding-bottom: 0px">
Expand All @@ -168,6 +174,7 @@ def render(self):
on "Setup new code".
</div>
"""),
self.plugin_override_notification,
self.tabs,
self.sssp_installation,
self.qe_setup,
Expand All @@ -190,6 +197,7 @@ def render(self):
]

self.rendered = True

self._update_tabs()

def submit(self, _=None):
Expand Down Expand Up @@ -218,6 +226,14 @@ def _on_input_parameters_change(self, _):
self._model.update_process_label()
self._model.update_submission_blockers()

def _on_plugin_resources_override_change(self, _):
overrides = [
identifier
for identifier, model in self._model.get_models()
if identifier != "global" and model.override
]
self._model.update_plugin_override_notification(overrides)

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

Expand Down Expand Up @@ -329,6 +345,10 @@ def _fetch_plugin_resource_settings(self):

panel = resources["panel"]
model: ResourceSettingsModel = resources["model"]()
model.observe(
self._on_plugin_resources_override_change,
"override",
)
model.observe(
self._on_plugin_submission_blockers_change,
["submission_blockers"],
Expand Down
25 changes: 23 additions & 2 deletions src/aiidalab_qe/app/submission/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ class SubmissionStepModel(
process_label = tl.Unicode("")
process_description = tl.Unicode("")

plugin_override_notification = tl.Unicode("""
<div class="alert alert-info">
You can override resource settings per plugin in the plugin tabs.
</div>
""")
submission_blocker_messages = tl.Unicode("")
submission_warning_messages = tl.Unicode("")

Expand Down Expand Up @@ -103,6 +108,22 @@ def update_process_label(self):
label = f"{structure_label} [{relax_info}, {protocol_and_magnetic_info}] {properties_info}".strip()
self.process_label = label

def update_plugin_override_notification(self, overrides):
if overrides:
formatted = ", ".join(overrides)
self.plugin_override_notification = f"""
<div class="alert alert-info">
You can override resource settings per plugin in the plugin tabs.
<br>
<strong>Currently overriding plugin resources for: </strong>
{formatted}
</div>
"""
else:
self.plugin_override_notification = self.traits()[
"plugin_override_notification"
].default_value

def update_submission_blockers(self):
submission_blockers = list(self._check_submission_blockers())
for _, model in self.get_models():
Expand All @@ -120,12 +141,12 @@ def update_submission_warnings(self):
def update_submission_blocker_message(self):
blockers = self.internal_submission_blockers + self.external_submission_blockers
if any(blockers):
fmt_list = "\n".join(f"<li>{item}</li>" for item in sorted(blockers))
formatted = "\n".join(f"<li>{item}</li>" for item in blockers)
self.submission_blocker_messages = f"""
<div class="alert alert-danger">
<b>The submission is blocked due to the following reason(s):</b>
<ul>
{fmt_list}
{formatted}
</ul>
</div>
"""
Expand Down
22 changes: 9 additions & 13 deletions src/aiidalab_qe/common/code/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,14 @@ def set_model_state(self, parameters):
self.cpus_per_task = parameters.get("cpus_per_task", 1)
self.max_wallclock_seconds = parameters.get("max_wallclock_seconds", 3600 * 12)

def reset(self):
# TODO reset to global resources
pass

def _get_uuid(self, identifier):
if not self.selected:
try:
uuid = orm.load_code(identifier).uuid
except NotExistent:
uuid = None
# If the code was imported from another user, it is not usable
# in the app and thus will not be considered as an option!
self.selected = uuid if uuid in [opt[1] for opt in self.options] else None
return self.selected
try:
uuid = orm.load_code(identifier).uuid
except NotExistent:
uuid = None
# If the code was imported from another user, it is not usable
# in the app and thus will not be considered as an option!
return uuid if uuid in [opt[1] for opt in self.options] else None

def _get_codes(self, user_email: str = ""):
user = orm.User.collection.get(email=user_email)
Expand Down Expand Up @@ -159,6 +153,8 @@ def set_model_state(self, parameters):
if "parallelization" in parameters and "npool" in parameters["parallelization"]:
self.parallelization_override = True
self.npool = parameters["parallelization"].get("npool", 1)
else:
self.parallelization_override = False


CodesDict = dict[str, CodeModel]
Expand Down
34 changes: 14 additions & 20 deletions src/aiidalab_qe/common/panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,9 +272,8 @@ def set_selected_codes(self, code_data=DEFAULT["codes"]):
code_model.set_model_state(code_data[name])

def reset(self):
"""Reset the model to its default state."""
for code_model in self.codes.values():
code_model.reset()
"""If not overridden, updates the model w.r.t the global resources."""
self.update()

def _link_codes(self):
for code_model in self.codes.values():
Expand Down Expand Up @@ -341,17 +340,8 @@ def _on_global_codes_change(self, _):
def _on_code_resource_change(self, _):
"""Update the submission blockers and warning messages."""

def _on_override_change(self, change):
if change["new"]:
for code_widget in self.code_widgets.values():
code_widget.num_nodes.disabled = False
code_widget.num_cpus.disabled = False
code_widget.code_selection.code_select_dropdown.disabled = False
else:
for code_widget in self.code_widgets.values():
code_widget.num_nodes.disabled = True
code_widget.num_cpus.disabled = True
code_widget.code_selection.code_select_dropdown.disabled = True
def _on_override_change(self, _):
self._model.reset()

def _toggle_code(self, code_model: CodeModel):
if not self.rendered:
Expand All @@ -377,19 +367,14 @@ def _render_code_widget(
code_widget: QEAppComputationalResourcesWidget,
):
code_model.update()
ipw.dlink(
ipw.link(
(code_model, "options"),
(code_widget.code_selection.code_select_dropdown, "options"),
)
ipw.link(
(code_model, "selected"),
(code_widget.code_selection.code_select_dropdown, "value"),
)
ipw.dlink(
(code_model, "selected"),
(code_widget.code_selection.code_select_dropdown, "disabled"),
lambda selected: not selected,
)
ipw.dlink(
(code_model, "override"),
(code_widget.code_selection.code_select_dropdown, "disabled"),
Expand Down Expand Up @@ -449,9 +434,18 @@ def _render_code_widget(
(code_widget.parallelization.override, "disabled"),
lambda override: not override,
)
code_model.observe(
self._on_code_resource_change,
[
"parallelization_override",
"npool",
],
)
code_model.observe(
self._on_code_resource_change,
[
"options",
"selected",
"num_cpus",
"num_nodes",
"ntasks_per_node",
Expand Down

0 comments on commit f0d57ee

Please sign in to comment.