Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mig/2.1 #271

Merged
merged 18 commits into from
Nov 22, 2022
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 22 additions & 15 deletions .github/workflows/di.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,42 @@ on:
workflow_dispatch:
schedule:
- cron: 41 3 * * *
pull_request:

jobs:

test-app:

runs-on: ubuntu-latest
timeout-minutes: 10

strategy:
matrix:
tag: [latest, stable]
browser: [chrome, firefox]
tag: [latest]
browser: [Chrome, Firefox]
python-version: ['3.8', '3.10']
fail-fast: false

runs-on: ubuntu-latest
timeout-minutes: 60

steps:

- name: Check out app
uses: actions/checkout@v2

- name: Test app
uses: aiidalab/aiidalab-test-app-action@v2
- name: Cache Python dependencies
uses: actions/cache@v1
with:
image: aiidalab/aiidalab-docker-stack:${{ matrix.tag }}
browser: ${{ matrix.browser }}
name: quantum-espresso
path: ~/.cache/pip
key: pip-${{ matrix.python-version }}-tests-${{ hashFiles('**/setup.json') }}
restore-keys: pip-${{ matrix.python-version }}-tests

- name: Upload screenshots as artifacts
uses: actions/upload-artifact@v2
if: ${{ always() }}
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
name: Screenshots-${{ matrix.tag }}-${{ matrix.browser }}
path: screenshots/
python-version: ${{ matrix.python-version }}

- name: Install dependencies for test
run: |
pip install -U -r requirements_test.txt

- name: Run pytest
run: TAG=${{ matrix.tag }} JUPYTER_TOKEN=$(openssl rand -hex 32) pytest --driver ${{ matrix.browser }}
3 changes: 2 additions & 1 deletion aiidalab_qe/setup_codes.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def _setup_code(code_name, computer_name="localhost"):
try:
load_code(f"{code_name}-{QE_VERSION}@localhost")
except NotExistent:
# TODO replace with API setup after aiida-core 2.1 support
run(
[
"verdi",
Expand All @@ -82,7 +83,7 @@ def _setup_code(code_name, computer_name="localhost"):
"--computer",
computer_name,
"--prepend-text",
f"conda activate {CONDA_ENV_PREFIX}\nexport OMP_NUM_THREADS=1",
f'eval "$(conda shell.posix hook)"\nconda activate {CONDA_ENV_PREFIX}\nexport OMP_NUM_THREADS=1',
"--remote-abs-path",
CONDA_ENV_PREFIX.joinpath("bin", f"{code_name}.x"),
],
Expand Down
55 changes: 30 additions & 25 deletions aiidalab_qe/steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import traitlets
from aiida.common import NotExistent
from aiida.engine import ProcessBuilderNamespace, ProcessState, submit
from aiida.orm import ProcessNode, WorkChainNode, load_code
from aiida.orm import WorkChainNode, load_code, load_node
from aiida.plugins import DataFactory
from aiida_quantumespresso.common.types import ElectronicType, RelaxType, SpinType
from aiida_quantumespresso.workflows.pw.base import PwBaseWorkChain
Expand Down Expand Up @@ -614,9 +614,9 @@ def _identify_submission_blockers(self):
and len(
set(
(
self.pw_code.value.computer.pk,
self.dos_code.value.computer.pk,
self.projwfc_code.value.computer.pk,
load_code(self.pw_code.value).computer.pk,
load_code(self.dos_code.value).computer.pk,
load_code(self.projwfc_code.value).computer.pk,
)
)
)
Expand Down Expand Up @@ -667,7 +667,7 @@ def _auto_select_code(self, change):
try:
code_widget = getattr(self, code)
code_widget.refresh()
code_widget.value = load_code(DEFAULT_PARAMETERS[code])
code_widget.value = load_code(DEFAULT_PARAMETERS[code]).uuid
except NotExistent:
pass

Expand All @@ -689,9 +689,10 @@ def _show_alert_message(self, message, alert_class="info"):
def _update_resources(self, change):
if change["new"] and (
change["old"] is None
or change["new"].computer.pk != change["old"].computer.pk
or load_code(change["new"]).computer.pk
!= load_code(change["old"]).computer.pk
):
self.set_resource_defaults(change["new"].computer)
self.set_resource_defaults(load_code(change["new"]).computer)

def set_resource_defaults(self, computer=None):

Expand Down Expand Up @@ -728,7 +729,7 @@ def _check_resources(self):
return # No code selected, nothing to do.

num_cpus = self.resources_config.num_cpus.value
on_localhost = self.pw_code.value.computer.get_hostname() == "localhost"
on_localhost = load_node(self.pw_code.value).computer.hostname == "localhost"
if self.pw_code.value and on_localhost and num_cpus > 1:
self._show_alert_message(
"The selected code would be executed on the local host, but "
Expand Down Expand Up @@ -788,9 +789,9 @@ def get_input_parameters(self):
run_pdos=self.workchain_settings.pdos_run.value,
protocol=self.workchain_settings.workchain_protocol.value,
# Codes
pw_code=self.pw_code.value.uuid,
dos_code=self.dos_code.value.uuid,
projwfc_code=self.projwfc_code.value.uuid,
pw_code=self.pw_code.value,
dos_code=self.dos_code.value,
projwfc_code=self.projwfc_code.value,
# Advanced settings
pseudo_family=self.pseudo_family_selector.value,
)
Expand All @@ -808,18 +809,18 @@ def set_selected_codes(self, parameters):
"""Set the inputs in the GUI based on a set of parameters."""

# Codes
def _load_code(code):
def _get_code_uuid(code):
if code is not None:
try:
return load_code(code)
return load_code(code).uuid
except NotExistent:
return None

with self.hold_trait_notifications():
# Codes
self.pw_code.value = _load_code(parameters["pw_code"])
self.dos_code.value = _load_code(parameters["dos_code"])
self.projwfc_code.value = _load_code(parameters["projwfc_code"])
self.pw_code.value = _get_code_uuid(parameters["pw_code"])
self.dos_code.value = _get_code_uuid(parameters["dos_code"])
self.projwfc_code.value = _get_code_uuid(parameters["projwfc_code"])

def set_pdos_status(self):
if self.workchain_settings.pdos_run.value:
Expand Down Expand Up @@ -904,11 +905,14 @@ def reset(self):

class ViewQeAppWorkChainStatusAndResultsStep(ipw.VBox, WizardAppWidgetStep):

process = traitlets.Instance(ProcessNode, allow_none=True)
process_uuid = traitlets.Unicode(allow_none=True)

def __init__(self, **kwargs):
self.process_tree = ProcessNodesTreeWidget()
ipw.dlink((self, "process"), (self.process_tree, "process"))
ipw.dlink(
(self, "process_uuid"),
(self.process_tree, "process_uuid"),
)

self.node_view = NodeViewWidget(layout={"width": "auto", "height": "auto"})
ipw.dlink(
Expand All @@ -926,7 +930,7 @@ def __init__(self, **kwargs):
self._update_state,
],
)
ipw.dlink((self, "process"), (self.process_monitor, "process"))
ipw.dlink((self, "process_uuid"), (self.process_monitor, "process_uuid"))

