aiida.engine.processes package

Module for processes and related utilities.

class aiida.engine.processes.BaseRestartWorkChain(*args: Any, **kwargs: Any)[source]

Bases: aiida.engine.processes.workchains.workchain.WorkChain

Base restart work chain.

This work chain serves as the starting point for more complex work chains that will be designed to run a sub process that might need multiple restarts to come to a successful end. These restarts may be necessary because a single process run is not sufficient to achieve a fully converged result, or certain errors maybe encountered which are recoverable.

This work chain implements the most basic functionality to achieve this goal. It will launch the sub process, restarting until it is completed successfully or the maximum number of iterations is reached. After completion of the sub process it will be inspected, and a list of process handlers are called successively. These process handlers are defined as class methods that are decorated with process_handler().

The idea is to sub class this work chain and leverage the generic error handling that is implemented in the few outline methods. The minimally required outline would look something like the following:

cls.setup
while_(cls.should_run_process)(
    cls.run_process,
    cls.inspect_process,
)

Each of these methods can of course be overriden but they should be general enough to fit most process cycles. The run_process method will take the inputs for the process from the context under the key inputs. The user should, therefore, make sure that before the run_process method is called, that the to be used inputs are stored under self.ctx.inputs. One can update the inputs based on the results from a prior process by calling an outline method just before the run_process step, for example:

cls.setup
while_(cls.should_run_process)(
    cls.prepare_inputs,
    cls.run_process,
    cls.inspect_process,
)

Where in the prepare_calculation method, the inputs dictionary at self.ctx.inputs is updated before the next process will be run with those inputs.

The _process_class attribute should be set to the Process class that should be run in the loop. Finally, to define handlers that will be called during the inspect_process simply define a class method with the signature (self, node) and decorate it with the process_handler decorator, for example:

@process_handler
def handle_problem(self, node):
    if some_problem:
        self.ctx.inputs = improved_inputs
        return ProcessHandlerReport()

The process_handler and ProcessHandlerReport support various arguments to control the flow of the logic of the inspect_process. Refer to their respective documentation for details.

__abstractmethods__ = frozenset({})
__annotations__ = {'_process_class': typing.Union[typing.Type[ForwardRef('Process')], NoneType]}
__init__(*args, **kwargs)None[source]

Construct the instance.

__module__ = 'aiida.engine.processes.workchains.restart'
_abc_impl = <_abc_data object>
_considered_handlers_extra = 'considered_handlers'
_process_class: Optional[Type[Process]] = None
_spec = <aiida.engine.processes.workchains.workchain.WorkChainSpec object>
_wrap_bare_dict_inputs(port_namespace: PortNamespace, inputs: Dict[str, Any])aiida.common.extendeddicts.AttributeDict[source]

Wrap bare dictionaries in inputs in a Dict node if dictated by the corresponding inputs portnamespace.

Parameters
  • port_namespace – a PortNamespace

  • inputs – a dictionary of inputs intended for submission of the process

Returns

an attribute dictionary with all bare dictionaries wrapped in Dict if dictated by the port namespace

classmethod define(spec: ProcessSpec)None[source]

Define the process specification.

classmethod get_process_handlers() → List[function][source]
inspect_process() → Optional[ExitCode][source]

Analyse the results of the previous process and call the handlers when necessary.

If the process is excepted or killed, the work chain will abort. Otherwise any attached handlers will be called in order of their specified priority. If the process was failed and no handler returns a report indicating that the error was handled, it is considered an unhandled process failure and the process is relaunched. If this happens twice in a row, the work chain is aborted. In the case that at least one handler returned a report the following matrix determines the logic that is followed:

Process Handler Handler Action result report? exit code —————————————– Success yes == 0 Restart Success yes != 0 Abort Failed yes == 0 Restart Failed yes != 0 Abort

If no handler returned a report and the process finished successfully, the work chain’s work is considered done and it will move on to the next step that directly follows the while conditional, if there is one defined in the outline.

classmethod is_process_handler(process_handler_name: Union[str, function])bool[source]

Return whether the given method name corresponds to a process handler of this class.

Parameters

process_handler_name – string name of the instance method

Returns

boolean, True if corresponds to process handler, False otherwise

on_terminated()[source]

Clean the working directories of all child calculation jobs if clean_workdir=True in the inputs.

property process_class

Return the process class to run in the loop.

results() → Optional[ExitCode][source]

Attach the outputs specified in the output specification from the last completed process.

run_process()dict[source]

Run the next process, taking the input dictionary from the context at self.ctx.inputs.

setup()None[source]

Initialize context variables that are used during the logical flow of the BaseRestartWorkChain.

should_run_process()bool[source]

Return whether a new process should be run.

This is the case as long as the last process has not finished successfully and the maximum number of restarts has not yet been exceeded.

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

Bases: aiida.engine.processes.process.Process

Implementation of the CalcJob process.

__abstractmethods__ = frozenset({})
__annotations__ = {'link_label_retrieved': <class 'str'>}
__init__(*args, **kwargs)None[source]

Construct a CalcJob instance.

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

See documentation of aiida.engine.Process.

__module__ = 'aiida.engine.processes.calcjobs.calcjob'
_abc_impl = <_abc_data object>
_node_class

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

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

alias of aiida.engine.processes.process_spec.CalcJobProcessSpec

classmethod define(spec: aiida.engine.processes.process_spec.CalcJobProcessSpec)None[source]

Define the process specification, including its inputs, outputs and known exit codes.

Ports are added to the metadata input namespace (inherited from the base Process), and a code input Port, a remote_folder output Port and retrieved folder output Port are added.

Parameters

spec – the calculation job process spec to define.

classmethod get_state_classes() → Dict[Hashable, Type[plumpy.process_states.State]][source]

A mapping of the State constants to the corresponding state class.

Overrides the waiting state with the Calcjob specific version.

