-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test/Improve
PhBaseWorkChain
overrides/protocol
The `PhBaseWorkChain.get_builder_from_protocol` was untested. Tests are added, and the `electronic_type` input is added to allow for the computation of the dielectric and effective charge tensors when an insulator is in input. This is useful in other workchains, so that the `electronic_type` input can be passed seamlessly as a kwargs input at an higher level.
- Loading branch information
Showing
5 changed files
with
139 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
# -*- coding: utf-8 -*- | ||
# pylint: disable=no-member,redefined-outer-name | ||
"""Tests for the ``PhBaseWorkChain.get_builder_from_protocol`` method.""" | ||
from aiida.engine import ProcessBuilder | ||
import pytest | ||
|
||
from aiida_quantumespresso.common.types import ElectronicType | ||
from aiida_quantumespresso.workflows.ph.base import PhBaseWorkChain | ||
|
||
|
||
def test_get_available_protocols(): | ||
"""Test ``PhBaseWorkChain.get_available_protocols``.""" | ||
protocols = PhBaseWorkChain.get_available_protocols() | ||
assert sorted(protocols.keys()) == ['fast', 'moderate', 'precise'] | ||
assert all('description' in protocol for protocol in protocols.values()) | ||
|
||
|
||
def test_get_default_protocol(): | ||
"""Test ``PhBaseWorkChain.get_default_protocol``.""" | ||
assert PhBaseWorkChain.get_default_protocol() == 'moderate' | ||
|
||
|
||
def test_default(fixture_code, data_regression, serialize_builder): | ||
"""Test ``PhBaseWorkChain.get_builder_from_protocol`` for the default protocol.""" | ||
code = fixture_code('quantumespresso.ph') | ||
builder = PhBaseWorkChain.get_builder_from_protocol(code) | ||
|
||
assert isinstance(builder, ProcessBuilder) | ||
data_regression.check(serialize_builder(builder)) | ||
|
||
|
||
def test_electronic_type(fixture_code): | ||
"""Test ``PhBaseWorkChain.get_builder_from_protocol`` with ``electronic_type`` keyword.""" | ||
code = fixture_code('quantumespresso.ph') | ||
|
||
with pytest.raises(NotImplementedError): | ||
for electronic_type in [ElectronicType.AUTOMATIC]: | ||
PhBaseWorkChain.get_builder_from_protocol(code, electronic_type=electronic_type) | ||
|
||
builder = PhBaseWorkChain.get_builder_from_protocol(code, electronic_type=ElectronicType.INSULATOR) | ||
parameters = builder.ph.parameters.get_dict() # pylint: disable=no-member | ||
|
||
assert parameters['INPUTPH']['epsil'] | ||
|
||
|
||
def test_parameter_overrides(fixture_code): | ||
"""Test specifying parameter ``overrides`` for the ``get_builder_from_protocol()`` method.""" | ||
code = fixture_code('quantumespresso.ph') | ||
|
||
overrides = {'ph': {'parameters': {'INPUTHP': {'nmix_ph': 20}}}} | ||
builder = PhBaseWorkChain.get_builder_from_protocol(code, overrides=overrides) | ||
assert builder.ph.parameters['INPUTHP']['nmix_ph'] == 20 # pylint: disable=no-member | ||
|
||
|
||
def test_settings_overrides(fixture_code): | ||
"""Test specifying settings ``overrides`` for the ``get_builder_from_protocol()`` method.""" | ||
code = fixture_code('quantumespresso.ph') | ||
|
||
overrides = {'ph': {'settings': {'cmdline': ['--kickass-mode']}}} | ||
builder = PhBaseWorkChain.get_builder_from_protocol(code, overrides=overrides) | ||
assert builder.ph.settings['cmdline'] == ['--kickass-mode'] # pylint: disable=no-member | ||
|
||
|
||
def test_metadata_overrides(fixture_code): | ||
"""Test specifying metadata ``overrides`` for the ``get_builder_from_protocol()`` method.""" | ||
code = fixture_code('quantumespresso.ph') | ||
|
||
overrides = {'ph': {'metadata': {'options': {'resources': {'num_machines': 1e90}, 'max_wallclock_seconds': 1}}}} | ||
builder = PhBaseWorkChain.get_builder_from_protocol(code, overrides=overrides) | ||
metadata = builder.ph.metadata # pylint: disable=no-member | ||
|
||
assert metadata['options']['resources']['num_machines'] == 1e90 | ||
assert metadata['options']['max_wallclock_seconds'] == 1 | ||
|
||
|
||
def test_options(fixture_code): | ||
"""Test specifying ``options`` for the ``get_builder_from_protocol()`` method.""" | ||
code = fixture_code('quantumespresso.ph') | ||
|
||
queue_name = 'super-fast' | ||
withmpi = False # The protocol default is ``True`` | ||
|
||
options = {'queue_name': queue_name, 'withmpi': withmpi} | ||
builder = PhBaseWorkChain.get_builder_from_protocol(code, options=options) | ||
metadata = builder.ph.metadata # pylint: disable=no-member | ||
|
||
assert metadata['options']['queue_name'] == queue_name | ||
assert metadata['options']['withmpi'] == withmpi | ||
|
||
|
||
def test_parent_folder(fixture_code, generate_remote_data, fixture_localhost, fixture_sandbox): | ||
"""Test specifying ``options`` for the ``get_builder_from_protocol()`` method.""" | ||
code = fixture_code('quantumespresso.ph') | ||
remote_folder = generate_remote_data(fixture_localhost, fixture_sandbox.abspath, 'quantumespresso.pw') | ||
|
||
builder = PhBaseWorkChain.get_builder_from_protocol(code, parent_folder=remote_folder) | ||
|
||
assert builder.ph.parent_folder == remote_folder # pylint: disable=no-member |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
clean_workdir: false | ||
max_iterations: 5 | ||
ph: | ||
code: test.quantumespresso.ph@localhost | ||
metadata: | ||
options: | ||
max_wallclock_seconds: 43200 | ||
resources: | ||
num_machines: 1 | ||
withmpi: true | ||
parameters: | ||
INPUTPH: | ||
tr2_ph: 1.0e-18 | ||
qpoints: | ||
- - 3 | ||
- 3 | ||
- 3 | ||
- - 0.0 | ||
- 0.0 | ||
- 0.0 |