seqlib.nodes package¶
Sequencer nodes
Implements all node types and utility functions.
Action nodes¶
Implements Action
and ActionInThread
nodes.
Actions are the leaf nodes in any Sequencer script. They execute python methods or functions.
Coroutines are associated to Action
nodes while normal callable objects must be
associated to ActionInThread
nodes.
-
class
seq.lib.nodes.action.
Action
(f=None, parent_tpl=None, *, id=None, name=None, runtime_flags=0, description='')[source]¶ Bases:
seq.lib.nodes.interface._BaseNode
Action ctor.
Action nodes executes coroutines in a Sequencer script.
- Parameters
f (coroutine) – The coroutine the node will execute
- Keyword Arguments
- Raises
TypeError – is f is not a coroutine.
-
current_node
= <ContextVar name='current_node' default=None>¶
-
property
context
¶ Get context from the running Sequence
-
property
full_state
¶ Gets the node state.
-
property
state
¶ Gets the node state.
-
class
seq.lib.nodes.action.
ActionInThread
(f=None, parent_tpl=None, *, id=None, name=None, runtime_flags=0, description='')[source]¶ Bases:
seq.lib.nodes.action.Action
ActionInThread ctor.
ActionInThread nodes executes python callables (functions or methods) in a Sequencer script.
-
class
seq.lib.nodes.action.
StartNode
(*args, **kw)[source]¶ Bases:
seq.lib.nodes.action.Action
This is Starting Node.
marks node as unskipabble
-
class
seq.lib.nodes.action.
EndNode
(*args, **kw)[source]¶ Bases:
seq.lib.nodes.action.Action
This is the finish Node.
marks node as unskippable
Checkbox node¶
Implements a Checkbox node.
Checkbox pauses execution of a Sequencer script until the ‘check’ command is given to it. That is to say, until the user confirms some condition and allows the script to continue.
Warning
This node is intended to use on interactive Sequencer scripts only. Do not seq run a script that contains it. It will hang forever.
-
class
seq.lib.nodes.checkbox.
Checkbox
(parent_tpl=None, *, id=None, name=None, runtime_flags=0, description='')[source]¶ Bases:
seq.lib.nodes.action.Action
Checkbox ctor.
Checkbox node waits for user to confirm some condition.
- Parameters
msg (str) – Checkbox message
- Keyword Arguments
Container nodes¶
-
class
seq.lib.nodes.
Sequence
(*, id=None, name=None, runtime_flags=0, description='')[source]¶ Bases:
seq.lib.nodes.interface._BaseNode
Basic sequencer node.
Use
create()
to properly buildSequence
objects.-
state
¶ node state
Context Variables
Name
Desc
current_seq
The parent of the current node
root
Top level DAG’s root
Examples
>>> s = Sequence.create(a,b, name="my sequence") # execute Sequence >>> await s.start() # Get running Sequence from Inside function a(): >>> def a(): ... current_seq = Sequence.current_seq ... # now current_seq is the node s ... assert current_seq == s
-
current_seq
= <ContextVar name='current_seq' default=None>¶
-
root
= <ContextVar name='root' default=None>¶
-
property
context
¶ Get context dictionary, preferably from root node.
-
property
G
¶ returns the graph object
-
async
end_step
()[source]¶ Standard sequence’s end step.
Evaluates the sequence’s final state. Collects node’s result and put them in the sequence’s result attribute.
-
property
start_node
¶ Returns the start node.
If it does not exist, it creates it.
-
property
end_node
¶ Returns the end node.
If it does not exist, it creates it.
-
make_sequence
(parent_tpl=None)[source]¶ Builds this sequence execution graph. Joins the Sequence’s nodes together.
-
start
(make_sequence=True, resume=False)[source]¶ This is the entry point for Sequence execution.
- Returns
Returns the
SeqTask
object that executes the sequence- Raises
Exception – Any exception received is re-raised and the sequence is aborted.
-
async
execute
(resume=False, propagate=False)[source]¶ Executes node – this just creates the asyncio task
-
abort
()[source]¶ Aborts the sequence.
Goes trough the full graph and aborts the tasks associated to nodes (if any). Do not allow nodes to run by taking away its running_checkpoint attribute.
-
property
parameters
¶ Return parameters
-
property
state
¶ Gets the node state.
-
property
full_state
¶ Gets the node state.
-
-
class
seq.lib.nodes.
Parallel
(*, id=None, name=None, runtime_flags=0, description='', seq_args=NOTHING)[source]¶ Bases:
seq.lib.nodes.sequence.Sequence
Parallel node definition.
Use the
create()
method to build properlyParallel
nodes. Since it inherits fromSequence
it has access to the same context variables.Example
One can access the running Sequence using Sequence.current_seq context variable.
>>> s = Parallel.create(a,b, name="my sequence") # execute Sequence >>> await s.start() # Get running Sequence from Inside function a(): >>> def a(): ... current_seq = Sequence.current_seq ... # now current_seq is the node s ... assert current_seq == s
-
class
seq.lib.nodes.
Loop
(parent_tpl=None, *, id=None, name=None, runtime_flags=0, description='', block_args=NOTHING, condition=None, init=None)[source]¶ Bases:
seq.lib.nodes.sequence.Sequence
Loop node definition.
Use the
create()
method to build properlyLoop
node. Since it inherits fromSequence
it has access to the same context variables.Context Variables
Name
Desc
current_seq
The parent of the current node (from
Sequence
)root
Top level DAG’s root (from
Sequence
)index
The Loop’s current index (starts at 0)
- Keyword Arguments
id (Optional str) – Node id.
name (Optional str) – Node name.
init (Optional) – Initialization node.
condition (callale) – A Python method that returns a boolean value.
block (list) – The loop’s body.
-
index
= <ContextVar name='index' default=0>¶
-
static
create
(*args, **kw)[source]¶ Creates a
Loop
node- Parameters
*args –
Variable length list of nodes or coroutines that comprises the Loop`s body.
- Keyword Args:
id: Node id name: node name init (node) : initialization node
Action
orActionInThread
. condition(node): condition nodeAction
orActionInThread
.- Returns:
A new
Loop
object
Example:
Creating a loop.
def eval_condition(): return False class Tpl: def initialize(self, context): # performs some initialization pass async def a(): pass async def b(): pass @staticmethod def create() t = MyClass() l = Loop.create(t.a, t.b, condition=eval_condition, init=t.initialize)
-
class
seq.lib.nodes.
Template
(tpl_name=None, params=NOTHING, content=NOTHING, *, id=None, name=None, runtime_flags=0, description='')[source]¶ Bases:
seq.lib.nodes.sequence.Sequence
The Template node
A
Template
is just aSequence
node with access to a set of variables as defined in anObservingBlock
.The
ObservingBlock
takes care of instantiating theTemplate
objects as needed by the Observation Block.Context Variables
Name
Desc
current_tpl
The current Template being executed
Warning
Objects of type
Template
should not be directly constructed. Leave that for theObservingBlock
.-
P
= <ContextVar name='P' default={}>¶
-
current_tpl
= <ContextVar name='current_tpl' default=None>¶
-
async
execute
(resume=False, propagate=False)[source]¶ Executes node – this just creates the asyncio task
-
-
class
seq.lib.nodes.
ObservingBlock
(fname=None, *, id=None, name=None, runtime_flags=0, description='', from_otto=False)[source]¶ Bases:
seq.lib.nodes.sequence.Sequence
Represents a Sequence from an OB file (json). The JSON file contains a lot of data, however the Sequencer only cares about the templates section:
"templates": [ { "templateName": "seq.samples.a", "type": "string" }, { "templateName": "seq.samples.tpa", "type": "string", "parameters": [ { "name": "par_b", "type": "integer", "value": 0 }, { "name": "par_c", "type": "number", "value": 77 } ] } ],
Inside the templates section there is list of templateName objects. The templateName defines a Python module that can be directly imported (it is reachable from PYTHONPATH).
Each template might contain a list of parameters that can be accessed from corresponding python code that implements the template.
-
template_parameters
= {}¶
-
property
parameters
¶ Returns a dictionary with template’s parameters
The returned dictionary enumerates the OB’s templates as keys and the values are Template’s parameters
-
static
create
(f, *args, **kw)[source]¶ Creates a
ObservingBlock
node- Parameters
f –
JSON file with OB definition
- Keyword Args:
id: Node id name: node name
-
property
module
¶ Returns OB filename
-
property
doc
¶ Returns OB name from the corresponding kw
-