from pytket.circuit import CircBox, Circuit, Bit, Qubit
from pytket.qasm import circuit_to_qasm_str
from pytket.passes import DecomposeBoxes
c_inner: Circuit = Circuit(4, 1)
cbox: CircBox = CircBox(Circuit(4).H(0).H(1).H(2).H(3).CX(0, 1).CX(1, 2).CX(2, 3))
c_inner.add_circbox(cbox, [Qubit(i) for i in range(4)], condition=Bit(0))
c_outer: Circuit = Circuit(4, 2)
c_outer.add_circbox(CircBox(c_inner), c_inner.qubits + c_inner.bits, condition=Bit(1))
DecomposeBoxes().apply(c_outer)
print(circuit_to_qasm_str(c_outer, header="hqslib1"))
This code gives an error as c_outer still has a CircBox internally. Printing the circuit commands will give IF ([c[1]] == 1) THEN IF ([c[0]] == 1) THEN CircBox q[0], q[1], q[2], q[3];.
Alternatively, applying auto_rebase_pass({OpType.ZZPhase, OpType.PhasedX, OpType.Rz}).apply(c_outer) to the circuit throws a BadOpType error, complaining about a conditional operation.
See:
This code gives an error as
c_outer
still has aCircBox
internally. Printing the circuit commands will giveIF ([c[1]] == 1) THEN IF ([c[0]] == 1) THEN CircBox q[0], q[1], q[2], q[3];
.