Functions and decorators

The callables gpype exports beside its classes.

gpype.canonicalize(document)[source]

Return document with every node’s id filled in.

Call this once, on the authoring side, and give the result to both halves of a distributed pipeline – or store it, which is the same thing done earlier. The ids are minted the way ioiocore mints them, so a canonicalized document is indistinguishable from one that came out of serialize().

Idempotent: a node that already has an id keeps it, so canonicalizing twice changes nothing and canonicalizing a document that gained a new node touches only the new node. That is the property that makes this safe to run in a save path.

The input is not modified. A caller holding a document it intends to reuse should not find it silently altered.

Parameters:

document (dict) – A pipeline document, as loaded from JSON.

Returns:

A copy with an id on every node.

Return type:

dict

Raises:

TypeError – If document is not a mapping.

Note

Malformed nodes are left alone rather than repaired. Deciding what a node with no module means is the loader’s job, and it already refuses such a document with a message naming the field; a second opinion here would only produce a different error for the same mistake.

gpype.common.document.node_ids(document)[source]

The id of every node in document, in order.

For checking that two halves really are reading the same document – the failure this module exists to prevent is silent, so being able to compare the two lists is worth the six lines.

Parameters:

document (dict) – A pipeline document.

Returns:

One entry per node; None where a node carries no id.

Return type:

list

gpype.allow_modules(*modules)

Permit additional modules in documents loaded by this process.

For a host program that defines its own node classes and loads its own documents. Call it before deserializing.

This is not a hole in the policy the way a control-plane command would be: the caller is already executing in this interpreter.

Parameters:

*modules (str) – Fully qualified module names, such as "my_nodes.filters"; or a package, "my_nodes.*", which permits that package and everything under it.

Raises:

ValueError – If a name is not a non-empty string.

Return type:

None

gpype.deployment_report()[source]

Describe this process as the licence gate would judge it now.

Reading it decides nothing and latches nothing; Pipeline.start() still makes the decision for a run. The licence is read from the local store, with no network. The residency is read as the gate will read it, and the process-wide LaunchConfig is left as it was found: a report taken before an application configures itself must not fix that configuration from the command line.

Returns:

  • gpype_version, api_version

  • frozen: whether the process is a frozen application, read from the operating system rather than from sys.

  • process: one line on how that was decided, for a support question.

  • residency: standalone, edge or server.

  • licence: product, the product the gate asks about; state, one of licensed, unlicensed or unknown; detail, the underlying verdict; permission, one of full, limited or abort, what the licence gate (G1) would grant; reason, why, empty when full.

It does not say what a run would be granted. The device gate (G2) is decided at start() from the pipeline’s own sources, and a run takes the stricter of the two: a fully licensed pipeline whose sources attest nothing, a Generator say, still runs marked.

Return type:

Dict[str, Any]

gpype.node(function)[source]

Turn a function into something a pipeline can be handed.

Sugar over Apply, and nothing more: the decorated name becomes a factory, so the function stays callable in its own right and can be unit-tested without a pipeline anywhere near it.

@gp.node
def to_microvolts(block):
    return block * 1e6

p.connect(reader, to_microvolts())
assert to_microvolts.function(block).max() == ...

Batch only, for the reasons in Apply.

Parameters:

function (Callable) – The transform. One array in, one of the same shape out.

Return type:

Callable

Returns:

A factory taking the same **kwargs as Apply, with the original function on its function attribute.

gpype.controllable(fn)

Declare get_control or set_control as reachable.

Parameters:

fn (Callable) – The method being declared. Only the two names GET_CONTROL and SET_CONTROL are ever looked up, so marking any other method has no effect.

Return type:

Callable

Returns:

fn itself, marked and otherwise unchanged.

gpype.action(fn)

Declare a method as a named action.

An action is something the node does, which is why it cannot be a key in the control dict: {"reset": True} is not idempotent, and a second identical update either does nothing or fires again depending on how the node reads it.

Parameters:

fn (Callable) – The method being declared, with the signature (self, arg: dict) -> dict | None.

Return type:

Callable

Returns:

fn itself, marked and otherwise unchanged.