From d16f6aac704ba0c92cec2e8d3cd47b4790a0e1b8 Mon Sep 17 00:00:00 2001 From: Alexander Goscinski Date: Wed, 15 May 2024 13:46:11 +0200 Subject: [PATCH 1/2] Doc: Fixed recursive workchain in code snippets The recursive workchain in code snippets can theoretically not run and is just confusing to have as an example for a user. It has been fixed by using different name for the inner workchain. --- .../snippets/workchains/run_workchain_submit_append.py | 5 ++++- .../snippets/workchains/run_workchain_submit_complete.py | 5 ++++- .../snippets/workchains/run_workchain_submit_parallel.py | 5 ++++- .../workchains/run_workchain_submit_parallel_nested.py | 5 ++++- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/docs/source/topics/workflows/include/snippets/workchains/run_workchain_submit_append.py b/docs/source/topics/workflows/include/snippets/workchains/run_workchain_submit_append.py index 07bb32a7e4..1073e7b59b 100644 --- a/docs/source/topics/workflows/include/snippets/workchains/run_workchain_submit_append.py +++ b/docs/source/topics/workflows/include/snippets/workchains/run_workchain_submit_append.py @@ -1,4 +1,7 @@ from aiida.engine import WorkChain, append_ +from aiida.plugins.factories import CalculationFactory + +SomeOtherWorkChain = CalculationFactory('some.module') class SomeWorkChain(WorkChain): @@ -12,7 +15,7 @@ def define(cls, spec): def submit_workchains(self): for i in range(3): - future = self.submit(SomeWorkChain) + future = self.submit(SomeOtherWorkChain) self.to_context(workchains=append_(future)) def inspect_workchains(self): diff --git a/docs/source/topics/workflows/include/snippets/workchains/run_workchain_submit_complete.py b/docs/source/topics/workflows/include/snippets/workchains/run_workchain_submit_complete.py index 8b7d2f5041..b325ab5c59 100644 --- a/docs/source/topics/workflows/include/snippets/workchains/run_workchain_submit_complete.py +++ b/docs/source/topics/workflows/include/snippets/workchains/run_workchain_submit_complete.py @@ -1,4 +1,7 @@ from aiida.engine import ToContext, WorkChain +from aiida.plugins.factories import CalculationFactory + +SomeOtherWorkChain = CalculationFactory('some.module') class SomeWorkChain(WorkChain): @@ -11,7 +14,7 @@ def define(cls, spec): ) def submit_workchain(self): - future = self.submit(SomeWorkChain) + future = self.submit(SomeOtherWorkChain) return ToContext(workchain=future) def inspect_workchain(self): diff --git a/docs/source/topics/workflows/include/snippets/workchains/run_workchain_submit_parallel.py b/docs/source/topics/workflows/include/snippets/workchains/run_workchain_submit_parallel.py index 1db43470f0..313c1b02e1 100644 --- a/docs/source/topics/workflows/include/snippets/workchains/run_workchain_submit_parallel.py +++ b/docs/source/topics/workflows/include/snippets/workchains/run_workchain_submit_parallel.py @@ -1,4 +1,7 @@ from aiida.engine import WorkChain +from aiida.plugins.factories import CalculationFactory + +SomeOtherWorkChain = CalculationFactory('some.module') class SomeWorkChain(WorkChain): @@ -12,7 +15,7 @@ def define(cls, spec): def submit_workchains(self): for i in range(3): - future = self.submit(SomeWorkChain) + future = self.submit(SomeOtherWorkChain) key = f'workchain_{i}' self.to_context(**{key: future}) diff --git a/docs/source/topics/workflows/include/snippets/workchains/run_workchain_submit_parallel_nested.py b/docs/source/topics/workflows/include/snippets/workchains/run_workchain_submit_parallel_nested.py index 7b42042c83..cf80bd02b5 100644 --- a/docs/source/topics/workflows/include/snippets/workchains/run_workchain_submit_parallel_nested.py +++ b/docs/source/topics/workflows/include/snippets/workchains/run_workchain_submit_parallel_nested.py @@ -1,4 +1,7 @@ from aiida.engine import WorkChain +from aiida.plugins.factories import CalculationFactory + +SomeOtherWorkChain = CalculationFactory('some.module') class SomeWorkChain(WorkChain): @@ -12,7 +15,7 @@ def define(cls, spec): def submit_workchains(self): for i in range(3): - future = self.submit(SomeWorkChain) + future = self.submit(SomeOtherWorkChain) key = f'workchains.sub{i}' self.to_context(**{key: future}) From fa4183d47b400c9386c7a62d1ce62e55c36d92bb Mon Sep 17 00:00:00 2001 From: Alexander Goscinski Date: Thu, 16 May 2024 16:52:35 +0200 Subject: [PATCH 2/2] Doc: is_valid_cache wrongly marked as methods In the classes NodeCaching and ProcessNodeCaching the `is valid_cache` is a property. To not render it with method brackets we use now the :attr: sphinx directive in the. --- docs/source/internals/engine.rst | 4 ++-- docs/source/topics/provenance/caching.rst | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/source/internals/engine.rst b/docs/source/internals/engine.rst index 42652c3132..3e6f30360b 100644 --- a/docs/source/internals/engine.rst +++ b/docs/source/internals/engine.rst @@ -20,14 +20,14 @@ There are several methods which the internal classes of AiiDA use to control the On the level of the generic :class:`orm.Node ` class: -* The :meth:`~aiida.orm.nodes.caching.NodeCaching.is_valid_cache` property determines whether a particular node can be used as a cache. +* The :attr:`~aiida.orm.nodes.caching.NodeCaching.is_valid_cache` property determines whether a particular node can be used as a cache. This is used for example to disable caching from failed calculations. * Node classes have a ``_cachable`` attribute, which can be set to ``False`` to completely switch off caching for nodes of that class. This avoids performing queries for the hash altogether. On the level of the :class:`Process ` and :class:`orm.ProcessNode ` classes: -* The :meth:`ProcessNodeCaching.is_valid_cache ` calls :meth:`Process.is_valid_cache `, passing the node itself. +* The :attr:`ProcessNodeCaching.is_valid_cache ` calls :meth:`Process.is_valid_cache `, passing the node itself. This can be used in :class:`~aiida.engine.processes.process.Process` subclasses (e.g. in calculation plugins) to implement custom ways of invalidating the cache. * The :meth:`ProcessNodeCaching._hash_ignored_inputs ` attribute lists the inputs that should be ignored when creating the hash. This is checked by the :meth:`ProcessNodeCaching.get_objects_to_hash ` method. diff --git a/docs/source/topics/provenance/caching.rst b/docs/source/topics/provenance/caching.rst index 6a923d8931..b15a3cbeda 100644 --- a/docs/source/topics/provenance/caching.rst +++ b/docs/source/topics/provenance/caching.rst @@ -146,9 +146,9 @@ This method calls the iterator :meth:`~aiida.orm.nodes.caching.NodeCaching._iter To find the list of `source` nodes that are equivalent to the `target` that is being stored, :meth:`~aiida.orm.nodes.caching.NodeCaching._iter_all_same_nodes` performs the following steps: 1. It queries the database for all nodes that have the same hash as the `target` node. -2. From the result, only those nodes are returned where the property :meth:`~aiida.orm.nodes.caching.NodeCaching.is_valid_cache` returns ``True``. +2. From the result, only those nodes are returned where the property :attr:`~aiida.orm.nodes.caching.NodeCaching.is_valid_cache` returns ``True``. -The property :meth:`~aiida.orm.nodes.caching.NodeCaching.is_valid_cache` therefore allows to control whether a stored node can be used as a `source` in the caching mechanism. +The property :attr:`~aiida.orm.nodes.caching.NodeCaching.is_valid_cache` therefore allows to control whether a stored node can be used as a `source` in the caching mechanism. By default, for all nodes, the property returns ``True``. However, this can be changed on a per-node basis, by setting it to ``False`` @@ -166,8 +166,8 @@ Setting the property to ``False``, will cause an extra to be stored on the node Through this method, it is possible to guarantee that individual nodes are never used as a `source` for caching. -The :class:`~aiida.engine.processes.process.Process` class overrides the :meth:`~aiida.orm.nodes.caching.NodeCaching.is_valid_cache` property to give more fine-grained control on process nodes as caching sources. -If either :meth:`~aiida.orm.nodes.caching.NodeCaching.is_valid_cache` of the base class or :meth:`~aiida.orm.nodes.process.process.ProcessNode.is_finished` returns ``False``, the process node is not a valid source. +The :class:`~aiida.engine.processes.process.Process` class overrides the :attr:`~aiida.orm.nodes.caching.NodeCaching.is_valid_cache` property to give more fine-grained control on process nodes as caching sources. +If either :attr:`~aiida.orm.nodes.caching.NodeCaching.is_valid_cache` of the base class or :meth:`~aiida.orm.nodes.process.process.ProcessNode.is_finished` returns ``False``, the process node is not a valid source. Likewise, if the process class cannot be loaded from the node, through the :meth:`~aiida.orm.nodes.process.process.ProcessNode.process_class`, the node is not a valid caching source. Finally, if the associated process class implements the :meth:`~aiida.engine.processes.process.Process.is_valid_cache` method, it is called, passing the node as an argument. If that returns ``True``, the node is considered to be a valid caching source.