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
5.21k stars 2.36k forks source link

phase visualization seems broken #5845

Open 1ucian0 opened 3 years ago

1ucian0 commented 3 years ago

This issues is coming from my attempt to answer this question https://stackoverflow.com/questions/66180030/qiskit-difference-on-statevector-no-difference-on-vizualization

import numpy as np
from qiskit.tools.visualization import plot_state_qsphere

display(plot_state_qsphere(np.array([1, 0])))
display(plot_state_qsphere(np.array([-1, 0])))

image image

The color of the vector in the second draw should be different .

1ucian0 commented 3 years ago

Same for plot_state_paulivec?

display(plot_state_paulivec(np.array([1, 0])))
display(plot_state_paulivec(np.array([-1, 0])))

image

image

nonhermitian commented 3 years ago

It is bot broken per say, but implicitly normalizes the global phase via the largest magnitude component. It has done this since v1 of the qsphere code.

delapuente commented 3 years ago

I found this too and figure out it was normalizing as indicated by @nonhermitian. Maybe we can deprecate this behavior in favor of not normalizing. I think the way it is, currently, produces unexpected results, following the implicit normalization, and also goes against the construction of the q-sphere.

delapuente commented 3 years ago

At this point, the class DensityMatrix removes the global phase. Is it intended? https://github.com/delapuente/qiskit-terra/blob/c3b2d7acb80fa89043e6f38efb501275ec296616/qiskit/quantum_info/states/densitymatrix.py#L98

mrvee-qC commented 3 years ago

Would like to also bump this up. In a course while teaching, people where confused why there wasnt a phase change in the QSphere visualization when Y gate was applied to the circuit. It indeed does normalize the phase which confuses a few people when the output on the composer does not really match with the output locally. Would be great if this was fixed!

raghavven commented 3 years ago

Found a similar error. Y Gate not flip phase when run on circuit composer while GUI composer show the flip. Also on local computer, it doesn't flip phase.

First three are from circuit composer from IBM-q website, same holds when run on local computer. The last one is GUI based circuit composer which seems to work fine.

YGate_Circuit_Composer_1 YGate_Circuit_Composer_2 YGate_Circuit_Composer_3

Ygate_GUI_Composer

mvanwaveren commented 3 years ago

Hello,

I also found the same error. Could someone be assigned to the bug?

I want to code the following circuit:

Bug report 1

Result on IBM Composer

If I code it on IBM Composer, I get the following state vector: [ 0+0j, 0+0j, 0.707+0j, -0.707+0j ]

The plot of the state vector is:

Bug report 4 Composer

This corresponds to the following result:

Bug report 2

The Python code shown on the IBM Composer is:

OPENQASM 2.0; include "qelib1.inc"; qreg q[2]; creg c[2]; h q[0]; x q[1]; z q[0];

Result on Qiskit

If I code it on Qiskit, I get the same state vector : Statevector([ 0.+0.j, 0.+0.j, 0.70710678+0.j, -0.70710678+0.j], dims=(2, 2))

The plot of the state vector is different, though.

Bug report 5 Qiskit

The plot suggests that the result is:

Bug report 3

which is incorrect.

The Python code used on Qiskit is: def create_circuit(): qc = QuantumCircuit(2) qc.h(0) qc.x(1) qc.z(0) return qc qc = create_circuit() sv = Statevector.from_label('00') sv = sv.evolve(qc) print(sv) plot_state_qsphere(sv.data, show_state_labels=True, show_state_phases=True)

Conclusion

There is a bug in the plot of the state vector on Qiskit.