aiida.engine.processes package

Module for processes and related utilities.

class aiida.engine.processes.CalcJob(*args, **kwargs)[source]

Bases: aiida.engine.processes.process.Process

Implementation of the CalcJob process.

_Process__called = True
__abstractmethods__ = frozenset([])
__init__(*args, **kwargs)[source]

Construct the instance only if it is a sub class of CalcJob otherwise raise InvalidOperation.

__module__ = 'aiida.engine.processes.calcjobs.calcjob'
_abc_cache = <_weakrefset.WeakSet object>
_abc_negative_cache = <_weakrefset.WeakSet object>
_abc_negative_cache_version = 102
_abc_registry = <_weakrefset.WeakSet object>
_node_class

alias of aiida.orm.nodes.process.calculation.calcjob.CalcJobNode

_spec = <aiida.engine.processes.process_spec.CalcJobProcessSpec object>
_spec_type

alias of aiida.engine.processes.process_spec.CalcJobProcessSpec

classmethod define(spec)[source]
classmethod get_state_classes()[source]
on_terminated()[source]

Cleanup the node by deleting the calulation job state.

Note

This has to be done before calling the super because that will seal the node after we cannot change it

parse(retrieved_temporary_folder=None)[source]

Parse a retrieved job calculation.

This is called once it’s finished waiting for the calculation to be finished and the data has been retrieved.

prepare_for_submission(folder)[source]

Docs.

presubmit(folder)[source]

Prepares the calculation folder with all inputs, ready to be copied to the cluster.

Parameters:folder – a SandboxFolder, empty in input, that will be filled with calculation input files and the scheduling script.
Return calcinfo:
 the CalcInfo object containing the information needed by the daemon to handle operations.
run()[source]

Run the calculation, we put it in the TOSUBMIT state and then wait for it to be completed.

class aiida.engine.processes.ExitCode(status, message)

Bases: tuple

__dict__ = dict_proxy({'status': <property object>, '__module__': 'aiida.engine.processes.exit_code', '__getstate__': <function __getstate__>, '__new__': <staticmethod object>, '_make': <classmethod object>, '_fields': ('status', 'message'), '_replace': <function _replace>, '__slots__': (), '_asdict': <function _asdict>, '__repr__': <function __repr__>, '__dict__': <property object>, 'message': <property object>, '__getnewargs__': <function __getnewargs__>, '__doc__': 'ExitCode(status, message)'})
__getnewargs__()

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

__getstate__()

Exclude the OrderedDict from pickling

__module__ = 'aiida.engine.processes.exit_code'
static __new__(_cls, status=0, message=None)

Create new instance of ExitCode(status, message)

__repr__()

Return a nicely formatted representation string

__slots__ = ()
_asdict()

Return a new OrderedDict which maps field names to their values

_fields = ('status', 'message')
classmethod _make(iterable, new=<built-in method __new__ of type object>, len=<built-in function len>)

Make a new ExitCode object from a sequence or iterable

_replace(**kwds)

Return a new ExitCode object replacing specified fields with new values

message

Alias for field number 1

status

Alias for field number 0

class aiida.engine.processes.ExitCodesNamespace[source]

Bases: aiida.common.extendeddicts.AttributeDict

A namespace of ExitCode tuples that can be accessed through getattr as well as getitem. Additionally, the collection can be called with an identifier, that can either reference the integer status of the ExitCode that needs to be retrieved or the key in the collection

__call__(identifier)[source]

Return a specific exit code identified by either its exit status or label

Parameters:identifier – the identifier of the exit code. If the type is integer, it will be interpreted as the exit code status, otherwise it be interpreted as the exit code label
Returns:an ExitCode named tuple
Raises:ValueError – if no exit code with the given label is defined for this process
__module__ = 'aiida.engine.processes.exit_code'
aiida.engine.processes.calcfunction(function)[source]

A decorator to turn a standard python function into a calcfunction. Example usage:

>>> from aiida.orm import Int
>>>
>>> # Define the calcfunction
>>> @calcfunction
>>> def sum(a, b):
>>>    return a + b
>>> # Run it with some input
>>> r = sum(Int(4), Int(5))
>>> print(r)
9
>>> r.get_incoming().all() # doctest: +SKIP
[Neighbor(link_type='', link_label='result',
node=<CalcFunctionNode: uuid: ce0c63b3-1c84-4bb8-ba64-7b70a36adf34 (pk: 3567)>)]
>>> r.get_incoming().get_node_by_label('result').get_incoming().all_nodes()
[4, 5]
aiida.engine.processes.workfunction(function)[source]

A decorator to turn a standard python function into a workfunction. Example usage:

>>> from aiida.orm import Int
>>>
>>> # Define the workfunction
>>> @workfunction
>>> def select(a, b):
>>>    return a
>>> # Run it with some input
>>> r = select(Int(4), Int(5))
>>> print(r)
4
>>> r.get_incoming().all() # doctest: +SKIP
[Neighbor(link_type='', link_label='result',
node=<WorkFunctionNode: uuid: ce0c63b3-1c84-4bb8-ba64-7b70a36adf34 (pk: 3567)>)]
>>> r.get_incoming().get_node_by_label('result').get_incoming().all_nodes()
[4, 5]
class aiida.engine.processes.Process(inputs=None, logger=None, runner=None, parent_pid=None, enable_persistence=True)[source]

