aiida.orm.utils package#

Utilities related to the ORM.

Subpackages#

Submodules#

Utilities to operate on CalcJobNode instances.

class aiida.orm.utils.calcjob.CalcJobResultManager(node)[source]#

Bases: object

Utility class to easily access the contents of the ‘default output’ node of a CalcJobNode.

A CalcJob process can mark one of its outputs as the ‘default output’. The default output node will always be returned by the CalcJob and will always be a Dict node.

If a CalcJob defines such a default output node, this utility class will simplify retrieving the result of said node through the CalcJobNode instance produced by the execution of the CalcJob.

The default results are only defined if the CalcJobNode has a process_type that can be successfully used to load the corresponding CalcJob process class and if its process spec defines a default_output_node. If both these conditions are met, the results are defined as the dictionary contained within the default output node.

__dict__ = mappingproxy({'__module__': 'aiida.orm.utils.calcjob', '__doc__': "Utility class to easily access the contents of the 'default output' node of a `CalcJobNode`.\n\n    A `CalcJob` process can mark one of its outputs as the 'default output'. The default output node will always be\n    returned by the `CalcJob` and will always be a `Dict` node.\n\n    If a `CalcJob` defines such a default output node, this utility class will simplify retrieving the result of said\n    node through the `CalcJobNode` instance produced by the execution of the `CalcJob`.\n\n    The default results are only defined if the `CalcJobNode` has a `process_type` that can be successfully used\n    to load the corresponding `CalcJob` process class *and* if its process spec defines a `default_output_node`.\n    If both these conditions are met, the results are defined as the dictionary contained within the default\n    output node.\n    ", '__init__': <function CalcJobResultManager.__init__>, 'node': <property object>, '_load_results': <function CalcJobResultManager._load_results>, 'get_results': <function CalcJobResultManager.get_results>, '__dir__': <function CalcJobResultManager.__dir__>, '__iter__': <function CalcJobResultManager.__iter__>, '__getattr__': <function CalcJobResultManager.__getattr__>, '__getitem__': <function CalcJobResultManager.__getitem__>, '__dict__': <attribute '__dict__' of 'CalcJobResultManager' objects>, '__weakref__': <attribute '__weakref__' of 'CalcJobResultManager' objects>, '__annotations__': {}})#
__dir__()[source]#

Add the keys of the results dictionary such that they can be autocompleted.

__getattr__(name)[source]#

Return an attribute from the results dictionary.

Parameters:

name – name of the result return

Returns:

value of the attribute

Raises:

AttributeError – if the results node cannot be retrieved or it does not contain the name attribute

__getitem__(name)[source]#

Return an attribute from the results dictionary.

Parameters:

name – name of the result return

Returns:

value of the attribute

Raises:

KeyError – if the results node cannot be retrieved or it does not contain the name attribute

__init__(node)[source]#

Construct an instance of the CalcJobResultManager.

Parameters:

calc – the CalcJobNode instance.

__iter__()[source]#

Return an iterator over the keys of the result dictionary.

__module__ = 'aiida.orm.utils.calcjob'#
__weakref__#

list of weak references to the object

_load_results()[source]#

Try to load the results for the CalcJobNode of this result manager.

Raises:

ValueError – if no default output node could be loaded

get_results()[source]#

Return the results dictionary of the default results node of the calculation node.

This property will lazily load the dictionary.

Returns:

the dictionary of the default result node

property node#

Return the CalcJobNode associated with this result manager instance.

class aiida.orm.utils.links.LinkManager(link_triples: List[LinkTriple])[source]#

Bases: object

Class to convert a list of LinkTriple tuples into an iterator.

It defines convenience methods to retrieve certain subsets of LinkTriple while checking for consistency. For example:

LinkManager.one(): returns the only entry in the list or it raises an exception
LinkManager.first(): returns the first entry from the list
LinkManager.all(): returns all entries from list

The methods all_nodes and all_link_labels are syntactic sugar wrappers around all to get a list of only the incoming nodes or link labels, respectively.

__bool__()[source]#
__dict__ = mappingproxy({'__module__': 'aiida.orm.utils.links', '__doc__': 'Class to convert a list of LinkTriple tuples into an iterator.\n\n    It defines convenience methods to retrieve certain subsets of LinkTriple while checking for consistency.\n    For example::\n\n        LinkManager.one(): returns the only entry in the list or it raises an exception\n        LinkManager.first(): returns the first entry from the list\n        LinkManager.all(): returns all entries from list\n\n    The methods `all_nodes` and `all_link_labels` are syntactic sugar wrappers around `all` to get a list of only the\n    incoming nodes or link labels, respectively.\n    ', '__init__': <function LinkManager.__init__>, '__iter__': <function LinkManager.__iter__>, '__next__': <function LinkManager.__next__>, '__bool__': <function LinkManager.__bool__>, 'next': <function LinkManager.next>, 'one': <function LinkManager.one>, 'first': <function LinkManager.first>, 'all': <function LinkManager.all>, 'all_nodes': <function LinkManager.all_nodes>, 'all_link_pairs': <function LinkManager.all_link_pairs>, 'all_link_labels': <function LinkManager.all_link_labels>, 'get_node_by_label': <function LinkManager.get_node_by_label>, 'nested': <function LinkManager.nested>, '__dict__': <attribute '__dict__' of 'LinkManager' objects>, '__weakref__': <attribute '__weakref__' of 'LinkManager' objects>, '__annotations__': {}})#
__init__(link_triples: List[LinkTriple])[source]#

Initialise the collection.

__iter__() Iterator[LinkTriple][source]#

Return an iterator of LinkTriple instances.

Returns:

iterator of LinkTriple instances

__module__ = 'aiida.orm.utils.links'#
__next__() Generator[LinkTriple, None, None][source]#

Return the next element in the iterator.

Returns:

LinkTriple

__weakref__#

list of weak references to the object

all() List[LinkTriple][source]#

Return all entries from the list.

Returns:

list of LinkTriple instances

Return a list of all link labels.

Returns:

list of link labels

Return a list of all link pairs.

Returns:

list of LinkPair instances

all_nodes() List[Node][source]#

Return a list of all nodes.

Returns:

list of nodes

first() LinkTriple | None[source]#

Return the first entry from the iterator.

Returns:

LinkTriple instance or None if no entries were matched

get_node_by_label(label: str) Node[source]#

Return the node from list for given label.

Returns:

node that corresponds to the given label

Raises:

aiida.common.NotExistent – if the label is not present among the link_triples

nested(sort=True)[source]#

Construct (nested) dictionary of matched nodes that mirrors the original nesting of link namespaces.

Process input and output namespaces can be nested, however the link labels that represent them in the database have a flat hierarchy, and so the link labels are flattened representations of the nested namespaces. This function reconstructs the original node nesting based on the flattened links.

Returns:

dictionary of nested namespaces

Raises:

KeyError – if there are duplicate link labels in a namespace

next() Generator[LinkTriple, None, None][source]#

Return the next element in the iterator.

Returns:

LinkTriple

one() LinkTriple[source]#

