From d2d28dd2e89ff9cc639f266af0f1092b832047ec Mon Sep 17 00:00:00 2001 From: Xing Wang Date: Tue, 14 Jan 2025 10:41:29 +0100 Subject: [PATCH 1/4] Use try/except to catch error when install QE (#917) --- src/aiidalab_qe/setup/codes.py | 46 +++++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 9 deletions(-) diff --git a/src/aiidalab_qe/setup/codes.py b/src/aiidalab_qe/setup/codes.py index c63a76bb7..984575c6c 100644 --- a/src/aiidalab_qe/setup/codes.py +++ b/src/aiidalab_qe/setup/codes.py @@ -1,3 +1,4 @@ +import json import subprocess from pathlib import Path from shutil import which @@ -44,18 +45,45 @@ def get_qe_env(): def qe_installed(): - import json + """Check if Quantum Espresso (QE) is installed in the specified conda environment. - env_exist = get_qe_env().exists() - proc = subprocess.run( - ["conda", "list", "-n", f"{get_qe_env().name}", "--json", "--full-name", "qe"], - check=True, - capture_output=True, - ) + Returns: + bool: True if the environment exists and QE is installed; False otherwise. + """ + try: + # Verify if the specified conda environment exists + env_exist = get_qe_env().exists() + + if not env_exist: + return False + + # Run the conda list command to check for the QE package + proc = subprocess.run( + [ + "conda", + "list", + "-n", + f"{get_qe_env().name}", + "--json", + "--full-name", + "qe", + ], + check=True, + capture_output=True, + ) - info = json.loads(str(proc.stdout.decode()))[0] + # Load and interpret the JSON output + info = json.loads(proc.stdout.decode()) - return env_exist and "qe" == info["name"] + # Check if 'qe' is listed in the environment + for package in info: + if package.get("name") == "qe": + return True + return False # noqa: TRY300 + except Exception as error: + raise RuntimeError( + "Failed to check if Quantum Espresso is installed." + ) from error def install_qe(): From 969ba0efaaa48562b6ccbd56fe172614602a17aa Mon Sep 17 00:00:00 2001 From: Edan Bainglass <45081142+edan-bainglass@users.noreply.github.com> Date: Tue, 14 Jan 2025 11:13:45 +0100 Subject: [PATCH 2/4] Add `schema.json` to package data (#1093) --- setup.cfg | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.cfg b/setup.cfg index f6c5d894e..b18b40480 100644 --- a/setup.cfg +++ b/setup.cfg @@ -54,6 +54,7 @@ aiidalab_qe.app.parameters = qeapp.yaml aiidalab_qe.app.static.styles = *.css aiidalab_qe.app.static.templates = *.jinja aiidalab_qe.app.structure.examples = * +aiidalab_qe.app.result.components.summary = schema.json aiidalab_qe.plugins.xas = pseudo_toc.yaml aiidalab_qe.plugins.xps.structure_examples = * aiidalab_qe.plugins.xas.structure_examples = * From 74ef3cb52a8be5eb57714f5d2b771c5f743cda4d Mon Sep 17 00:00:00 2001 From: Xing Wang Date: Tue, 14 Jan 2025 11:33:57 +0100 Subject: [PATCH 3/4] Handle cpu and memory check gracefully (#1094) This old HQ script assumes a cgroupv2 environment, but the issue arises because some system doesn't have the required cgroupv2 files (/sys/fs/cgroup/cpu.max and /sys/fs/cgroup/memory.max). - If cpu.max and memory.max are missing, fall back to cgroupv1 - If neither cpu.max nor cpu.cfs_quota_us exists, use default values. --- before-notebook.d/43_start-hq.sh | 55 +++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 19 deletions(-) diff --git a/before-notebook.d/43_start-hq.sh b/before-notebook.d/43_start-hq.sh index c20a462e4..b90a8e952 100644 --- a/before-notebook.d/43_start-hq.sh +++ b/before-notebook.d/43_start-hq.sh @@ -10,34 +10,51 @@ set -x # But for developers, please update your cgroup version to v2. # See: https://kubernetes.io/docs/concepts/architecture/cgroups/#using-cgroupv2 -# computer memory from runtime -MEMORY_LIMIT=$(cat /sys/fs/cgroup/memory.max) +# Default to cgroupv1 paths +CPU_QUOTA_PATH="/sys/fs/cgroup/cpu/cpu.cfs_quota_us" +CPU_PERIOD_PATH="/sys/fs/cgroup/cpu/cpu.cfs_period_us" +MEMORY_LIMIT_PATH="/sys/fs/cgroup/memory/memory.limit_in_bytes" -if [ "$MEMORY_LIMIT" = "max" ]; then - MEMORY_LIMIT=4096 - echo "No memory limit set, use 4GiB" -else - MEMORY_LIMIT=$(echo "scale=0; $MEMORY_LIMIT / (1024 * 1024)" | bc) - echo "Memory Limit: ${MEMORY_LIMIT} MiB" +# Fallback if cgroupv2 paths exist +if [ -f /sys/fs/cgroup/cpu.max ]; then + CPU_QUOTA_PATH="/sys/fs/cgroup/cpu.max" + CPU_PERIOD_PATH="/sys/fs/cgroup/cpu.max" +fi + +if [ -f /sys/fs/cgroup/memory.max ]; then + MEMORY_LIMIT_PATH="/sys/fs/cgroup/memory.max" fi -# Compute number of cpus allocated to the container -CPU_LIMIT=$(awk '{print $1}' /sys/fs/cgroup/cpu.max) -CPU_PERIOD=$(awk '{print $2}' /sys/fs/cgroup/cpu.max) +# Compute memory limit +if [ -f "$MEMORY_LIMIT_PATH" ]; then + MEMORY_LIMIT=$(cat "$MEMORY_LIMIT_PATH") + if [ "$MEMORY_LIMIT" = "max" ] || [ "$MEMORY_LIMIT" -eq -1 ]; then + MEMORY_LIMIT=4096 + else + MEMORY_LIMIT=$(echo "scale=0; $MEMORY_LIMIT / (1024 * 1024)" | bc) + fi +else + MEMORY_LIMIT=4096 +fi +echo "Memory Limit: ${MEMORY_LIMIT} MiB" -if [ "$CPU_PERIOD" -ne 0 ]; then - CPU_NUMBER=$(echo "scale=2; $CPU_LIMIT / $CPU_PERIOD" | bc) - echo "Number of CPUs allocated: $CPU_NUMBER" +# Compute CPU limit +if [ -f "$CPU_QUOTA_PATH" ] && [ -f "$CPU_PERIOD_PATH" ]; then + CPU_LIMIT=$(cat "$CPU_QUOTA_PATH") + CPU_PERIOD=$(cat "$CPU_PERIOD_PATH") - # for HQ setting round to integer number of CPUs, the left are for system tasks - CPU_LIMIT=$(echo "scale=0; $CPU_LIMIT / $CPU_PERIOD" | bc) + if [ "$CPU_LIMIT" != "max" ] && [ "$CPU_PERIOD" -ne 0 ]; then + CPU_NUMBER=$(echo "scale=2; $CPU_LIMIT / $CPU_PERIOD" | bc) + CPU_LIMIT=$(echo "$CPU_NUMBER / 1" | bc) # Round down to integer + else + CPU_LIMIT=$(nproc) + fi else - # if no limit (with local OCI without setting cpu limit, use all CPUs) CPU_LIMIT=$(nproc) - echo "No CPU limit set" fi +echo "Number of CPUs allocated: $CPU_LIMIT" -# Start hq server with a worker +# Start HQ server and worker run-one-constantly hq server start 1>$HOME/.hq-stdout 2>$HOME/.hq-stderr & run-one-constantly hq worker start --cpus=${CPU_LIMIT} --resource "mem=sum(${MEMORY_LIMIT})" --no-detect-resources & From ef43cc729131d35a73640b087817a704d48453b3 Mon Sep 17 00:00:00 2001 From: superstar54 Date: Tue, 14 Jan 2025 10:38:34 +0000 Subject: [PATCH 4/4] Bump version v24.10.0a6 -> v24.10.0a7 --- docs/source/conf.py | 2 +- setup.cfg | 4 ++-- src/aiidalab_qe/version.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index 04845b682..d4f31b56c 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -13,7 +13,7 @@ # -- Project information ----------------------------------------------------- -version = "v24.10.0a6" +version = "v24.10.0a7" release = f"{version}-dev" project = "Quantum ESPRESSO App" copyright_first_year = "2023" diff --git a/setup.cfg b/setup.cfg index b18b40480..75bf27bfb 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = aiidalab_qe -version = 24.10.0a6 +version = 24.10.0a7 description = Package for the AiiDAlab QE app long_description = file: README.md long_description_content_type = text/markdown @@ -77,7 +77,7 @@ categories = quantum [bumpver] -current_version = "v24.10.0a6" +current_version = "v24.10.0a7" version_pattern = "v0Y.0M.PATCH[PYTAGNUM]" commit_message = "Bump version {old_version} -> {new_version}" commit = True diff --git a/src/aiidalab_qe/version.py b/src/aiidalab_qe/version.py index b73b302d4..d2908f901 100644 --- a/src/aiidalab_qe/version.py +++ b/src/aiidalab_qe/version.py @@ -2,4 +2,4 @@ """This module contains project version information for both the app and the workflow.""" -__version__ = "v24.10.0a6" +__version__ = "v24.10.0a7"