Bases: plumpy.processes.Process

This class represents an AiiDA process which can be executed and will have full provenance saved in the database.

SINGLE_OUTPUT_LINKNAME = 'result'
class SaveKeys[source]

Bases: enum.Enum

Keys used to identify things in the saved instance state bundle.

CALC_ID = 'calc_id'
__module__ = 'aiida.engine.processes.process'
_Process__called = True
__abstractmethods__ = frozenset([])
__init__(inputs=None, logger=None, runner=None, parent_pid=None, enable_persistence=True)[source]

The signature of the constructor should not be changed by subclassing processes.

Parameters:
  • inputs (dict) – A dictionary of the process inputs
  • pid – The process ID, can be manually set, if not a unique pid will be chosen
  • logger (logging.Logger) – An optional logger for the process to use
  • loop – The event loop
  • communicator (plumpy.Communicator) – The (optional) communicator
__module__ = 'aiida.engine.processes.process'
_abc_cache = <_weakrefset.WeakSet object>
_abc_negative_cache = <_weakrefset.WeakSet object>
_abc_negative_cache_version = 102
_abc_registry = <_weakrefset.WeakSet object>
_auto_persist = set(['_CREATION_TIME', '_enable_persistence', '_future', '_parent_pid', '_paused', '_pid', '_pre_paused_status', '_status'])
_create_and_setup_db_record()[source]

Create and setup the database record for this process

Returns:the uuid of the process
_flat_inputs()[source]

Return a flattened version of the parsed inputs dictionary.

The eventual keys will be a concatenation of the nested keys. Note that the metadata dictionary, if present, is not passed, as those are dealt with separately in _setup_metadata.

Returns:flat dictionary of parsed inputs
_flatten_inputs(port, port_value, parent_name='', separator='_')[source]

Function that will recursively flatten the inputs dictionary, omitting inputs for ports that are marked as being non database storable

Parameters:
  • port – port against which to map the port value, can be InputPort or PortNamespace
  • port_value – value for the current port, can be a Mapping
  • parent_name – the parent key with which to prefix the keys
  • separator – character to use for the concatenation of keys
static _get_namespace_list(namespace=None, agglomerate=True)[source]

Get the list of namespaces in a given namespace

_node_class

alias of aiida.orm.nodes.process.process.ProcessNode

_save_checkpoint()[source]

Save the current state in a chechpoint if persistence is enabled and the process state is not terminal

If the persistence call excepts with a PersistenceError, it will be caught and a warning will be logged.

_setup_db_record()[source]

Create the database record for this process and the links with respect to its inputs

This function will set various attributes on the node that serve as a proxy for attributes of the Process. This is essential as otherwise this information could only be introspected through the Process itself, which is only available to the interpreter that has it in memory. To make this data introspectable from any interpreter, for example for the command line interface, certain Process attributes are proxied through the calculation node.

In addition, the parent calculation will be setup with a CALL link if applicable and all inputs will be linked up as well.

_setup_inputs()[source]

Create the links between the input nodes and the ProcessNode that represents this process.

_setup_metadata()[source]

Store the metadata on the ProcessNode.

_spec = <aiida.engine.processes.process_spec.ProcessSpec object>
_spec_type

alias of aiida.engine.processes.process_spec.ProcessSpec

classmethod build_process_type()[source]

The process type.

Returns:string of the process type
Return type:str

Note: This could be made into a property ‘process_type’ but in order to have it be a property of the class it would need to be defined in the metaclass, see https://bugs.python.org/issue20659

decode_input_args(encoded)[source]

Decode saved input arguments as they came from the saved instance state Bundle

Parameters:encoded
Returns:The decoded input args
classmethod define(spec)[source]
encode_input_args(inputs)[source]

Encode input arguments such that they may be saved in a Bundle

Parameters:inputs – A mapping of the inputs as passed to the process
Returns:The encoded inputs
exit_codes = {}
exposed_inputs(process_class, namespace=None, agglomerate=True)[source]

Gather a dictionary of the inputs that were exposed for a given Process class under an optional namespace.

Parameters:
  • process_class – Process class whose inputs to try and retrieve
  • namespace (str) – PortNamespace in which to look for the inputs
  • agglomerate (bool) – If set to true, all parent namespaces of the given namespace will also be searched for inputs. Inputs in lower-lying namespaces take precedence.
exposed_outputs(process_instance, process_class, namespace=None, agglomerate=True)[source]

Gather the outputs which were exposed from the process_class and emitted by the specific process_instance in a dictionary.

Parameters:
  • namespace (str) – Namespace in which to search for exposed outputs.
  • agglomerate (bool) – If set to true, all parent namespaces of the given namespace will also be searched for outputs. Outputs in lower-lying namespaces take precedence.
