laboneq.workflow.reference
¶
Module for workflow reference.
notset = object()
module-attribute
¶
Reference(ref, default=notset)
¶
A reference class.
A Reference
is a placeholder for objects used while a workflow
graph is being constructed.
If tasks are the nodes in the workflow graph, then references define the edges.
For example, in a workflow definition like:
@workflow
def add_and_multiply(a, b):
c = add_task(a, 2)
d = multiply_task(c, 3)
the values a
, b
, c
and d
are all references. By tracking where references
are used, the graph builder can determine how inputs and outputs are passed between
tasks in the graph.
References also track some Python operations performed on them, so one can also use
references like a["value"]
. This creates a reference for "the item named 'value'
from reference 'a'".
When a workflow graph is run, the references are used to determine the input values to the next task from the outputs returned by the earlier tasks.
The following operations are supported
- getitem()
- getattr()
- eq()
Notes on specific Python operations¶
Equality comparison
For equality comparison, especially with booleans, use ==
instead of is
.
Equality with is
will always return False
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ref
|
object
|
An object this reference points to. |
required |
default
|
object
|
Default value of |
notset
|
add_overwrite(one, other)
¶
Add an overwrite to an reference.
are_equal(one, other)
¶
Check if two references are equal.
get_default(reference)
¶
Get reference default value.
get_ref(reference)
¶
Return an object the reference points to.
resolve_to_value(ref, states, *, only_ref=False)
¶
Resolve reference.
The resolve order is following:
* Look value from `states`
* Iterate over overwritten values and return the first one that
exists in `states` or is constant
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ref
|
Reference
|
Root reference |
required |
states
|
dict
|
A mapping of reference to actual values |
required |
only_ref
|
bool
|
Check only the root reference |
False
|
Raises:
Type | Description |
---|---|
WorkflowError
|
Value cannot be resolved. |
unwrap(reference, value)
¶
Unwrap the reference and any operations done on it.