Node#

class hugr.hugr.node_port.Node(idx: int, _metadata: dict[str, object] = <factory>, _num_out_ports: int | None = None)[source]#

Bases: ToNode

Node in hierarchical Hugr graph, with globally unique index.

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.

idx

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.

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.