classmethod get_builder()[source]
classmethod get_or_create_db_record()[source]

Create a database calculation node that represents what happened in this process. :return: A calculation

get_parent_calc()[source]

Get the parent process node

Returns:the parent process node if there is one
Return type:aiida.orm.nodes.process.process.ProcessNode
get_provenance_inputs_iterator()[source]
init()[source]
kill(msg=None)[source]

Kill the process and all the children calculations it called

load_instance_state(saved_state, load_context)[source]
metadata

Return the metadata passed when launching this process.

Returns:metadata dictionary
node

Return the ProcessNode used by this process to represent itself in the database.

Returns:instance of sub class of ProcessNode
on_create()[source]
on_entered(from_state)[source]
on_entering(state)[source]
on_except(exc_info)[source]

Log the exception by calling the report method with formatted stack trace from exception info object and store the exception string as a node attribute

Parameters:exc_info – the sys.exc_info() object
on_finish(result, successful)[source]

Set the finish status on the process node

on_output_emitting(output_port, value)[source]

The process has emitted a value on the given output port.

Parameters:
  • output_port – The output port name the value was emitted on
  • value – The value emitted
on_paused(msg=None)[source]

The Process was paused so set the paused attribute on the process node

on_playing()[source]

The Process was unpaused so remove the paused attribute on the process node

on_terminated()[source]

Called when a Process enters a terminal state.

options

Return the options of the metadata passed when launching this process.

Returns:options dictionary
out(output_port, value=None)[source]

Record an output value for a specific output port. If the output port matches an explicitly defined Port it will be validated against that. If not it will be validated against the PortNamespace, which means it will be checked for dynamicity and whether the type of the value is valid

Parameters:
  • output_port (str) – the name of the output port, can be namespaced
  • value – the value for the output port
Raises:

TypeError if the output value is not validated against the port

out_many(out_dict)[source]

Add all values given in out_dict to the outputs. The keys of the dictionary will be used as output names.

report(msg, *args, **kwargs)[source]

Log a message to the logger, which should get saved to the database through the attached DbLogHandler.

The pk, class name and function name of the caller are prepended to the given message

Parameters:
  • msg – message to log
  • args – args to pass to the log call
  • kwargs – kwargs to pass to the log call
runner
save_instance_state(out_state, save_context)[source]

Ask the process to save its current instance state.

Parameters:
  • out_state (plumpy.Bundle) – A bundle to save the state to
  • save_context – The save context
set_status(status)[source]

The status of the Process is about to be changed, so we reflect this is in node’s attribute proxy.

Parameters:status – the status message
submit(process, *args, **kwargs)[source]
update_node_state(state)[source]
update_outputs()[source]

Attach any new outputs to the node since the last time this was called, if store provenance is True.

uuid

Return the UUID of the process which corresponds to the UUID of its associated ProcessNode.

Returns:the UUID associated to this process instance
class aiida.engine.processes.ProcessState[source]

Bases: enum.Enum

The possible states that a Process can be in.

CREATED = 'created'
EXCEPTED = 'excepted'
FINISHED = 'finished'
KILLED = 'killed'
RUNNING = 'running'
WAITING = 'waiting'
__module__ = 'plumpy.process_states'
aiida.engine.processes.ToContext

alias of __builtin__.dict

aiida.engine.processes.assign_(target)[source]

Convenience function that will construct an Awaitable for a given class instance with the context action set to ASSIGN. When the awaitable target is completed it will be assigned to the context for a key that is to be defined later

Parameters:target – an instance of a Process or Awaitable
Returns:the awaitable
Return type:Awaitable
aiida.engine.processes.append_(target)[source]

Convenience function that will construct an Awaitable for a given class instance with the context action set to APPEND. When the awaitable target is completed it will be appended to a list in the context for a key that is to be defined later

Parameters:target – an instance of a Process or Awaitable
Returns:the awaitable
Return type:Awaitable
class aiida.engine.processes.WorkChain(inputs=None, logger=None, runner=None, enable_persistence=True)[source]

Bases: aiida.engine.processes.process.Process

A WorkChain, the base class for AiiDA workflows.

_CONTEXT = 'CONTEXT'
_Process__called = True
_STEPPER_STATE = 'stepper_state'
__abstractmethods__ = frozenset([])
__init__(inputs=None, logger=None, runner=None, enable_persistence=True)[source]

Construct the instance only if it is a sub class of WorkChain otherwise raise InvalidOperation.

__module__ = 'aiida.engine.processes.workchains.workchain'
_abc_cache = <_weakrefset.WeakSet object>
_abc_negative_cache = <_weakrefset.WeakSet object>
_abc_negative_cache_version = 102
_abc_registry = <_weakrefset.WeakSet object>
_auto_persist = set(['_CREATION_TIME', '_awaitables', '_enable_persistence', '_future', '_parent_pid', '_paused', '_pid', '_pre_paused_status', '_status'])
_do_step()[source]

Execute the next step in the outline and return the result.