on_terminated()None[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

property options

Return the options of the metadata that were specified when this process instance was launched.

Returns

options dictionary

parse(retrieved_temporary_folder: Optional[str] = None)aiida.engine.processes.exit_code.ExitCode[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.

Parameters

retrieved_temporary_folder – The path to the temporary folder

parse_retrieved_output(retrieved_temporary_folder: Optional[str] = None) → Optional[aiida.engine.processes.exit_code.ExitCode][source]

Parse the retrieved data by calling the parser plugin if it was defined in the inputs.

parse_scheduler_output(retrieved: aiida.orm.nodes.node.Node) → Optional[aiida.engine.processes.exit_code.ExitCode][source]

Parse the output of the scheduler if that functionality has been implemented for the plugin.

prepare_for_submission(folder: aiida.common.folders.Folder)aiida.common.datastructures.CalcInfo[source]

Prepare the calculation for submission.

Convert the input nodes into the corresponding input files in the format that the code will expect. In addition, define and return a CalcInfo instance, which is a simple data structure that contains information for the engine, for example, on what files to copy to the remote machine, what files to retrieve once it has completed, specific scheduler settings and more.

Parameters

folder – a temporary folder on the local file system.

Returns

the CalcInfo instance

presubmit(folder: aiida.common.folders.Folder)aiida.common.datastructures.CalcInfo[source]

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

Parameters

folder – a SandboxFolder that can be used to write calculation input files and the scheduling script.

Return calcinfo

the CalcInfo object containing the information needed by the daemon to handle operations.

run() → Union[plumpy.process_states.Stop, int, plumpy.process_states.Wait][source]

Run the calculation job.

This means invoking the presubmit and storing the temporary folder in the node’s repository. Then we move the process in the Wait state, waiting for the UPLOAD transport task to be started.

Returns

the Stop command if a dry run, int if the process has an exit status, Wait command if the calcjob is to be uploaded

spec_options = <aiida.engine.processes.ports.PortNamespace object>
class aiida.engine.processes.CalcJobOutputPort(*args, **kwargs)[source]

Bases: plumpy.ports.OutputPort

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

__init__(*args, **kwargs)None[source]

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

__module__ = 'aiida.engine.processes.ports'
property pass_to_parser
class aiida.engine.processes.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__()None[source]

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

__module__ = 'aiida.engine.processes.process_spec'
property default_output_node
class aiida.engine.processes.ExitCode(status: int = 0, message: Optional[str] = None, invalidates_cache: bool = False)[source]

Bases: tuple

A simple data class to define an exit code for a Process.

When an instance of this class is returned from a Process._run() call, it will be interpreted that the Process should be terminated and that the exit status and message of the namedtuple should be set to the corresponding attributes of the node.

Parameters
  • status – positive integer exit status, where a non-zero value indicated the process failed, default is 0

  • message – optional message with more details about the failure mode

  • invalidates_cache – optional flag, indicating that a process should not be used in caching

__annotations__ = {'invalidates_cache': <class 'bool'>, 'message': typing.Union[str, NoneType], 'status': <class 'int'>}
__getnewargs__()

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

__module__ = 'aiida.engine.processes.exit_code'
static __new__(_cls, status: int = 0, message: Optional[str] = None, invalidates_cache: bool = False)

Create new instance of ExitCode(status, message, invalidates_cache)

__repr__()

Return a nicely formatted representation string

__slots__ = ()
_asdict()

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

_field_defaults = {'invalidates_cache': False, 'message': None, 'status': 0}
_field_types = {'invalidates_cache': <class 'bool'>, 'message': typing.Union[str, NoneType], 'status': <class 'int'>}
_fields = ('status', 'message', 'invalidates_cache')
_fields_defaults = {}
classmethod _make(iterable)

Make a new ExitCode object from a sequence or iterable

_replace(**kwds)

Return a new ExitCode object replacing specified fields with new values

format(**kwargs: str)aiida.engine.processes.exit_code.ExitCode[source]

Create a clone of this exit code where the template message is replaced by the keyword arguments.

Parameters

kwargs – replacement parameters for the template message

invalidates_cache: bool

Alias for field number 2

message: Optional[str]

Alias for field number 1

status: int

Alias for field number 0

class aiida.engine.processes.ExitCodesNamespace(dictionary=None)[source]

Bases: aiida.common.extendeddicts.AttributeDict

A namespace of ExitCode instances 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: str)aiida.engine.processes.exit_code.ExitCode[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 instance

Raises

ValueError – if no exit code with the given label is defined for this process

__module__ = 'aiida.engine.processes.exit_code'
class aiida.engine.processes.FunctionProcess(*args: Any, **kwargs: Any)[source]

Bases: aiida.engine.processes.process.Process

Function process class used for turning functions into a Process

__abstractmethods__ = frozenset({})
__annotations__ = {'_func_args': typing.Sequence[str]}
__init__(*args, **kwargs)None[source]

Process constructor.

Parameters
  • inputs – process inputs

  • logger – aiida logger

  • runner – process runner

  • parent_pid – id of parent process

  • enable_persistence – whether to persist this process

__module__ = 'aiida.engine.processes.functions'
_abc_impl = <_abc_data object>
static _func(*_args, **_kwargs)dict[source]

This is used internally to store the actual function that is being wrapped and will be replaced by the build method.

_func_args: Sequence[str] = ()
_setup_db_record()None[source]

Set up the database record for the process.

_spec = <aiida.engine.processes.process_spec.ProcessSpec object>
classmethod args_to_dict(*args: Any) → Dict[str, Any][source]

Create an input dictionary (of form label -> value) from supplied args.

Parameters

args – The values to use for the dictionary

Returns

A label -> value dictionary

static build(func: Callable[[], Any], node_class: Type[ProcessNode]) → Type[aiida.engine.processes.functions.FunctionProcess][source]

Build a Process from the given function.

All function arguments will be assigned as process inputs. If keyword arguments are specified then these will also become inputs.

Parameters
  • func – The function to build a process from

  • node_class – Provide a custom node class to be used, has to be constructable with no arguments. It has to be a sub class of ProcessNode and the mixin FunctionCalculationMixin.

Returns

A Process class that represents the function

classmethod create_inputs(*args: Any, **kwargs: Any) → Dict[str, Any][source]

Create the input args for the FunctionProcess.

execute() → Optional[Dict[str, Any]][source]

Execute the process.

classmethod get_or_create_db_record()aiida.orm.nodes.process.process.ProcessNode[source]

Create a process node that represents what happened in this process.

Returns

A process node

property process_class

Return the class that represents this Process, for the FunctionProcess this is the function itself.

For a standard Process or sub class of Process, this is the class itself. However, for legacy reasons, the Process class is a wrapper around another class. This function returns that original class, i.e. the class that really represents what was being executed.

Returns

A Process class that represents the function

run() → Optional[ExitCode][source]

Run the process.

classmethod validate_inputs(*args: Any, **kwargs: Any)None[source]

Validate the positional and keyword arguments passed in the function call.

Raises

TypeError – if more positional arguments are passed than the function defines

class aiida.engine.processes.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.

__init__(*args, **kwargs)None[source]

Override the constructor to check the type of the default if set and warn if not immutable.

__module__ = 'aiida.engine.processes.ports'
get_description() → Dict[str, str][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.OutputPort(name: str, valid_type: Optional[Type[Any]] = None, help: Optional[str] = None, required: bool = True, validator: Optional[Callable[[Any, Port], Optional[str]]] = None)[source]

Bases: plumpy.ports.Port

__module__ = 'plumpy.ports'
class aiida.engine.processes.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'
__setitem__(key: str, port: plumpy.ports.Port)None[source]

Ensure that a Port being added inherits the non_db attribute if not explicitly defined at construction.

The reasoning is that if a PortNamespace has non_db=True, which is different from the default value, very often all leaves should be also non_db=True. To prevent a user from having to specify it manually everytime we overload the value here, unless it was specifically set during construction.

Note that the non_db attribute is not present for all Port sub classes so we have to check for it first.

_abc_impl = <_abc_data object>
serialize(mapping: Optional[Dict[str, Any]], breadcrumbs: Sequence[str] = ()) → Optional[Dict[str, Any]][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

  • breadcrumbs – a tuple with the namespaces of parent namespaces

Returns

the serialized mapping

static validate_port_name(port_name: str)None[source]

Validate the given port name.

Valid port names adhere to the following restrictions:

  • Is a valid link label (see below)

  • Does not contain two or more consecutive underscores

Valid link labels adhere to the following restrictions:

  • Has to be a valid python identifier

  • Can only contain alphanumeric characters and underscores

  • Can not start or end with an underscore

Parameters

port_name – the proposed name of the port to be added

Raises
  • TypeError – if the port name is not a string type

  • ValueError – if the port name is invalid

class aiida.engine.processes.Process(*args: Any, **kwargs: Any)[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: str = 'result'
class SaveKeys(value)[source]

Bases: enum.Enum

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

CALC_ID: str = 'calc_id'
__annotations__ = {'CALC_ID': <class 'str'>}
__module__ = 'aiida.engine.processes.process'
__abstractmethods__ = frozenset({})
__annotations__ = {'SINGLE_OUTPUT_LINKNAME': <class 'str'>}
__called = True
__init__(inputs: Optional[Dict[str, Any]] = None, logger: Optional[logging.Logger] = None, runner: Optional[Runner] = None, parent_pid: Optional[int] = None, enable_persistence: bool = True)None[source]

Process constructor.

Parameters
  • inputs – process inputs

  • logger – aiida logger

  • runner – process runner

  • parent_pid – id of parent process

  • enable_persistence – whether to persist this process

__module__ = 'aiida.engine.processes.process'
_abc_impl = <_abc_data object>
_auto_persist: Optional[Set[str]] = {'_creation_time', '_enable_persistence', '_future', '_parent_pid', '_paused', '_pid', '_pre_paused_status', '_status'}
_create_and_setup_db_record() → Union[int, uuid.UUID][source]

Create and setup the database record for this process

Returns

the uuid or pk of the process

_flat_inputs() → Dict[str, Any][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

_flat_outputs() → Dict[str, Any][source]

Return a flattened version of the registered outputs dictionary.

The eventual keys will be a concatenation of the nested keys.

Returns

flat dictionary of parsed outputs

_flatten_inputs(port: Union[None, aiida.engine.processes.ports.InputPort, aiida.engine.processes.ports.PortNamespace], port_value: Any, parent_name: str = '', separator: str = '__') → List[Tuple[str, Any]][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

Returns

flat list of inputs

_flatten_outputs(port: Union[None, plumpy.ports.OutputPort, aiida.engine.processes.ports.PortNamespace], port_value: Any, parent_name: str = '', separator: str = '__') → List[Tuple[str, Any]][source]

Function that will recursively flatten the outputs dictionary.

Parameters
  • port – port against which to map the port value, can be OutputPort 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

Returns

flat list of outputs

static _get_namespace_list(namespace: Optional[str] = None, agglomerate: bool = True) → List[Optional[str]][source]

Get the list of namespaces in a given namespace.

Parameters
  • namespace – name space

  • agglomerate – If set to true, all parent namespaces of the given namespace will also be searched.

Returns

namespace list

_node_class

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

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

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

_setup_metadata()None[source]

Store the metadata on the ProcessNode.

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

alias of aiida.engine.processes.process_spec.ProcessSpec

classmethod build_process_type()str[source]

The process type.

Returns

string of the process type

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: str) → Dict[str, Any][source]

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

Parameters

encoded – encoded (serialized) inputs

Returns

The decoded input args

classmethod define(spec: aiida.engine.processes.process_spec.ProcessSpec)None[source]

Define the specification of the process, including its inputs, outputs and known exit codes.

A metadata input namespace is defined, with optional ports that are not stored in the database.

encode_input_args(inputs: Dict[str, Any])str[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 (serialized) inputs

exit_codes = {'ERROR_INVALID_OUTPUT': ExitCode(status=10, message='The process returned an invalid output.', invalidates_cache=False), 'ERROR_LEGACY_FAILURE': ExitCode(status=2, message='The process failed with legacy failure mode.', invalidates_cache=False), 'ERROR_MISSING_OUTPUT': ExitCode(status=11, message='The process did not register a required output.', invalidates_cache=False), 'ERROR_UNSPECIFIED': ExitCode(status=1, message='The process has failed with an unspecified error.', invalidates_cache=False)}
exposed_inputs(process_class: Type[Process], namespace: Optional[str] = None, agglomerate: bool = True)aiida.common.extendeddicts.AttributeDict[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 – PortNamespace in which to look for the inputs

  • agglomerate – If set to true, all parent namespaces of the given namespace will also be searched for inputs. Inputs in lower-lying namespaces take precedence.

Returns

exposed inputs

exposed_outputs(node: aiida.orm.nodes.process.process.ProcessNode, process_class: Type[Process], namespace: Optional[str] = None, agglomerate: bool = True)aiida.common.extendeddicts.AttributeDict[source]

Return the outputs which were exposed from the process_class and emitted by the specific node

Parameters
  • node – process node whose outputs to try and retrieve

  • namespace – Namespace in which to search for exposed outputs.

  • agglomerate – If set to true, all parent namespaces of the given namespace will also be searched for outputs. Outputs in lower-lying namespaces take precedence.

Returns

exposed outputs

classmethod get_builder()aiida.engine.processes.builder.ProcessBuilder[source]
classmethod get_exit_statuses(exit_code_labels: Iterable[str]) → List[int][source]

Return the exit status (integers) for the given exit code labels.

Parameters

exit_code_labels – a list of strings that reference exit code labels of this process class

Returns

list of exit status integers that correspond to the given exit code labels

Raises

AttributeError – if at least one of the labels does not correspond to an existing exit code

classmethod get_or_create_db_record()aiida.orm.nodes.process.process.ProcessNode[source]

Create a process node that represents what happened in this process.

Returns

A process node

get_parent_calc() → Optional[aiida.orm.nodes.process.process.ProcessNode][source]

Get the parent process node

Returns

the parent process node if there is one

get_provenance_inputs_iterator() → Iterator[Tuple[str, Union[aiida.engine.processes.ports.InputPort, aiida.engine.processes.ports.PortNamespace]]][source]

Get provenance input iterator.

Return type

filter

init()None[source]
classmethod is_valid_cache(node: aiida.orm.nodes.process.process.ProcessNode)bool[source]

Check if the given node can be cached from.

Warning

When overriding this method, make sure to call super().is_valid_cache(node) and respect its output. Otherwise, the ‘invalidates_cache’ keyword on exit codes will not work.

This method allows extending the behavior of ProcessNode.is_valid_cache from Process sub-classes, for example in plug-ins.

kill(msg: Optional[str] = None) → Union[bool, _asyncio.Future][source]

Kill the process and all the children calculations it called

Parameters

msg – message

load_instance_state(saved_state: MutableMapping[str, Any], load_context: plumpy.persistence.LoadSaveContext)None[source]

Load instance state.

Parameters
  • saved_state – saved instance state

  • load_context

property metadata

Return the metadata that were specified when this process instance was launched.

Returns

metadata dictionary

property node

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

Returns

instance of sub class of ProcessNode

on_create()None[source]

Called when a Process is created.

on_entered(from_state: Optional[plumpy.process_states.State])None[source]

After entering a new state, save a checkpoint and update the latest process state change timestamp.

on_entering(state: plumpy.process_states.State)None[source]
on_except(exc_info: Tuple[Any, Exception, traceback])None[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 (type, value, traceback)

on_finish(result: Union[int, aiida.engine.processes.exit_code.ExitCode], successful: bool)None[source]

Set the finish status on the process node.

Parameters
  • result – result of the process

  • successful – whether execution was successful

on_output_emitting(output_port: str, value: Any)None[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: Optional[str] = None)None[source]

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

Parameters

msg – message

on_playing()None[source]

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

on_terminated()None[source]

Called when a Process enters a terminal state.

out(output_port: str, value: Any = None)None[source]

Attach output to output port.

The name of the port will be used as the link label.

Parameters
  • output_port – name of output port

  • value – value to put inside output port

out_many(out_dict: Dict[str, Any])None[source]

Attach outputs to multiple output ports.

Keys of the dictionary will be used as output port names, values as outputs.

Parameters

out_dict (dict) – output dictionary

report(msg: str, *args, **kwargs)None[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

property runner

Get process runner.

save_instance_state(out_state: MutableMapping[str, Any], save_context: Optional[plumpy.persistence.LoadSaveContext])None[source]

Save instance state.

See documentation of plumpy.processes.Process.save_instance_state().

set_status(status: Optional[str])None[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

classmethod spec()aiida.engine.processes.process_spec.ProcessSpec[source]
spec_metadata = <aiida.engine.processes.ports.PortNamespace object>
submit(process: Type[Process], *args, **kwargs)aiida.orm.nodes.process.process.ProcessNode[source]

Submit process for execution.

Parameters

process – process

Returns

the calculation node of the process

update_node_state(state: plumpy.process_states.State)None[source]
update_outputs()None[source]

Attach new outputs to the node since the last call.

Does nothing, if self.metadata.store_provenance is False.

property 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.ProcessBuilder(process_class: Type[Process])[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: Type[Process])[source]

Construct a ProcessBuilder instance for the given Process class.

Parameters

process_class – the Process subclass

__module__ = 'aiida.engine.processes.builder'
_abc_impl = <_abc_data object>
property process_class

Return the process class for which this builder is constructed.

class aiida.engine.processes.ProcessBuilderNamespace(port_namespace: aiida.engine.processes.ports.PortNamespace)[source]

Bases: collections.abc.MutableMapping

Input namespace for the ProcessBuilder.

Dynamically generates the getters and setters for the input ports of a given PortNamespace

__abstractmethods__ = frozenset({})
__delattr__(item)[source]

Implement delattr(self, name).

__delitem__(item)[source]
__dict__ = mappingproxy({'__module__': 'aiida.engine.processes.builder', '__doc__': 'Input namespace for the `ProcessBuilder`.\n\n Dynamically generates the getters and setters for the input ports of a given PortNamespace\n ', '__init__': <function ProcessBuilderNamespace.__init__>, '__setattr__': <function ProcessBuilderNamespace.__setattr__>, '__repr__': <function ProcessBuilderNamespace.__repr__>, '__dir__': <function ProcessBuilderNamespace.__dir__>, '__iter__': <function ProcessBuilderNamespace.__iter__>, '__len__': <function ProcessBuilderNamespace.__len__>, '__getitem__': <function ProcessBuilderNamespace.__getitem__>, '__setitem__': <function ProcessBuilderNamespace.__setitem__>, '__delitem__': <function ProcessBuilderNamespace.__delitem__>, '__delattr__': <function ProcessBuilderNamespace.__delattr__>, '_update': <function ProcessBuilderNamespace._update>, '_inputs': <function ProcessBuilderNamespace._inputs>, '_prune': <function ProcessBuilderNamespace._prune>, '__dict__': <attribute '__dict__' of 'ProcessBuilderNamespace' objects>, '__weakref__': <attribute '__weakref__' of 'ProcessBuilderNamespace' objects>, '__abstractmethods__': frozenset(), '_abc_impl': <_abc_data object>})
__dir__()[source]

Default dir() implementation.

__getitem__(item)[source]
__init__(port_namespace: aiida.engine.processes.ports.PortNamespace)None[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__()[source]

Return repr(self).

__setattr__(attr: str, value: Any)None[source]

Assign the given value to the port with key attr.

Note

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

__setitem__(item, value)[source]
__weakref__

list of weak references to the object (if defined)

_abc_impl = <_abc_data object>
_inputs(prune: bool = False)dict[source]

Return the entire mapping of inputs specified for this builder.

Parameters

prune – boolean, when True, will prune nested namespaces that contain no actual values whatsoever

Returns

mapping of inputs ports and their input values.

_prune(value)[source]

Prune a nested mapping from all mappings that are completely empty.

Note

a nested mapping that is completely empty means it contains at most other empty mappings. Other null values, such as None or empty lists, should not be pruned.

Parameters

value – a nested mapping of port values

Returns

the same mapping but without any nested namespace that is completely empty.

_update(*args, **kwds)[source]

Update the values of the builder namespace passing a mapping as argument or individual keyword value pairs.

The method is prefixed with an underscore in order to not reserve the name for a potential port, but in principle the method functions just as collections.abc.MutableMapping.update.

Parameters
  • args – a single mapping that should be mapped on the namespace

  • kwds – keyword value pairs that should be mapped onto the ports

class aiida.engine.processes.ProcessHandlerReport(do_break: bool = False, exit_code: aiida.engine.processes.exit_code.ExitCode = ExitCode(status=0, message=None, invalidates_cache=False))[source]

Bases: tuple

A namedtuple to define a process handler report for a aiida.engine.BaseRestartWorkChain.

This namedtuple should be returned by a process handler of a work chain instance if the condition of the handler was met by the completed process. If no further handling should be performed after this method the do_break field should be set to True. If the handler encountered a fatal error and the work chain needs to be terminated, an ExitCode with non-zero exit status can be set. This exit code is what will be set on the work chain itself. This works because the value of the exit_code field returned by the handler, will in turn be returned by the inspect_process step and returning a non-zero exit code from any work chain step will instruct the engine to abort the work chain.

Parameters
  • do_break – boolean, set to True if no further process handlers should be called, default is False

  • exit_code – an instance of the ExitCode tuple. If not explicitly set, the default ExitCode will be instantiated, which has status 0 meaning that the work chain step will be considered successful and the work chain will continue to the next step.

__annotations__ = {'do_break': <class 'bool'>, 'exit_code': <class 'aiida.engine.processes.exit_code.ExitCode'>}
__getnewargs__()

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

__module__ = 'aiida.engine.processes.workchains.utils'
static __new__(_cls, do_break: bool = False, exit_code: aiida.engine.processes.exit_code.ExitCode = ExitCode(status=0, message=None, invalidates_cache=False))

Create new instance of ProcessHandlerReport(do_break, exit_code)

__repr__()

Return a nicely formatted representation string

__slots__ = ()
_asdict()

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

_field_defaults = {'do_break': False, 'exit_code': ExitCode(status=0, message=None, invalidates_cache=False)}
_field_types = {'do_break': <class 'bool'>, 'exit_code': <class 'aiida.engine.processes.exit_code.ExitCode'>}
_fields = ('do_break', 'exit_code')
_fields_defaults = {}
classmethod _make(iterable)

Make a new ProcessHandlerReport object from a sequence or iterable

_replace(**kwds)

Return a new ProcessHandlerReport object replacing specified fields with new values

do_break: bool

Alias for field number 0

exit_code: aiida.engine.processes.exit_code.ExitCode

Alias for field number 1

class aiida.engine.processes.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: str = 'metadata'
METADATA_OPTIONS_KEY: str = 'options'
PORT_NAMESPACE_TYPE

alias of aiida.engine.processes.ports.PortNamespace

__annotations__ = {'METADATA_KEY': <class 'str'>, 'METADATA_OPTIONS_KEY': <class 'str'>}
__init__()None[source]

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

__module__ = 'aiida.engine.processes.process_spec'
exit_code(status: int, label: str, message: str, invalidates_cache: bool = False)None[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

  • invalidates_cache – when set to True, a process exiting with this exit code will not be considered for caching

property exit_codes

Return the namespace of exit codes defined for this ProcessSpec

Returns

ExitCodesNamespace of ExitCode named tuples

property inputs

Get the input port namespace of the process specification

Returns

the input PortNamespace

property metadata_key
property options_key
property outputs

Get the output port namespace of the process specification

Returns

the outputs PortNamespace

property ports
class aiida.engine.processes.ProcessState(value)[source]

Bases: enum.Enum

The possible states that a Process can be in.

CREATED: str = 'created'
EXCEPTED: str = 'excepted'
FINISHED: str = 'finished'
KILLED: str = 'killed'
RUNNING: str = 'running'
WAITING: str = 'waiting'
__annotations__ = {'CREATED': <class 'str'>, 'EXCEPTED': <class 'str'>, 'FINISHED': <class 'str'>, 'KILLED': <class 'str'>, 'RUNNING': <class 'str'>, 'WAITING': <class 'str'>}
__module__ = 'plumpy.process_states'
aiida.engine.processes.ToContext

alias of builtins.dict

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

Bases: object

A mixin that adds support to a port to flag that it 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__ = mappingproxy({'__module__': 'aiida.engine.processes.ports', '__doc__': '\n A mixin that adds support to a port to flag that it 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 WithNonDb.__init__>, 'non_db_explicitly_set': <property object>, 'non_db': <property object>, '__dict__': <attribute '__dict__' of 'WithNonDb' objects>, '__weakref__': <attribute '__weakref__' of 'WithNonDb' objects>})
__init__(*args, **kwargs)None[source]

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

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

list of weak references to the object (if defined)

property non_db

Return whether the value of this Port should be stored as a Node in the database.

Returns

boolean, True if it should be storable as a Node, False otherwise

property non_db_explicitly_set

Return whether the a value for non_db was explicitly passed in the construction of the Port.

Returns

boolean, True if non_db was explicitly defined during construction, False otherwise

class aiida.engine.processes.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__ = mappingproxy({'__module__': 'aiida.engine.processes.ports', '__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 WithSerialize.__init__>, 'serialize': <function WithSerialize.serialize>, '__dict__': <attribute '__dict__' of 'WithSerialize' objects>, '__weakref__': <attribute '__weakref__' of 'WithSerialize' objects>})
__init__(*args, **kwargs)None[source]

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

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

list of weak references to the object (if defined)

serialize(value: Any)aiida.orm.nodes.data.data.Data[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

class aiida.engine.processes.WorkChain(*args: Any, **kwargs: Any)[source]

Bases: aiida.engine.processes.process.Process

The WorkChain class is the principle component to implement workflows in AiiDA.

_CONTEXT = 'CONTEXT'
_STEPPER_STATE = 'stepper_state'
__abstractmethods__ = frozenset({})
__init__(inputs: Optional[dict] = None, logger: Optional[logging.Logger] = None, runner: Optional[Runner] = None, enable_persistence: bool = True)None[source]

Construct a WorkChain instance.

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

Parameters
  • inputs – work chain inputs

  • logger – aiida logger

  • runner – work chain runner

  • enable_persistence – whether to persist this work chain

__module__ = 'aiida.engine.processes.workchains.workchain'
_abc_impl = <_abc_data object>
_auto_persist: Optional[Set[str]] = {'_awaitables', '_creation_time', '_enable_persistence', '_future', '_parent_pid', '_paused', '_pid', '_pre_paused_status', '_status'}
_do_step() → Any[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_class

alias of WorkChainSpec

_store_nodes(data: Any)None[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

_update_process_status()None[source]

Set the process status with a message accounting the current sub processes that we are waiting for.

action_awaitables()None[source]

Handle the awaitables that are currently registered with the work chain.

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

property ctx

Get the context.

insert_awaitable(awaitable: aiida.engine.processes.workchains.awaitable.Awaitable)None[source]

Insert an awaitable that should be terminated before 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]

Load instance state.

Parameters
  • saved_state – saved instance state

  • load_context

on_exiting()None[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: aiida.engine.processes.workchains.awaitable.Awaitable)None[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 work chain and removed from the internal list. If all awaitables have been dealt with, the work chain process is resumed.

Parameters

awaitable – an Awaitable instance

on_run()[source]
on_wait(awaitables: Sequence[aiida.engine.processes.workchains.awaitable.Awaitable])[source]

Entering the WAITING state.

resolve_awaitable(awaitable: aiida.engine.processes.workchains.awaitable.Awaitable, value: Any)None[source]

Resolve an awaitable.

Precondition: must be an awaitable that was previously inserted.

Parameters

awaitable – the awaitable to resolve

run() → Any[source]

This function will be run when the process is triggered. It should be overridden by a subclass.

save_instance_state(out_state, save_context)[source]

Save instance state.

Parameters
  • out_state – state to save in

  • save_context (plumpy.persistence.LoadSaveContext) –

classmethod spec() → aiida.engine.processes.workchains.workchain.WorkChainSpec[source]
to_context(**kwargs: Union[aiida.engine.processes.workchains.awaitable.Awaitable, aiida.orm.nodes.process.process.ProcessNode])None[source]

Add a dictionary of awaitables to the context.

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

aiida.engine.processes.append_(target: Union[aiida.engine.processes.workchains.awaitable.Awaitable, aiida.orm.nodes.process.process.ProcessNode])aiida.engine.processes.workchains.awaitable.Awaitable[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

aiida.engine.processes.assign_(target: Union[aiida.engine.processes.workchains.awaitable.Awaitable, aiida.orm.nodes.process.process.ProcessNode])aiida.engine.processes.workchains.awaitable.Awaitable[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

aiida.engine.processes.calcfunction(function: Callable[[], Any]) → Callable[[], Any][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() 
[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]
Parameters

function (callable) – The function to decorate.

Returns

The decorated function.

Return type

callable

aiida.engine.processes.if_(condition: Callable[[WorkChain], bool]) → plumpy.workchains._If[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.process_handler(wrapped: Optional[function] = None, *, priority: int = 0, exit_codes: Union[None, aiida.engine.processes.exit_code.ExitCode, List[aiida.engine.processes.exit_code.ExitCode]] = None, enabled: bool = True) → function[source]

Decorator to register a BaseRestartWorkChain instance method as a process handler.

The decorator will validate the priority and exit_codes optional keyword arguments and then add itself as an attribute to the wrapped instance method. This is used in the inspect_process to return all instance methods of the class that have been decorated by this function and therefore are considered to be process handlers.

Requirements on the function signature of process handling functions. The function to which the decorator is applied needs to take two arguments:

  • self: This is the instance of the work chain itself

  • node: This is the process node that finished and is to be investigated

The function body typically consists of a conditional that will check for a particular problem that might have occurred for the sub process. If a particular problem is handled, the process handler should return an instance of the aiida.engine.ProcessHandlerReport tuple. If no other process handlers should be considered, the set do_break attribute should be set to True. If the work chain is to be aborted entirely, the exit_code of the report can be set to an ExitCode instance with a non-zero status.

Parameters
  • wrapped – the work chain method to register the process handler with

  • priority – optional integer that defines the order in which registered handlers will be called during the handling of a finished process. Higher priorities will be handled first. Default value is 0. Multiple handlers with the same priority is allowed, but the order of those is not well defined.

  • exit_codes – single or list of ExitCode instances. If defined, the handler will return None if the exit code set on the node does not appear in the exit_codes. This is useful to have a handler called only when the process failed with a specific exit code.

  • enabled – boolean, by default True, which will cause the handler to be called during inspect_process. When set to False, the handler will be skipped. This static value can be overridden on a per work chain instance basis through the input handler_overrides.

aiida.engine.processes.while_(condition: Callable[[WorkChain], bool]) → plumpy.workchains._While[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

aiida.engine.processes.workfunction(function: Callable[[], Any]) → Callable[[], Any][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() 
[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]
Parameters

function (callable) – The function to decorate.

Returns

The decorated function.

Submodules

Convenience classes to help building the input dictionaries for Processes.

class aiida.engine.processes.builder.ProcessBuilder(process_class: Type[Process])[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: Type[Process])[source]

Construct a ProcessBuilder instance for the given Process class.

Parameters

process_class – the Process subclass

__module__ = 'aiida.engine.processes.builder'
_abc_impl = <_abc_data object>
property process_class

Return the process class for which this builder is constructed.

class aiida.engine.processes.builder.ProcessBuilderNamespace(port_namespace: aiida.engine.processes.ports.PortNamespace)[source]

Bases: collections.abc.MutableMapping

Input namespace for the ProcessBuilder.

Dynamically generates the getters and setters for the input ports of a given PortNamespace

__abstractmethods__ = frozenset({})
__delattr__(item)[source]

Implement delattr(self, name).

__delitem__(item)[source]
__dict__ = mappingproxy({'__module__': 'aiida.engine.processes.builder', '__doc__': 'Input namespace for the `ProcessBuilder`.\n\n Dynamically generates the getters and setters for the input ports of a given PortNamespace\n ', '__init__': <function ProcessBuilderNamespace.__init__>, '__setattr__': <function ProcessBuilderNamespace.__setattr__>, '__repr__': <function ProcessBuilderNamespace.__repr__>, '__dir__': <function ProcessBuilderNamespace.__dir__>, '__iter__': <function ProcessBuilderNamespace.__iter__>, '__len__': <function ProcessBuilderNamespace.__len__>, '__getitem__': <function ProcessBuilderNamespace.__getitem__>, '__setitem__': <function ProcessBuilderNamespace.__setitem__>, '__delitem__': <function ProcessBuilderNamespace.__delitem__>, '__delattr__': <function ProcessBuilderNamespace.__delattr__>, '_update': <function ProcessBuilderNamespace._update>, '_inputs': <function ProcessBuilderNamespace._inputs>, '_prune': <function ProcessBuilderNamespace._prune>, '__dict__': <attribute '__dict__' of 'ProcessBuilderNamespace' objects>, '__weakref__': <attribute '__weakref__' of 'ProcessBuilderNamespace' objects>, '__abstractmethods__': frozenset(), '_abc_impl': <_abc_data object>})
__dir__()[source]

Default dir() implementation.

__getitem__(item)[source]
__init__(port_namespace: aiida.engine.processes.ports.PortNamespace)None[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__()[source]

Return repr(self).

__setattr__(attr: str, value: Any)None[source]

Assign the given value to the port with key attr.

Note

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

__setitem__(item, value)[source]
__weakref__

list of weak references to the object (if defined)

_abc_impl = <_abc_data object>
_inputs(prune: bool = False)dict[source]

Return the entire mapping of inputs specified for this builder.

Parameters

prune – boolean, when True, will prune nested namespaces that contain no actual values whatsoever

Returns

mapping of inputs ports and their input values.

_prune(value)[source]

Prune a nested mapping from all mappings that are completely empty.

Note

a nested mapping that is completely empty means it contains at most other empty mappings. Other null values, such as None or empty lists, should not be pruned.

Parameters

value – a nested mapping of port values

Returns

the same mapping but without any nested namespace that is completely empty.

_update(*args, **kwds)[source]

Update the values of the builder namespace passing a mapping as argument or individual keyword value pairs.

The method is prefixed with an underscore in order to not reserve the name for a potential port, but in principle the method functions just as collections.abc.MutableMapping.update.

Parameters
  • args – a single mapping that should be mapped on the namespace

  • kwds – keyword value pairs that should be mapped onto the ports

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

class aiida.engine.processes.exit_code.ExitCode(status: int = 0, message: Optional[str] = None, invalidates_cache: bool = False)[source]

Bases: tuple

A simple data class to define an exit code for a Process.

When an instance of this class is returned from a Process._run() call, it will be interpreted that the Process should be terminated and that the exit status and message of the namedtuple should be set to the corresponding attributes of the node.

Parameters
  • status – positive integer exit status, where a non-zero value indicated the process failed, default is 0

  • message – optional message with more details about the failure mode

  • invalidates_cache – optional flag, indicating that a process should not be used in caching

__annotations__ = {'invalidates_cache': <class 'bool'>, 'message': typing.Union[str, NoneType], 'status': <class 'int'>}
__getnewargs__()

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

__module__ = 'aiida.engine.processes.exit_code'
static __new__(_cls, status: int = 0, message: Optional[str] = None, invalidates_cache: bool = False)

Create new instance of ExitCode(status, message, invalidates_cache)

__repr__()

Return a nicely formatted representation string

__slots__ = ()
_asdict()

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

_field_defaults = {'invalidates_cache': False, 'message': None, 'status': 0}
_field_types = {'invalidates_cache': <class 'bool'>, 'message': typing.Union[str, NoneType], 'status': <class 'int'>}
_fields = ('status', 'message', 'invalidates_cache')
_fields_defaults = {}
classmethod _make(iterable)

Make a new ExitCode object from a sequence or iterable

_replace(**kwds)

Return a new ExitCode object replacing specified fields with new values

format(**kwargs: str)aiida.engine.processes.exit_code.ExitCode[source]

Create a clone of this exit code where the template message is replaced by the keyword arguments.

Parameters

kwargs – replacement parameters for the template message

invalidates_cache: bool

Alias for field number 2

message: Optional[str]

Alias for field number 1

status: int

Alias for field number 0

class aiida.engine.processes.exit_code.ExitCodesNamespace(dictionary=None)[source]

Bases: aiida.common.extendeddicts.AttributeDict

A namespace of ExitCode instances 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: str)aiida.engine.processes.exit_code.ExitCode[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 instance

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.

class aiida.engine.processes.functions.FunctionProcess(*args: Any, **kwargs: Any)[source]

Bases: aiida.engine.processes.process.Process

Function process class used for turning functions into a Process

__abstractmethods__ = frozenset({})
__annotations__ = {'_func_args': typing.Sequence[str]}
__init__(*args, **kwargs)None[source]

Process constructor.

Parameters
  • inputs – process inputs

  • logger – aiida logger

  • runner – process runner

  • parent_pid – id of parent process

  • enable_persistence – whether to persist this process

__module__ = 'aiida.engine.processes.functions'
_abc_impl = <_abc_data object>
static _func(*_args, **_kwargs)dict[source]

This is used internally to store the actual function that is being wrapped and will be replaced by the build method.

_func_args: Sequence[str] = ()
_setup_db_record()None[source]

Set up the database record for the process.

_spec = <aiida.engine.processes.process_spec.ProcessSpec object>
classmethod args_to_dict(*args: Any) → Dict[str, Any][source]

Create an input dictionary (of form label -> value) from supplied args.

Parameters

args – The values to use for the dictionary

Returns

A label -> value dictionary

static build(func: Callable[[], Any], node_class: Type[ProcessNode]) → Type[aiida.engine.processes.functions.FunctionProcess][source]

Build a Process from the given function.

All function arguments will be assigned as process inputs. If keyword arguments are specified then these will also become inputs.

Parameters
  • func – The function to build a process from

  • node_class – Provide a custom node class to be used, has to be constructable with no arguments. It has to be a sub class of ProcessNode and the mixin FunctionCalculationMixin.

Returns

A Process class that represents the function

classmethod create_inputs(*args: Any, **kwargs: Any) → Dict[str, Any][source]

Create the input args for the FunctionProcess.

execute() → Optional[Dict[str, Any]][source]

Execute the process.

classmethod get_or_create_db_record()aiida.orm.nodes.process.process.ProcessNode[source]

Create a process node that represents what happened in this process.

Returns

A process node

property process_class

Return the class that represents this Process, for the FunctionProcess this is the function itself.

For a standard Process or sub class of Process, this is the class itself. However, for legacy reasons, the Process class is a wrapper around another class. This function returns that original class, i.e. the class that really represents what was being executed.

Returns

A Process class that represents the function

run() → Optional[ExitCode][source]

Run the process.

classmethod validate_inputs(*args: Any, **kwargs: Any)None[source]

Validate the positional and keyword arguments passed in the function call.

Raises

TypeError – if more positional arguments are passed than the function defines

aiida.engine.processes.functions.calcfunction(function: Callable[[], Any]) → Callable[[], Any][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() 
[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]
Parameters

function (callable) – The function to decorate.

Returns

The decorated function.

Return type

callable

aiida.engine.processes.functions.workfunction(function: Callable[[], Any]) → Callable[[], Any][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() 
[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]
Parameters

function (callable) – The function to decorate.

Returns

The decorated function.

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

class aiida.engine.processes.futures.ProcessFuture(pk: int, loop: Optional[asyncio.events.AbstractEventLoop] = None, poll_interval: Union[None, int, float] = None, communicator: Optional[kiwipy.communications.Communicator] = None)[source]

Bases: _asyncio.Future

Future that waits for a process to complete using both polling and listening for broadcast events if possible.

__init__(pk: int, loop: Optional[asyncio.events.AbstractEventLoop] = None, poll_interval: Union[None, int, float] = None, communicator: Optional[kiwipy.communications.Communicator] = None)[source]

Construct a future for a process 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 – process pk

  • loop – An event loop

  • poll_interval – optional polling interval, if None, polling is not activated.

  • communicator – optional communicator, if None, will not subscribe to broadcasts.

__module__ = 'aiida.engine.processes.futures'
_filtered = None
async _poll_process(node: aiida.orm.nodes.node.Node, poll_interval: Union[int, float])None[source]

Poll whether the process node has reached a terminal state.

cleanup()None[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.

__init__(*args, **kwargs)None[source]

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

__module__ = 'aiida.engine.processes.ports'
property 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.

__init__(*args, **kwargs)None[source]

Override the constructor to check the type of the default if set and warn if not immutable.

__module__ = 'aiida.engine.processes.ports'
get_description() → Dict[str, str][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.OutputPort(name: str, valid_type: Optional[Type[Any]] = None, help: Optional[str] = None, required: bool = True, validator: Optional[Callable[[Any, Port], Optional[str]]] = None)[source]

Bases: plumpy.ports.Port

__module__ = 'plumpy.ports'
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'
__setitem__(key: str, port: plumpy.ports.Port)None[source]

Ensure that a Port being added inherits the non_db attribute if not explicitly defined at construction.

The reasoning is that if a PortNamespace has non_db=True, which is different from the default value, very often all leaves should be also non_db=True. To prevent a user from having to specify it manually everytime we overload the value here, unless it was specifically set during construction.

Note that the non_db attribute is not present for all Port sub classes so we have to check for it first.

_abc_impl = <_abc_data object>
serialize(mapping: Optional[Dict[str, Any]], breadcrumbs: Sequence[str] = ()) → Optional[Dict[str, Any]][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

  • breadcrumbs – a tuple with the namespaces of parent namespaces

Returns

the serialized mapping

static validate_port_name(port_name: str)None[source]

Validate the given port name.

Valid port names adhere to the following restrictions:

  • Is a valid link label (see below)

  • Does not contain two or more consecutive underscores

Valid link labels adhere to the following restrictions:

  • Has to be a valid python identifier

  • Can only contain alphanumeric characters and underscores

  • Can not start or end with an underscore

Parameters

port_name – the proposed name of the port to be added

Raises
  • TypeError – if the port name is not a string type

  • ValueError – if the port name is invalid

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

Bases: object

A mixin that adds support to a port to flag that it 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__ = mappingproxy({'__module__': 'aiida.engine.processes.ports', '__doc__': '\n A mixin that adds support to a port to flag that it 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 WithNonDb.__init__>, 'non_db_explicitly_set': <property object>, 'non_db': <property object>, '__dict__': <attribute '__dict__' of 'WithNonDb' objects>, '__weakref__': <attribute '__weakref__' of 'WithNonDb' objects>})
__init__(*args, **kwargs)None[source]

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

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

list of weak references to the object (if defined)

property non_db

Return whether the value of this Port should be stored as a Node in the database.

Returns

boolean, True if it should be storable as a Node, False otherwise

property non_db_explicitly_set

Return whether the a value for non_db was explicitly passed in the construction of the Port.

Returns

boolean, True if non_db was explicitly defined during construction, False otherwise

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__ = mappingproxy({'__module__': 'aiida.engine.processes.ports', '__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 WithSerialize.__init__>, 'serialize': <function WithSerialize.serialize>, '__dict__': <attribute '__dict__' of 'WithSerialize' objects>, '__weakref__': <attribute '__weakref__' of 'WithSerialize' objects>})
__init__(*args, **kwargs)None[source]

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

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

list of weak references to the object (if defined)

serialize(value: Any)aiida.orm.nodes.data.data.Data[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(*args: Any, **kwargs: Any)[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: str = 'result'
class SaveKeys(value)[source]

Bases: enum.Enum

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

CALC_ID: str = 'calc_id'
__annotations__ = {'CALC_ID': <class 'str'>}
__module__ = 'aiida.engine.processes.process'
__abstractmethods__ = frozenset({})
__annotations__ = {'SINGLE_OUTPUT_LINKNAME': <class 'str'>}
__called = True
__init__(inputs: Optional[Dict[str, Any]] = None, logger: Optional[logging.Logger] = None, runner: Optional[Runner] = None, parent_pid: Optional[int] = None, enable_persistence: bool = True)None[source]

Process constructor.

Parameters
  • inputs – process inputs

  • logger – aiida logger

  • runner – process runner

  • parent_pid – id of parent process

  • enable_persistence – whether to persist this process

__module__ = 'aiida.engine.processes.process'
_abc_impl = <_abc_data object>
_auto_persist: Optional[Set[str]] = {'_creation_time', '_enable_persistence', '_future', '_parent_pid', '_paused', '_pid', '_pre_paused_status', '_status'}
_create_and_setup_db_record() → Union[int, uuid.UUID][source]

Create and setup the database record for this process

Returns

the uuid or pk of the process

_flat_inputs() → Dict[str, Any][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

_flat_outputs() → Dict[str, Any][source]

Return a flattened version of the registered outputs dictionary.

The eventual keys will be a concatenation of the nested keys.

Returns

flat dictionary of parsed outputs

_flatten_inputs(port: Union[None, aiida.engine.processes.ports.InputPort, aiida.engine.processes.ports.PortNamespace], port_value: Any, parent_name: str = '', separator: str = '__') → List[Tuple[str, Any]][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

Returns

flat list of inputs

_flatten_outputs(port: Union[None, plumpy.ports.OutputPort, aiida.engine.processes.ports.PortNamespace], port_value: Any, parent_name: str = '', separator: str = '__') → List[Tuple[str, Any]][source]

Function that will recursively flatten the outputs dictionary.

Parameters
  • port – port against which to map the port value, can be OutputPort 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

Returns

flat list of outputs

static _get_namespace_list(namespace: Optional[str] = None, agglomerate: bool = True) → List[Optional[str]][source]

Get the list of namespaces in a given namespace.

Parameters
  • namespace – name space

  • agglomerate – If set to true, all parent namespaces of the given namespace will also be searched.

Returns

namespace list

_node_class

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

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

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

_setup_metadata()None[source]

Store the metadata on the ProcessNode.

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

alias of aiida.engine.processes.process_spec.ProcessSpec

classmethod build_process_type()str[source]

The process type.

Returns

string of the process type

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: str) → Dict[str, Any][source]

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

Parameters

encoded – encoded (serialized) inputs

Returns

The decoded input args

classmethod define(spec: aiida.engine.processes.process_spec.ProcessSpec)None[source]

Define the specification of the process, including its inputs, outputs and known exit codes.

A metadata input namespace is defined, with optional ports that are not stored in the database.

encode_input_args(inputs: Dict[str, Any])str[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 (serialized) inputs

exit_codes = {'ERROR_INVALID_OUTPUT': ExitCode(status=10, message='The process returned an invalid output.', invalidates_cache=False), 'ERROR_LEGACY_FAILURE': ExitCode(status=2, message='The process failed with legacy failure mode.', invalidates_cache=False), 'ERROR_MISSING_OUTPUT': ExitCode(status=11, message='The process did not register a required output.', invalidates_cache=False), 'ERROR_UNSPECIFIED': ExitCode(status=1, message='The process has failed with an unspecified error.', invalidates_cache=False)}
exposed_inputs(process_class: Type[Process], namespace: Optional[str] = None, agglomerate: bool = True)aiida.common.extendeddicts.AttributeDict[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 – PortNamespace in which to look for the inputs

  • agglomerate – If set to true, all parent namespaces of the given namespace will also be searched for inputs. Inputs in lower-lying namespaces take precedence.

Returns

exposed inputs

exposed_outputs(node: aiida.orm.nodes.process.process.ProcessNode, process_class: Type[Process], namespace: Optional[str] = None, agglomerate: bool = True)aiida.common.extendeddicts.AttributeDict[source]

Return the outputs which were exposed from the process_class and emitted by the specific node

Parameters
  • node – process node whose outputs to try and retrieve

  • namespace – Namespace in which to search for exposed outputs.

  • agglomerate – If set to true, all parent namespaces of the given namespace will also be searched for outputs. Outputs in lower-lying namespaces take precedence.

Returns

exposed outputs

classmethod get_builder()aiida.engine.processes.builder.ProcessBuilder[source]
classmethod get_exit_statuses(exit_code_labels: Iterable[str]) → List[int][source]

Return the exit status (integers) for the given exit code labels.

Parameters

exit_code_labels – a list of strings that reference exit code labels of this process class

Returns

list of exit status integers that correspond to the given exit code labels

Raises

AttributeError – if at least one of the labels does not correspond to an existing exit code

classmethod get_or_create_db_record()aiida.orm.nodes.process.process.ProcessNode[source]

Create a process node that represents what happened in this process.

Returns

A process node

get_parent_calc() → Optional[aiida.orm.nodes.process.process.ProcessNode][source]

Get the parent process node

Returns

the parent process node if there is one

get_provenance_inputs_iterator() → Iterator[Tuple[str, Union[aiida.engine.processes.ports.InputPort, aiida.engine.processes.ports.PortNamespace]]][source]

Get provenance input iterator.

Return type

filter

init()None[source]
classmethod is_valid_cache(node: aiida.orm.nodes.process.process.ProcessNode)bool[source]

Check if the given node can be cached from.

Warning

When overriding this method, make sure to call super().is_valid_cache(node) and respect its output. Otherwise, the ‘invalidates_cache’ keyword on exit codes will not work.

This method allows extending the behavior of ProcessNode.is_valid_cache from Process sub-classes, for example in plug-ins.

kill(msg: Optional[str] = None) → Union[bool, _asyncio.Future][source]

Kill the process and all the children calculations it called

Parameters

msg – message

load_instance_state(saved_state: MutableMapping[str, Any], load_context: plumpy.persistence.LoadSaveContext)None[source]

Load instance state.

Parameters
  • saved_state – saved instance state

  • load_context

property metadata

Return the metadata that were specified when this process instance was launched.

Returns

metadata dictionary

property node

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

Returns

instance of sub class of ProcessNode

on_create()None[source]

Called when a Process is created.

on_entered(from_state: Optional[plumpy.process_states.State])None[source]

After entering a new state, save a checkpoint and update the latest process state change timestamp.

on_entering(state: plumpy.process_states.State)None[source]
on_except(exc_info: Tuple[Any, Exception, traceback])None[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 (type, value, traceback)

on_finish(result: Union[int, aiida.engine.processes.exit_code.ExitCode], successful: bool)None[source]

Set the finish status on the process node.

Parameters
  • result – result of the process

  • successful – whether execution was successful

on_output_emitting(output_port: str, value: Any)None[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: Optional[str] = None)None[source]

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

Parameters

msg – message

on_playing()None[source]

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

on_terminated()None[source]

Called when a Process enters a terminal state.

out(output_port: str, value: Any = None)None[source]

Attach output to output port.

The name of the port will be used as the link label.

Parameters
  • output_port – name of output port

  • value – value to put inside output port

out_many(out_dict: Dict[str, Any])None[source]

Attach outputs to multiple output ports.

Keys of the dictionary will be used as output port names, values as outputs.

Parameters

out_dict (dict) – output dictionary

report(msg: str, *args, **kwargs)None[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

property runner

Get process runner.

save_instance_state(out_state: MutableMapping[str, Any], save_context: Optional[plumpy.persistence.LoadSaveContext])None[source]

Save instance state.

See documentation of plumpy.processes.Process.save_instance_state().

set_status(status: Optional[str])None[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

classmethod spec()aiida.engine.processes.process_spec.ProcessSpec[source]
spec_metadata = <aiida.engine.processes.ports.PortNamespace object>
submit(process: Type[Process], *args, **kwargs)aiida.orm.nodes.process.process.ProcessNode[source]

Submit process for execution.

Parameters

process – process

Returns

the calculation node of the process

update_node_state(state: plumpy.process_states.State)None[source]
update_outputs()None[source]

Attach new outputs to the node since the last call.

Does nothing, if self.metadata.store_provenance is False.

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

Bases: enum.Enum

The possible states that a Process can be in.

CREATED: str = 'created'
EXCEPTED: str = 'excepted'
FINISHED: str = 'finished'
KILLED: str = 'killed'
RUNNING: str = 'running'
WAITING: str = 'waiting'
__annotations__ = {'CREATED': <class 'str'>, 'EXCEPTED': <class 'str'>, 'FINISHED': <class 'str'>, 'KILLED': <class 'str'>, 'RUNNING': <class 'str'>, 'WAITING': <class 'str'>}
__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__()None[source]

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

__module__ = 'aiida.engine.processes.process_spec'
property 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: str = 'metadata'
METADATA_OPTIONS_KEY: str = 'options'
PORT_NAMESPACE_TYPE

alias of aiida.engine.processes.ports.PortNamespace

__annotations__ = {'METADATA_KEY': <class 'str'>, 'METADATA_OPTIONS_KEY': <class 'str'>}
__init__()None[source]

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

__module__ = 'aiida.engine.processes.process_spec'
exit_code(status: int, label: str, message: str, invalidates_cache: bool = False)None[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

  • invalidates_cache – when set to True, a process exiting with this exit code will not be considered for caching

property exit_codes

Return the namespace of exit codes defined for this ProcessSpec

Returns

ExitCodesNamespace of ExitCode named tuples

property inputs

Get the input port namespace of the process specification

Returns

the input PortNamespace

property metadata_key
property options_key
property outputs

Get the output port namespace of the process specification

Returns

the outputs PortNamespace

property ports