Engine#
控制缓存#
重要
本节涉及缓存机制的一些细节,这些细节在 topics 章节 中没有讨论。如果您正在开发插件并希望修改类的缓存行为,我们建议您先阅读该部分。
AiiDA 的内部类使用几种方法来控制缓存机制:
在通用 orm.Node
类的层面上:
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.节点类有一个
_cachable
属性,可将其设置为False
,以完全关闭该类节点的缓存。这样就可以完全避免执行散列查询。
在 Process
和 orm.ProcessNode
类的级别上:
The
ProcessNodeCaching.is_valid_cache
callsProcess.is_valid_cache
, passing the node itself. This can be used inProcess
subclasses (e.g. in calculation plugins) to implement custom ways of invalidating the cache.The
ProcessNodeCaching._hash_ignored_inputs
attribute lists the inputs that should be ignored when creating the hash. This is checked by theProcessNodeCaching.get_objects_to_hash
method.The
Process.is_valid_cache
is where theexit_codes
that have been marked byinvalidates_cache
are checked.
WorkflowNode
示例#
正如 topic section 中所讨论的,不能缓存可能有 RETURN
链接的节点。这在两个层面上强制执行:
在
Node
中,_cachable
属性被设置为False
,只有在CalculationNode
中才重新启用(影响 CalcJobs 和 calcfunctions)。这意味着WorkflowNode
不会被缓存。_store_from_cache
方法用于克隆``现有节点,如果现有节点有任何 ``RETURN
链接,该方法将引发错误。这种额外的安全保护可以防止用户错误地覆盖WorkflowNode
子类上的_cachable
属性。