If the stepper returns a non-finished status and the return value is of type ToContext, the contents of the ToContext container will be turned into awaitables if necessary. If any awaitables were created, the process will enter in the Wait state, otherwise it will go to Continue. When the stepper returns that it is done, the stepper result will be converted to None and returned, unless it is an integer or instance of ExitCode.

_node_class

alias of aiida.orm.nodes.process.workflow.workchain.WorkChainNode

_spec = <aiida.engine.processes.workchains.workchain.WorkChainSpec object>
_spec_type

alias of WorkChainSpec

_store_nodes(data)[source]

Recurse through a data structure and store any unstored nodes that are found along the way

Parameters:data – a data structure potentially containing unstored nodes
action_awaitables()[source]

Handle the awaitables that are currently registered with the workchain

Depending on the class type of the awaitable’s target a different callback function will be bound with the awaitable and the runner will be asked to call it when the target is completed

ctx
classmethod define(spec)[source]
insert_awaitable(awaitable)[source]

Insert a awaitable that will cause the workchain to wait until the wait on is finished before continuing to the next step.

Parameters:awaitable (aiida.engine.processes.workchains.awaitable.Awaitable) – The thing to await
load_instance_state(saved_state, load_context)[source]
on_exiting()[source]

Ensure that any unstored nodes in the context are stored, before the state is exited

After the state is exited the next state will be entered and if persistence is enabled, a checkpoint will be saved. If the context contains unstored nodes, the serialization necessary for checkpointing will fail.

on_process_finished(awaitable, pk)[source]

Callback function called by the runner when the process instance identified by pk is completed. The awaitable will be effectuated on the context of the workchain and removed from the internal list. If all awaitables have been dealt with, the workchain process is resumed

Parameters:
  • awaitable – an Awaitable instance
  • pk – the pk of the awaitable’s target
on_run()[source]
on_wait(awaitables)[source]
remove_awaitable(awaitable)[source]

Remove a awaitable.

Precondition: must be a awaitable that was previously inserted

Parameters:awaitable – The awaitable to remove
run()[source]
save_instance_state(out_state, save_context)[source]

Ask the process to save its current instance state.

Parameters:
  • out_state (plumpy.Bundle) – A bundle to save the state to
  • save_context – The save context
to_context(**kwargs)[source]

This is a convenience method that provides syntactic sugar, for a user to add multiple intersteps that will assign a certain value to the corresponding key in the context of the workchain

aiida.engine.processes.if_(condition)[source]

A conditional that can be used in a workchain outline.

Use as:

if_(cls.conditional)(
  cls.step1,
  cls.step2
)

Each step can, of course, also be any valid workchain step e.g. conditional.

Parameters:condition – The workchain method that will return True or False
aiida.engine.processes.while_(condition)[source]

A while loop that can be used in a workchain outline.

Use as:

while_(cls.conditional)(
  cls.step1,
  cls.step2
)

Each step can, of course, also be any valid workchain step e.g. conditional.

Parameters:condition – The workchain method that will return True or False

Submodules

Convenience classes to help building the input dictionaries for Processes.

class aiida.engine.processes.builder.ProcessBuilder(process_class)[source]

Bases: aiida.engine.processes.builder.ProcessBuilderNamespace

A process builder that helps setting up the inputs for creating a new process.

__abstractmethods__ = frozenset([])
__init__(process_class)[source]

Dynamically construct the get and set properties for the ports of the given port namespace

For each port in the given port namespace a get and set property will be constructed dynamically and added to the ProcessBuilderNamespace. The docstring for these properties will be defined by calling str() on the Port, which should return the description of the Port.

Parameters:port_namespace – the inputs PortNamespace for which to construct the builder
__module__ = 'aiida.engine.processes.builder'
_abc_cache = <_weakrefset.WeakSet object>
_abc_negative_cache = <_weakrefset.WeakSet object>
_abc_negative_cache_version = 102
_abc_registry = <_weakrefset.WeakSet object>
process_class
class aiida.engine.processes.builder.CalcJobBuilder(process_class)[source]

Bases: aiida.engine.processes.builder.ProcessBuilder

A process builder specific to CalcJob implementations that provides also the submit_test functionality.

__abstractmethods__ = frozenset([])
__dir__()[source]
__module__ = 'aiida.engine.processes.builder'
_abc_cache = <_weakrefset.WeakSet object>
_abc_negative_cache = <_weakrefset.WeakSet object>
_abc_negative_cache_version = 102
_abc_registry = <_weakrefset.WeakSet object>
submit_test(folder=None, subfolder_name=None)[source]

Run a test submission by creating the files that would be generated for the real calculation in a local folder, without actually storing the calculation nor the input nodes. This functionality therefore also does not require any of the inputs nodes to be stored yet.

Parameters:
  • folder – a Folder object, within which to create the calculation files. By default a folder will be created in the current working directory
  • subfolder_name – the name of the subfolder to use within the directory of the folder object. By default a unique string will be generated based on the current datetime with the format yymmdd- followed by an auto incrementing index
