UnpackTuple#

class hugr.ops.UnpackTuple(_types: list[Type] | None = None)[source]#

Bases: AsExtOp, _PartialOp

Operation to unpack a tuple into its elements.

Methods

cached_signature

Cached signature of the operation, if there is one.

from_ext

Load from a ExtOp operation.

name

Name of the operation.

op_def

The tys.OpDef for this operation.

outer_signature

The external signature of this operation.

port_kind

Get the kind of the given port.

port_type

Get the type of the given dataflow port from the signature of the operation.

type_args

Type arguments of the operation.

Attributes

ext_op

ExtOp operation that this type represents.

num_out

The number of output ports for this operation.

types

If set, the types of the tuple elements.

exception InvalidExtOp(msg: str)#

Bases: Exception

Extension operation does not match the expected type.

with_traceback()#

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

cached_signature() FunctionType | None[source]#

Cached signature of the operation, if there is one.

Used by op_def, so must be deterministic.

property ext_op: ExtOp#

ExtOp operation that this type represents.

Computed once using op_def() type_args() and type_args(). Each of those methods should be deterministic.

classmethod from_ext(ext_op: ExtOp) Self | None#

Load from a ExtOp operation.

By default assumes the type of cls is a singleton, and compares the result of to_ext() with the given ext_op.

If successful, returns the singleton, else None.

Non-singleton types should override this method.

Raises:
  • InvalidCustomOp – If the given ext_op does not match the expected one for a

  • given extension/operation name.

name() str[source]#

Name of the operation.

property num_out: int#

The number of output ports for this operation.

Example

>>> op = Const(val.TRUE)
>>> op.num_out
1
op_def() ext.OpDef[source]#

The tys.OpDef for this operation.

Used by ext_op, so must be deterministic.

outer_signature() FunctionType[source]#

The external signature of this operation. Defines the valid external connectivity of the node the operation belongs to.

port_kind(port: InPort | OutPort) ValueKind | ConstKind | FunctionKind | CFKind | OrderKind#

Get the kind of the given port.

Example

>>> op = Const(val.TRUE)
>>> op.port_kind(OutPort(Node(0), 0))
ConstKind(Bool)
port_type(port: InPort | OutPort) Type#

Get the type of the given dataflow port from the signature of the operation.

Example

>>> op = Input([tys.Bool])
>>> op.port_type(OutPort(Node(0), 0))
Bool
type_args() list[TypeArg][source]#

Type arguments of the operation.

Used by op_def, so must be deterministic.

property types: list[Type]#

If set, the types of the tuple elements.

Raises:

IncompleteOp – If the types have not been set.