Return a single entry from the iterator.

If the iterator contains no or more than one entry, an exception will be raised :return: LinkTriple instance :raises ValueError: if the iterator contains anything but one entry

class aiida.orm.utils.links.LinkPair(link_type, link_label)[source]#

Bases: NamedTuple

__annotations__ = {'link_label': <class 'str'>, 'link_type': ForwardRef('LinkType')}#
__getnewargs__()#

Return self as a plain tuple. Used by copy and pickle.

__match_args__ = ('link_type', 'link_label')#
__module__ = 'aiida.orm.utils.links'#
static __new__(_cls, link_type: LinkType, link_label: str)#

Create new instance of LinkPair(link_type, link_label)

__orig_bases__ = (<function NamedTuple>,)#
__repr__()#

Return a nicely formatted representation string

__slots__ = ()#
_asdict()#

Return a new dict which maps field names to their values.

_field_defaults = {}#
_fields = ('link_type', 'link_label')#
classmethod _make(iterable)#

Make a new LinkPair object from a sequence or iterable

_replace(**kwds)#

Return a new LinkPair object replacing specified fields with new values

Alias for field number 1

Alias for field number 0

class aiida.orm.utils.links.LinkQuadruple(source_id, target_id, link_type, link_label)[source]#

Bases: NamedTuple

__annotations__ = {'link_label': <class 'str'>, 'link_type': ForwardRef('LinkType'), 'source_id': <class 'int'>, 'target_id': <class 'int'>}#
__getnewargs__()#

Return self as a plain tuple. Used by copy and pickle.

__match_args__ = ('source_id', 'target_id', 'link_type', 'link_label')#
__module__ = 'aiida.orm.utils.links'#
static __new__(_cls, source_id: int, target_id: int, link_type: LinkType, link_label: str)#

Create new instance of LinkQuadruple(source_id, target_id, link_type, link_label)

__orig_bases__ = (<function NamedTuple>,)#
__repr__()#

Return a nicely formatted representation string

__slots__ = ()#
_asdict()#

Return a new dict which maps field names to their values.

_field_defaults = {}#
_fields = ('source_id', 'target_id', 'link_type', 'link_label')#
classmethod _make(iterable)#

Make a new LinkQuadruple object from a sequence or iterable

_replace(**kwds)#

Return a new LinkQuadruple object replacing specified fields with new values

Alias for field number 3

Alias for field number 2

source_id: int#

Alias for field number 0

target_id: int#

Alias for field number 1

class aiida.orm.utils.links.LinkTriple(node, link_type, link_label)[source]#

Bases: NamedTuple

__annotations__ = {'link_label': <class 'str'>, 'link_type': ForwardRef('LinkType'), 'node': ForwardRef('Node')}#
__getnewargs__()#

Return self as a plain tuple. Used by copy and pickle.

__match_args__ = ('node', 'link_type', 'link_label')#
__module__ = 'aiida.orm.utils.links'#
static __new__(_cls, node: Node, link_type: LinkType, link_label: str)#

Create new instance of LinkTriple(node, link_type, link_label)

__orig_bases__ = (<function NamedTuple>,)#
__repr__()#

Return a nicely formatted representation string

__slots__ = ()#
_asdict()#

Return a new dict which maps field names to their values.

_field_defaults = {}#
_fields = ('node', 'link_type', 'link_label')#
classmethod _make(iterable)#

Make a new LinkTriple object from a sequence or iterable

_replace(**kwds)#

Return a new LinkTriple object replacing specified fields with new values

Alias for field number 2

Alias for field number 1

node: Node#

Alias for field number 0

Return whether a link with the given type and label exists between the given source and target node.

Parameters:
  • source – node from which the link is outgoing

  • target – node to which the link is incoming

  • link_type – the link type

  • link_label – the link label

Returns:

boolean, True if the link triple exists, False otherwise

Validate adding a link of the given type and label from a given node to ourself.

This function will first validate the class types of the inputs and will subsequently validate whether a link of the specified type is allowed at all between the nodes types of the source and target.

Subsequently, the validity of the “indegree” and “outdegree” of the proposed link is validated, which means validating that the uniqueness constraints of the incoming links into the target node and the outgoing links from the source node are not violated. In AiiDA’s provenance graph each link type has one of the following three types of “degree” character:

* unique
* unique pair
* unique triple

Each degree character has a different unique constraint on its links, here defined for the indegree:

* unique: any target node, it can only have a single incoming link of this type, regardless of the link label.
* unique pair: a node can have an infinite amount of incoming links of this type, as long as the labels within
    that sub set, are unique. In short, it is the link pair, i.e. the tuple of the link type and label, that has
    a uniquess constraint for the incoming links to a given node.
* unique triple: a node can have an infinite amount of incoming links of this type, as long as the triple tuple
    of source node, link type and link label is unique. In other words, it is the link triple that has a
    uniqueness constraint for the incoming links.

The same holds for outdegree, but then it concerns outgoing links from the source node to the target node.

For illustration purposes, consider the following example provenance graphs that are considered legal, where WN, DN and CN represent a WorkflowNode, a DataNode and a CalculationNode, respectively:

         1                    2                    3
 ______     ______          ______          ______     ______
|      |   |      |        |      |        |      |   |      |
|  WN  |   |  DN  |        |  DN  |        |  WN  |   |  WN  |
|______|   |______|        |______|        |______|   |______|
     |     /                |   |               |     /
   a |    / a             a |   | b           a |    / a
    _|___/                  |___|_             _|___/
   |      |                |      |           |      |
   |  CN  |                |  CN  |           |  DN  |
   |______|                |______|           |______|

In example 1, the link uniqueness constraint is not violated because despite the labels having the same label a, their link types, CALL_CALC and INPUT_CALC, respectively, are different and their unique_pair indegree is not violated.

Similarly, in the second example, the constraint is not violated, because despite both links having the same link type INPUT_CALC, the have different labels, so the unique_pair indegree of the INPUT_CALC is not violated.

Finally, in the third example, we see two WorkflowNodes both returning the same DataNode and with the same label. Despite the two incoming links here having both the same type as well as the same label, the uniqueness constraint is not violated, because the indegree for RETURN links is unique_triple which means that the triple of source node and link type and label should be unique.

Parameters:
  • source – the node from which the link is coming

  • target – the node to which the link is going

  • link_type – the type of link

  • link_label – link label

Raises:
  • TypeError – if source or target is not a Node instance, or link_type is not a LinkType enum

  • ValueError – if the proposed link is invalid

Module with OrmEntityLoader and its sub classes that simplify loading entities through their identifiers.

class aiida.orm.utils.loaders.CalculationEntityLoader[source]#

Bases: OrmEntityLoader

Loader for the Calculation entity and sub classes.

__module__ = 'aiida.orm.utils.loaders'#
classmethod _get_query_builder_label_identifier(identifier, classes, operator='==', project='*')[source]#

Return the query builder instance that attempts to map the identifier onto an entity of the orm class, defined for this loader class, interpreting the identifier as a LABEL like identifier