class aiida.engine.processes.builder.ProcessBuilderNamespace(port_namespace)[source]

Bases: _abcoll.Mapping

Input namespace for the ProcessBuilder. Dynamically generates the getters and setters for the input ports of a given PortNamespace

__abstractmethods__ = frozenset([])
__dir__()[source]
__getitem__(item)[source]
__init__(port_namespace)[source]

Dynamically construct the get and set properties for the ports of the given port namespace

For each port in the given port namespace a get and set property will be constructed dynamically and added to the ProcessBuilderNamespace. The docstring for these properties will be defined by calling str() on the Port, which should return the description of the Port.

Parameters:port_namespace – the inputs PortNamespace for which to construct the builder
__iter__()[source]
__len__()[source]
__module__ = 'aiida.engine.processes.builder'
__repr__() <==> repr(x)[source]
__setattr__(attr, value)[source]

Any attributes without a leading underscore being set correspond to inputs and should hence be validated with respect to the corresponding input port from the process spec

_abc_cache = <_weakrefset.WeakSet object>
_abc_negative_cache = <_weakrefset.WeakSet object>
_abc_negative_cache_version = 102
_abc_registry = <_weakrefset.WeakSet object>

A namedtuple and namespace for ExitCodes that can be used to exit from Processes.

class aiida.engine.processes.exit_code.ExitCode(status, message)

Bases: tuple

__dict__ = dict_proxy({'status': <property object>, '__module__': 'aiida.engine.processes.exit_code', '__getstate__': <function __getstate__>, '__new__': <staticmethod object>, '_make': <classmethod object>, '_fields': ('status', 'message'), '_replace': <function _replace>, '__slots__': (), '_asdict': <function _asdict>, '__repr__': <function __repr__>, '__dict__': <property object>, 'message': <property object>, '__getnewargs__': <function __getnewargs__>, '__doc__': 'ExitCode(status, message)'})
__getnewargs__()

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

__getstate__()

Exclude the OrderedDict from pickling

__module__ = 'aiida.engine.processes.exit_code'
static __new__(_cls, status=0, message=None)

Create new instance of ExitCode(status, message)

__repr__()

Return a nicely formatted representation string

__slots__ = ()
_asdict()

Return a new OrderedDict which maps field names to their values

_fields = ('status', 'message')
classmethod _make(iterable, new=<built-in method __new__ of type object>, len=<built-in function len>)

Make a new ExitCode object from a sequence or iterable

_replace(**kwds)

Return a new ExitCode object replacing specified fields with new values

message

Alias for field number 1

status

Alias for field number 0

class aiida.engine.processes.exit_code.ExitCodesNamespace[source]

Bases: aiida.common.extendeddicts.AttributeDict

A namespace of ExitCode tuples that can be accessed through getattr as well as getitem. Additionally, the collection can be called with an identifier, that can either reference the integer status of the ExitCode that needs to be retrieved or the key in the collection

__call__(identifier)[source]

Return a specific exit code identified by either its exit status or label

Parameters:identifier – the identifier of the exit code. If the type is integer, it will be interpreted as the exit code status, otherwise it be interpreted as the exit code label
Returns:an ExitCode named tuple
Raises:ValueError – if no exit code with the given label is defined for this process
__module__ = 'aiida.engine.processes.exit_code'

Class and decorators to generate processes out of simple python functions.

aiida.engine.processes.functions.calcfunction(function)[source]

A decorator to turn a standard python function into a calcfunction. Example usage:

>>> from aiida.orm import Int
>>>
>>> # Define the calcfunction
>>> @calcfunction
>>> def sum(a, b):
>>>    return a + b
>>> # Run it with some input
>>> r = sum(Int(4), Int(5))
>>> print(r)
9
>>> r.get_incoming().all() # doctest: +SKIP
[Neighbor(link_type='', link_label='result',
node=<CalcFunctionNode: uuid: ce0c63b3-1c84-4bb8-ba64-7b70a36adf34 (pk: 3567)>)]
>>> r.get_incoming().get_node_by_label('result').get_incoming().all_nodes()
[4, 5]
aiida.engine.processes.functions.workfunction(function)[source]

A decorator to turn a standard python function into a workfunction. Example usage:

>>> from aiida.orm import Int
>>>
>>> # Define the workfunction
>>> @workfunction
>>> def select(a, b):
>>>    return a
>>> # Run it with some input
>>> r = select(Int(4), Int(5))
>>> print(r)
4
>>> r.get_incoming().all() # doctest: +SKIP
[Neighbor(link_type='', link_label='result',
node=<WorkFunctionNode: uuid: ce0c63b3-1c84-4bb8-ba64-7b70a36adf34 (pk: 3567)>)]
>>> r.get_incoming().get_node_by_label('result').get_incoming().all_nodes()
[4, 5]

Futures that can poll or receive broadcasted messages while waiting for a task to be completed.

class aiida.engine.processes.futures.CalculationFuture(pk, loop=None, poll_interval=None, communicator=None)[source]

