Skip to content

Commit

Permalink
Merge branch 'main' into fix/warning_precise_small_depl
Browse files Browse the repository at this point in the history
  • Loading branch information
mikibonacci authored Dec 19, 2024
2 parents e597052 + bac49aa commit 7136b86
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 22 deletions.
16 changes: 5 additions & 11 deletions src/aiidalab_qe/app/submission/global_settings/model.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from __future__ import annotations

import os

import traitlets as tl

from aiida import orm
Expand Down Expand Up @@ -126,12 +124,8 @@ def check_resources(self):
num_sites = len(self.input_structure.sites)
volume = self.input_structure.get_cell_volume()

try:
localhost_cpus = len(os.sched_getaffinity(0))
except Exception:
# Fallback, in some OS os.sched_getaffinity(0) is not supported
# However, not so reliable in containers
localhost_cpus = os.cpu_count()
code = orm.load_node(pw_code_model.selected)
machine_cpus = code.computer.get_default_mpiprocs_per_machine()

large_system = (
num_sites > self._RUN_ON_LOCALHOST_NUM_SITES_WARN_THRESHOLD
Expand Down Expand Up @@ -183,11 +177,11 @@ def check_resources(self):
+ suggestions["change_configuration"]
+ "</ul>"
)
if on_localhost and num_cpus / localhost_cpus > 0.8:
if on_localhost and num_cpus / machine_cpus > 0.8:
# Warning-3: on localhost, more than half of the available cpus
alert_message += (
"<span>&#9888;</span> Warning: the selected pw.x code will run locally, but "
f"the number of requested CPUs ({num_cpus}) is larger than the 80% of the available resources ({localhost_cpus}). "
f"the number of requested CPUs ({num_cpus}) is larger than the 80% of the available resources ({machine_cpus}). "
"Please be sure that your local "
"environment has enough free CPUs for the calculation. Consider the following: "
"<ul>"
Expand All @@ -198,7 +192,7 @@ def check_resources(self):

self.submission_warning_messages = (
""
if (on_localhost and num_cpus / localhost_cpus) <= 0.8
if (on_localhost and num_cpus / machine_cpus) <= 0.8
and (not large_system or estimated_CPUs <= num_cpus)
else self._ALERT_MESSAGE.format(
alert_class="warning",
Expand Down
14 changes: 8 additions & 6 deletions src/aiidalab_qe/common/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -707,19 +707,21 @@ def update_resources(self, change):
self.set_resource_defaults(load_code(change["new"]).computer)

def set_resource_defaults(self, computer=None):
import os

if computer is None or computer.hostname == "localhost":
if computer is None:
self.num_nodes.disabled = True
self.num_nodes.value = 1
self.num_cpus.max = os.cpu_count()
self.num_cpus.max = 1
self.num_cpus.value = 1
self.num_cpus.description = "CPUs"
else:
default_mpiprocs = computer.get_default_mpiprocs_per_machine()
self.num_nodes.disabled = False
self.num_nodes.disabled = (
True if computer.hostname == "localhost" else False
)
self.num_cpus.max = default_mpiprocs
self.num_cpus.value = default_mpiprocs
self.num_cpus.value = (
1 if computer.hostname == "localhost" else default_mpiprocs
)
self.num_cpus.description = "CPUs"

@property
Expand Down
6 changes: 1 addition & 5 deletions tests/test_submit_qe_workchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,8 @@ def test_warning_messages(
global_model = submit_model.get_model("global")

pw_code = global_model.get_model("quantumespresso.pw")
pw_code.num_cpus = 1
global_model.check_resources()
# no warning:
assert submit_model.submission_warning_messages == ""

# now we increase the resources, so we should have the Warning-3
# we increase the resources, so we should have the Warning-3
pw_code.num_cpus = len(os.sched_getaffinity(0))
global_model.check_resources()
for suggestion in ["avoid_overloading", "go_remote"]:
Expand Down

0 comments on commit 7136b86

Please sign in to comment.