0
$\begingroup$

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)
circuit.y(0)
statevector = execute(circuit, backend=Aer.get_backend('statevector_simulator')).result().get_statevector()
print(statevector) # [0.-0.j 0.+1.j]
plot_state_qsphere(statevector)

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

$\endgroup$
4
  • 1
    $\begingroup$ There is an internal step that sets the phase of the largest component to one. $\endgroup$ Sep 6, 2020 at 17:47
  • $\begingroup$ Thank you for your comment. Is there any way to avoid this behavior? $\endgroup$
    – incud
    Sep 6, 2020 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$ Sep 7, 2020 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, 2020 at 14:09

1 Answer 1

1
$\begingroup$

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

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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