Bases: plumpy.futures.Future

A future that waits for a calculation to complete using both polling and listening for broadcast events if possible

__init__(pk, loop=None, poll_interval=None, communicator=None)[source]

Get a future for a calculation node being finished. If a None poll_interval is supplied polling will not be used. If a communicator is supplied it will be used to listen for broadcast messages.

Parameters:
  • pk – The calculation pk
  • loop – An event loop
  • poll_interval – The polling interval. Can be None in which case no polling.
  • communicator – A communicator. Can be None in which case no broadcast listens.
__module__ = 'aiida.engine.processes.futures'
_filtered = None
_poll_calculation(**kwargs)[source]

Poll whether the calculation node has reached a terminal state.

cleanup()[source]

Clean up the future by removing broadcast subscribers from the communicator if it still exists.

AiiDA specific implementation of plumpy Ports and PortNamespaces for the ProcessSpec.

class aiida.engine.processes.ports.CalcJobOutputPort(*args, **kwargs)[source]

Bases: plumpy.ports.OutputPort

Sub class of plumpy.OutputPort which adds the _pass_to_parser attribute.

__abstractmethods__ = frozenset([])
__init__(*args, **kwargs)[source]

x.__init__(…) initializes x; see help(type(x)) for signature

__module__ = 'aiida.engine.processes.ports'
_abc_cache = <_weakrefset.WeakSet object>
_abc_negative_cache = <_weakrefset.WeakSet object>
_abc_negative_cache_version = 102
_abc_registry = <_weakrefset.WeakSet object>
pass_to_parser
class aiida.engine.processes.ports.InputPort(*args, **kwargs)[source]

Bases: aiida.engine.processes.ports.WithSerialize, aiida.engine.processes.ports.WithNonDb, plumpy.ports.InputPort

Sub class of plumpy.InputPort which mixes in the WithSerialize and WithNonDb mixins to support automatic value serialization to database storable types and support non database storable input types as well.

__abstractmethods__ = frozenset([])
__module__ = 'aiida.engine.processes.ports'
__slotnames__ = []
_abc_cache = <_weakrefset.WeakSet object>
_abc_negative_cache = <_weakrefset.WeakSet object>
_abc_negative_cache_version = 102
_abc_registry = <_weakrefset.WeakSet object>
get_description()[source]

Return a description of the InputPort, which will be a dictionary of its attributes

Returns:a dictionary of the stringified InputPort attributes
class aiida.engine.processes.ports.PortNamespace(*args, **kwargs)[source]

Bases: aiida.engine.processes.ports.WithNonDb, plumpy.ports.PortNamespace

Sub class of plumpy.PortNamespace which implements the serialize method to support automatic recursive serialization of a given mapping onto the ports of the PortNamespace.

__abstractmethods__ = frozenset([])
__module__ = 'aiida.engine.processes.ports'
__slotnames__ = []
_abc_cache = <_weakrefset.WeakSet object>
_abc_negative_cache = <_weakrefset.WeakSet object>
_abc_negative_cache_version = 102
_abc_registry = <_weakrefset.WeakSet object>
serialize(mapping)[source]

Serialize the given mapping onto this Portnamespace. It will recursively call this function on any nested PortNamespace or the serialize function on any Ports.

Parameters:mapping – a mapping of values to be serialized
Returns:the serialized mapping
class aiida.engine.processes.ports.WithNonDb(*args, **kwargs)[source]

Bases: object

A mixin that adds support to a port to flag a that should not be stored in the database using the non_db=True flag.

The mixins have to go before the main port class in the superclass order to make sure the mixin has the chance to strip out the non_db keyword.

__dict__ = dict_proxy({'__module__': 'aiida.engine.processes.ports', 'non_db': <property object>, '__dict__': <attribute '__dict__' of 'WithNonDb' objects>, '__weakref__': <attribute '__weakref__' of 'WithNonDb' objects>, '__doc__': '\n A mixin that adds support to a port to flag a that should not be stored\n in the database using the non_db=True flag.\n\n The mixins have to go before the main port class in the superclass order\n to make sure the mixin has the chance to strip out the non_db keyword.\n ', '__init__': <function __init__>})
__init__(*args, **kwargs)[source]

x.__init__(…) initializes x; see help(type(x)) for signature

__module__ = 'aiida.engine.processes.ports'
__weakref__

list of weak references to the object (if defined)

non_db
class aiida.engine.processes.ports.WithSerialize(*args, **kwargs)[source]

Bases: object

A mixin that adds support for a serialization function which is automatically applied on inputs that are not AiiDA data types.

__dict__ = dict_proxy({'__module__': 'aiida.engine.processes.ports', 'serialize': <function serialize>, '__dict__': <attribute '__dict__' of 'WithSerialize' objects>, '__weakref__': <attribute '__weakref__' of 'WithSerialize' objects>, '__doc__': '\n A mixin that adds support for a serialization function which is automatically applied on inputs\n that are not AiiDA data types.\n ', '__init__': <function __init__>})
__init__(*args, **kwargs)[source]

