CQCL / tket

Source code for the TKET quantum compiler, Python bindings and utilities
https://docs.quantinuum.com/tket/
Apache License 2.0
256 stars 48 forks source link

DecomposeBoxes doesn't decompose CircBox with nested classical control #1583

Open sjdilkes opened 1 month ago

sjdilkes commented 1 month ago

See:

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];.

sjdilkes commented 1 month ago

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.