Skip to content

← utilities package

WithBackend

Run the given computational graph with a specified compute backend and precision.

This will override the default backend used by any node that has its backend and/or precision setting set to "keep" and which has, no template array input whose backend/precision to keep. As a result, this node primarily affects the source nodes of a given computation (e.g., RandomNormal) whose results trickle down through the rest of the graph. You can also specify the device (usually the GPU index if you have multiple GPUs) to run the computation on (if the selected backend supports multiple devices). By default this node will run the entire graph that is wired into it under the given backend context. However, you can also tag a subgraph that shall run under the given context by placing a dummy Placeholder node in your graph, giving it a unique slotname (one would usually name it "with" as a reminder that it pairs with a downstream "With..." node), and then and selectively wiring that placeholder's update output port to select nodes of your graph. Then only the nodes downstream of that placeholder will run under the given context. You will also need to set the "Graph [tag]" option (graph__signature in code) to name the tag that you used (e.g. "(with)" in this example). Note that, when you use a node that uses multiple processes (like the Parallel Foreach loop via its multiprocess_backend option), then this context will not automatically apply the nodes running under the control of such a node (although you can nest a WithBackend node inside such a loop to apply the context there as needed). Version 0.9.0

Ports/Properties

graph

Computation to run.

  • verbose name: Graph
  • default value: None
  • port type: GraphPort
  • value type: Graph

graph__signature

Optionally the slotname of a Placeholder node that shall mark the starting point of the graph that runs under the with context. As with all "With" context manager nodes in NeuroPype, the graph that runs under the context managed by this node is preceding the context manager node in the graph, rather than following it. This is accomplished by wiring the final node of the graph that shall execute under the governance of the context manager into the "graph" input port of the subsequent "With" node. In graphical UIs, this edge will be drawn in dotted style to indicate that this is not normal forward data flow where first the preceding node executes and then the subsequent node receives its output, but that instead the subsequent node (the context manager) receives a portion of the preceding graph, which it then runs in such a way that the context applies. You can use a "tilde" binding, spelled as (~), which affects the same nodes that a then or else branch in an IfElse node would control, which is normally what one would expect. However, note that this can have sometimes the unexpected consequence that simply wiring a value into your graph may "infect" an upstream portion of the graph with unintentionally running under the context, too. As an alternative, you can instead rely on a named Placeholder node to mark the beginning of the managed graph. The typical way to do this is to list a single placeholder name, e.g., (with), and then to create a Placeholder in your graph whose slotname is set to "with". Then, only the nodes that are downstream of (i.e., formally depending on) that placeholder will run under the context defined by the "With" node. In this case you need to make everything that shall be part of the context dependent on the placeholder, which can be accomplished by wiring the update output port of the Placeholder into the update input port of any nodes that shall run under the context (this dependency propagates down the graph, so you don't need to wire it to every node, just to the first node(s) that you want to be part of the context). Any nodes in this graph that have a backend and/or precision argument set to "keep" will be overridden by the backend and/or precision setting of this node.

  • verbose name: Graph [Tag]
  • default value: (~)
  • port type: Port
  • value type: object (can be None)

result

Result of the computation.

  • verbose name: Result
  • default value: None
  • port type: DataPort
  • value type: object (can be None)
  • data direction: OUT

backend

Optional compute backend to use. Keep means to not override, which causes operations to resolve the backend of any input or template array if one is provided and otherwise numpy (unless overridden by an outer WithBackend). Numpy is the standard CPU backend that underpins most of NeuroPype's operations. The others require one or more GPUs to be present on the system, except for torch-cpu. For best performance, keep all arrays that interact with each other (via processing nodes) on the same backend.

  • verbose name: Backend
  • default value: keep
  • port type: EnumPort
  • value type: str (can be None)

precision

Numeric precision to use. Keep means to not override, which causes nodes to default to the precision of the input/template array if one is provided, and otherwise to whatever is the default for the specific backend, which is usually 64-bit, unless there is an outer WithBackend that overrides it. Can be reduced to save memory and improve throughput (e.g. if running on GPU).

  • verbose name: Precision
  • default value: keep
  • port type: EnumPort
  • value type: str (can be None)

compile_loops

Compile any loops that have a compile option set to 'auto'. Note that this requires the loop bodies to be very clean (typically mainly math operations, optionally with data reformatting). See the respective loop node(s) for more details on applicable caveats.

  • verbose name: Compile Loops
  • default value: False
  • port type: BoolPort
  • value type: bool (can be None)

device

Device index to use. This is only relevant for backends that support multiple devices. If None, no change to the current default is made.

  • verbose name: Device
  • default value: None
  • port type: IntPort
  • value type: int (can be None)

is_global

If True, the context implicitly applies to the entire graph (except for those parts that are configuring the context itself). In this case the node must not have anything wired into its graph input and must not have any successors.

  • verbose name: Is Global
  • default value: False
  • port type: BoolPort
  • value type: bool (can be None)

set_breakpoint

Set a breakpoint on this node. If this is enabled, your debugger (if one is attached) will trigger a breakpoint.

  • verbose name: Set Breakpoint (Debug Only)
  • default value: False
  • port type: BoolPort
  • value type: bool (can be None)

metadata

User-definable meta-data associated with the node. Usually reserved for technical purposes.

  • verbose name: Metadata
  • default value: {}
  • port type: DictPort
  • value type: dict (can be None)