CQCL / tket

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

Assertion failure from getting state-vector after `GlobalisePhasedX` pass #1552

Open Bennybenassius opened 2 months ago

Bennybenassius commented 2 months ago

Ilan and I found this bug when testing on random circuits using the GlobalisePhasedX pass:

The circuit below fails when run:

from pytket import Circuit, Qubit
from pytket.circuit import CircBox, OpType, MultiplexorBox, Op
from sympy import Symbol
from pytket.passes import *

# Writing multiplexor 
U3_op = Op.create(OpType.U3,(-0.63,0.37,0.26))
U2_op = Op.create(OpType.U2,(-0.04,0.71))
op_map = {(0,):U3_op,(1,):U2_op}
multiplexor = MultiplexorBox(op_map)

main_circ = Circuit(4, 2, "main_circ")
# Adding qregs and qubit resources 
qbit_0 = Qubit("qbit_0", 0)
main_circ.add_qubit(qbit_0)
qreg_1 = main_circ.add_q_register("qreg_1",1)

# Adding symbols 
a = Symbol("a")
b = Symbol("b")
s_map = {a: -6.681, b: 0.844} 

# Applying gates
main_circ.U3(b,-0.2,0.79,qbit_0)
main_circ.add_gate(multiplexor,[0, 2])
main_circ.U2(b,0.66,qbit_0)
main_circ.add_gate(OpType.XXPhase,[-0.27],[2, 3])

main_circ.symbol_substitution(s_map)

GlobalisePhasedX().apply(main_circ)

sv1 = main_circ.get_statevector()

print(sv1)

Which causes an assertion failure:

Assertion '!"slice is empty"' (/root/.conan2/p/b/tketa8cd64ce2b167/b/src/Circuit/macro_circ_info.cpp : operator++ : 935) failed.  Aborting.

The issue seems to only work with this specific order of gates and qubits used. If the XXPhase gate used qubits 1 and 3, the circuit will compile without an issue.

cqc-alec commented 2 months ago

Possibly related to #1324 .

IlanIwumbwe commented 2 months ago

Ah, I see. Thanks!