Parameters:
  • identifier – the LABEL identifier

  • classes – a tuple of orm classes to which the identifier should be mapped

  • operator – the operator to use in the query

  • project – the property or properties to project for entities matching the query

Returns:

the query builder instance that should retrieve the entity corresponding to the identifier

Raises:
orm_base_class#

alias of CalculationNode

class aiida.orm.utils.loaders.CodeEntityLoader[source]#

Bases: OrmEntityLoader

Loader for the Code entity and sub classes.

__annotations__ = {}#
__module__ = 'aiida.orm.utils.loaders'#
classmethod _get_query_builder_label_identifier(identifier, classes, operator='==', project='*')[source]#

Return the query builder instance that attempts to map the identifier onto an entity of the orm class, defined for this loader class, interpreting the identifier as a LABEL like identifier

Parameters:
  • identifier – the LABEL identifier

  • classes – a tuple of orm classes to which the identifier should be mapped

  • operator – the operator to use in the query

  • project – the property or properties to project for entities matching the query

Returns:

the query builder instance that should retrieve the entity corresponding to the identifier

Raises:
orm_base_class#

alias of Code

class aiida.orm.utils.loaders.ComputerEntityLoader[source]#

Bases: OrmEntityLoader

Loader for the Computer entity and sub classes.

__annotations__ = {}#
__module__ = 'aiida.orm.utils.loaders'#
classmethod _get_query_builder_label_identifier(identifier, classes, operator='==', project='*')[source]#

Return the query builder instance that attempts to map the identifier onto an entity of the orm class, defined for this loader class, interpreting the identifier as a LABEL like identifier

Parameters:
  • identifier – the LABEL identifier

  • classes – a tuple of orm classes to which the identifier should be mapped

  • operator – the operator to use in the query

  • project – the property or properties to project for entities matching the query

Returns:

the query builder instance that should retrieve the entity corresponding to the identifier

Raises:
orm_base_class#

alias of Computer

class aiida.orm.utils.loaders.DataEntityLoader[source]#

Bases: OrmEntityLoader

Loader for the Data entity and sub classes.

__annotations__ = {}#
__module__ = 'aiida.orm.utils.loaders'#
classmethod _get_query_builder_label_identifier(identifier, classes, operator='==', project='*')[source]#

Return the query builder instance that attempts to map the identifier onto an entity of the orm class, defined for this loader class, interpreting the identifier as a LABEL like identifier

Parameters:
  • identifier – the LABEL identifier

  • classes – a tuple of orm classes to which the identifier should be mapped

  • operator – the operator to use in the query

  • project – the property or properties to project for entities matching the query

Returns:

the query builder instance that should retrieve the entity corresponding to the identifier

Raises:
orm_base_class#

alias of Data

class aiida.orm.utils.loaders.GroupEntityLoader[source]#

Bases: OrmEntityLoader

Loader for the Group entity and sub classes.

__annotations__ = {}#
__module__ = 'aiida.orm.utils.loaders'#
classmethod _get_query_builder_label_identifier(identifier, classes, operator='==', project='*')[source]#

Return the query builder instance that attempts to map the identifier onto an entity of the orm class, defined for this loader class, interpreting the identifier as a LABEL like identifier

Parameters:
  • identifier – the LABEL identifier

  • classes – a tuple of orm classes to which the identifier should be mapped

  • operator – the operator to use in the query

  • project – the property or properties to project for entities matching the query

Returns:

the query builder instance that should retrieve the entity corresponding to the identifier

Raises:
orm_base_class#

alias of Group

class aiida.orm.utils.loaders.IdentifierType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]#

Bases: Enum

The enumeration that defines the three types of identifier that can be used to identify an orm entity. The ID is always an integer, the UUID a base 16 encoded integer with optional dashes and the LABEL can be any string based label or name, the format of which will vary per orm class

ID = 'ID'#
LABEL = 'LABEL'#
UUID = 'UUID'#
__module__ = 'aiida.orm.utils.loaders'#
class aiida.orm.utils.loaders.NodeEntityLoader[source]#

Bases: OrmEntityLoader

Loader for the Node entity and sub classes.

__annotations__ = {}#
__module__ = 'aiida.orm.utils.loaders'#
classmethod _get_query_builder_label_identifier(identifier, classes, operator='==', project='*')[source]#

Return the query builder instance that attempts to map the identifier onto an entity of the orm class, defined for this loader class, interpreting the identifier as a LABEL like identifier

Parameters:
  • identifier – the LABEL identifier

  • classes – a tuple of orm classes to which the identifier should be mapped

  • operator – the operator to use in the query

  • project – the property or properties to project for entities matching the query

Returns:

the query builder instance that should retrieve the entity corresponding to the identifier

Raises:
orm_base_class#

alias of Node

class aiida.orm.utils.loaders.OrmEntityLoader[source]#

Bases: object

Base class for entity loaders.

__annotations__ = {}#
__dict__ = mappingproxy({'__module__': 'aiida.orm.utils.loaders', '__doc__': 'Base class for entity loaders.', 'label_ambiguity_breaker': '!', 'orm_base_class': <aiida.common.lang.classproperty object>, '_get_query_builder_label_identifier': <classmethod(<function OrmEntityLoader._get_query_builder_label_identifier>)>, '_get_query_builder_id_identifier': <classmethod(<function OrmEntityLoader._get_query_builder_id_identifier>)>, '_get_query_builder_uuid_identifier': <classmethod(<function OrmEntityLoader._get_query_builder_uuid_identifier>)>, 'get_query_builder': <classmethod(<function OrmEntityLoader.get_query_builder>)>, 'get_options': <classmethod(<function OrmEntityLoader.get_options>)>, 'load_entity': <classmethod(<function OrmEntityLoader.load_entity>)>, 'get_query_classes': <classmethod(<function OrmEntityLoader.get_query_classes>)>, 'infer_identifier_type': <classmethod(<function OrmEntityLoader.infer_identifier_type>)>, '__dict__': <attribute '__dict__' of 'OrmEntityLoader' objects>, '__weakref__': <attribute '__weakref__' of 'OrmEntityLoader' objects>, '__annotations__': {}})#
__module__ = 'aiida.orm.utils.loaders'#
__weakref__#

list of weak references to the object

classmethod _get_query_builder_id_identifier(identifier, classes)[source]#

Return the query builder instance that attempts to map the identifier onto an entity of the orm class, defined for this loader class, interpreting the identifier as an ID like identifier

Parameters:
  • identifier – the ID identifier

  • classes – a tuple of orm classes to which the identifier should be mapped

Returns:

the query builder instance

abstract classmethod _get_query_builder_label_identifier(identifier, classes, operator='==', project='*')[source]#

Return the query builder instance that attempts to map the identifier onto an entity of the orm class, defined for this loader class, interpreting the identifier as a LABEL like identifier

Parameters:
  • identifier – the LABEL identifier

  • classes – a tuple of orm classes to which the identifier should be mapped

  • operator – the operator to use in the query

  • project – the property or properties to project for entities matching the query

Returns:

the query builder instance

Raises:
classmethod _get_query_builder_uuid_identifier(identifier, classes, query_with_dashes)[source]#

Return the query builder instance that attempts to map the identifier onto an entity of the orm class, defined for this loader class, interpreting the identifier as a UUID like identifier

Parameters:
  • identifier – the UUID identifier

  • classes – a tuple of orm classes to which the identifier should be mapped

Returns:

the query builder instance

classmethod get_options(incomplete, project='*')[source]#

Return the list of entities that match the incomplete identifier.

Note

For the time being only LABEL auto-completion is supported so the identifier type is not inferred but hard-coded to be IdentifierType.LABEL

Parameters:
  • incomplete – the incomplete identifier

  • project – the field(s) to project for each entity that matches the incomplete identifier

Returns:

list of entities matching the incomplete identifier

classmethod get_query_builder(identifier, identifier_type=None, sub_classes=None, query_with_dashes=True, operator='==', project='*')[source]#

Return the query builder instance that attempts to map the identifier onto an entity of the orm class, defined for this loader class, inferring the identifier type if it is not defined.

Parameters:
  • identifier – the identifier

  • identifier_type – the type of the identifier

  • sub_classes – an optional tuple of orm classes, that should each be strict sub classes of the base orm class of the loader, that will narrow the queryset

  • operator – the operator to use in the query

  • project – the property or properties to project for entities matching the query

Returns:

the query builder instance and a dictionary of used query parameters

classmethod get_query_classes(sub_classes=None)[source]#

Get the tuple of classes to be used for the entity query. If sub_classes is defined, each class will be validated by verifying that it is a sub class of the loader’s orm base class. Validate a tuple of classes if a user passes in a specific one when attempting to load an entity. Each class should be a sub class of the entity loader’s orm base class

Parameters:

sub_classes – an optional tuple of orm classes, that should each be strict sub classes of the base orm class of the loader, that will narrow the queryset

Returns:

the tuple of orm classes to be used for the entity query

Raises:

ValueError – if any of the classes are not a sub class of the entity loader’s orm base class

classmethod infer_identifier_type(value)[source]#

Attempt to automatically distinguish which identifier type is implied for the given value.

The strategy is to first attempt to convert the value to an integer. If successful, it is assumed that the value represents an ID. If that fails, we attempt to interpret the value as a base 16 encoded integer, after having removed any dashes from the string. If that succeeds, it is most likely a UUID. If it seems to be neither an ID nor a UUID, it is assumed to be a LABEL like identifier.

With this approach there is the possibility for ambiguity. Since it is allowed to pass a partial UUID, it is possible that the partial UUID is also a valid ID. Likewise, a LABEL identifier might also be a valid ID, or a valid (partial) UUID. Fortunately, these ambiguities can be solved though:

  • ID/UUID: can always be solved by passing a partial UUID with at least one dash

  • ID/LABEL: appending an exclamation point ! to the identifier, will force LABEL interpretation

  • UUID/LABEL: appending an exclamation point ! to the identifier, will force LABEL interpretation

As one can see, the user will always be able to include at least one dash of the UUID identifier to prevent it from being interpreted as an ID. For the potential ambiguities in LABEL identifiers, we had to introduce a special marker to provide a surefire way of breaking any ambiguity that may arise. Adding an exclamation point will break the normal strategy and the identifier will directly be interpreted as a LABEL identifier.

Parameters:

value – the value of the identifier

Returns:

the identifier and identifier type

Raises:

ValueError – if the value is an invalid identifier

label_ambiguity_breaker = '!'#
classmethod load_entity(identifier, identifier_type=None, sub_classes=None, query_with_dashes=True)[source]#

Load an entity that uniquely corresponds to the provided identifier of the identifier type.

Parameters:
  • identifier – the identifier

  • identifier_type – the type of the identifier

  • sub_classes – an optional tuple of orm classes, that should each be strict sub classes of the base orm class of the loader, that will narrow the queryset

Returns:

the loaded entity

Raises:
orm_base_class#

A class that, when used as a decorator, works as if the two decorators @property and @classmethod where applied together (i.e., the object works as a property, both for the Class and for any of its instance; and is called with the class cls rather than with the instance as its first argument).

class aiida.orm.utils.loaders.ProcessEntityLoader[source]#

Bases: OrmEntityLoader

Loader for the Process entity and sub classes.

__annotations__ = {}#
__module__ = 'aiida.orm.utils.loaders'#
classmethod _get_query_builder_label_identifier(identifier, classes, operator='==', project='*')[source]#

Return the query builder instance that attempts to map the identifier onto an entity of the orm class, defined for this loader class, interpreting the identifier as a LABEL like identifier

Parameters:
  • identifier – the LABEL identifier

  • classes – a tuple of orm classes to which the identifier should be mapped

  • operator – the operator to use in the query

  • project – the property or properties to project for entities matching the query

Returns:

the query builder instance that should retrieve the entity corresponding to the identifier

Raises:
orm_base_class#

alias of ProcessNode

class aiida.orm.utils.loaders.WorkflowEntityLoader[source]#

Bases: OrmEntityLoader

Loader for the Workflow entity and sub classes.

__annotations__ = {}#
__module__ = 'aiida.orm.utils.loaders'#
classmethod _get_query_builder_label_identifier(identifier, classes, operator='==', project='*')[source]#

Return the query builder instance that attempts to map the identifier onto an entity of the orm class, defined for this loader class, interpreting the identifier as a LABEL like identifier

Parameters:
  • identifier – the LABEL identifier

  • classes – a tuple of orm classes to which the identifier should be mapped

  • operator – the operator to use in the query

  • project – the property or properties to project for entities matching the query

Returns:

the query builder instance that should retrieve the entity corresponding to the identifier

Raises:
orm_base_class#

alias of WorkflowNode

aiida.orm.utils.loaders.get_loader(orm_class)[source]#

Return the correct OrmEntityLoader for the given orm class.

Parameters:

orm_class – the orm class

Returns:

a subclass of OrmEntityLoader

Raises:

ValueError – if no OrmEntityLoader subclass can be found for the given orm class

aiida.orm.utils.loaders.load_code(identifier=None, pk=None, uuid=None, label=None, sub_classes=None, query_with_dashes=True) Code[source]#

Load a Code instance by one of its identifiers: pk, uuid or label

If the type of the identifier is unknown simply pass it without a keyword and the loader will attempt to automatically infer the type.

Parameters:
  • identifier – pk (integer), uuid (string) or label (string) of a Code

  • pk – pk of a Code

  • uuid – uuid of a Code, or the beginning of the uuid

  • label – label of a Code

  • sub_classes – an optional tuple of orm classes to narrow the queryset. Each class should be a strict sub class of the ORM class of the given entity loader.

  • query_with_dashes (bool) – allow to query for a uuid with dashes

Returns:

the Code instance

Raises:
aiida.orm.utils.loaders.load_computer(identifier=None, pk=None, uuid=None, label=None, sub_classes=None, query_with_dashes=True) Computer[source]#