x.__init__(…) initializes x; see help(type(x)) for signature

__module__ = 'aiida.engine.processes.ports'
__weakref__

list of weak references to the object (if defined)

serialize(value)[source]

Serialize the given value if it is not already a Data type and a serializer function is defined

Parameters:value – the value to be serialized
Returns:a serialized version of the value or the unchanged value

The AiiDA process class

class aiida.engine.processes.process.Process(inputs=None, logger=None, runner=None, parent_pid=None, enable_persistence=True)[source]

Bases: plumpy.processes.Process

This class represents an AiiDA process which can be executed and will have full provenance saved in the database.

SINGLE_OUTPUT_LINKNAME = 'result'
class SaveKeys[source]

Bases: enum.Enum

Keys used to identify things in the saved instance state bundle.

CALC_ID = 'calc_id'
__module__ = 'aiida.engine.processes.process'
_Process__called = True
__abstractmethods__ = frozenset([])
__init__(inputs=None, logger=None, runner=None, parent_pid=None, enable_persistence=True)[source]

The signature of the constructor should not be changed by subclassing processes.

Parameters:
  • inputs (dict) – A dictionary of the process inputs
  • pid – The process ID, can be manually set, if not a unique pid will be chosen
  • logger (logging.Logger) – An optional logger for the process to use
  • loop – The event loop
  • communicator (plumpy.Communicator) – The (optional) communicator
__module__ = 'aiida.engine.processes.process'
_abc_cache = <_weakrefset.WeakSet object>
_abc_negative_cache = <_weakrefset.WeakSet object>
_abc_negative_cache_version = 102
_abc_registry = <_weakrefset.WeakSet object>
_auto_persist = set(['_CREATION_TIME', '_enable_persistence', '_future', '_parent_pid', '_paused', '_pid', '_pre_paused_status', '_status'])
_create_and_setup_db_record()[source]

Create and setup the database record for this process

Returns:the uuid of the process
_flat_inputs()[source]

Return a flattened version of the parsed inputs dictionary.

The eventual keys will be a concatenation of the nested keys. Note that the metadata dictionary, if present, is not passed, as those are dealt with separately in _setup_metadata.

Returns:flat dictionary of parsed inputs
_flatten_inputs(port, port_value, parent_name='', separator='_')[source]

Function that will recursively flatten the inputs dictionary, omitting inputs for ports that are marked as being non database storable

Parameters:
  • port – port against which to map the port value, can be InputPort or PortNamespace
  • port_value – value for the current port, can be a Mapping
  • parent_name – the parent key with which to prefix the keys
  • separator – character to use for the concatenation of keys
static _get_namespace_list(namespace=None, agglomerate=True)[source]

Get the list of namespaces in a given namespace

_node_class

alias of aiida.orm.nodes.process.process.ProcessNode

_save_checkpoint()[source]

Save the current state in a chechpoint if persistence is enabled and the process state is not terminal

If the persistence call excepts with a PersistenceError, it will be caught and a warning will be logged.

_setup_db_record()[source]

Create the database record for this process and the links with respect to its inputs

This function will set various attributes on the node that serve as a proxy for attributes of the Process. This is essential as otherwise this information could only be introspected through the Process itself, which is only available to the interpreter that has it in memory. To make this data introspectable from any interpreter, for example for the command line interface, certain Process attributes are proxied through the calculation node.

In addition, the parent calculation will be setup with a CALL link if applicable and all inputs will be linked up as well.

_setup_inputs()[source]

Create the links between the input nodes and the ProcessNode that represents this process.

_setup_metadata()[source]

Store the metadata on the ProcessNode.

_spec = <aiida.engine.processes.process_spec.ProcessSpec object>
_spec_type

alias of aiida.engine.processes.process_spec.ProcessSpec

classmethod build_process_type()[source]

The process type.

Returns:string of the process type
Return type:str

Note: This could be made into a property ‘process_type’ but in order to have it be a property of the class it would need to be defined in the metaclass, see https://bugs.python.org/issue20659

decode_input_args(encoded)[source]

Decode saved input arguments as they came from the saved instance state Bundle

Parameters:encoded
Returns:The decoded input args
classmethod define(spec)[source]
encode_input_args(inputs)[source]

Encode input arguments such that they may be saved in a Bundle

Parameters:inputs – A mapping of the inputs as passed to the process
Returns:The encoded inputs
exit_codes = {}
exposed_inputs(process_class, namespace=None, agglomerate=True)[source]

Gather a dictionary of the inputs that were exposed for a given Process class under an optional namespace.

Parameters:
  • process_class – Process class whose inputs to try and retrieve
  • namespace (str) – PortNamespace in which to look for the inputs
  • agglomerate (bool) – If set to true, all parent namespaces of the given namespace will also be searched for inputs. Inputs in lower-lying namespaces take precedence.
exposed_outputs(process_instance, process_class, namespace=None, agglomerate=True)[source]

Gather the outputs which were exposed from the process_class and emitted by the specific process_instance in a dictionary.

