Engine#
Controlling caching#
Important
This section covers some details of the caching mechanism which are not discussed in the topics section. If you are developing plugins and want to modify the caching behavior of your classes, we recommend you read that section first.
There are several methods which the internal classes of AiiDA use to control the caching mechanism:
On the level of the generic orm.Node class:
The
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
_cachableattribute, which can be set toFalseto completely switch off caching for nodes of that class. This avoids performing queries for the hash altogether.
On the level of the Process and orm.ProcessNode classes:
The
ProcessNode.is_valid_cachecallsProcess.is_valid_cache, passing the node itself. This can be used inProcesssubclasses (e.g. in calculation plugins) to implement custom ways of invalidating the cache.The
ProcessNode._hash_ignored_inputsattribute lists the inputs that should be ignored when creating the hash. This is checked by theProcessNode._get_objects_to_hashmethod.The
Process.is_valid_cacheis where theexit_codesthat have been marked byinvalidates_cacheare checked.
The WorkflowNode example#
As discussed in the topic section, nodes which can have RETURN links cannot be cached.
This is enforced on two levels:
The
_cachableproperty is set toFalsein theNode, and only re-enabled inCalculationNode(which affects CalcJobs and calcfunctions). This means that aWorkflowNodewill not be cached.The
_store_from_cachemethod, which is used to “clone” an existing node, will raise an error if the existing node has anyRETURNlinks. This extra safe-guard prevents cases where a user might incorrectly override the_cachableproperty on aWorkflowNodesubclass.