From efa2c64dab2a1eaa3474aec40e79c845fdfaf9b8 Mon Sep 17 00:00:00 2001 From: Timo Reents <77727843+t-reents@users.noreply.github.com> Date: Tue, 12 Nov 2024 08:41:39 +0100 Subject: [PATCH] Fix: Set common inputs to `non_db` (#339) Due to the updates in version 2.6 of `aiida-core`, the `to_aiida_type` serializer is used as a default. Therefore, the validation fails for the inputs defined in the common interfaces, as those are typically defined as Python datatypes. Since these inputs are anyway not stored in the database, we fix it by explicitly setting `non_db = True` for those inputs. --- src/aiida_common_workflows/cli/options.py | 2 +- src/aiida_common_workflows/workflows/bands/generator.py | 1 + .../workflows/relax/castep/generator.py | 8 ++------ .../workflows/relax/cp2k/generator.py | 8 ++------ .../workflows/relax/fleur/generator.py | 2 +- src/aiida_common_workflows/workflows/relax/generator.py | 6 ++++++ tests/conftest.py | 2 +- 7 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/aiida_common_workflows/cli/options.py b/src/aiida_common_workflows/cli/options.py index 534d46d2..74532704 100644 --- a/src/aiida_common_workflows/cli/options.py +++ b/src/aiida_common_workflows/cli/options.py @@ -107,7 +107,7 @@ def convert(self, value, param, ctx): duplicate = ( QueryBuilder() - .append(StructureData, filters={'extras._aiida_hash': structure.base.caching._get_hash()}) + .append(StructureData, filters={'extras._aiida_hash': structure.base.caching._compute_hash()}) .first() ) diff --git a/src/aiida_common_workflows/workflows/bands/generator.py b/src/aiida_common_workflows/workflows/bands/generator.py index 1e4ee5e6..16c44d78 100644 --- a/src/aiida_common_workflows/workflows/bands/generator.py +++ b/src/aiida_common_workflows/workflows/bands/generator.py @@ -52,6 +52,7 @@ def define(cls, spec): spec.input( 'engines.bands.options', valid_type=dict, + non_db=True, required=False, help='Options for the bands calculation jobs.', ) diff --git a/src/aiida_common_workflows/workflows/relax/castep/generator.py b/src/aiida_common_workflows/workflows/relax/castep/generator.py index 655ccbfc..a70e5bbc 100644 --- a/src/aiida_common_workflows/workflows/relax/castep/generator.py +++ b/src/aiida_common_workflows/workflows/relax/castep/generator.py @@ -46,12 +46,8 @@ def define(cls, spec): The ports defined on the specification are the inputs that will be accepted by the ``get_builder`` method. """ super().define(spec) - spec.input( - 'protocol', - valid_type=ChoiceType(('fast', 'moderate', 'precise', 'verification-PBE-v1', 'verification-PBE-v1-a0')), - default='moderate', - help='The protocol to use for the automated input generation. This value indicates the level of precision ' - 'of the results and computational cost that the input parameters will be selected for.', + spec.inputs['protocol'].valid_type = ChoiceType( + ('fast', 'moderate', 'precise', 'verification-PBE-v1', 'verification-PBE-v1-a0') ) spec.inputs['spin_type'].valid_type = ChoiceType((SpinType.NONE, SpinType.COLLINEAR, SpinType.NON_COLLINEAR)) spec.inputs['relax_type'].valid_type = ChoiceType(tuple(RelaxType)) diff --git a/src/aiida_common_workflows/workflows/relax/cp2k/generator.py b/src/aiida_common_workflows/workflows/relax/cp2k/generator.py index 8bff177e..f40c4f85 100644 --- a/src/aiida_common_workflows/workflows/relax/cp2k/generator.py +++ b/src/aiida_common_workflows/workflows/relax/cp2k/generator.py @@ -157,12 +157,8 @@ def define(cls, spec): The ports defined on the specification are the inputs that will be accepted by the ``get_builder`` method. """ super().define(spec) - spec.input( - 'protocol', - valid_type=ChoiceType(('fast', 'moderate', 'precise', 'verification-PBE-v1', 'verification-PBE-v1-sirius')), - default='moderate', - help='The protocol to use for the automated input generation. This value indicates the level of precision ' - 'of the results and computational cost that the input parameters will be selected for.', + spec.inputs['protocol'].valid_type = ChoiceType( + ('fast', 'moderate', 'precise', 'verification-PBE-v1', 'verification-PBE-v1-sirius') ) spec.inputs['spin_type'].valid_type = ChoiceType((SpinType.NONE, SpinType.COLLINEAR)) spec.inputs['relax_type'].valid_type = ChoiceType( diff --git a/src/aiida_common_workflows/workflows/relax/fleur/generator.py b/src/aiida_common_workflows/workflows/relax/fleur/generator.py index 587bcb51..95851102 100644 --- a/src/aiida_common_workflows/workflows/relax/fleur/generator.py +++ b/src/aiida_common_workflows/workflows/relax/fleur/generator.py @@ -57,7 +57,7 @@ def define(cls, spec): ('fast', 'moderate', 'precise', 'oxides_validation', 'verification-PBE-v1') ) spec.input('engines.inpgen.code', valid_type=orm.Code, serializer=orm.load_code) - spec.input('engines.inpgen.options', valid_type=dict, required=False) + spec.input('engines.inpgen.options', non_db=True, valid_type=dict, required=False) spec.inputs['engines']['relax']['code'].valid_type = CodeType('fleur.fleur') spec.inputs['engines']['inpgen']['code'].valid_type = CodeType('fleur.inpgen') diff --git a/src/aiida_common_workflows/workflows/relax/generator.py b/src/aiida_common_workflows/workflows/relax/generator.py index ab4c1d9e..d7cc5907 100644 --- a/src/aiida_common_workflows/workflows/relax/generator.py +++ b/src/aiida_common_workflows/workflows/relax/generator.py @@ -33,6 +33,7 @@ def define(cls, spec): 'protocol', valid_type=ChoiceType(('fast', 'moderate', 'precise')), default='moderate', + non_db=True, help='The protocol to use for the automated input generation. This value indicates the level of precision ' 'of the results and computational cost that the input parameters will be selected for.', ) @@ -61,6 +62,7 @@ def define(cls, spec): 'magnetization_per_site', valid_type=list, required=False, + non_db=True, help='The initial magnetization of the system. Should be a list of floats, where each float represents the ' 'spin polarization in units of electrons, meaning the difference between spin up and spin down ' 'electrons, for the site. This also corresponds to the magnetization of the site in Bohr magnetons ' @@ -70,6 +72,7 @@ def define(cls, spec): 'threshold_forces', valid_type=float, required=False, + non_db=True, help='A real positive number indicating the target threshold for the forces in eV/Å. If not specified, ' 'the protocol specification will select an appropriate value.', ) @@ -77,12 +80,14 @@ def define(cls, spec): 'threshold_stress', valid_type=float, required=False, + non_db=True, help='A real positive number indicating the target threshold for the stress in eV/Å^3. If not specified, ' 'the protocol specification will select an appropriate value.', ) spec.input( 'reference_workchain', valid_type=orm.WorkChainNode, + non_db=True, required=False, help='The node of a previously completed process of the same type whose inputs should be taken into ' 'account when generating inputs. This is important for particular workflows where certain inputs have ' @@ -106,5 +111,6 @@ def define(cls, spec): 'engines.relax.options', valid_type=dict, required=False, + non_db=True, help='Options for the geometry optimization calculation jobs.', ) diff --git a/tests/conftest.py b/tests/conftest.py index 3d89bb06..a170fdea 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -87,7 +87,7 @@ def define(cls, spec): if inputs_dict is not None: for k, val in inputs_dict.items(): - spec.input(k, valid_type=val) + spec.input(k, valid_type=val, non_db=True) def _construct_builder(self, **kwargs) -> engine.ProcessBuilder: builder = self.process_class.get_builder()