Skip to content

Commit

Permalink
Use num_machines * num_mpiprocs_per_machines to set num_cpus (#33)
Browse files Browse the repository at this point in the history
For backward compatibility where num_machines and num_mpiprocs_per_machine are setting.

I only setting the default value as 1 for num_mpiprocs_per_machine because aiida-quantumespresso override
resources default with num_machines set to 1 and then get builder with such setting.
The num_mpiprocs_per_machine sometime can be read from "Default #procs/machine" of computer setup but if it is not exist the builder can not be properly get without passing option to builder generator.
It is anyway a workaround for backward compatibility so this default is implemented despite it is quite specific for the qe plugin.
  • Loading branch information
unkcpz authored Sep 16, 2024
1 parent fc97821 commit bd6eb68
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion aiida_hyperqueue/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import json
import typing as t
import warnings

from aiida.common.extendeddicts import AttributeDict
from aiida.schedulers import Scheduler, SchedulerError
Expand All @@ -26,6 +27,10 @@
}


class AiiDAHypereQueueDeprecationWarning(Warning):
"""Class for HypereQueue plugin deprecations."""


class HyperQueueJobResource(JobResource):
"""Class for HyperQueue job resources."""

Expand Down Expand Up @@ -57,7 +62,26 @@ def validate_resources(cls, **kwargs):
try:
resources.num_cpus = kwargs.pop("num_cpus")
except KeyError:
raise KeyError("Must specify `num_cpus`")
try:
# For backward compatibility where `num_machines` and `num_mpiprocs_per_machine` are setting
# TODO: I only setting the default value as 1 for `num_mpiprocs_per_machine` because aiida-quantumespresso override
# resources default with `num_machines` set to 1 and then get builder with such setting.
# The `num_mpiprocs_per_machine` sometime can be read from "Default #procs/machine" of computer setup but if it is not exist
# the builder can not be properly get without passing `option` to builder generator.
# It is anyway a workaround for backward compatibility so this default is implemented despite it is quite specific for the qe plugin.
resources.num_cpus = kwargs.pop("num_machines") * kwargs.pop(
"num_mpiprocs_per_machine", 1
)
except KeyError:
raise KeyError(
"Must specify `num_cpus`, or (`num_machines` and `num_mpiprocs_per_machine`)"
)
else:
message = "The `num_machines` and `num_mpiprocs_per_machine` for setting hyperqueue resources are deprecated. "
"Please set `num_cpus` and `memory_mb`."

message = f"{message} (this will be removed in aiida-hyperqueue v1.0)"
warnings.warn(message, AiiDAHypereQueueDeprecationWarning, stacklevel=3)
else:
if not isinstance(resources.num_cpus, int):
raise ValueError("`num_cpus` must be an integer")
Expand Down

0 comments on commit bd6eb68

Please sign in to comment.