I'm trying to visualize a simple circuit in Qiskit. A single gate $Y$ is applied to the single-qubit register. The expected state is:

$$ Y |0\rangle = \begin{bmatrix} 0 & -i \\ i & 0 \end{bmatrix} \begin{bmatrix} 1 \\ 0 \end{bmatrix} = \begin{bmatrix} 0 \\ i \end{bmatrix} = i |1\rangle $$

Then I visualize the final state with plot_state_qsphere function (documentation). Since the coefficient of $|1\rangle$ is $i$ I'm expecting phase $\pi/2$ since $i = e^{i \pi/2}$.

from qiskit import *
from qiskit.tools.visualization import plot_state_qsphere
print(qiskit.__qiskit_version__) # {'qiskit-terra': '0.15.1', 'qiskit-aer': '0.6.1', 'qiskit-ignis': '0.4.0', 'qiskit-ibmq-provider': '0.8.0', 'qiskit-aqua': '0.7.5', 'qiskit': '0.20.0'}
circuit = QuantumCircuit(1)
statevector = execute(circuit, backend=Aer.get_backend('statevector_simulator')).result().get_statevector()
print(statevector) # [0.-0.j 0.+1.j]

In this representation, $\pi/2$ phase corresponds to green color. However, I visualize the red color ($0$ phase). Is it a known bug? Am I missing something?

Jupyter notebook with phase bug shown

  • 1
    $\begingroup$ There is an internal step that sets the phase of the largest component to one. $\endgroup$ – Paul Nation Sep 6 at 17:47
  • $\begingroup$ Thank you for your comment. Is there any way to avoid this behavior? $\endgroup$ – incud Sep 6 at 19:01
  • $\begingroup$ Not in Qiskit; you would have to modify the source code. An alternative is here: nonhermitian.org/kaleido/tutorials/interactive/qsphere.html $\endgroup$ – Paul Nation Sep 7 at 13:16
  • $\begingroup$ Thank you @PaulNation. If you want to add your comment as an answer, I'll accept it. $\endgroup$ – incud Sep 7 at 14:09

This is due to an internal normalization based on setting the phase of the largest magnitude element to one. This cannot be changed without modifications to the source code. As an alternative, see the following examples from the Kaleidoscope package I made: https://nonhermitian.org/kaleido/tutorials/interactive/qsphere.html

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.