Skip to content

Commit

Permalink
docs: document the workchain context nesting
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-zero committed Jun 4, 2021
1 parent 678dd0b commit 38da950
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
from aiida.engine import WorkChain


class SomeWorkChain(WorkChain):

@classmethod
def define(cls, spec):
super().define(spec)
spec.outline(
cls.submit_workchains,
cls.inspect_workchains,
)

def submit_workchains(self):
for i in range(3):
future = self.submit(SomeWorkChain)
key = f'workchain.sub{i}'
self.to_context(**{key: future})

def inspect_workchains(self):
for i in range(3):
assert self.ctx.workchain[f'sub{i}'].is_finished_ok
11 changes: 11 additions & 0 deletions docs/source/topics/workflows/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,17 @@ The ``self.ctx.workchains`` now contains a list with the nodes of the completed
Note that the use of ``append_`` is not just limited to the ``to_context`` method.
You can also use it in exactly the same way with ``ToContext`` to append a process to a list in the context in multiple outline steps.

Nested context keys
^^^^^^^^^^^^^^^^^^^

To simplify the organization of the context, the keys may contain dots ``.``, transparently creating namespaces in the process.
As an example compare the following to the parallel submission example above:

.. include:: include/snippets/workchains/run_workchain_submit_append.py
:code: python

This allows to create intuitively grouped and easily accessible structures of child calculations or workchains.

.. _topics:workflows:usage:workchains:reporting:

Reporting
Expand Down

0 comments on commit 38da950

Please sign in to comment.