Workflows¶
This section describes the different classes related to workflows, workfunctions and WorkChains.
-
class
aiida.work.process.
Process
[source]¶ This class represents an AiiDA process which can be executed and will have full provenance saved in the database.
-
class
aiida.work.process_registry.
ProcessRegistry
[source]¶ This class is a knowledge provider that uses the AiiDA database to answer questions related to processes.
-
class
aiida.work.run.
RunningInfo
(type, pid)¶ -
pid
¶ Alias for field number 1
-
type
¶ Alias for field number 0
-
-
class
aiida.work.run.
RunningType
[source]¶ A type to indicate what type of object is running: a process, a calculation or a workflow
-
aiida.work.run.
legacy_calc
(pk)[source]¶ Create a
RunningInfo
object for a legacy calculationParameters: pk (int) – The calculation pk Returns: The running info Return type: RunningInfo
-
aiida.work.run.
legacy_workflow
(pk)[source]¶ Create a
RunningInfo
object for a legacy workflow.This can be used in conjunction with
aiida.work.workchain.ToContext
as follows:>>> from aiida.work.workchain 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(wf.pk)) >>> >>> 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
-
aiida.work.run.
queue_up
(process_class, inputs, storage)[source]¶ This queues up the Process so that it’s executed by the daemon when it gets around to it.
Parameters: - 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)
Returns: The pid of the queued process.
-
aiida.work.run.
run
(process_class, *args, **inputs)[source]¶ Synchronously (i.e. blocking) run a workfunction or process.
Parameters: - process_class – The process class or workfunction
- _attributes – Optional attributes (only for process)
- args – Positional arguments for a workfunction
- inputs – The list of inputs
-
class
aiida.work.test_utils.
BadOutput
[source]¶ A Process that emits an output that isn’t part of the spec raising an exception.
-
class
aiida.work.util.
ProcessStack
[source]¶ 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.
Parameters: - process – The process instance
- pid – The process id.
-
classmethod
-
aiida.work.util.
get_or_create_output_group
(calculation)[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
-
class
aiida.work.workchain.
Interstep
[source]¶ An internstep is an action that is performed between steps of a workchain. These allow the user to perform action when a step is finished and when the next step (if there is one) is about the start.
-
on_last_step_finished
(workchain)[source]¶ Called when the last step has finished
Parameters: workchain ( WorkChain
) – The workchain this interstep belongs to
-
-
class
aiida.work.workchain.
ToContext
(**kwargs)[source]¶ Class to wrap future objects and return them in a WorkChain step.
-
class
aiida.work.workchain.
WorkChain
[source]¶ A WorkChain, the base class for AiiDA workflows.
-
aiida.work.workchain.
if_
(condition)[source]¶ A conditional that can be used in a workchain outline.
Use as:
if_(cls.conditional)( cls.step1, cls.step2 )
Each step can, of course, also be any valid workchain step e.g. conditional.
Parameters: condition – The workchain method that will return True or False
-
aiida.work.workchain.
while_
(condition)[source]¶ A while loop that can be used in a workchain outline.
Use as:
while_(cls.conditional)( cls.step1, cls.step2 )
Each step can, of course, also be any valid workchain step e.g. conditional.
Parameters: condition – The workchain method that will return True or False
-
class
aiida.work.workflow.
Workflow
[source]¶ 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.
-
aiida.work.workfunction.
workfunction
(func)[source]¶ A decorator to turn a standard python function into a workfunction. Example usage:
>>> from aiida.orm.data.base import Int >>> from aiida.work.workfunction 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) 9 >>> r.get_inputs_dict() {u'_return': <WorkCalculation: uuid: ce0c63b3-1c84-4bb8-ba64-7b70a36adf34 (pk: 3567)>} >>> r.get_inputs_dict()['_return'].get_inputs() [4, 5]