From bd6eb6896cf2a86251dddf32f7541411357a1af0 Mon Sep 17 00:00:00 2001 From: Jusong Yu Date: Mon, 16 Sep 2024 09:28:26 +0200 Subject: [PATCH] Use num_machines * num_mpiprocs_per_machines to set num_cpus (#33) 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. --- aiida_hyperqueue/scheduler.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/aiida_hyperqueue/scheduler.py b/aiida_hyperqueue/scheduler.py index 5523b7f..a49d3f5 100644 --- a/aiida_hyperqueue/scheduler.py +++ b/aiida_hyperqueue/scheduler.py @@ -11,6 +11,7 @@ import json import typing as t +import warnings from aiida.common.extendeddicts import AttributeDict from aiida.schedulers import Scheduler, SchedulerError @@ -26,6 +27,10 @@ } +class AiiDAHypereQueueDeprecationWarning(Warning): + """Class for HypereQueue plugin deprecations.""" + + class HyperQueueJobResource(JobResource): """Class for HyperQueue job resources.""" @@ -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")