Conditional#

class hugr.ops.Conditional(sum_ty: Sum, other_inputs: list[Type], _outputs: list[Type] | None = None)[source]#

Bases: DataflowOp

‘Switch’ operation on the variants of an incoming sum type, evaluating the corresponding one of the child Case operations.

Methods

name

Name of the operation.

nth_inputs

The inputs passed to the nth child case.

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.

Attributes

num_out

The number of output ports for this operation.

outputs

Outputs of the conditional, common to all cases.

signature

Dataflow signature of the conditional operation.

sum_ty

Sum type to switch on.

other_inputs

Non-sum inputs that are passed to all cases.

name() str[source]#

Name of the operation.

nth_inputs(n: int) list[Type][source]#

The inputs passed to the nth child case. Concatenation of the nth variant of the sum type and the other inputs.

property num_out: int#

The number of output ports for this operation.

Example

>>> op = Const(val.TRUE)
>>> op.num_out
1
other_inputs: list[Type]#

Non-sum inputs that are passed to all cases.

outer_signature() FunctionType[source]#

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

property outputs: list[Type]#

Outputs of the conditional, common to all cases.

Raises:

IncompleteOp – If the outputs have not been set.

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
property signature: FunctionType#

Dataflow signature of the conditional operation.

Raises:

IncompleteOp – If the outputs have not been set.

sum_ty: Sum#

Sum type to switch on.