Skip to content

Commit

Permalink
add identify_submission_blockers, codes_visibility
Browse files Browse the repository at this point in the history
  • Loading branch information
superstar54 committed Oct 20, 2023
1 parent a02927a commit 931f61b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 20 deletions.
31 changes: 18 additions & 13 deletions src/aiidalab_qe/app/submission/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,9 @@ def __init__(self, qe_auto_setup=True, **kwargs):
for name, code in entry_point.items():
self.codes[name] = code
self.code_children.append(self.codes[name])
# set default codes
self.set_selected_codes(DEFAULT_PARAMETERS["codes"])
# s
#
self.submit_button = ipw.Button(
description="Submit",
tooltip="Submit the calculation with the selected parameters.",
Expand Down Expand Up @@ -152,10 +153,15 @@ def _identify_submission_blockers(self):
if self.qe_setup_status.busy or self.sssp_installation_status.busy:
yield "Background setup processes must finish."

# No code selected (this is ignored while the setup process is running).
# No pw code selected (this is ignored while the setup process is running).
if self.pw_code.value is None and not self.qe_setup_status.busy:
yield ("No pw code selected")

# code related to the selected property is not installed
properties = self.input_parameters.get("workchain", {}).get("properties", [])
for identifer in properties:
for name, code in self.code_entries.get(identifer, {}).items():
if code.value is None:
yield f"Calculating the {identifer} property requires code {name} to be set."
# SSSP library not installed
if not self.sssp_installation_status.installed:
yield "The SSSP library is not installed."
Expand Down Expand Up @@ -304,7 +310,7 @@ def _observe_state(self, change):
@tl.observe("previous_step_state")
def _observe_input_structure(self, _):
self._update_state()
self.set_codes_status()
self.udpate_codes_visibility()

@tl.observe("process")
def _observe_process(self, change):
Expand Down Expand Up @@ -341,19 +347,18 @@ def _get_code_uuid(code):
for name, code in self.codes.items():
code.value = _get_code_uuid(codes.get(name))

def set_codes_status(self):
"""Disable code if no related property is selected."""
# disable all codes except pw
def udpate_codes_visibility(self):
"""Hide code if no related property is selected."""
# hide all codes except pw
for name, code in self.codes.items():
if name == "pw":
continue
code.code_select_dropdown.disabled = True
# enable code if the related property is selected.
code.layout.visibility = "hidden"
properties = self.input_parameters.get("workchain", {}).get("properties", [])
for identifer, codes in self.code_entries.items():
if identifer in properties:
for name in codes:
self.codes[name].code_select_dropdown.disabled = False
# show the code if the related property is selected.
for identifer in properties:
for code in self.code_entries.get(identifer, {}).values():
code.layout.visibility = "visible"

def submit(self, _=None):
"""Submit the work chain with the current inputs."""
Expand Down
29 changes: 22 additions & 7 deletions tests/test_codes.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,30 @@ def test_set_selected_codes(submit_app_generator):
assert new_submit_step.get_selected_codes() == submit_step.get_selected_codes()


def test_set_code_status():
"""Test set_codes_status method.
If the workchain property is not selected, the related code should be disabled.
def test_udpate_codes_visibility():
"""Test udpate_codes_visibility method.
If the workchain property is not selected, the related code should be hidden.
"""
from aiidalab_qe.app.submission import SubmitQeAppWorkChainStep

submit = SubmitQeAppWorkChainStep(qe_auto_setup=False)
submit.set_codes_status()
assert submit.codes["dos"].code_select_dropdown.disabled is True
submit.udpate_codes_visibility()
assert submit.codes["dos"].layout.visibility == "hidden"
submit.input_parameters = {"workchain": {"properties": ["pdos"]}}
submit.set_codes_status()
assert submit.codes["dos"].code_select_dropdown.disabled is False
submit.udpate_codes_visibility()
assert submit.codes["dos"].layout.visibility == "visible"


def test_identify_submission_blockers(app):
"""Test identify_submission_blockers method."""
submit = app.submit_step
blockers = list(submit._identify_submission_blockers())
# there is one blocker: ['The SSSP library is not installed.']
assert len(blockers) == 1
submit.input_parameters = {"workchain": {"properties": ["pdos"]}}
blockers = list(submit._identify_submission_blockers())
assert len(blockers) == 1
# set dos code to None, will introduce another blocker
submit.codes["dos"].value = None
blockers = list(submit._identify_submission_blockers())
assert len(blockers) == 2

0 comments on commit 931f61b

Please sign in to comment.