This section describes the different classes related to workflows, workfunctions and WorkChains.

class'/tmp/running', finished_directory='/tmp/running/finished', failed_directory='/tmp/running/failed')[source]

Class that uses pickles stored in particular directories to persist the instance state of Processes.

classmethod create_from_basedir(basedir, **kwargs)[source]
Create using a base directory, the pickles will be stored in:
  • running: [basedir]/running
  • finished: [basedir]/finished
  • failed: [basedir]/failed
  • basedir (str) – The base directory to storage pickle under
  • kwargs – Any additional arguments to pass to the constructor

A new instance.


Try and load a process from a file and recreate the Process instance. To prevent multiple threads from recreating a Process from the same pickle, before loading the state from the file, a reentrant lock is created, which will except if the file is already locked. Within a lock context manager, we then attempt to recreate the Process from the process state and when successful we acquire the lock.

Parameters:filepath – path to the pickle to be loaded as a Process
Returns:Process instance

Get the path where the pickle for a process with pid will be stored while it’s running.

Parameters:pid – The process pid
Returns:A string to the absolute path of where the pickle is stored.
Return type:str

Will detect all pickles in the running directory and will try to load them up into Processes. As soon as a pickle is considered for loading, a lock is placed on it, which is not released until the process is destroyed. This is necessary to prevent another thread from loading up the same process.

Returns:a list of Process instances
class, mode='a', timeout=5, check_interval=0.25, fail_when_locked=False, flags=6)[source]

A reentrant lock, functions in a similar way to threading.RLock in that it can be acquired multiple times. When the corresponding number of release() calls are made the lock will finally release the underlying file lock.


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

class SaveKeys[source]

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

classmethod create_db_record()[source]

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


Called when a Process enters the DESTROYED state which should be the final process state and so we seal the calculation node


Called when a Process enters the FINISHED state at which point we set the corresponding attribute of the workcalculation node

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

Log a message to the logger, which should get saved to the database through the attached DbLogHandler. The class name and function name of the caller are prepended to the given message


This class is a knowledge provider that uses the AiiDA database to answer questions related to processes.

class, pid)

Alias for field number 1


Alias for field number 0


A type to indicate what type of object is running: a process, a calculation or a workflow[source]

Create a RunningInfo object for a legacy calculation

Parameters:pk (int) – The calculation pk
Returns:The running info
Return type:RunningInfo[source]

Create a RunningInfo object for a legacy workflow.

This can be used in conjunction with as follows:

>>> from import WorkChain, ToContext, Outputs
>>> class MyWf(WorkChain):
>>>     @classmethod
>>>     def define(cls, spec):
>>>         super(MyWf, cls).define(spec)
>>>         spec.outline(cls.step1, cls.step2)
>>>     def step1(self):
>>>         wf = OldEquationOfState()
>>>         wf.start()
>>>         return ToContext(eos=legacy_workflow(
>>>     def step2(self):
>>>         # Now self.ctx.eos contains the terminated workflow
>>>         pass
Parameters:pk (int) – The workflow pk
Returns:The running info
Return type:RunningInfo, inputs, storage)[source]

This queues up the Process so that it’s executed by the daemon when it gets around to it.

  • process_class – The process class to queue up.
  • inputs (Mapping) – The inputs to the process.
  • storage – The storage engine which will be used to save the process (of type plum.persistence)

The pid of the queued process., *args, **inputs)[source]

Synchronously (i.e. blocking) run a workfunction or process.

  • process_class – The process class or workfunction
  • _attributes – Optional attributes (only for process)
  • args – Positional arguments for a workfunction
  • inputs – The list of inputs

A Process that emits an output that isn’t part of the spec raising an exception.


A Process that does nothing when it runs.


Keep track of the per-thread call stack of processes.

classmethod get_active_process_calc_node()[source]

Get the calculation node of the process at the top of the stack

Returns:The calculation node
Return type:aiida.orm.implementation.general.calculation.job.AbstractJobCalculation
classmethod get_active_process_id()[source]

Get the pid of the process at the top of the stack

Returns:The pid
classmethod pop(process=None, pid=None)[source]

Pop a process from the stack. To make sure the stack is not corrupted the process instance or pid of the calling process should be supplied so we can verify that is really is top of the stack.

  • process – The process instance
  • pid – The process id.[source]

For a given Calculation, get or create a new frozendict Data node that has as its values all output Data nodes of the Calculation.

Parameters:calculation – Calculation[source]

Load a class from a string**kwargs)[source]

Utility function that returns a list of UpdateContext Interstep instances

NOTE: This is effectively a copy of WorkChain.to_context method added to keep backwards compatibility, but should eventually be deprecated


A WorkChain, the base class for AiiDA workflows.

abort(msg=None, timeout=None)[source]

Abort the workchain by calling the abort method of the Process and also adding the abort message to the report

  • msg (str) – The abort message
  • timeout (float) – Wait for the given time until the process has aborted

True if the process is aborted at the end of the function, False otherwise


Abort the workchain at the next state transition without waiting which is achieved by passing a timeout value of zero

Parameters:msg (str) – The abort message

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

Parameters:wait_on – The thing to wait on (of type plum.wait.wait_on)

Insert an interstep to be executed after the current step ends but before the next step ends

Parameters:interstep – class:Interstep

Remove a barrier.

Precondition: must be a barrier that was previously inserted

Parameters:wait_on – The wait on to remove (of type plum.wait.wait_on)

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

A conditional that can be used in a workchain outline.

Use as:


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

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

Use as:


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

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

This file provides very simple workflows for testing purposes. Do not delete, otherwise ‘verdi developertest’ will stop to work.[source]

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

>>> from import Int
>>> from import workfunction as wf
>>> # Define the workfunction
>>> @wf
>>> def sum(a, b):
>>>    return a + b
>>> # Run it with some input
>>> r = sum(Int(4), Int(5))
>>> print(r)
>>> r.get_inputs_dict() 
{u'_return': <WorkCalculation: uuid: ce0c63b3-1c84-4bb8-ba64-7b70a36adf34 (pk: 3567)>}
>>> r.get_inputs_dict()['_return'].get_inputs()
[4, 5]