aiida.engine.processes.workchains package¶
Module for the WorkChain process and related utilities.
-
aiida.engine.processes.workchains.
ToContext
¶ alias of
builtins.dict
-
aiida.engine.processes.workchains.
assign_
(target)[source]¶ Convenience function that will construct an Awaitable for a given class instance with the context action set to ASSIGN. When the awaitable target is completed it will be assigned to the context for a key that is to be defined later
- Parameters
target – an instance of a Process or Awaitable
- Returns
the awaitable
- Return type
-
aiida.engine.processes.workchains.
append_
(target)[source]¶ Convenience function that will construct an Awaitable for a given class instance with the context action set to APPEND. When the awaitable target is completed it will be appended to a list in the context for a key that is to be defined later
- Parameters
target – an instance of a Process or Awaitable
- Returns
the awaitable
- Return type
-
class
aiida.engine.processes.workchains.
WorkChain
(inputs=None, logger=None, runner=None, enable_persistence=True)[source]¶ Bases:
aiida.engine.processes.process.Process
The WorkChain class is the principle component to implement workflows in AiiDA.
-
_CONTEXT
= 'CONTEXT'¶
-
_Process__called
= True¶
-
_STEPPER_STATE
= 'stepper_state'¶
-
__abstractmethods__
= frozenset({})¶
-
__init__
(inputs=None, logger=None, runner=None, enable_persistence=True)[source]¶ Construct a WorkChain instance.
Construct the instance only if it is a sub class of WorkChain, otherwise raise InvalidOperation.
- Parameters
inputs (dict) – work chain inputs
logger (
logging.Logger
) – aiida loggerrunner – work chain runner
enable_persistence (bool) – whether to persist this work chain
- Type
-
__module__
= 'aiida.engine.processes.workchains.workchain'¶
-
_abc_impl
= <_abc_data object>¶
-
_auto_persist
= {'_CREATION_TIME', '_awaitables', '_enable_persistence', '_future', '_parent_pid', '_paused', '_pid', '_pre_paused_status', '_status'}¶
-
_do_step
()[source]¶ Execute the next step in the outline and return the result.
If the stepper returns a non-finished status and the return value is of type ToContext, the contents of the ToContext container will be turned into awaitables if necessary. If any awaitables were created, the process will enter in the Wait state, otherwise it will go to Continue. When the stepper returns that it is done, the stepper result will be converted to None and returned, unless it is an integer or instance of ExitCode.
-
_node_class
¶ alias of
aiida.orm.nodes.process.workflow.workchain.WorkChainNode
-
_spec
= <aiida.engine.processes.workchains.workchain.WorkChainSpec object>¶
-
_spec_class
¶ alias of
WorkChainSpec
-
_store_nodes
(data)[source]¶ Recurse through a data structure and store any unstored nodes that are found along the way
- Parameters
data – a data structure potentially containing unstored nodes
-
_update_process_status
()[source]¶ Set the process status with a message accounting the current sub processes that we are waiting for.
-
action_awaitables
()[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 context.
- Return type
-
insert_awaitable
(awaitable)[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 (
plumpy.persistence.LoadSaveContext
) –
-
on_exiting
()[source]¶ Ensure that any unstored nodes in the context are stored, before the state is exited
After the state is exited the next state will be entered and if persistence is enabled, a checkpoint will be saved. If the context contains unstored nodes, the serialization necessary for checkpointing will fail.
-
on_process_finished
(awaitable, pk)[source]¶ Callback function called by the runner when the process instance identified by pk is completed.
The awaitable will be effectuated on the context of the 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
pk (int) – the pk of the awaitable’s target
-
remove_awaitable
(awaitable)[source]¶ Remove an awaitable.
Precondition: must be an awaitable that was previously inserted.
- Parameters
awaitable – the awaitable to remove
-
-
aiida.engine.processes.workchains.
if_
(condition)[source]¶ A conditional that can be used in a workchain outline.
Use as:
if_(cls.conditional)( cls.step1, cls.step2 )
Each step can, of course, also be any valid workchain step e.g. conditional.
- Parameters
condition – The workchain method that will return True or False
-
aiida.engine.processes.workchains.
while_
(condition)[source]¶ A while loop that can be used in a workchain outline.
Use as:
while_(cls.conditional)( cls.step1, cls.step2 )
Each step can, of course, also be any valid workchain step e.g. conditional.
- Parameters
condition – The workchain method that will return True or False
Submodules¶
Enums and function for the awaitables of Processes.
-
class
aiida.engine.processes.workchains.awaitable.
Awaitable
(**kwargs)[source]¶ Bases:
plumpy.utils.AttributesDict
An attribute dictionary that represents an action that a Process could be waiting for to finish.
-
__module__
= 'aiida.engine.processes.workchains.awaitable'¶
-
-
class
aiida.engine.processes.workchains.awaitable.
AwaitableTarget
[source]¶ Bases:
enum.Enum
Enum that describes the class of the target a given awaitable.
-
PROCESS
= 'process'¶
-
__module__
= 'aiida.engine.processes.workchains.awaitable'¶
-
-
class
aiida.engine.processes.workchains.awaitable.
AwaitableAction
[source]¶ Bases:
enum.Enum
Enum that describes the action to be taken for a given awaitable.
-
APPEND
= 'append'¶
-
ASSIGN
= 'assign'¶
-
__module__
= 'aiida.engine.processes.workchains.awaitable'¶
-
-
aiida.engine.processes.workchains.awaitable.
construct_awaitable
(target)[source]¶ Construct an instance of the Awaitable class that will contain the information related to the action to be taken with respect to the context once the awaitable object is completed.
The awaitable is a simple dictionary with the following keys
pk: the pk of the node that is being waited on
action: the context action to be performed upon completion
outputs: a boolean that toggles whether the node itself
Currently the only awaitable classes are ProcessNode and Workflow The only awaitable actions are the Assign and Append operators
Convenience functions to add awaitables to the Context of a WorkChain.
-
aiida.engine.processes.workchains.context.
ToContext
¶ alias of
builtins.dict
-
aiida.engine.processes.workchains.context.
assign_
(target)[source]¶ Convenience function that will construct an Awaitable for a given class instance with the context action set to ASSIGN. When the awaitable target is completed it will be assigned to the context for a key that is to be defined later
- Parameters
target – an instance of a Process or Awaitable
- Returns
the awaitable
- Return type
-
aiida.engine.processes.workchains.context.
append_
(target)[source]¶ Convenience function that will construct an Awaitable for a given class instance with the context action set to APPEND. When the awaitable target is completed it will be appended to a list in the context for a key that is to be defined later
- Parameters
target – an instance of a Process or Awaitable
- Returns
the awaitable
- Return type
Components for the WorkChain concept of the workflow engine.
-
class
aiida.engine.processes.workchains.workchain.
WorkChain
(inputs=None, logger=None, runner=None, enable_persistence=True)[source]¶ Bases:
aiida.engine.processes.process.Process
The WorkChain class is the principle component to implement workflows in AiiDA.
-
_CONTEXT
= 'CONTEXT'¶
-
_Process__called
= True¶
-
_STEPPER_STATE
= 'stepper_state'¶
-
__abstractmethods__
= frozenset({})¶
-
__init__
(inputs=None, logger=None, runner=None, enable_persistence=True)[source]¶ Construct a WorkChain instance.
Construct the instance only if it is a sub class of WorkChain, otherwise raise InvalidOperation.
- Parameters
inputs (dict) – work chain inputs
logger (
logging.Logger
) – aiida loggerrunner – work chain runner
enable_persistence (bool) – whether to persist this work chain
- Type
-
__module__
= 'aiida.engine.processes.workchains.workchain'¶
-
_abc_impl
= <_abc_data object>¶
-
_auto_persist
= {'_CREATION_TIME', '_awaitables', '_enable_persistence', '_future', '_parent_pid', '_paused', '_pid', '_pre_paused_status', '_status'}¶
-
_do_step
()[source]¶ Execute the next step in the outline and return the result.
If the stepper returns a non-finished status and the return value is of type ToContext, the contents of the ToContext container will be turned into awaitables if necessary. If any awaitables were created, the process will enter in the Wait state, otherwise it will go to Continue. When the stepper returns that it is done, the stepper result will be converted to None and returned, unless it is an integer or instance of ExitCode.
-
_node_class
¶ alias of
aiida.orm.nodes.process.workflow.workchain.WorkChainNode
-
_spec
= <aiida.engine.processes.workchains.workchain.WorkChainSpec object>¶
-
_spec_class
¶ alias of
WorkChainSpec
-
_store_nodes
(data)[source]¶ Recurse through a data structure and store any unstored nodes that are found along the way
- Parameters
data – a data structure potentially containing unstored nodes
-
_update_process_status
()[source]¶ Set the process status with a message accounting the current sub processes that we are waiting for.
-
action_awaitables
()[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 context.
- Return type
-
insert_awaitable
(awaitable)[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 (
plumpy.persistence.LoadSaveContext
) –
-
on_exiting
()[source]¶ Ensure that any unstored nodes in the context are stored, before the state is exited
After the state is exited the next state will be entered and if persistence is enabled, a checkpoint will be saved. If the context contains unstored nodes, the serialization necessary for checkpointing will fail.
-
on_process_finished
(awaitable, pk)[source]¶ Callback function called by the runner when the process instance identified by pk is completed.
The awaitable will be effectuated on the context of the 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
pk (int) – the pk of the awaitable’s target
-
remove_awaitable
(awaitable)[source]¶ Remove an awaitable.
Precondition: must be an awaitable that was previously inserted.
- Parameters
awaitable – the awaitable to remove
-
-
aiida.engine.processes.workchains.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.engine.processes.workchains.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