Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PP plugin, add back 'settings' input #537

Merged
merged 4 commits into from
Jul 14, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions aiida_quantumespresso/calculations/pp.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ def define(cls, spec):
help='Output folder of a completed `PwCalculation`')
spec.input('parameters', valid_type=orm.Dict, required=True, validator=validate_parameters,
help='Use a node that specifies the input parameters for the namelists')
spec.input('settings', valid_type=orm.Dict, required=False,
help='Optional parameters to affect the way the calculation job is performed.')
spec.input('metadata.options.input_filename', valid_type=str, default=cls._DEFAULT_INPUT_FILE)
spec.input('metadata.options.output_filename', valid_type=str, default=cls._DEFAULT_OUTPUT_FILE)
spec.input('metadata.options.parser_name', valid_type=str, default='quantumespresso.pp')
Expand Down Expand Up @@ -130,6 +132,12 @@ def prepare_for_submission(self, folder): # pylint: disable=too-many-branches,t
parameters = _uppercase_dict(self.inputs.parameters.get_dict(), dict_name='parameters')
parameters = {k: _lowercase_dict(v, dict_name=k) for k, v in parameters.items()}

# Same for settings.
if 'settings' in self.inputs:
settings = _uppercase_dict(self.inputs.settings.get_dict(), dict_name='settings')
else:
settings = {}

# Set default values. NOTE: this is different from PW/CP
for blocked in self._blocked_keywords:
namelist = blocked[0].upper()
Expand Down Expand Up @@ -204,6 +212,7 @@ def prepare_for_submission(self, folder): # pylint: disable=too-many-branches,t
))

codeinfo = datastructures.CodeInfo()
codeinfo.cmdline_params = settings.pop('CMDLINE', [])
codeinfo.stdin_name = self.inputs.metadata.options.input_filename
codeinfo.stdout_name = self.inputs.metadata.options.output_filename
codeinfo.code_uuid = self.inputs.code.uuid
Expand Down
12 changes: 11 additions & 1 deletion tests/calculations/test_pp.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
def generate_inputs(fixture_localhost, fixture_sandbox, fixture_code, generate_remote_data):
"""Return only those inputs that the parser will expect to be there."""

def _generate_inputs(parameters=None):
def _generate_inputs(parameters=None, settings=None):
from aiida_quantumespresso.utils.resources import get_default_options

if parameters is None:
Expand All @@ -24,6 +24,8 @@ def _generate_inputs(parameters=None):
generate_remote_data(fixture_localhost, fixture_sandbox.abspath, 'quantumespresso.pw'),
'parameters':
orm.Dict(dict=parameters),
'settings':
orm.Dict(dict=settings) or orm.Dict(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this works as expected. The or won't be applied to the value of settings but orm.Dict(dict=settings), so no matter the value of settings you will always hit the first clause. Since orm.Dict(dict=None) is fine and is exactly equal to orm.Dict() you might as well get rid of or orm.Dict()

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, didn't know. And you are right, empty AiiDA Dict object is not falsy:

In [3]: if Dict(dict={}):
   ...:     print("Hello")
   ...:
Hello

Maybe one should fix this here as well:

'settings': orm.Dict(dict=settings) or orm.Dict(),

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yes, please do

Copy link
Collaborator Author

@yakutovicha yakutovicha Jul 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, just a side note:

In [6]: Dict(dict=None) == Dict(dict=None)
Out[6]: False

not sure whether this is what we expect.

'metadata': {
'options': get_default_options()
}
Expand Down Expand Up @@ -79,6 +81,14 @@ def test_pp_keep_plot_file(aiida_profile, fixture_sandbox, generate_calc_job, ge
assert element in calc_info.retrieve_list


def test_pp_cmdline_setting(aiida_profile, fixture_sandbox, generate_calc_job, generate_inputs):
"""Test a `PpCalculation` with user-defined cmdline setting."""
yakutovicha marked this conversation as resolved.
Show resolved Hide resolved
entry_point_name = 'quantumespresso.pp'
inputs = generate_inputs(settings={'cmdline': ['-npools', '2']})
calc_info = generate_calc_job(fixture_sandbox, entry_point_name, inputs)
assert ['-npools', '2'] == calc_info.codes_info[0].cmdline_params
yakutovicha marked this conversation as resolved.
Show resolved Hide resolved


@pytest.mark.parametrize(
('parameters', 'message'),
(
Expand Down