CQCL / pytket-qiskit

pytket-qiskit, extensions for pytket quantum SDK
Apache License 2.0
17 stars 13 forks source link

Incorrect conversion of parameterised gates with large angles with `qiskit_to_tk` #367

Open CalMacCQ opened 4 months ago

CalMacCQ commented 4 months ago
from pytket.extensions.qiskit import qiskit_to_tk
from pytket.qasm import circuit_to_qasm_str
from qiskit import QuantumCircuit
import numpy as np

qc = QuantumCircuit(1)
qc.rx((1e14 + 0.12)*np.pi, 0) # rx gate with a large parameter value

circ = qiskit_to_tk(qc)
print(circuit_to_qasm_str(circ))

QASM output

OPENQASM 2.0;
include "qelib1.inc";

qreg q[1];
rx(0.21875*pi) q[0];

The operators for rx(0.21875*pi) and rx(0.12*pi) are not unitarily equivalent. Seems like there is some rounding error occuring when converting the large parameter value to pytket.

As far as I know for the converision from qiskit params to pytket params simply consists in dividing by sympy.pi (for numeric values) to account for the differing angle conventions.

See https://github.com/CQCL/pytket-qiskit/blob/main/pytket/extensions/qiskit/qiskit_convert.py#L571

CalMacCQ commented 4 months ago

One option would be to normalise these large angles mod $2 \pi$ in qiskit_to_tk