laboneq.workflow.core
¶
Core workflow objects.
Parameters = ParamSpec('Parameters')
module-attribute
¶
Workflow(root, input=None)
¶
Bases: Generic[Parameters]
Workflow for task execution.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
root |
WorkflowBlock
|
A root workflow block. |
required |
input |
dict | None
|
Input parameters of the workflow. |
None
|
graph: WorkflowGraph
property
¶
Workflow graph object.
input: dict
property
¶
Input parameters of the workflow.
name: str
property
¶
Workflow name.
from_callable(func, name=None, input=None)
classmethod
¶
resume(until=None)
¶
Resume workflow execution.
Resumes the workflow execution from the previous state.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
until |
str | None
|
Run until a first task with the given name.
Until cannot be used for tasks and sub-workflows inside loops. |
None
|
Returns:
Type | Description |
---|---|
WorkflowResult
|
Result of the workflow execution. |
WorkflowResult
|
if |
Raises:
Type | Description |
---|---|
WorkflowError
|
An error occurred during workflow execution or workflow is not in progress. |
ValueError
|
'until' value is invalid. |
run(until=None)
¶
Run the workflow.
Resets the state of an workflow before execution.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
until |
str | None
|
Run until the first task or sub-workflow with the given name.
Until cannot be used for tasks and sub-workflows inside loops. If |
None
|
Returns:
Type | Description |
---|---|
WorkflowResult
|
Result of the workflow execution. |
WorkflowResult
|
if |
Raises:
Type | Description |
---|---|
WorkflowError
|
An error occurred during workflow execution. |
ValueError
|
'until' value is invalid. |
WorkflowBuilder(func, name=None)
¶
Bases: Generic[Parameters]
A workflow builder.
Builds a workflow out of the given Python function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
func |
Callable[Parameters]
|
A python function, which acts as the core of the workflow. |
required |
name |
str | None
|
Name of the workflow. Defaults to wrapped function name. |
None
|
src: str
property
¶
Source code of the workflow.
options()
¶
Create default options for the workflow.
The option attribute tasks
is populated with all the sub-task
and sub-workflow options within this workflow.
recover()
¶
Recover the result of the last run to raise an exception.
Returns the result of the last failed run of a workflow created from this workflow builder. In no run has failed, an exception is raised.
After a result is recovered, the result is cleared and further calls
to .recover
will raise an exception.
Returns:
Type | Description |
---|---|
WorkflowResult
|
Latest workflow that raised an exception. |
Raises:
Type | Description |
---|---|
WorkflowError
|
Raised if no previous run failed. |
workflow(func=None, name=None)
¶
A decorator to mark a function as workflow.
The arguments of the function will be the input values for the wrapped function.
If workflow
decorated function is called within another workflow definition,
it adds a sub-graph to the workflow being built.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
func |
Callable[Parameters] | None
|
A function that defines the workflow structure. The arguments of |
None
|
name |
str | None
|
Name of the workflow. Defaults to wrapped function name. |
None
|
Returns:
Type | Description |
---|---|
WorkflowBuilder[Parameters] | Callable[[Callable[Parameters]], WorkflowBuilder[Parameters]]
|
A wrapper which returns a |
WorkflowBuilder[Parameters] | Callable[[Callable[Parameters]], WorkflowBuilder[Parameters]]
|
A wrapper which returns a |
Example
from laboneq import workflow
@workflow.workflow
def my_workflow(x: int): ...
wf = my_workflow(x=123)
results = wf.run()