Controlling a Running Pipeline

Some settings can only be found while the pipeline runs: a neurofeedback threshold is moved until the subject can just hold it, and stopping to edit and restart does not get you there. A control surface lets code outside a node read and change named values while it runs, and a probe lets it watch any output port.

Your program reads and changes a running node's values through the pipeline, by the node or its id: get_control, set_control and invoke_action. A Threshold's level, release and dwell change while it runs. A probe publishes one port's output to a viewer on a server's data socket.

Changing a node while it runs

Four calls on the pipeline; the last three take the node itself or its id:

  • p.get_nodes() lists every node with its id, name and class, whether it is controllable and which actions it has.

  • p.get_control(node) returns the node’s current values.

  • p.set_control(node, {...}) changes them, and returns them as they now are.

  • p.invoke_action(node, name, {...}) runs a named action the node offers.

Threshold is the shipped node with a control surface – level, release and dwell:

th = gp.Threshold(level=0.5, name="decide")
# ... connect it, then:
p.start()

p.get_control(th)                   # {'level': 0.5, 'release': 0.5, 'dwell': 1}
p.set_control(th, {"level": 0.99})  # the running Threshold uses it at once

A program that does not hold the node – one that drives the pipeline from outside – uses its id instead, which the pipeline assigns: look it up by name, next(n["id"] for n in p.get_nodes() if n["name"] == "decide"). A string is always taken as an id, so p.get_control("decide") is refused: “no node with id ‘decide’ in this pipeline”. Passing the node itself is new in gp.API_VERSION 1.1.

A refused change leaves the node as it was. A name the node does not have is a KeyError that lists the ones it does – “unknown control key(s) [‘levle’]; accepted keys are [‘dwell’, ‘level’, ‘release’]” – and a value the node cannot take is a ValueError from the node itself: “dwell must be at least 1 sample, got -5”.

A control changes the running node, not its configuration. A serialized pipeline – what p.serialize() returns – written after set_control still says level: 0.5. To keep a value found this way, write it into the constructor.

A node of your own gets a control surface by decorating its get_control and set_control methods with @gp.controllable, and each action with @gp.action; Season 7, Episode 4 builds one. The node catalogue marks such nodes controllable, so a tool composing a pipeline can see the surface before anything runs.

Watching a port with a probe

p.attach_probe(node, port="out"), given the node or its id, publishes what one output port emits, live, under a stream id that a client can subscribe to; p.detach_probe(stream_id) removes it, and p.list_probes() reports each probe’s samples sent, frames dropped and current subscribers. The pipeline does not change: a probe copies what goes past and never delays or alters it.

A probe is delivered over the pipeline’s data socket, so it needs a process that has one, such as a server watched from another program. In a plain standalone script there is none, and attaching refuses: “no data socket is bound in this process, so there is nowhere to publish a probe.” There, a scope or a Collector shows the same data. Three more things to know:

  • It is a subsample, not a measurement. It decimates to max_rate, 256 Hz by default, with no anti-aliasing filter, and the context it publishes says so.

  • It never slows the pipeline. Unwatched, it costs one lookup per frame; when the socket cannot keep up, it drops frames and counts them rather than holding the producer back.

  • It shows the port as it is. A probe on a source sees its output before the arrival stamp is stripped, one channel wider than what the nodes after it receive (Time and Synchronisation).

p.stop() detaches every probe, so none carries over into the next run.