-
Notifications
You must be signed in to change notification settings - Fork 192
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
Process
: refactor out input handling specific to CalcJob
#5539
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -11,6 +11,7 @@ | |||
import asyncio | ||||
import collections | ||||
from collections.abc import Mapping | ||||
import copy | ||||
import enum | ||||
import inspect | ||||
import logging | ||||
|
@@ -684,27 +685,22 @@ def _setup_db_record(self) -> None: | |||
elif isinstance(self.node, orm.WorkflowNode): | ||||
self.node.base.links.add_incoming(parent_calc, LinkType.CALL_WORK, self.metadata.call_link_label) | ||||
|
||||
self._setup_metadata() | ||||
self._setup_metadata(copy.copy(dict(self.inputs.metadata))) | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do not quite get the idea of using copy here. Could you give me an example of a subclass that has a custom key, what issue will happen? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The aiida-core/aiida/engine/processes/process.py Line 709 in 9d903ca
will raise in the Process._setup_metadata step.
|
||||
self._setup_inputs() | ||||
|
||||
def _setup_metadata(self) -> None: | ||||
def _setup_metadata(self, metadata: dict) -> None: | ||||
"""Store the metadata on the ProcessNode.""" | ||||
version_info = self.runner.plugin_version_provider.get_version_info(self.__class__) | ||||
self.node.base.attributes.set_many(version_info) | ||||
|
||||
for name, metadata in self.metadata.items(): | ||||
for name, value in metadata.items(): | ||||
if name in ['store_provenance', 'dry_run', 'call_link_label']: | ||||
continue | ||||
|
||||
if name == 'label': | ||||
self.node.label = metadata | ||||
self.node.label = value | ||||
elif name == 'description': | ||||
self.node.description = metadata | ||||
elif name == 'computer': | ||||
self.node.computer = metadata | ||||
elif name == 'options': | ||||
for option_name, option_value in metadata.items(): | ||||
self.node.set_option(option_name, option_value) | ||||
self.node.description = value | ||||
else: | ||||
raise RuntimeError(f'unsupported metadata key: {name}') | ||||
|
||||
|
@@ -716,10 +712,6 @@ def _setup_inputs(self) -> None: | |||
if node is None: | ||||
continue | ||||
|
||||
# Special exception: set computer if node is a remote Code and our node does not yet have a computer set | ||||
if isinstance(node, orm.InstalledCode) and not self.node.computer: | ||||
self.node.computer = node.computer | ||||
|
||||
# Need this special case for tests that use ProcessNodes as classes | ||||
if isinstance(self.node, orm.CalculationNode): | ||||
self.node.base.links.add_incoming(node, LinkType.INPUT_CALC, name) | ||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -874,11 +874,12 @@ class TestImport: | |||||||||||||||
"""Test the functionality to import existing calculations completed outside of AiiDA.""" | ||||||||||||||||
|
||||||||||||||||
@pytest.fixture(autouse=True) | ||||||||||||||||
def init_profile(self, aiida_profile_clean, aiida_localhost): # pylint: disable=unused-argument | ||||||||||||||||
def init_profile(self, aiida_profile_clean, aiida_localhost, aiida_local_code_factory): # pylint: disable=unused-argument | ||||||||||||||||
"""Initialize the profile.""" | ||||||||||||||||
# pylint: disable=attribute-defined-outside-init | ||||||||||||||||
self.computer = aiida_localhost | ||||||||||||||||
self.inputs = { | ||||||||||||||||
'code': aiida_local_code_factory('core.arithmetic.add', '/bin/bash', computer=aiida_localhost), | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just out of curiosity. I think the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is in fact not required in the port. For normal executions it is sort of required because the validator will make sure it is defined. However, there is an exception for imported jobs. See these lines aiida-core/aiida/engine/processes/calcjobs/calcjob.py Lines 57 to 63 in 9d903ca
If a |
||||||||||||||||
'x': orm.Int(1), | ||||||||||||||||
'y': orm.Int(2), | ||||||||||||||||
'metadata': { | ||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am thinking is there any possibility that
_setup_inputs
is called before_setup_metadata
? then the computer is not set yet and will cause a problem?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, nevermind. It is sure about the order in
_setup_db_record
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you are right though, if we were to change that in
Process._setup_db_record
it would fail.