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

Engine: fix bug when caching from process with nested outputs #5538

Merged
merged 1 commit into from
May 23, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 4 additions & 2 deletions aiida/engine/processes/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,11 +582,13 @@ def _create_and_setup_db_record(self) -> Union[int, UUID]:
for entry in self.node.base.links.get_outgoing(link_type=LinkType.RETURN):
if entry.link_label.endswith(f'_{entry.node.pk}'):
continue
self.out(entry.link_label, entry.node)
label = entry.link_label.replace(PORT_NAMESPACE_SEPARATOR, self.spec().namespace_separator)
self.out(label, entry.node)
# This is needed for CalcJob. In that case, the outputs are
# returned regardless of whether they end in '_pk'
for entry in self.node.base.links.get_outgoing(link_type=LinkType.CREATE):
self.out(entry.link_label, entry.node)
label = entry.link_label.replace(PORT_NAMESPACE_SEPARATOR, self.spec().namespace_separator)
self.out(label, entry.node)
except exceptions.ModificationNotAllowed:
# The calculation was already stored
pass
Expand Down
37 changes: 37 additions & 0 deletions tests/engine/processes/test_caching.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# -*- coding: utf-8 -*-
"""Test the caching functionality for a :class:`aiida.engine.processes.process.Process`."""
from aiida.engine import Process, run
from aiida.manage import enable_caching
from aiida.orm import CalcJobNode, Int


class NestedOutputsProcess(Process):
"""Process with dynamic nested output namespace."""

_node_class = CalcJobNode

@classmethod
def define(cls, spec):
super().define(spec)
spec.input('a')
spec.output_namespace('nested', dynamic=True)

def run(self):
self.out('nested', {'a': self.inputs.a + 2})


def test_caching_nested_output_namespace():
"""Test that caching from a process with a nested output namespace works."""
_, node_original = run.get_node(NestedOutputsProcess, a=Int(1))
assert not node_original.is_created_from_cache

with enable_caching():
_, node_clone = run.get_node(NestedOutputsProcess, a=Int(1))

assert node_clone.is_created_from_cache
assert node_clone.get_cache_source() == node_original.uuid
Copy link
Member

@ltalirz ltalirz May 23, 2022

Choose a reason for hiding this comment

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

do you maybe want to check here that the structure of the cloned node outputs is as expected?
I guess it's fine, just to be safe

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added the test


outputs = node_clone.get_outgoing().nested()
assert list(outputs.keys()) == ['nested']
assert list(outputs['nested'].keys()) == ['a']
assert isinstance(outputs['nested']['a'], Int)