Qiskit / qiskit

Qiskit is an open-source SDK for working with quantum computers at the level of extended quantum circuits, operators, and primitives.
https://www.ibm.com/quantum/qiskit
Apache License 2.0
4.85k stars 2.29k forks source link

inconsistency in Weyl decomposition of points in (pi/4, y, z) #9605

Open ajavadia opened 1 year ago

ajavadia commented 1 year ago

This is not a bug, but rather an annoying inconsistency in how TwoQubitWeylDecomposition handles points of the form (pi/4, y, z). These points are locally equivalent to (pi/4, y, -z), but the decomposer seems to be randomly picking between them. This makes it hard to write code on top of it.

What is happening?

For example by sweeping the parameter α in the following circuit I generate circuits whose Weyl coordinates lie in (pi/4, y, z). Then I invert the circuit. The expectation is that the inverse should decompose as (pi/4, y, -z) (this is true in general, not just when x=pi/4, i.e. CAN(x, y, z)† ~ CAN(x, y, -z)). However it sometimes decomposes as (pi/4, y, z) and sometimes as (pi/4, y, -z). As I said this is technically correct for this special case, but why does this happen?

How can we reproduce the issue?

import numpy as np
from qiskit.circuit.library import iSwapGate
from qiskit.circuit import QuantumCircuit, Parameter
from qiskit.quantum_info import Operator
from qiskit.quantum_info.synthesis.two_qubit_decompose import TwoQubitWeylDecomposition
import matplotlib.pyplot as plt

α = Parameter('α')
c = QuantumCircuit(2)
c.append(iSwapGate().power(1/2), [0, 1])
c.rx(-α, 0)
c.rx(α, 1)
c.append(iSwapGate().power(1/2), [0, 1])
print(c)

rs = range(200)
xs = []
ys = []
zs = []
for r in rs:
    c_bound = c.bind_parameters([r*np.pi/100])
    c_decomp = TwoQubitWeylDecomposition(Operator(c_bound.inverse()))
    x = c_decomp.a
    y = c_decomp.b
    z = c_decomp.c
    xs.append(x)
    ys.append(y)
    zs.append(z)
    abszs = [-abs(z) for z in zs]

plt.plot(rs, xs, label='x')
plt.plot(rs, ys, label='y')
plt.plot(rs, zs, label='z')
plt.plot(rs, abszs, label='-abs(z)', linestyle='--')
plt.legend()
plt.ylim(-np.pi/4-.1, np.pi/4+.1)
plt.title(f'weyl coordinates for siswap sandwich circuits')

image

What should happen?

The green line should follow the red dotted line (i.e. all decompositions should be of the form (pi/4, y, -z)).

Any suggestions?

No response

levbishop commented 1 year ago

Generally you should try to write code that doesn't care about such a jump. There will always be discontinuities in Weyl chamber expansions by necessity but I'll add a check to move the discontinuity epsilon away from the high symmetry point alpha =pi/4