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

Doc: Fixing several small issues #6392

Merged
merged 3 commits into from
Jun 28, 2024
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
4 changes: 2 additions & 2 deletions docs/source/internals/engine.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <aiida.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 <aiida.engine.processes.process.Process>` and :class:`orm.ProcessNode <aiida.orm.ProcessNode>` classes:

* The :meth:`ProcessNodeCaching.is_valid_cache <aiida.orm.nodes.process.process.ProcessNodeCaching.is_valid_cache>` calls :meth:`Process.is_valid_cache <aiida.engine.processes.process.Process.is_valid_cache>`, passing the node itself.
* The :attr:`ProcessNodeCaching.is_valid_cache <aiida.orm.nodes.process.process.ProcessNodeCaching.is_valid_cache>` calls :meth:`Process.is_valid_cache <aiida.engine.processes.process.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 <aiida.orm.nodes.process.process.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 <aiida.orm.nodes.process.process.ProcessNodeCaching.get_objects_to_hash>` method.
Expand Down
8 changes: 4 additions & 4 deletions docs/source/topics/provenance/caching.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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``

Expand All @@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from aiida.engine import WorkChain, append_
from aiida.plugins.factories import CalculationFactory

SomeOtherWorkChain = CalculationFactory('some.module')
Copy link
Contributor Author

@agoscinski agoscinski May 15, 2024

Choose a reason for hiding this comment

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

had to define this somewhere, because mypy was complaining



class SomeWorkChain(WorkChain):
Expand All @@ -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):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from aiida.engine import ToContext, WorkChain
from aiida.plugins.factories import CalculationFactory

SomeOtherWorkChain = CalculationFactory('some.module')


class SomeWorkChain(WorkChain):
Expand All @@ -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):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from aiida.engine import WorkChain
from aiida.plugins.factories import CalculationFactory

SomeOtherWorkChain = CalculationFactory('some.module')


class SomeWorkChain(WorkChain):
Expand All @@ -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})

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from aiida.engine import WorkChain
from aiida.plugins.factories import CalculationFactory

SomeOtherWorkChain = CalculationFactory('some.module')


class SomeWorkChain(WorkChain):
Expand All @@ -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})

Expand Down
Loading