aiida.orm.utils package

Utilities related to the ORM.

aiida.orm.utils.load_code(identifier=None, pk=None, uuid=None, label=None, sub_classes=None, query_with_dashes=True)[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.load_computer(identifier=None, pk=None, uuid=None, label=None, sub_classes=None, query_with_dashes=True)[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.load_group(identifier=None, pk=None, uuid=None, label=None, sub_classes=None, query_with_dashes=True)[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.load_node(identifier=None, pk=None, uuid=None, label=None, sub_classes=None, query_with_dashes=True)[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

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__': "\n 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>})
__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 dictionary does not contain an attribute with the given name

__getitem__(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 dictionary does not contain an attribute with the given name

__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 (if defined)

_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.

Utilities for dealing with links between nodes.

class aiida.orm.utils.links.LinkPair(link_type, link_label)

Bases: tuple

__getnewargs__()

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

__module__ = 'aiida.orm.utils.links'
static __new__(_cls, link_type, link_label)

Create new instance of LinkPair(link_type, link_label)

__repr__()

Return a nicely formatted representation string

__slots__ = ()
_asdict()

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

_fields = ('link_type', 'link_label')
_fields_defaults = {}
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.LinkTriple(node, link_type, link_label)

Bases: tuple

__getnewargs__()

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

__module__ = 'aiida.orm.utils.links'
static __new__(_cls, node, link_type, link_label)

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

__repr__()

Return a nicely formatted representation string

__slots__ = ()
_asdict()

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

_fields = ('node', 'link_type', 'link_label')
_fields_defaults = {}
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

property node

Alias for field number 0

class aiida.orm.utils.links.LinkManager(link_triples)[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__': '\n 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__>, '__nonzero__': <function LinkManager.__nonzero__>, '__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>})
__init__(link_triples)[source]

Initialise the collection.

__iter__()[source]

Return an iterator of LinkTriple instances.

Returns

iterator of LinkTriple instances

__module__ = 'aiida.orm.utils.links'
__next__()[source]

Return the next element in the iterator.

Returns

LinkTriple

__nonzero__()[source]
__weakref__

list of weak references to the object (if defined)

all()[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()[source]

Return a list of all nodes.

Returns

list of nodes

first()[source]

Return the first entry from the iterator.

Returns

LinkTriple instance or None if no entries were matched

get_node_by_label(label)[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()[source]

Return the next element in the iterator.

Returns

LinkTriple

one()[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

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.

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

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

Bases: object

Base class for entity loaders.

__abstractmethods__ = frozenset({'_get_query_builder_label_identifier'})
__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': <aiida.common.lang.abstractclassmethod object>, '_get_query_builder_id_identifier': <classmethod object>, '_get_query_builder_uuid_identifier': <classmethod object>, 'get_query_builder': <classmethod object>, 'get_options': <classmethod object>, 'load_entity': <classmethod object>, 'get_query_classes': <classmethod object>, 'infer_identifier_type': <classmethod object>, '__dict__': <attribute '__dict__' of 'OrmEntityLoader' objects>, '__weakref__': <attribute '__weakref__' of 'OrmEntityLoader' objects>, '__abstractmethods__': frozenset({'_get_query_builder_label_identifier'}), '_abc_impl': <_abc_data object>})
__module__ = 'aiida.orm.utils.loaders'
__weakref__

list of weak references to the object (if defined)

_abc_impl = <_abc_data 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
  • ValueError – if the identifier is invalid

  • aiida.common.NotExistent – if the orm base class does not support a LABEL like identifier

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]

This method will attempt to automatically distinguish which identifier type is implied for the given value, if the value itself has no type from which it can be inferred.

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.CalculationEntityLoader[source]

Bases: aiida.orm.utils.loaders.OrmEntityLoader

Loader for the Calculation entity and sub classes.

__abstractmethods__ = frozenset({})
__module__ = 'aiida.orm.utils.loaders'
_abc_impl = <_abc_data object>
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
  • ValueError – if the identifier is invalid

  • aiida.common.NotExistent – if the orm base class does not support a LABEL like identifier

orm_base_class

alias of aiida.orm.nodes.process.calculation.calculation.CalculationNode

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

Bases: aiida.orm.utils.loaders.OrmEntityLoader

Loader for the Code entity and sub classes.

__abstractmethods__ = frozenset({})
__module__ = 'aiida.orm.utils.loaders'
_abc_impl = <_abc_data object>
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
  • ValueError – if the identifier is invalid

  • aiida.common.NotExistent – if the orm base class does not support a LABEL like identifier

orm_base_class

alias of aiida.orm.nodes.data.code.Code

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

Bases: aiida.orm.utils.loaders.OrmEntityLoader

Loader for the Computer entity and sub classes.

__abstractmethods__ = frozenset({})
__module__ = 'aiida.orm.utils.loaders'
_abc_impl = <_abc_data object>
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
  • ValueError – if the identifier is invalid

  • aiida.common.NotExistent – if the orm base class does not support a LABEL like identifier

orm_base_class

alias of aiida.orm.computers.Computer

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

Bases: aiida.orm.utils.loaders.OrmEntityLoader

Loader for the Group entity and sub classes.

__abstractmethods__ = frozenset({})
__module__ = 'aiida.orm.utils.loaders'
_abc_impl = <_abc_data object>
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
  • ValueError – if the identifier is invalid

  • aiida.common.NotExistent – if the orm base class does not support a LABEL like identifier

orm_base_class

alias of aiida.orm.groups.Group

class aiida.orm.utils.loaders.NodeEntityLoader[source]

Bases: aiida.orm.utils.loaders.OrmEntityLoader

Loader for the Node entity and sub classes.

__abstractmethods__ = frozenset({})
__module__ = 'aiida.orm.utils.loaders'
_abc_impl = <_abc_data object>
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
  • ValueError – if the identifier is invalid

  • aiida.common.NotExistent – if the orm base class does not support a LABEL like identifier

orm_base_class

alias of aiida.orm.nodes.node.Node

Module for logging methods/classes that need the ORM.

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

Bases: logging.Handler

A custom db log handler for writing logs tot he database

__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 act 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.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.

__dict__ = mappingproxy({'__module__': 'aiida.orm.utils.managers', '__doc__': '\n 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 ', '__init__': <function NodeLinksManager.__init__>, '_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__>, '__getitem__': <function NodeLinksManager.__getitem__>, '__str__': <function NodeLinksManager.__str__>, '__repr__': <function NodeLinksManager.__repr__>, '__dict__': <attribute '__dict__' of 'NodeLinksManager' objects>, '__weakref__': <attribute '__weakref__' of 'NodeLinksManager' objects>})
__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 (if defined)

_get_keys()[source]

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

Return the linked node with a given link label

Parameters

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

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__': '\n 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__>, '__getitem__': <function AttributeManager.__getitem__>, '__dict__': <attribute '__dict__' of 'AttributeManager' objects>, '__weakref__': <attribute '__weakref__' of 'AttributeManager' objects>})
__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'
__weakref__

list of weak references to the object (if defined)

_get_dict()[source]

Return the internal dictionary

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_SOURCE_FILE_PATH = 'source_file'
FUNCTION_STARTING_LINE_KEY = 'function_starting_line_number'
__dict__ = mappingproxy({'__module__': 'aiida.orm.utils.mixins', '__doc__': '\n 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_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>, 'get_function_source_code': <function FunctionCalculationMixin.get_function_source_code>, '__dict__': <attribute '__dict__' of 'FunctionCalculationMixin' objects>, '__weakref__': <attribute '__weakref__' of 'FunctionCalculationMixin' objects>})
__module__ = 'aiida.orm.utils.mixins'
__weakref__

list of weak references to the object (if defined)

_set_function_name(function_name)[source]

Set the function name of the wrapped function.

Parameters

function_name – the function name

_set_function_namespace(function_namespace)[source]

Set the function namespace of the wrapped function.

Parameters

function_namespace – the function namespace

_set_function_starting_line_number(function_starting_line_number)[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

Return the function name of the wrapped function.

Returns

the function name or None

property function_namespace

Return the function namespace of the wrapped function.

Returns

the function namespace or None

property function_starting_line_number

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

Returns

the starting line number or None

get_function_source_code()[source]

Return the absolute path to the source file in the repository.

Returns

the absolute path of the source file in the repository, or None if it does not exist

store_source_info(func)[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'
__dict__ = mappingproxy({'__module__': 'aiida.orm.utils.mixins', '__doc__': 'Mixin to mark a Node as `sealable`.', 'SEALED_KEY': 'sealed', '_updatable_attributes': <aiida.common.lang.classproperty object>, 'validate_incoming': <function Sealable.validate_incoming>, 'validate_outgoing': <function Sealable.validate_outgoing>, 'is_sealed': <property object>, 'seal': <function Sealable.seal>, 'set_attribute': <function Sealable.set_attribute>, 'delete_attribute': <function Sealable.delete_attribute>, '__dict__': <attribute '__dict__' of 'Sealable' objects>, '__weakref__': <attribute '__weakref__' of 'Sealable' objects>})
__module__ = 'aiida.orm.utils.mixins'
__weakref__

list of weak references to the object (if defined)

_updatable_attributes = ('sealed',)
delete_attribute(key)[source]

Delete an attribute.

Parameters

key – name of the attribute

Raises
property is_sealed

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

seal()[source]

Seal the node by setting the sealed attribute to True.

set_attribute(key, value)[source]

Set an attribute to the given value.

Parameters
  • key – name of the attribute

  • value – value of the attribute

Raises

aiida.common.exceptions.ModificationNotAllowed – if the node is already sealed or if the node is already stored and the attribute is not updatable.

validate_incoming(source, link_type, link_label)[source]

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

Adding an incoming link to a sealed node is forbidden.

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

  • link_type – the link type

  • link_label – the link label

Raises

aiida.common.ModificationNotAllowed – if the target node (self) is sealed

validate_outgoing(target, link_type, link_label)[source]

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

Adding an outgoing link from a sealed node is forbidden.

Parameters
  • target – the node to which the link is going

  • link_type – the link type

  • link_label – the link label

Raises

aiida.common.ModificationNotAllowed – if the source node (self) is sealed

Utilities to operate on Node classes.

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

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.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

class aiida.orm.utils.node.AbstractNodeMeta[source]

Bases: abc.ABCMeta

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

__module__ = 'aiida.orm.utils.node'
static __new__(mcs, name, bases, namespace)[source]

Create and return a new object. See help(type) for accurate signature.

aiida.orm.utils.node.validate_attribute_extra_key(key)[source]

Validate the key for a node attribute or extra.

Raises

aiida.common.ValidationError – if the key is not a string or contains reserved separator character

aiida.orm.utils.node.clean_value(value)[source]

Get value from input and (recursively) replace, if needed, all occurrences of BaseType AiiDA data nodes with their value, and List with a standard list. It also makes a deep copy of everything The purpose of this function is to convert data to a type which can be serialized and deserialized for storage in the DB without its value changing.

Note however that there is no logic to avoid infinite loops when the user passes some perverse recursive dictionary or list. In any case, however, this would not be storable by AiiDA…

Parameters

value – A value to be set as an attribute or an extra

Returns

a “cleaned” value, potentially identical to value, but with values replaced where needed.

aiida.orm.utils.remote.clean_remote(transport, path)[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=None, past_days=None, older_than=None, computers=None, user=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 – onlu 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

Returns

mapping of computer uuid and list of remote paths, or None

Class that represents the repository of a Node instance.

class aiida.orm.utils.repository.File(name, type)

Bases: tuple

__getnewargs__()

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

__module__ = 'aiida.orm.utils.repository'
static __new__(_cls, name, type)

Create new instance of File(name, type)

__repr__()

Return a nicely formatted representation string

__slots__ = ()
_asdict()

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

_fields = ('name', 'type')
_fields_defaults = {}
classmethod _make(iterable)

Make a new File object from a sequence or iterable

_replace(**kwds)

Return a new File object replacing specified fields with new values

property name

Alias for field number 0

property type

Alias for field number 1

class aiida.orm.utils.repository.FileType[source]

Bases: enum.Enum

An enumeration.

DIRECTORY = 0
FILE = 1
__module__ = 'aiida.orm.utils.repository'
class aiida.orm.utils.repository.Repository(uuid, is_stored, base_path=None)[source]

Bases: object

Class that represents the repository of a Node instance.

__del__()[source]

Clean the sandboxfolder if it was instantiated.

__dict__ = mappingproxy({'__module__': 'aiida.orm.utils.repository', '__doc__': 'Class that represents the repository of a `Node` instance.', '_section_name': 'node', '__init__': <function Repository.__init__>, '__del__': <function Repository.__del__>, 'validate_mutability': <function Repository.validate_mutability>, 'validate_object_key': <staticmethod object>, 'list_objects': <function Repository.list_objects>, 'list_object_names': <function Repository.list_object_names>, 'open': <function Repository.open>, 'get_object': <function Repository.get_object>, 'get_object_content': <function Repository.get_object_content>, 'put_object_from_tree': <function Repository.put_object_from_tree>, 'put_object_from_file': <function Repository.put_object_from_file>, 'put_object_from_filelike': <function Repository.put_object_from_filelike>, 'delete_object': <function Repository.delete_object>, 'erase': <function Repository.erase>, 'store': <function Repository.store>, 'restore': <function Repository.restore>, '_get_base_folder': <function Repository._get_base_folder>, '_get_temp_folder': <function Repository._get_temp_folder>, '__dict__': <attribute '__dict__' of 'Repository' objects>, '__weakref__': <attribute '__weakref__' of 'Repository' objects>})
__init__(uuid, is_stored, base_path=None)[source]

Initialize self. See help(type(self)) for accurate signature.

__module__ = 'aiida.orm.utils.repository'
__weakref__

list of weak references to the object (if defined)

_get_base_folder()[source]

Return the base sub folder in the repository.

Returns

a Folder object.

_get_temp_folder()[source]

Return the temporary sandbox folder.

Returns

a SandboxFolder object mapping the node in the repository.

_section_name = 'node'
delete_object(key, force=False)[source]

Delete the object from the repository.

Warning

If the repository belongs to a stored node, a ModificationNotAllowed exception will be raised. This check can be avoided by using the force flag, but this should be used with extreme caution!

Parameters
  • key – fully qualified identifier for the object within the repository

  • force – boolean, if True, will skip the mutability check

Raises

aiida.common.ModificationNotAllowed – if repository is immutable and force=False

erase(force=False)[source]

Delete the repository folder.

Warning

If the repository belongs to a stored node, a ModificationNotAllowed exception will be raised. This check can be avoided by using the force flag, but this should be used with extreme caution!

Parameters

force – boolean, if True, will skip the mutability check

Raises

aiida.common.ModificationNotAllowed – if repository is immutable and force=False

get_object(key)[source]

Return the object identified by key.

Parameters

key – fully qualified identifier for the object within the repository

Returns

a File named tuple representing the object located at key

get_object_content(key, mode='r')[source]

Return the content of a object identified by key.

Parameters
  • key – fully qualified identifier for the object within the repository

  • mode – the mode under which to open the handle

list_object_names(key=None)[source]

Return a list of the object names contained in this repository, optionally in the given sub directory.

Parameters

key – fully qualified identifier for the object within the repository

Returns

a list of File named tuples representing the objects present in directory with the given key

list_objects(key=None)[source]

Return a list of the objects contained in this repository, optionally in the given sub directory.

Parameters

key – fully qualified identifier for the object within the repository

Returns

a list of File named tuples representing the objects present in directory with the given key

open(key, mode='r')[source]

Open a file handle to an object stored under the given key.

Parameters
  • key – fully qualified identifier for the object within the repository

  • mode – the mode under which to open the handle

put_object_from_file(path, key, mode=None, encoding=None, force=False)[source]

Store a new object under key with contents of the file located at path on this file system.

Warning

If the repository belongs to a stored node, a ModificationNotAllowed exception will be raised. This check can be avoided by using the force flag, but this should be used with extreme caution!

Parameters
  • path – absolute path of file whose contents to copy to the repository

  • key – fully qualified identifier for the object within the repository

  • mode – the file mode with which the object will be written Deprecated: will be removed in v2.0.0

  • encoding – the file encoding with which the object will be written Deprecated: will be removed in v2.0.0

  • force – boolean, if True, will skip the mutability check

Raises

aiida.common.ModificationNotAllowed – if repository is immutable and force=False

put_object_from_filelike(handle, key, mode='w', encoding='utf8', force=False)[source]

Store a new object under key with contents of filelike object handle.

Warning

If the repository belongs to a stored node, a ModificationNotAllowed exception will be raised. This check can be avoided by using the force flag, but this should be used with extreme caution!

Parameters
  • handle – filelike object with the content to be stored

  • key – fully qualified identifier for the object within the repository

  • mode – the file mode with which the object will be written

  • encoding – the file encoding with which the object will be written

  • force – boolean, if True, will skip the mutability check

Raises

aiida.common.ModificationNotAllowed – if repository is immutable and force=False

put_object_from_tree(path, key=None, contents_only=True, force=False)[source]

Store a new object under key with the contents of the directory located at path on this file system.

Warning

If the repository belongs to a stored node, a ModificationNotAllowed exception will be raised. This check can be avoided by using the force flag, but this should be used with extreme caution!

Parameters
  • path – absolute path of directory whose contents to copy to the repository

  • key – fully qualified identifier for the object within the repository

  • contents_only – boolean, if True, omit the top level directory of the path and only copy its contents.

  • force – boolean, if True, will skip the mutability check

Raises

aiida.common.ModificationNotAllowed – if repository is immutable and force=False

restore()[source]

Move the contents from the repository folder back into the sandbox folder.

store()[source]

Store the contents of the sandbox folder into the repository folder.

validate_mutability()[source]

Raise if the repository is immutable.

Raises

aiida.common.ModificationNotAllowed – if repository is marked as immutable because the corresponding node is stored

static validate_object_key(key)[source]

Validate the key of an object.

Parameters

key – an object key in the repository

Raises

ValueError – if the key is not a valid object key

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=None, canonical=None, indent=None, width=None, allow_unicode=None, line_break=None, encoding=None, explicit_start=None, explicit_end=None, version=None, tags=None)[source]

Bases: yaml.dumper.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 'str'>: <function SafeRepresenter.represent_str>, <class 'bytes'>: <function SafeRepresenter.represent_binary>, <class 'bool'>: <function SafeRepresenter.represent_bool>, <class 'int'>: <function SafeRepresenter.represent_int>, <class 'float'>: <function SafeRepresenter.represent_float>, <class 'list'>: <function SafeRepresenter.represent_list>, <class 'tuple'>: <function Representer.represent_tuple>, <class 'dict'>: <function SafeRepresenter.represent_dict>, <class 'set'>: <function SafeRepresenter.represent_set>, <class 'datetime.date'>: <function SafeRepresenter.represent_date>, <class 'datetime.datetime'>: <function SafeRepresenter.represent_datetime>, None: <function SafeRepresenter.represent_undefined>, <class 'complex'>: <function Representer.represent_complex>, <class 'type'>: <function Representer.represent_name>, <class 'collections.OrderedDict'>: <function Representer.represent_ordered_dict>, <class 'function'>: <function Representer.represent_name>, <class 'builtin_function_or_method'>: <function Representer.represent_name>, <class 'module'>: <function Representer.represent_module>, <class 'plumpy.persistence.Bundle'>: <function represent_bundle>, <class 'aiida.common.extendeddicts.AttributeDict'>: functools.partial(<function represent_mapping>, '!aiida_attributedict'), <class 'plumpy.utils.AttributesFrozendict'>: functools.partial(<function represent_mapping>, '!plumpy:attributes_frozendict')}
class aiida.orm.utils.serialize.AiiDALoader(stream)[source]

Bases: yaml.loader.Loader

AiiDA specific yaml loader

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

Construct an plumpy.Bundle from the representation

Parameters
  • loader (yaml.loader.Loader) – the yaml loader

  • bundle – the bundle representation

Returns

the mapping type

aiida.orm.utils.serialize.computer_constructor(loader, computer)[source]

Load a computer from the yaml representation.

Parameters
  • loader – the yaml loader

  • computer – the yaml representation

Returns

the aiida computer

Return type

aiida.orm.Computer

aiida.orm.utils.serialize.deserialize(serialized)[source]

Deserialize a yaml dump that represents a serialized data structure.

Parameters

serialized – a yaml serialized string representation

Returns

the deserialized data structure

aiida.orm.utils.serialize.group_constructor(loader, group)[source]

Load a group from the yaml representation.

Parameters
  • loader – the yaml loader

  • group – the yaml representation

Returns

the aiida group

Return type

aiida.orm.Group

aiida.orm.utils.serialize.mapping_constructor(mapping_type, loader, mapping)[source]

Construct a mapping from the representation.

Parameters
  • mapping_type – the class of the mapping to construct, must accept a dictionary as a sole constructor argument to be compatible.

  • loader (yaml.loader.Loader) – the yaml loader

  • mapping – the mapping representation

Returns

the reconstructed mapping

aiida.orm.utils.serialize.node_constructor(loader, node)[source]

Load a node from the yaml representation.

Parameters
  • loader – the yaml loader

  • node – the yaml representation

Returns

the aiida node

Return type

aiida.orm.nodes.node.Node

aiida.orm.utils.serialize.represent_bundle(dumper, bundle)[source]

Represent an plumpy.Bundle in yaml

Parameters
  • tag – the yaml tag to use

  • dumper (yaml.dumper.Dumper) – the dumper to use

  • bundle – the bundle to represent

Returns

the representation

aiida.orm.utils.serialize.represent_computer(dumper, computer)[source]

Represent a computer in yaml.

Parameters
  • dumper – the dumper to use

  • computer (aiida.orm.Computer) – the computer to represent

Returns

the representation

aiida.orm.utils.serialize.represent_group(dumper, group)[source]

Represent a group in yaml.

Parameters
  • dumper – the dumper to use

  • group (aiida.orm.Group) – the group to represent

Returns

the representation

aiida.orm.utils.serialize.represent_mapping(tag, dumper, mapping)[source]

Represent a mapping in yaml.

Parameters
  • tag – the yaml tag to use

  • dumper (yaml.dumper.Dumper) – the dumper to use

  • mapping – the mapping to represent

Returns

the representation

aiida.orm.utils.serialize.represent_node(dumper, node)[source]

Represent a node in yaml.

Parameters
Returns

the representation

aiida.orm.utils.serialize.serialize(data, encoding=None)[source]

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