Load a Computer instance by one of its identifiers: pk, uuid or label

If the type of the identifier is unknown simply pass it without a keyword and the loader will attempt to automatically infer the type.

Parameters:
  • identifier – pk (integer), uuid (string) or label (string) of a Computer

  • pk – pk of a Computer

  • uuid – uuid of a Computer, or the beginning of the uuid

  • label – label of a Computer

  • sub_classes – an optional tuple of orm classes to narrow the queryset. Each class should be a strict sub class of the ORM class of the given entity loader.

  • query_with_dashes (bool) – allow to query for a uuid with dashes

Returns:

the Computer instance

Raises:
aiida.orm.utils.loaders.load_entity(entity_loader=None, identifier=None, pk=None, uuid=None, label=None, sub_classes=None, query_with_dashes=True)[source]#

Load an entity instance by one of its identifiers: pk, uuid or label

If the type of the identifier is unknown simply pass it without a keyword and the loader will attempt to automatically infer the type.

Parameters:
  • identifier – pk (integer), uuid (string) or label (string) of a Code

  • pk – pk of a Code

  • uuid – uuid of a Code, or the beginning of the uuid

  • label – label of a Code

  • sub_classes – an optional tuple of orm classes to narrow the queryset. Each class should be a strict sub class of the ORM class of the given entity loader.

  • query_with_dashes (bool) – allow to query for a uuid with dashes

Returns:

the Code instance

Raises:
aiida.orm.utils.loaders.load_group(identifier=None, pk=None, uuid=None, label=None, sub_classes=None, query_with_dashes=True) Group[source]#

Load a Group instance by one of its identifiers: pk, uuid or label

If the type of the identifier is unknown simply pass it without a keyword and the loader will attempt to automatically infer the type.

Parameters:
  • identifier – pk (integer), uuid (string) or label (string) of a Group

  • pk – pk of a Group

  • uuid – uuid of a Group, or the beginning of the uuid

  • label – label of a Group

  • sub_classes – an optional tuple of orm classes to narrow the queryset. Each class should be a strict sub class of the ORM class of the given entity loader.

  • query_with_dashes (bool) – allow to query for a uuid with dashes

Returns:

the Group instance

Raises:
aiida.orm.utils.loaders.load_node(identifier=None, pk=None, uuid=None, label=None, sub_classes=None, query_with_dashes=True) Node[source]#

Load a node by one of its identifiers: pk or uuid. If the type of the identifier is unknown simply pass it without a keyword and the loader will attempt to infer the type

Parameters:
  • identifier – pk (integer) or uuid (string)

  • pk – pk of a node

  • uuid – uuid of a node, or the beginning of the uuid

  • label – label of a Node

  • sub_classes – an optional tuple of orm classes to narrow the queryset. Each class should be a strict sub class of the ORM class of the given entity loader.

  • query_with_dashes (bool) – allow to query for a uuid with dashes

Returns:

the node instance

Raises:

Module for logging methods/classes that need the ORM.

class aiida.orm.utils.log.DBLogHandler(level=0)[source]#

Bases: Handler

A custom db log handler for writing logs tot he database

__annotations__ = {}#
__module__ = 'aiida.orm.utils.log'#
emit(record)[source]#

Do whatever it takes to actually log the specified logging record.

This version is intended to be implemented by subclasses and so raises a NotImplementedError.

aiida.orm.utils.log.create_logger_adapter(logger, node)[source]#

Create a logger adapter for the given Node instance.

Parameters:
  • logger – the logger to adapt

  • node – the node instance to create the adapter for

Returns:

the logger adapter

Return type:

logging.LoggerAdapter

aiida.orm.utils.log.get_dblogger_extra(node)[source]#

Return the additional information necessary to attach any log records to the given node instance.

Parameters:

node – a Node instance

Contain utility classes for “managers”, i.e., classes that allow to access members of other classes via TAB-completable attributes (e.g. the class underlying calculation.inputs to allow to do calculation.inputs.<label>).

class aiida.orm.utils.managers.AttributeManager(node)[source]#

Bases: object

An object used internally to return the attributes as a dictionary. This is currently used in Dict, for instance.

Note:

Important! It cannot be used to change variables, just to read them. To change values (of unstored nodes), use the proper Node methods.

__dict__ = mappingproxy({'__module__': 'aiida.orm.utils.managers', '__doc__': 'An object used internally to return the attributes as a dictionary.\n    This is currently used in :py:class:`~aiida.orm.nodes.data.dict.Dict`,\n    for instance.\n\n    :note: Important! It cannot be used to change variables, just to read\n      them. To change values (of unstored nodes), use the proper Node methods.\n    ', '__init__': <function AttributeManager.__init__>, '__dir__': <function AttributeManager.__dir__>, '__iter__': <function AttributeManager.__iter__>, '_get_dict': <function AttributeManager._get_dict>, '__getattr__': <function AttributeManager.__getattr__>, '__setattr__': <function AttributeManager.__setattr__>, '__getitem__': <function AttributeManager.__getitem__>, '__dict__': <attribute '__dict__' of 'AttributeManager' objects>, '__weakref__': <attribute '__weakref__' of 'AttributeManager' objects>, '__annotations__': {}})#
__dir__()[source]#

Allow to list the keys of the dictionary

__getattr__(name)[source]#

Interface to get to dictionary values, using the key as an attribute.

Note:

it works only for attributes that only contain letters, numbers and underscores, and do not start with a number.

Parameters:

name – name of the key whose value is required.

__getitem__(name)[source]#

Interface to get to dictionary values as a dictionary.

Parameters:

name – name of the key whose value is required.

__init__(node)[source]#
Parameters:

node – the node object.

__iter__()[source]#

Return the keys as an iterator

__module__ = 'aiida.orm.utils.managers'#
__setattr__(name, value)[source]#

Implement setattr(self, name, value).

__weakref__#

list of weak references to the object

_get_dict()[source]#

Return the internal dictionary

class aiida.orm.utils.managers.NodeLinksManager(node, link_type, incoming)[source]#

Bases: object

A manager that allows to inspect, with tab-completion, nodes linked to a given one. See an example of its use in CalculationNode.inputs.

__contains__(key)[source]#

Override the operator of the base class to emit deprecation warning if double underscore is used in key.

__dict__ = mappingproxy({'__module__': 'aiida.orm.utils.managers', '__doc__': 'A manager that allows to inspect, with tab-completion, nodes linked to a given one.\n    See an example of its use in `CalculationNode.inputs`.\n    ', '_namespace_separator': '__', '__init__': <function NodeLinksManager.__init__>, '_construct_attribute_dict': <function NodeLinksManager._construct_attribute_dict>, '_get_keys': <function NodeLinksManager._get_keys>, '_get_node_by_link_label': <function NodeLinksManager._get_node_by_link_label>, '__dir__': <function NodeLinksManager.__dir__>, '__iter__': <function NodeLinksManager.__iter__>, '__getattr__': <function NodeLinksManager.__getattr__>, '__contains__': <function NodeLinksManager.__contains__>, '__getitem__': <function NodeLinksManager.__getitem__>, '__str__': <function NodeLinksManager.__str__>, '__repr__': <function NodeLinksManager.__repr__>, '__dict__': <attribute '__dict__' of 'NodeLinksManager' objects>, '__weakref__': <attribute '__weakref__' of 'NodeLinksManager' objects>, '__annotations__': {}})#
__dir__()[source]#

