CQCL/pytket-extensions

[pytket-qiskit] Incorrect conversion of `Unitary2qBox` from pytket to qiskit

cqc-alec opened this issue · 0 comments

When we process circuits containing Unitary2qBox operations using any Aer-based backend, we use the matrix directly to construct a qiskit UnitaryGate, neglecting to convert the indices from big-endian to little-endian. Consequently. unitaries and statevectors are incorrect, and shots and counts have the wrong distribution.

For example:

from pytket.circuit import Circuit, Unitary2qBox
from pytket.extensions.qiskit import AerUnitaryBackend
import numpy as np

u = np.array([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 0, 1], [0, 0, 1, 0]], dtype=complex)

ubox = Unitary2qBox(u)
c = Circuit(2)
c.add_unitary2qbox(ubox, 0, 1)
b = AerUnitaryBackend()
h = b.process_circuit(c)
r = b.get_result(h)
print(r.get_unitary())

prints:

[[1.+0.j 0.+0.j 0.+0.j 0.+0.j]
 [0.+0.j 0.+0.j 0.+0.j 1.+0.j]
 [0.+0.j 0.+0.j 1.+0.j 0.+0.j]
 [0.+0.j 1.+0.j 0.+0.j 0.+0.j]]