Skip to content

Commit

Permalink
Merge branch 'main' into aspect_ratio_plot
Browse files Browse the repository at this point in the history
  • Loading branch information
AndresOrtegaGuerrero authored Jan 14, 2025
2 parents 71a11e1 + 8df45a1 commit f93055a
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 32 deletions.
55 changes: 36 additions & 19 deletions before-notebook.d/43_start-hq.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 &

Expand Down
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 3 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 = *
Expand All @@ -76,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
Expand Down
46 changes: 37 additions & 9 deletions src/aiidalab_qe/setup/codes.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import subprocess
from pathlib import Path
from shutil import which
Expand Down Expand Up @@ -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():
Expand Down
2 changes: 1 addition & 1 deletion src/aiidalab_qe/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit f93055a

Please sign in to comment.