Allow to list all valid input links

__getattr__(name)[source]#
Parameters:

name – name of the attribute to be asked to the parser results.

__getitem__(name)[source]#

Interface to get to the parser results as a dictionary.

Parameters:

name – name of the attribute to be asked to the parser results.

__init__(node, link_type, incoming)[source]#

Initialise the link manager.

Parameters:
  • node – the reference node object

  • link_type – the link_type to inspect

  • incoming – if True, inspect incoming links, otherwise inspect outgoing links

__iter__()[source]#
__module__ = 'aiida.orm.utils.managers'#
__repr__()[source]#

Return repr(self).

__str__()[source]#

Return a string representation of the manager

__weakref__#

list of weak references to the object

_construct_attribute_dict(incoming)[source]#

Construct an attribute dict from all links of the node, recreating nested namespaces from flat link labels.

Parameters:

incoming – if True, inspect incoming links, otherwise inspect outgoing links.

_get_keys()[source]#

Return the valid link labels, used e.g. to make getattr() work

Return the linked node with a given link label.

Nested namespaces in link labels get represented by double underscores in the database. Up until now, the link manager didn’t automatically unroll these again into nested namespaces and so a user was forced to pass the link with double underscores to dereference the corresponding node. For example, when used with the inputs attribute of a ProcessNode one had to do:

node.inputs.nested__sub__namespace

Now it is possible to do

node.inputs.nested.sub.namespace

which is more intuitive since the double underscore replacement is just for the database and the user shouldn’t even have to know about it. For compatibility we support the old version a bit longer and it will emit a deprecation warning.

Parameters:

label – the link label connecting the current node to the node to get.

_namespace_separator = '__'#

Mixin classes for ORM classes.

class aiida.orm.utils.mixins.FunctionCalculationMixin[source]#

Bases: object

This mixin should be used for ProcessNode subclasses that are used to record the execution of a python function. For example the process nodes that are used for a function that was wrapped by the workfunction or calcfunction function decorators. The store_source_info method can then be called with the wrapped function to store information about that function in the calculation node through the inspect module. Various property getters are defined to later retrieve that information from the node

FUNCTION_NAMESPACE_KEY = 'function_namespace'#
FUNCTION_NAME_KEY = 'function_name'#
FUNCTION_NUMBER_OF_LINES_KEY = 'function_number_of_lines'#
FUNCTION_SOURCE_FILE_PATH = 'source_file'#
FUNCTION_STARTING_LINE_KEY = 'function_starting_line_number'#
__annotations__ = {}#
__dict__ = mappingproxy({'__module__': 'aiida.orm.utils.mixins', '__doc__': 'This mixin should be used for ProcessNode subclasses that are used to record the execution\n    of a python function. For example the process nodes that are used for a function that\n    was wrapped by the `workfunction` or `calcfunction` function decorators. The `store_source_info`\n    method can then be called with the wrapped function to store information about that function\n    in the calculation node through the inspect module. Various property getters are defined to\n    later retrieve that information from the node\n    ', 'FUNCTION_NAME_KEY': 'function_name', 'FUNCTION_NAMESPACE_KEY': 'function_namespace', 'FUNCTION_STARTING_LINE_KEY': 'function_starting_line_number', 'FUNCTION_NUMBER_OF_LINES_KEY': 'function_number_of_lines', 'FUNCTION_SOURCE_FILE_PATH': 'source_file', 'store_source_info': <function FunctionCalculationMixin.store_source_info>, 'function_name': <property object>, '_set_function_name': <function FunctionCalculationMixin._set_function_name>, 'function_namespace': <property object>, '_set_function_namespace': <function FunctionCalculationMixin._set_function_namespace>, 'function_starting_line_number': <property object>, '_set_function_starting_line_number': <function FunctionCalculationMixin._set_function_starting_line_number>, 'function_number_of_lines': <property object>, '_set_function_number_of_lines': <function FunctionCalculationMixin._set_function_number_of_lines>, 'get_function_source_code': <function FunctionCalculationMixin.get_function_source_code>, 'get_source_code_file': <function FunctionCalculationMixin.get_source_code_file>, 'get_source_code_function': <function FunctionCalculationMixin.get_source_code_function>, '__dict__': <attribute '__dict__' of 'FunctionCalculationMixin' objects>, '__weakref__': <attribute '__weakref__' of 'FunctionCalculationMixin' objects>, '__annotations__': {}})#
__module__ = 'aiida.orm.utils.mixins'#
__weakref__#

list of weak references to the object

_set_function_name(function_name: str)[source]#

Set the function name of the wrapped function.

Parameters:

function_name – the function name

_set_function_namespace(function_namespace: str) None[source]#

Set the function namespace of the wrapped function.

Parameters:

function_namespace – the function namespace

_set_function_number_of_lines(function_number_of_lines: int) None[source]#

Set the number of lines of the wrapped function in its source file.

Parameters:

function_number_of_lines – the number of lines

_set_function_starting_line_number(function_starting_line_number: int) None[source]#

Set the starting line number of the wrapped function in its source file.

Parameters:

function_starting_line_number – the starting line number

property function_name: str | None#

Return the function name of the wrapped function.

Returns:

the function name or None

property function_namespace: str | None#

Return the function namespace of the wrapped function.

Returns:

the function namespace or None

property function_number_of_lines: int | None#

Return the number of lines of the wrapped function in its source file.

Returns:

the number of lines or None

property function_starting_line_number: int | None#

Return the starting line number of the wrapped function in its source file.

Returns:

the starting line number or None

get_function_source_code() str | None[source]#

Return the source code of the function stored in the repository.

If the source code file does not exist, this will return None instead. This can happen for example when the function was defined in an interactive shell in which case store_source_info will have failed to retrieve the source code using inspect.getsourcefile.

Returns:

The source code of the function or None if it could not be determined when storing the node.

get_source_code_file() str | None[source]#

Return the source code of the file in which the process function was defined.

If the source code file does not exist, this will return None instead. This can happen for example when the function was defined in an interactive shell in which case store_source_info will have failed to retrieve the source code using inspect.getsourcefile.

Returns:

The source code of the function or None if it could not be determined when storing the node.

get_source_code_function() str | None[source]#

Return the source code of the function including the decorator.

Returns:

The source code of the function or None if not available.

store_source_info(func) None[source]#

Retrieve source information about the wrapped function func through the inspect module, and store it in the attributes and repository of the node. The function name, namespace and the starting line number in the source file will be stored in the attributes. The source file itself will be copied into the repository

Parameters:

func – the function to inspect and whose information to store in the node

class aiida.orm.utils.mixins.Sealable[source]#

Bases: object

Mixin to mark a Node as sealable.