super().__init__([self.process_status], **kwargs)

Expand All @@ -935,13 +939,14 @@ def can_reset(self):
return self.state is not self.State.ACTIVE

def reset(self):
self.process = None
self.process_uuid = None

def _update_state(self):
if self.process is None:
if self.process_uuid is None:
self.state = self.State.INIT
else:
process_state = self.process.process_state
process = load_node(self.process_uuid)
process_state = process.process_state
if process_state in (
ProcessState.CREATED,
ProcessState.RUNNING,
Expand All @@ -950,12 +955,12 @@ def _update_state(self):
self.state = self.State.ACTIVE
elif (
process_state in (ProcessState.EXCEPTED, ProcessState.KILLED)
or self.process.is_failed
or process.is_failed
):
self.state = self.State.FAIL
elif self.process.is_finished_ok:
elif process.is_finished_ok:
self.state = self.State.SUCCESS

@traitlets.observe("process")
@traitlets.observe("process_uuid")
def _observe_process(self, change):
self._update_state()
28 changes: 13 additions & 15 deletions aiidalab_qe/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import ipywidgets as ipw
import traitlets
from aiida.orm import CalcJobNode, Node
from aiida.orm import CalcJobNode, Node, load_node
from aiidalab_widgets_base import register_viewer_widget, viewer
from IPython.display import HTML, Javascript, clear_output, display

Expand Down Expand Up @@ -242,7 +242,7 @@ def _observe_value(self, change):

class CalcJobOutputFollower(traitlets.HasTraits):

calcjob = traitlets.Instance(CalcJobNode, allow_none=True)
calcjob_uuid = traitlets.Unicode(allow_none=True)
filename = traitlets.Unicode(allow_none=True)
output = traitlets.List(trait=traitlets.Unicode)
lineno = traitlets.Int()
Expand All @@ -258,14 +258,11 @@ def __init__(self, **kwargs):

super().__init__(**kwargs)

@traitlets.observe("calcjob")
@traitlets.observe("calcjob_uuid")
def _observe_calcjob(self, change):
try:
if change["old"].pk == change["new"].pk:
# Old and new process are identical.
return
except AttributeError:
pass
calcjob_uuid = change["new"]
if change["old"] == calcjob_uuid:
return

with self._lock:
# Stop following
Expand All @@ -283,15 +280,15 @@ def _observe_calcjob(self, change):
# (Re/)start following
if change["new"]:
self._follow_output_thread = Thread(
target=self._follow_output, args=(change["new"],)
target=self._follow_output, args=(calcjob_uuid,)
)
self._follow_output_thread.start()

def _follow_output(self, calcjob):
def _follow_output(self, calcjob_uuid):
"""Monitor calcjob and orchestrate pushing and pulling of output."""
self._pull_thread = Thread(target=self._pull_output, args=(calcjob,))
self._pull_thread = Thread(target=self._pull_output)
self._pull_thread.start()
self._push_thread = Thread(target=self._push_output, args=(calcjob,))
self._push_thread = Thread(target=self._push_output, args=(calcjob_uuid,))
self._push_thread.start()

def _fetch_output(self, calcjob):
Expand All @@ -318,9 +315,10 @@ def _fetch_output(self, calcjob):

_EOF = None

def _push_output(self, calcjob, delay=0.2):
def _push_output(self, calcjob_uuid, delay=0.2):
"""Push new log lines onto the queue."""
lineno = 0
calcjob = load_node(calcjob_uuid)
while True:
try:
lines = self._fetch_output(calcjob)
Expand All @@ -335,7 +333,7 @@ def _push_output(self, calcjob, delay=0.2):
self._output_queue.put(self._EOF)
break # noqa: B012

def _pull_output(self, calcjob):
def _pull_output(self):
"""Pull new log lines from the queue and update traitlets."""
while True:
item = self._output_queue.get()
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[build-system]
requires = [
"setuptools>=42",
"setuptools>=65",
unkcpz marked this conversation as resolved.
Show resolved Hide resolved
"wheel"
]
build-backend = "setuptools.build_meta"
6 changes: 3 additions & 3 deletions qe.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
"ipw.dlink((configure_qe_app_work_chain_step, 'smearing_settings'), (submit_qe_app_work_chain_step, 'smearing_settings'))\n",
"ipw.dlink((configure_qe_app_work_chain_step, 'pseudo_family_selector'), (submit_qe_app_work_chain_step, 'pseudo_family_selector'))\n",
"\n",
"ipw.dlink((submit_qe_app_work_chain_step, 'process'), (view_qe_app_work_chain_status_and_results_step, 'process'))\n",
"ipw.dlink((submit_qe_app_work_chain_step, 'process'), (view_qe_app_work_chain_status_and_results_step, 'process_uuid'), transform=lambda node: node.uuid if node is not None else None)\n",
"\n",
"# Add the application steps to the application\n",
"app = WizardAppWidget(\n",
Expand Down Expand Up @@ -157,7 +157,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
Expand All @@ -171,7 +171,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.9"
"version": "3.9.4"
}
},
"nbformat": 4,
Expand Down
4 changes: 4 additions & 0 deletions requirements_test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pytest~=6.0
pytest-docker~=1.0
pytest-selenium~=4.0
webdriver-manager~=3.8
15 changes: 9 additions & 6 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,23 @@ project_urls =
[options]
packages = find:
install_requires =
Jinja2~=2.11.3
aiida-core~=1.0
aiida-quantumespresso~=3.5
Jinja2~=3.0
aiida-core~=2.0
aiida-quantumespresso~=4.0
aiidalab-qe-workchain@https://github.com/aiidalab/aiidalab-qe/releases/download/v22.11.1/aiidalab_qe_workchain-22.11.1-py3-none-any.whl
aiidalab-widgets-base~=1.4.1
filelock~=3.3.0
aiidalab-widgets-base@git+https://github.com/aiidalab/aiidalab-widgets-base@fix/uuid-as-traitlets-threading-widget
filelock~=3.8
importlib-resources~=5.2.2
numpy~=1.23 # pined for pymatgen
widget-bandsplot~=0.2.8
python_requires = >=3.7
python_requires = >=3.8

[options.extras_require]
dev =
bumpver==2022.1119
pre-commit==2.11.1
test =
requirements-test.txt

[options.package_data]
aiidalab_qe.parameters = qeapp.yaml
Expand Down
16 changes: 8 additions & 8 deletions src/aiidalab_qe_workchain/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
PwBandsWorkChain = WorkflowFactory("quantumespresso.pw.bands")
PdosWorkChain = WorkflowFactory("quantumespresso.pdos")

Bool = DataFactory("bool")
Float = DataFactory("float")
Dict = DataFactory("dict")
Str = DataFactory("str")
XyData = DataFactory("array.xy")
StructureData = DataFactory("structure")
BandsData = DataFactory("array.bands")
Orbital = DataFactory("orbital")
Bool = DataFactory("core.bool")
Float = DataFactory("core.float")
Dict = DataFactory("core.dict")
Str = DataFactory("core.str")
XyData = DataFactory("core.array.xy")
StructureData = DataFactory("core.structure")
BandsData = DataFactory("core.array.bands")
Orbital = DataFactory("core.orbital")


class QeAppWorkChain(WorkChain):
Expand Down
Loading