plumpy.workchains module#
- class plumpy.workchains.WorkChain(*args: Any, **kwargs: Any)[source]#
Bases:
ContextMixin,ProcessA WorkChain is a series of instructions carried out with the ability to save state in between.
- _CONTEXT = 'CONTEXT'#
- _STEPPER_STATE = 'stepper_state'#
- _abc_impl = <_abc._abc_data object>#
- _awaitables: Dict[asyncio.Future | processes.Process, str]#
- _context: AttributesDict | None#
- _event_callbacks: Dict[Hashable, List[EVENT_CALLBACK_TYPE]]#
- _spec_class#
alias of
WorkChainSpec
- load_instance_state(saved_state: MutableMapping[str, Any], load_context: LoadSaveContext) None[source]#
Load the process from its saved instance state.
- Parameters:
saved_state – A bundle to load the state from
load_context – The load context
- async 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: MutableMapping[str, Any], save_context: LoadSaveContext | None) None[source]#
Add the instance state to
out_state. .. important:The instance state will contain a pointer to the ``ctx``, and so should be deep copied or serialised before persisting.
- classmethod spec() WorkChainSpec[source]#
- class plumpy.workchains.WorkChainSpec[source]#
Bases:
ProcessSpec
- plumpy.workchains.if_(condition: Callable[[WorkChain], bool]) _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
- plumpy.workchains.return_ = <plumpy.workchains._Return object>#
A global singleton that contains a Return instruction that allows to exit out of the workchain outline directly with None as exit code To set a specific exit code, call it with the desired exit code
Use as:
if_(cls.conditional)( return_ )
or:
if_(cls.conditional)( return_(EXIT_CODE) )
- Parameters:
exit_code – an integer exit code to pass as the return value, None by default
- plumpy.workchains.while_(condition: Callable[[WorkChain], bool]) _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