SEALED_KEY = 'sealed'#
__annotations__ = {}#
__dict__ = mappingproxy({'__module__': 'aiida.orm.utils.mixins', '__doc__': 'Mixin to mark a Node as `sealable`.', 'SEALED_KEY': 'sealed', '__qb_fields__': [QbField('sealed', dtype=bool, is_attribute=True)], '_updatable_attributes': <aiida.common.lang.classproperty object>, 'is_sealed': <property object>, 'seal': <function Sealable.seal>, '_check_mutability_attributes': <function Sealable._check_mutability_attributes>, '__dict__': <attribute '__dict__' of 'Sealable' objects>, '__weakref__': <attribute '__weakref__' of 'Sealable' objects>, '__annotations__': {}})#
__module__ = 'aiida.orm.utils.mixins'#
__qb_fields__ = [QbField('sealed', dtype=bool, is_attribute=True)]#
__weakref__#

list of weak references to the object

_check_mutability_attributes(keys: list[str] | None = None) None[source]#

Check if the entity is mutable and raise an exception if not.

This is called from NodeAttributes methods that modify the attributes.

Parameters:

keys – the keys that will be mutated, or all if None

_updatable_attributes = ('sealed',)#
property is_sealed: bool#

Returns whether the node is sealed, i.e. whether the sealed attribute has been set to True.

seal() Sealable[source]#

Seal the node by setting the sealed attribute to True.

Utilities to operate on Node classes.

class aiida.orm.utils.node.AbstractNodeMeta(name, bases, namespace, **kwargs)[source]#

Bases: EntityFieldMeta

Some python black magic to set correctly the logger also in subclasses.

__annotations__ = {}#
__module__ = 'aiida.orm.utils.node'#
static __new__(mcs, name, bases, namespace, **kwargs)[source]#
aiida.orm.utils.node.get_query_type_from_type_string(type_string)[source]#

Take the type string of a Node and create the queryable type string

Parameters:

type_string – the plugin_type_string attribute of a Node

Returns:

the type string that can be used to query for

aiida.orm.utils.node.get_type_string_from_class(class_module, class_name)[source]#

Given the module and name of a class, determine the orm_class_type string, which codifies the orm class that is to be used. The returned string will always have a terminating period, which is required to query for the string in the database

Parameters:
  • class_module – module of the class

  • class_name – name of the class

aiida.orm.utils.node.is_valid_node_type_string(type_string, raise_on_false=False)[source]#

Checks whether type string of a Node is valid.

Parameters:

type_string – the plugin_type_string attribute of a Node

Returns:

True if type string is valid, else false

aiida.orm.utils.node.load_node_class(type_string)[source]#

Return the Node sub class that corresponds to the given type string.

Parameters:

type_string – the type string of the node

Returns:

a sub class of Node

Utilities for operations on files on remote computers.

aiida.orm.utils.remote.clean_remote(transport: Transport, path: str) None[source]#

Recursively remove a remote folder, with the given absolute path, and all its contents. The path should be made accessible through the transport channel, which should already be open

Parameters:
  • transport – an open Transport channel

  • path – an absolute path on the remote made available through the transport

aiida.orm.utils.remote.get_calcjob_remote_paths(pks: list[int] | None = None, past_days: int | None = None, older_than: int | None = None, computers: Sequence[orm.Computer] | None = None, user: orm.User | None = None, backend: StorageBackend | None = None, exit_status: int | None = None, only_not_cleaned: bool = False) dict[str, list[RemoteData]] | None[source]#

Return a mapping of computer uuids to a list of remote paths, for a given set of calcjobs. The set of calcjobs will be determined by a query with filters based on the pks, past_days, older_than, computers and user arguments.

Parameters:
  • pks – only include calcjobs with a pk in this list

  • past_days – only include calcjobs created since past_days

  • older_than – only include calcjobs older than

  • computers – only include calcjobs that were ran on these computers

  • user – only include calcjobs of this user

  • exit_status – only select calcjob with this exit_status

  • only_not_cleaned – only include calcjobs whose workdir have not been cleaned

Returns:

mapping of computer uuid and list of remote folder

Serialisation functions for AiiDA types

WARNING: Changing the representation of things here may break people’s current saved e.g. things like checkpoints and messages in the RabbitMQ queue so do so with caution. It is fine to add representers for new types though.

class aiida.orm.utils.serialize.AiiDADumper(stream, default_style=None, default_flow_style=False, canonical=None, indent=None, width=None, allow_unicode=None, line_break=None, encoding=None, explicit_start=None, explicit_end=None, version=None, tags=None, sort_keys=True)[source]#

Bases: Dumper

Custom AiiDA yaml dumper.

Needed so that we don’t have to encode each type in the AiiDA graph hierarchy separately using a custom representer.

__module__ = 'aiida.orm.utils.serialize'#
represent_data(data)[source]#
yaml_representers = {<class 'NoneType'>: <function SafeRepresenter.represent_none>, <class 'aiida.common.extendeddicts.AttributeDict'>: functools.partial(<function represent_mapping>, '!aiida_attributedict'), <class 'bool'>: <function SafeRepresenter.represent_bool>, <class 'builtin_function_or_method'>: <function Representer.represent_name>, <class 'bytes'>: <function SafeRepresenter.represent_binary>, <class 'collections.OrderedDict'>: <function Representer.represent_ordered_dict>, <class 'complex'>: <function Representer.represent_complex>, <class 'datetime.date'>: <function SafeRepresenter.represent_date>, <class 'datetime.datetime'>: <function SafeRepresenter.represent_datetime>, <class 'dict'>: <function SafeRepresenter.represent_dict>, <class 'float'>: <function SafeRepresenter.represent_float>, <class 'function'>: <function Representer.represent_name>, <class 'int'>: <function SafeRepresenter.represent_int>, <class 'list'>: <function SafeRepresenter.represent_list>, <class 'module'>: <function Representer.represent_module>, <class 'plumpy.persistence.Bundle'>: <function represent_bundle>, <class 'plumpy.utils.AttributesFrozendict'>: functools.partial(<function represent_mapping>, '!plumpy:attributes_frozendict'), <class 'set'>: <function SafeRepresenter.represent_set>, <class 'str'>: <function SafeRepresenter.represent_str>, <class 'tuple'>: <function Representer.represent_tuple>, <enum 'Enum'>: <function represent_enum>, None: <function SafeRepresenter.represent_undefined>}#
class aiida.orm.utils.serialize.AiiDALoader(stream)[source]#

Bases: Loader

AiiDA specific yaml loader

Note

The AiiDALoader should only be used on trusted input, since it uses the yaml.Loader which is not safe. When importing a shared database, we strip all process node checkpoints to avoid this being a security risk.

__annotations__ = {}#
__module__ = 'aiida.orm.utils.serialize'#
yaml_constructors = {'!aiida_attributedict': functools.partial(<function mapping_constructor>, <class 'aiida.common.extendeddicts.AttributeDict'>), '!aiida_computer': <function computer_constructor>, '!aiida_group': <function group_constructor>, '!aiida_node': <function node_constructor>, '!aiida_node_links_manager': <function node_links_manager_constructor>, '!dataclass': <function dataclass_constructor>, '!enum': <function enum_constructor>, '!plumpy:Bundle': <function _bundle_constructor>, '!plumpy:attributes_frozendict': functools.partial(<function mapping_constructor>, <class 'plumpy.utils.AttributesFrozendict'>), '!plumpy:bundle': <function bundle_constructor>, 'tag:yaml.org,2002:binary': <function SafeConstructor.construct_yaml_binary>, 'tag:yaml.org,2002:bool': <function SafeConstructor.construct_yaml_bool>, 'tag:yaml.org,2002:float': <function SafeConstructor.construct_yaml_float>, 'tag:yaml.org,2002:int': <function SafeConstructor.construct_yaml_int>, 'tag:yaml.org,2002:map': <function SafeConstructor.construct_yaml_map>, 'tag:yaml.org,2002:null': <function SafeConstructor.construct_yaml_null>, 'tag:yaml.org,2002:omap': <function SafeConstructor.construct_yaml_omap>, 'tag:yaml.org,2002:pairs': <function SafeConstructor.construct_yaml_pairs>, 'tag:yaml.org,2002:python/bool': <function SafeConstructor.construct_yaml_bool>, 'tag:yaml.org,2002:python/bytes': <function FullConstructor.construct_python_bytes>, 'tag:yaml.org,2002:python/complex': <function FullConstructor.construct_python_complex>, 'tag:yaml.org,2002:python/dict': <function SafeConstructor.construct_yaml_map>, 'tag:yaml.org,2002:python/float': <function SafeConstructor.construct_yaml_float>, 'tag:yaml.org,2002:python/int': <function SafeConstructor.construct_yaml_int>, 'tag:yaml.org,2002:python/list': <function SafeConstructor.construct_yaml_seq>, 'tag:yaml.org,2002:python/long': <function FullConstructor.construct_python_long>, 'tag:yaml.org,2002:python/none': <function SafeConstructor.construct_yaml_null>, 'tag:yaml.org,2002:python/str': <function FullConstructor.construct_python_str>, 'tag:yaml.org,2002:python/tuple': <function FullConstructor.construct_python_tuple>, 'tag:yaml.org,2002:python/unicode': <function FullConstructor.construct_python_unicode>, 'tag:yaml.org,2002:seq': <function SafeConstructor.construct_yaml_seq>, 'tag:yaml.org,2002:set': <function SafeConstructor.construct_yaml_set>, 'tag:yaml.org,2002:str': <function SafeConstructor.construct_yaml_str>, 'tag:yaml.org,2002:timestamp': <function SafeConstructor.construct_yaml_timestamp>, None: <function SafeConstructor.construct_undefined>}#
class aiida.orm.utils.serialize._MappingType(mapping: dict)[source]#

Bases: Protocol

__abstractmethods__ = frozenset({})#
__dict__ = mappingproxy({'__module__': 'aiida.orm.utils.serialize', '__init__': <function _MappingType.__init__>, '__dict__': <attribute '__dict__' of '_MappingType' objects>, '__weakref__': <attribute '__weakref__' of '_MappingType' objects>, '__doc__': None, '__parameters__': (), '_is_protocol': True, '__subclasshook__': <function Protocol.__init_subclass__.<locals>._proto_hook>, '__abstractmethods__': frozenset(), '_abc_impl': <_abc._abc_data object>, '__annotations__': {}})#
__init__(mapping: dict) None[source]#
__module__ = 'aiida.orm.utils.serialize'#
__parameters__ = ()#
__subclasshook__()#

Abstract classes can override this to customize issubclass().

This is invoked early on by abc.ABCMeta.__subclasscheck__(). It should return True, False or NotImplemented. If it returns NotImplemented, the normal algorithm is used. Otherwise, it overrides the normal algorithm (and the outcome is cached).

__weakref__#

list of weak references to the object

_abc_impl = <_abc._abc_data object>#
_is_protocol = True#
aiida.orm.utils.serialize.bundle_constructor(loader: Loader, bundle: Node) Bundle[source]#

Construct an plumpy.Bundle from the representation.

aiida.orm.utils.serialize.computer_constructor(loader: Loader, computer: Node) Computer[source]#

Load a computer from the yaml representation.

aiida.orm.utils.serialize.dataclass_constructor(loader: Loader, serialized: Node) Any[source]#

Construct a dataclass from the serialized representation.

aiida.orm.utils.serialize.deserialize_unsafe(serialized: str) Any[source]#

Deserialize a yaml dump that represents a serialized data structure.

Note

This function should not be used on untrusted input, since it is built upon yaml.Loader which is unsafe.

Parameters:

serialized – a yaml serialized string representation

Returns:

the deserialized data structure

aiida.orm.utils.serialize.enum_constructor(loader: Loader, serialized: Node) Enum[source]#

Construct an enum from the serialized representation.

aiida.orm.utils.serialize.group_constructor(loader: Loader, group: Node) Group[source]#

Load a group from the yaml representation.

aiida.orm.utils.serialize.mapping_constructor(mapping_type: Type[_MappingType], loader: Loader, mapping: MappingNode) _MappingType[source]#

Construct a mapping from the representation.

aiida.orm.utils.serialize.node_constructor(loader: Loader, node: Node) Node[source]#

Load a node from the yaml representation.

Load a link from the yaml representation.

aiida.orm.utils.serialize.represent_bundle(dumper: Dumper, bundle: Bundle) MappingNode[source]#

Represent an plumpy.Bundle in yaml.

aiida.orm.utils.serialize.represent_computer(dumper: Dumper, computer: Computer) ScalarNode[source]#

Represent a computer in yaml.

aiida.orm.utils.serialize.represent_dataclass(dumper: Dumper, obj: Any) MappingNode[source]#

Represent an arbitrary dataclass in yaml.

aiida.orm.utils.serialize.represent_enum(dumper: Dumper, enum: Enum) ScalarNode[source]#

Represent an arbitrary enum in yaml.

aiida.orm.utils.serialize.represent_group(dumper: Dumper, group: Group) ScalarNode[source]#

Represent a group in yaml.

aiida.orm.utils.serialize.represent_mapping(tag: str, dumper: Dumper, mapping: Any) MappingNode[source]#

Represent a mapping in yaml.

aiida.orm.utils.serialize.represent_node(dumper: Dumper, node: Node) ScalarNode[source]#

Represent a node in yaml.

Represent a link in yaml.

aiida.orm.utils.serialize.serialize(data: Any, encoding: None = None) str[source]#
aiida.orm.utils.serialize.serialize(data: Any, encoding: str) bytes

Serialize the given data structure into a yaml dump.

The function supports standard data containers such as maps and lists as well as AiiDA nodes which will be serialized into strings, before the whole data structure is dumped into a string using yaml.

Parameters:
  • data – the general data to serialize

  • encoding – optional encoding for the serialized string

Returns:

string representation of the serialized data structure or byte array if specific encoding is specified