Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transpile bug when using sx basis with Y and -Y #5742

Closed
naezzell opened this issue Jan 28, 2021 · 2 comments
Closed

Transpile bug when using sx basis with Y and -Y #5742

naezzell opened this issue Jan 28, 2021 · 2 comments

Comments

@naezzell
Copy link

Informations

  • Qiskit version: 0.23.2
  • Python version: 3.9.1
  • Operating system: 10.15.7

What is the current behavior?

Transpile gives wrong native circuit with sx basis but correct circuit with u basis for Armonk.

Steps to reproduce the problem

We will define a 180 degree rotation about y axis (i.e. the Y gate) and about the -y axis (i.e. -Y gate) using the decomposition of an arbitrary rotation.

# First the Y circuit
y_circ = QuantumCircuit(1, 1)
y_circ.barrier(0)
y_circ.rz(-np.pi / 2, 0)
y_circ.ry(-np.pi / 2, 0)
y_circ.rz(np.pi, 0)
y_circ.ry(np.pi / 2, 0)
y_circ.rz(np.pi / 2, 0)
y_circ.barrier(0)

# Now the -Y circuit
my_circ = QuantumCircuit(1, 1)
my_circ.barrier(0)
my_circ.rz(-3*np.pi / 2, 0)
my_circ.ry(-np.pi / 2, 0)
my_circ.rz(np.pi, 0)
my_circ.ry(np.pi / 2, 0)
my_circ.rz(3*np.pi / 2, 0)
my_circ.barrier(0)

Now we will transpile these using Armonk as the backend (1) with the sx basis and (2) with the u basis.

y_tcirc = transpile(y_circ, armonk)
y_tcirc.draw()

Screen Shot 2021-01-28 at 12 07 16 PM

my_tcirc = transpile(my_circ, armonk)
my_tcirc.draw()

Screen Shot 2021-01-28 at 12 10 43 PM

y_tcirc_u = transpile(y_circ, armonk,  basis_gates=['u1', 'u2', 'u3', 'cx'])
y_tcirc_u.draw()

Screen Shot 2021-01-28 at 12 07 57 PM

my_tcirc_u = transpile(my_circ, armonk, basis_gates=['u1', 'u2', 'u3', 'cx'])
my_tcirc_u.draw()

Screen Shot 2021-01-28 at 12 10 24 PM

Notice that the sx basis gives same exact transpiled circuit whereas u basis differs in the argument of u3. If you simulate the circuit, they differ by a global phase (i.e. whether you get i|1> or -i|1>), and the phase difference between Y and -Y is important, i.e. for DD, so this isn't good.

Note: You can do the same procedure with X and -X, but you actually get a difference in both bases as expected.

What is the expected behavior?

Using the sx basis shouldn't destroy phase information that the u basis preserves, as this is important for implementing real procedures.

Suggested solutions

I'm not sure how transpile works under the hood, so it's hard to offer suggested solution. However, if it's expected that sx basis may loose phase information, it would be nice for a warning to be given.

P.S. If I specify things in u basis, are they still transpiled to sx before being run, and if so, how can I implement Y and -Y as I want?

@mtreinish mtreinish transferred this issue from Qiskit/qiskit-metapackage Jan 28, 2021
@mtreinish
Copy link
Member

@naezzell have you tried this on qiskit 0.23.3 or 0.23.4 (which was just released a little while ago)? 0.23.3 included some fixes for the transpiler around global phase tracking (see #5618 and #5474). I haven't looked at this issue in detail yet, so I'm not sure if it will fix it, or there is something else going on.

@naezzell
Copy link
Author

@naezzell have you tried this on qiskit 0.23.3 or 0.23.4 (which was just released a little while ago)? 0.23.3 included some fixes for the transpiler around global phase tracking (see #5618 and #5474). I haven't looked at this issue in detail yet, so I'm not sure if it will fix it, or there is something else going on.

Things seem to work in qiskit 0.23.4. Thanks for the heads up!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants