From 0566c7a556dcb433970efe977c6fd0e7a0d4b2ee Mon Sep 17 00:00:00 2001 From: t-reents Date: Mon, 19 Feb 2024 10:59:06 +0100 Subject: [PATCH 1/3] First steps to make protocols scheduler agnostic. The current protocols implicitly rely on the `Slurm` scheduler by specifying the number of machines in `metadata.options.resources`. This can cause problems when using different schedulers in combination with `get_builder_from_protocol`. Here, we add this information to the documentation and add a warning that the options need to be explicitly specified in future versions. --- src/aiida_quantumespresso/workflows/pw/bands.py | 3 +++ src/aiida_quantumespresso/workflows/pw/base.py | 11 +++++++++++ src/aiida_quantumespresso/workflows/pw/relax.py | 3 +++ 3 files changed, 17 insertions(+) diff --git a/src/aiida_quantumespresso/workflows/pw/bands.py b/src/aiida_quantumespresso/workflows/pw/bands.py index d4d0a32ef..ecd754359 100644 --- a/src/aiida_quantumespresso/workflows/pw/bands.py +++ b/src/aiida_quantumespresso/workflows/pw/bands.py @@ -123,6 +123,9 @@ def get_protocol_filepath(cls): def get_builder_from_protocol(cls, code, structure, protocol=None, overrides=None, options=None, **kwargs): """Return a builder prepopulated with inputs selected according to the chosen protocol. + The current protocols rely on the `Slurm` scheduler. To use them nonetheless with a different scheduler, the + protocols might need to be adjusted and explicit resources need to be provided in `options`. + :param code: the ``Code`` instance configured for the ``quantumespresso.pw`` plugin. :param structure: the ``StructureData`` instance to use. :param protocol: protocol to use, if not specified, the default will be used. diff --git a/src/aiida_quantumespresso/workflows/pw/base.py b/src/aiida_quantumespresso/workflows/pw/base.py index 4a3ab0381..edd1d557b 100644 --- a/src/aiida_quantumespresso/workflows/pw/base.py +++ b/src/aiida_quantumespresso/workflows/pw/base.py @@ -1,5 +1,7 @@ # -*- coding: utf-8 -*- """Workchain to run a Quantum ESPRESSO pw.x calculation with automated error handling and restarts.""" +import warnings + from aiida import orm from aiida.common import AttributeDict, exceptions from aiida.common.lang import type_check @@ -117,6 +119,9 @@ def get_builder_from_protocol( ): """Return a builder prepopulated with inputs selected according to the chosen protocol. + The current protocols rely on the `Slurm` scheduler. To use them nonetheless with a different scheduler, the + protocols might need to be adjusted and explicit resources need to be provided in `options`. + :param code: the ``Code`` instance configured for the ``quantumespresso.pw`` plugin. :param structure: the ``StructureData`` instance to use. :param protocol: protocol to use, if not specified, the default will be used. @@ -208,6 +213,12 @@ def get_builder_from_protocol( metadata = inputs['pw']['metadata'] + if not options or options.get('resources', None) is None: + warnings.warn( + 'No explicit resources were provided for `metadata.options.resources`. This approach is ' + 'deprecated and will cause an error in future versions.', UserWarning + ) + if options: metadata['options'] = recursive_merge(inputs['pw']['metadata']['options'], options) diff --git a/src/aiida_quantumespresso/workflows/pw/relax.py b/src/aiida_quantumespresso/workflows/pw/relax.py index 2888a3e36..c9329aa8c 100644 --- a/src/aiida_quantumespresso/workflows/pw/relax.py +++ b/src/aiida_quantumespresso/workflows/pw/relax.py @@ -90,6 +90,9 @@ def get_builder_from_protocol( ): """Return a builder prepopulated with inputs selected according to the chosen protocol. + The current protocols rely on the `Slurm` scheduler. To use them nonetheless with a different scheduler, the + protocols might need to be adjusted and explicit resources need to be provided in `options`. + :param code: the ``Code`` instance configured for the ``quantumespresso.pw`` plugin. :param structure: the ``StructureData`` instance to use. :param protocol: protocol to use, if not specified, the default will be used. From a1394651ca13173373ac54b82a9f686534ea76c8 Mon Sep 17 00:00:00 2001 From: Timo Reents Date: Thu, 16 May 2024 10:25:02 +0200 Subject: [PATCH 2/3] Add warning to other workflows In addition to the previous changes to the `pw` `WorkChain`s, this commit adds a warning to all the other `WorkChain`s that provide the `get_builder_from_protcol` method. --- src/aiida_quantumespresso/workflows/pdos.py | 3 +++ src/aiida_quantumespresso/workflows/ph/base.py | 10 ++++++++++ src/aiida_quantumespresso/workflows/xps.py | 3 +++ src/aiida_quantumespresso/workflows/xspectra/base.py | 11 +++++++++++ src/aiida_quantumespresso/workflows/xspectra/core.py | 3 +++ .../workflows/xspectra/crystal.py | 3 +++ 6 files changed, 33 insertions(+) diff --git a/src/aiida_quantumespresso/workflows/pdos.py b/src/aiida_quantumespresso/workflows/pdos.py index 311d8237f..b55b07017 100644 --- a/src/aiida_quantumespresso/workflows/pdos.py +++ b/src/aiida_quantumespresso/workflows/pdos.py @@ -320,6 +320,9 @@ def get_builder_from_protocol( ): """Return a builder prepopulated with inputs selected according to the chosen protocol. + The current protocols rely on the `Slurm` scheduler. To use them nonetheless with a different scheduler, the + protocols might need to be adjusted and explicit resources need to be provided in `options`. + :param pw_code: the ``Code`` instance configured for the ``quantumespresso.pw`` plugin. :param dos_code: the ``Code`` instance configured for the ``quantumespresso.dos`` plugin. :param projwfc_code: the ``Code`` instance configured for the ``quantumespresso.projwfc`` plugin. diff --git a/src/aiida_quantumespresso/workflows/ph/base.py b/src/aiida_quantumespresso/workflows/ph/base.py index a1ad3def8..d2d9bb283 100644 --- a/src/aiida_quantumespresso/workflows/ph/base.py +++ b/src/aiida_quantumespresso/workflows/ph/base.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- """Workchain to run a Quantum ESPRESSO ph.x calculation with automated error handling and restarts.""" from typing import Mapping +import warnings from aiida import orm from aiida.common import AttributeDict @@ -97,6 +98,9 @@ def get_builder_from_protocol( ): """Return a builder prepopulated with inputs selected according to the chosen protocol. + The current protocols rely on the `Slurm` scheduler. To use them nonetheless with a different scheduler, the + protocols might need to be adjusted and explicit resources need to be provided in `options`. + :param code: the ``Code`` instance configured for the ``quantumespresso.ph`` plugin. :param protocol: protocol to use, if not specified, the default will be used. :param overrides: optional dictionary of inputs to override the defaults of the protocol. @@ -123,6 +127,12 @@ def get_builder_from_protocol( metadata = inputs['ph']['metadata'] + if not options or options.get('resources', None) is None: + warnings.warn( + 'No explicit resources were provided for `metadata.options.resources`. This approach is ' + 'deprecated and will cause an error in future versions.', UserWarning + ) + if options: metadata['options'] = recursive_merge(inputs['ph']['metadata']['options'], options) diff --git a/src/aiida_quantumespresso/workflows/xps.py b/src/aiida_quantumespresso/workflows/xps.py index ed4fdc01b..dd71a66a5 100644 --- a/src/aiida_quantumespresso/workflows/xps.py +++ b/src/aiida_quantumespresso/workflows/xps.py @@ -381,6 +381,9 @@ def get_builder_from_protocol( ): # pylint: disable=too-many-statements """Return a builder prepopulated with inputs selected according to the chosen protocol. + The current protocols rely on the `Slurm` scheduler. To use them nonetheless with a different scheduler, the + protocols might need to be adjusted and explicit resources need to be provided in `options`. + :param code: the ``Code`` instance configured for the ``quantumespresso.pw`` plugin. :param structure: the ``StructureData`` instance to use. :param pseudos: the core-hole pseudopotential pairs (ground-state and diff --git a/src/aiida_quantumespresso/workflows/xspectra/base.py b/src/aiida_quantumespresso/workflows/xspectra/base.py index 59cea6a00..ead091ae5 100644 --- a/src/aiida_quantumespresso/workflows/xspectra/base.py +++ b/src/aiida_quantumespresso/workflows/xspectra/base.py @@ -1,5 +1,7 @@ # -*- coding: utf-8 -*- """Workchain to run a Quantum ESPRESSO xspectra.x calculation with automated error handling and restarts.""" +import warnings + from aiida import orm from aiida.common import AttributeDict from aiida.common.lang import type_check @@ -79,6 +81,9 @@ def get_builder_from_protocol( ): """Return a builder prepopulated with inputs selected according to the chosen protocol. + The current protocols rely on the `Slurm` scheduler. To use them nonetheless with a different scheduler, the + protocols might need to be adjusted and explicit resources need to be provided in `options`. + :param code: the ``Code`` instance configured for the ``quantumespresso.xspectra`` plugin. :param core_wfc_data: a ``SinglefileData`` object for the initial-state core wavefunction, normally derived from upf2plotcore.sh, required @@ -106,6 +111,12 @@ def get_builder_from_protocol( metadata = inputs['xspectra']['metadata'] parameters = inputs['xspectra']['parameters'] + if not options or options.get('resources', None) is None: + warnings.warn( + 'No explicit resources were provided for `metadata.options.resources`. This approach is ' + 'deprecated and will cause an error in future versions.', UserWarning + ) + if options: metadata['options'] = recursive_merge(inputs['xspectra']['metadata']['options'], options) diff --git a/src/aiida_quantumespresso/workflows/xspectra/core.py b/src/aiida_quantumespresso/workflows/xspectra/core.py index 377ea378c..b21f3a031 100644 --- a/src/aiida_quantumespresso/workflows/xspectra/core.py +++ b/src/aiida_quantumespresso/workflows/xspectra/core.py @@ -306,6 +306,9 @@ def get_builder_from_protocol( ): """Return a builder prepopulated with inputs selected according to the chosen protocol. + The current protocols rely on the `Slurm` scheduler. To use them nonetheless with a different scheduler, the + protocols might need to be adjusted and explicit resources need to be provided in `options`. + :param pw_code: the ``Code`` instance configured for the ``quantumespresso.pw`` plugin. :param xs_code: the ``Code`` instance configured for the diff --git a/src/aiida_quantumespresso/workflows/xspectra/crystal.py b/src/aiida_quantumespresso/workflows/xspectra/crystal.py index 1d56a50f9..2a65bd531 100644 --- a/src/aiida_quantumespresso/workflows/xspectra/crystal.py +++ b/src/aiida_quantumespresso/workflows/xspectra/crystal.py @@ -268,6 +268,9 @@ def get_builder_from_protocol( # pylint: disable=too-many-statements ): # pylint: enable:too-many-statments """Return a builder prepopulated with inputs selected according to the chosen protocol. + The current protocols rely on the `Slurm` scheduler. To use them nonetheless with a different scheduler, the + protocols might need to be adjusted and explicit resources need to be provided in `options`. + :param pw_code: the ``Code`` instance configured for the ``quantumespresso.pw`` plugin. :param xs_code: the ``Code`` instance configured for the From 300e4cce28b5809b96c8cf025ca0f5a4254ad1bb Mon Sep 17 00:00:00 2001 From: Timo Reents Date: Thu, 16 May 2024 10:28:59 +0200 Subject: [PATCH 3/3] Add documentation about `get_builder_from_protocol` This commit adds some general remarks about the `get_builder_from_protocol` methods in the `How to - Workflows` section. --- docs/source/howto/workflows/index.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/docs/source/howto/workflows/index.md b/docs/source/howto/workflows/index.md index 1b88f4f27..c5418d3be 100644 --- a/docs/source/howto/workflows/index.md +++ b/docs/source/howto/workflows/index.md @@ -2,6 +2,26 @@ # Workflows +## Default parameters + +The AiiDA Quantum ESPRESSO plugin comes with a set of tested protocols. These protocols define default input parameters for different levels of precision. This concept enables the initialization of a pre-populated `builder` for most of the different `WorkChain`s, which can be obtained by calling the `get_builder_from_protocol` method. + +The following example shows the working principle for the `PwBaseWorkChain`: + +``` +# code and structure are the mandatory input arguments + +builder = PwBaseWorkChain.get_builder_from_protocol( + code=pw_code, # load your pw-code + structure=structure, # provide your input structure here +) + +``` +We refer to the documentation of the {{ get_builder_from_protocol }} method for further details about additional default input arguments. + + + + ```{toctree} :maxdepth: 1