Parameters:
  • namespace (str) – Namespace in which to search for exposed outputs.
  • agglomerate (bool) – If set to true, all parent namespaces of the given namespace will also be searched for outputs. Outputs in lower-lying namespaces take precedence.
classmethod get_builder()[source]
classmethod get_or_create_db_record()[source]

Create a database calculation node that represents what happened in this process. :return: A calculation

get_parent_calc()[source]

Get the parent process node

Returns:the parent process node if there is one
Return type:aiida.orm.nodes.process.process.ProcessNode
get_provenance_inputs_iterator()[source]
init()[source]
kill(msg=None)[source]

Kill the process and all the children calculations it called

load_instance_state(saved_state, load_context)[source]
metadata

Return the metadata passed when launching this process.

Returns:metadata dictionary
node

Return the ProcessNode used by this process to represent itself in the database.

Returns:instance of sub class of ProcessNode
on_create()[source]
on_entered(from_state)[source]
on_entering(state)[source]
on_except(exc_info)[source]

Log the exception by calling the report method with formatted stack trace from exception info object and store the exception string as a node attribute

Parameters:exc_info – the sys.exc_info() object
on_finish(result, successful)[source]

Set the finish status on the process node

on_output_emitting(output_port, value)[source]

The process has emitted a value on the given output port.

Parameters:
  • output_port – The output port name the value was emitted on
  • value – The value emitted
on_paused(msg=None)[source]

The Process was paused so set the paused attribute on the process node

on_playing()[source]

The Process was unpaused so remove the paused attribute on the process node

on_terminated()[source]

Called when a Process enters a terminal state.

options

Return the options of the metadata passed when launching this process.

Returns:options dictionary
out(output_port, value=None)[source]

Record an output value for a specific output port. If the output port matches an explicitly defined Port it will be validated against that. If not it will be validated against the PortNamespace, which means it will be checked for dynamicity and whether the type of the value is valid

Parameters:
  • output_port (str) – the name of the output port, can be namespaced
  • value – the value for the output port
Raises:

TypeError if the output value is not validated against the port

out_many(out_dict)[source]

Add all values given in out_dict to the outputs. The keys of the dictionary will be used as output names.

report(msg, *args, **kwargs)[source]

Log a message to the logger, which should get saved to the database through the attached DbLogHandler.

The pk, class name and function name of the caller are prepended to the given message

Parameters:
  • msg – message to log
  • args – args to pass to the log call
  • kwargs – kwargs to pass to the log call
runner
save_instance_state(out_state, save_context)[source]

Ask the process to save its current instance state.

Parameters:
  • out_state (plumpy.Bundle) – A bundle to save the state to
  • save_context – The save context
set_status(status)[source]

The status of the Process is about to be changed, so we reflect this is in node’s attribute proxy.

Parameters:status – the status message
submit(process, *args, **kwargs)[source]
update_node_state(state)[source]
update_outputs()[source]

Attach any new outputs to the node since the last time this was called, if store provenance is True.

uuid

Return the UUID of the process which corresponds to the UUID of its associated ProcessNode.

Returns:the UUID associated to this process instance
class aiida.engine.processes.process.ProcessState[source]

Bases: enum.Enum

The possible states that a Process can be in.

CREATED = 'created'
EXCEPTED = 'excepted'
FINISHED = 'finished'
KILLED = 'killed'
RUNNING = 'running'
WAITING = 'waiting'
__module__ = 'plumpy.process_states'

AiiDA specific implementation of plumpy’s ProcessSpec.

class aiida.engine.processes.process_spec.CalcJobProcessSpec[source]

Bases: aiida.engine.processes.process_spec.ProcessSpec

Process spec intended for the CalcJob process class.

OUTPUT_PORT_TYPE

alias of aiida.engine.processes.ports.CalcJobOutputPort

__init__()[source]

x.__init__(…) initializes x; see help(type(x)) for signature

__module__ = 'aiida.engine.processes.process_spec'
default_output_node
class aiida.engine.processes.process_spec.ProcessSpec[source]

Bases: plumpy.process_spec.ProcessSpec

Default process spec for process classes defined in aiida-core.

This sub class defines custom classes for input ports and port namespaces. It also adds support for the definition of exit codes and retrieving them subsequently.

INPUT_PORT_TYPE

alias of aiida.engine.processes.ports.InputPort

METADATA_KEY = 'metadata'
METADATA_OPTIONS_KEY = 'options'
PORT_NAMESPACE_TYPE

alias of aiida.engine.processes.ports.PortNamespace

__init__()[source]

x.__init__(…) initializes x; see help(type(x)) for signature

__module__ = 'aiida.engine.processes.process_spec'
exit_code(status, label, message)[source]

Add an exit code to the ProcessSpec

Parameters:
  • status – the exit status integer
  • label – a label by which the exit code can be addressed
  • message – a more detailed description of the exit code
exit_codes

Return the namespace of exit codes defined for this ProcessSpec

Returns:ExitCodesNamespace of ExitCode named tuples
metadata_key
options_key