ParentBuilder#

class hugr.build.base.ParentBuilder(*args, **kwargs)[source]#

Bases: ToNode, Protocol[OpVar]

Abstract interface implemented by builders of nodes that contain child HUGRs.

Methods

inp

Generate an input port for this node.

out

Generate an output port for this node.

out_port

OutPort corresponding to this Wire.

outputs

Returns an iterator over the output ports of this node.

port

Generate a port in direction for this node with offset.

to_node

Convert to a Node.

Attributes

metadata

Metadata associated with this node.

parent_op

The parent node's operation.

hugr

The child HUGR.

parent_node

hugr: Hugr[OpVar]#

The child HUGR.

inp(offset: int) InPort#

Generate an input port for this node.

Parameters:

offset – port offset.

Returns:

Incoming port for this node.

Examples

>>> Node(0).inp(1)
InPort(Node(0), 1)
property metadata: dict[str, object]#

Metadata associated with this node.

out(offset: int) OutPort#

Generate an output port for this node.

Parameters:

offset – port offset.

Returns:

Outgoing port for this node.

Examples

>>> Node(0).out(1)
OutPort(Node(0), 1)
out_port() OutPort#

OutPort corresponding to this Wire.

outputs() Iterator[OutPort]#

Returns an iterator over the output ports of this node.

property parent_op: OpVar#

The parent node’s operation.

port(offset: int, direction: Direction) InPort | OutPort#

Generate a port in direction for this node with offset.

Examples

>>> Node(0).port(1, Direction.INCOMING)
InPort(Node(0), 1)
>>> Node(0).port(1, Direction.OUTGOING)
OutPort(Node(0), 1)
to_node() Node[source]#

Convert to a Node.