From ead283bf95917cadd08ecb9c1a7ddca68b55dc50 Mon Sep 17 00:00:00 2001 From: Marnik Bercx Date: Thu, 18 Feb 2021 15:47:06 +0100 Subject: [PATCH 1/4] Protocols: Add usage of metadata/paral. overrides The `metadata` and `parallelization` inputs of the `PwCalculation`, stored in the `pw` namespace of the `PwBaseWorkChain`, are not (properly) used in the `get_builder_from_protocol()` method. Here we make the following changes to correct this issue: * Move the `metadata` inputs under `pw` in the base.yaml file. * Correctly obtain the `metadata` from the inputs in the `get_builder_from_protocol()` method of the `PwBaseWorkChain`. * Check if there is `parallelization` input in the `pw` namespace of the inputs, and if so add it to the builder in the `get_builder_from_protocol()` method of the `PwBaseWorkChain`. --- .../workflows/protocols/pw/base.yaml | 12 ++++++------ aiida_quantumespresso/workflows/pw/base.py | 4 +++- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/aiida_quantumespresso/workflows/protocols/pw/base.yaml b/aiida_quantumespresso/workflows/protocols/pw/base.yaml index 0b3ce8041..81219e511 100644 --- a/aiida_quantumespresso/workflows/protocols/pw/base.yaml +++ b/aiida_quantumespresso/workflows/protocols/pw/base.yaml @@ -5,14 +5,14 @@ default_inputs: meta_parameters: conv_thr_per_atom: 0.2e-9 etot_conv_thr_per_atom: 1.e-5 - metadata: - options: - resources: - num_machines: 1 - max_wallclock_seconds: 43200 # Twelve hours - withmpi: True pseudo_family: 'SSSP/1.1/PBE/efficiency' pw: + metadata: + options: + resources: + num_machines: 1 + max_wallclock_seconds: 43200 # Twelve hours + withmpi: True parameters: CONTROL: calculation: scf diff --git a/aiida_quantumespresso/workflows/pw/base.py b/aiida_quantumespresso/workflows/pw/base.py index 859b82da6..6ac943346 100644 --- a/aiida_quantumespresso/workflows/pw/base.py +++ b/aiida_quantumespresso/workflows/pw/base.py @@ -204,7 +204,9 @@ def get_builder_from_protocol( builder.pw['pseudos'] = pseudo_family.get_pseudos(structure=structure) # pylint: disable=no-member builder.pw['structure'] = structure # pylint: disable=no-member builder.pw['parameters'] = orm.Dict(dict=parameters) # pylint: disable=no-member - builder.pw['metadata'] = inputs['metadata'] # pylint: disable=no-member + builder.pw['metadata'] = inputs['pw']['metadata'] # pylint: disable=no-member + if 'parallelization' in inputs['pw']: + builder.pw['parallelization'] = orm.Dict(dict=inputs['pw']['parallelization']) builder.clean_workdir = orm.Bool(inputs['clean_workdir']) builder.kpoints_distance = orm.Float(inputs['kpoints_distance']) builder.kpoints_force_parity = orm.Bool(inputs['kpoints_force_parity']) From 93c50e60b7746c111bebe6a3ca116adec4cd1ad0 Mon Sep 17 00:00:00 2001 From: Marnik Bercx Date: Thu, 18 Feb 2021 16:18:55 +0100 Subject: [PATCH 2/4] Fix pre-commit --- aiida_quantumespresso/workflows/pw/base.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/aiida_quantumespresso/workflows/pw/base.py b/aiida_quantumespresso/workflows/pw/base.py index 6ac943346..46d113f46 100644 --- a/aiida_quantumespresso/workflows/pw/base.py +++ b/aiida_quantumespresso/workflows/pw/base.py @@ -200,16 +200,18 @@ def get_builder_from_protocol( parameters['SYSTEM']['nspin'] = 2 parameters['SYSTEM']['starting_magnetization'] = starting_magnetization - builder.pw['code'] = code # pylint: disable=no-member - builder.pw['pseudos'] = pseudo_family.get_pseudos(structure=structure) # pylint: disable=no-member - builder.pw['structure'] = structure # pylint: disable=no-member - builder.pw['parameters'] = orm.Dict(dict=parameters) # pylint: disable=no-member - builder.pw['metadata'] = inputs['pw']['metadata'] # pylint: disable=no-member + # pylint: disable=no-member + builder.pw['code'] = code + builder.pw['pseudos'] = pseudo_family.get_pseudos(structure=structure) + builder.pw['structure'] = structure + builder.pw['parameters'] = orm.Dict(dict=parameters) + builder.pw['metadata'] = inputs['pw']['metadata'] if 'parallelization' in inputs['pw']: builder.pw['parallelization'] = orm.Dict(dict=inputs['pw']['parallelization']) builder.clean_workdir = orm.Bool(inputs['clean_workdir']) builder.kpoints_distance = orm.Float(inputs['kpoints_distance']) builder.kpoints_force_parity = orm.Bool(inputs['kpoints_force_parity']) + # pylint: enable=no-member return builder From 1bd67b41bb23822584c93ddf8e95d38938b0cfb1 Mon Sep 17 00:00:00 2001 From: Marnik Bercx Date: Thu, 6 May 2021 20:26:52 +0200 Subject: [PATCH 3/4] Add tests for Herr Huber --- tests/workflows/protocols/pw/test_base.py | 34 +++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/tests/workflows/protocols/pw/test_base.py b/tests/workflows/protocols/pw/test_base.py index c44275c0f..8d03f77e2 100644 --- a/tests/workflows/protocols/pw/test_base.py +++ b/tests/workflows/protocols/pw/test_base.py @@ -93,3 +93,37 @@ def test_initial_magnetic_moments(fixture_code, generate_structure): assert parameters['SYSTEM']['nspin'] == 2 assert parameters['SYSTEM']['starting_magnetization'] == {'Si': 0.25} + + +def test_metadata_overrides(fixture_code, generate_structure): + """Test that pw metadata is correctly passed through overrides.""" + code = fixture_code('quantumespresso.pw') + structure = generate_structure() + + overrides = {'pw': {'metadata': {'options': {'resources': {'num_machines': 2}, 'max_wallclock_seconds': 3600}}}} + builder = PwBaseWorkChain.get_builder_from_protocol( + code, + structure, + overrides=overrides, + ) + metadata = builder.pw.metadata + + assert metadata['options']['resources']['num_machines'] == 2 + assert metadata['options']['max_wallclock_seconds'] == 3600 + + +def test_parallelization_overrides(fixture_code, generate_structure): + """Test that pw parallelization settings are correctly passed through overrides.""" + code = fixture_code('quantumespresso.pw') + structure = generate_structure() + + overrides = {'pw': {'parallelization': {'npool': 4, 'ndiag': 12}}} + builder = PwBaseWorkChain.get_builder_from_protocol( + code, + structure, + overrides=overrides, + ) + parallelization = builder.pw.parallelization + + assert parallelization['npool'] == 4 + assert parallelization['ndiag'] == 12 From 0a963ebc9dfc4fc1ecd650af925777df4b64c9b6 Mon Sep 17 00:00:00 2001 From: Marnik Bercx Date: Thu, 6 May 2021 20:43:26 +0200 Subject: [PATCH 4/4] ludicrous! --- tests/workflows/protocols/pw/test_base.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/workflows/protocols/pw/test_base.py b/tests/workflows/protocols/pw/test_base.py index 8d03f77e2..356239ad1 100644 --- a/tests/workflows/protocols/pw/test_base.py +++ b/tests/workflows/protocols/pw/test_base.py @@ -100,7 +100,7 @@ def test_metadata_overrides(fixture_code, generate_structure): code = fixture_code('quantumespresso.pw') structure = generate_structure() - overrides = {'pw': {'metadata': {'options': {'resources': {'num_machines': 2}, 'max_wallclock_seconds': 3600}}}} + overrides = {'pw': {'metadata': {'options': {'resources': {'num_machines': 1e90}, 'max_wallclock_seconds': 1}}}} builder = PwBaseWorkChain.get_builder_from_protocol( code, structure, @@ -108,8 +108,8 @@ def test_metadata_overrides(fixture_code, generate_structure): ) metadata = builder.pw.metadata - assert metadata['options']['resources']['num_machines'] == 2 - assert metadata['options']['max_wallclock_seconds'] == 3600 + assert metadata['options']['resources']['num_machines'] == 1e90 + assert metadata['options']['max_wallclock_seconds'] == 1 def test_parallelization_overrides(fixture_code, generate_structure):