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.16k stars 2.35k forks source link

Plot_hinton imaginary section displays incorrect elements #8324

Closed dimple12M closed 1 year ago

dimple12M commented 2 years ago

Environment

Screenshot 2022-07-12 at 11 09 39 AM

What is happening?

In the Visualization section: plot_hinton It displays 2 plots : one for real and one for imaginary There are 2 issues:

  1. The imaginary elements displays the elements incorrect for real and negative numbers.
  2. The size of the square of the elements are not equal for the imaginary plot

How can we reproduce the issue?

Screenshot 2022-07-12 at 11 07 33 AM

What should happen?

We expect the following plot_hinton

Screenshot 2022-07-12 at 11 12 22 AM

Any suggestions?

We make few simple changes in the state_visualizaton.py file and we can obtain the correct plot for the imaginary section in the plot_hinton.

HuangJunye commented 2 years ago

The second part of this issue (The size of the square of the elements are not equal for the imaginary plot) will be fixed by https://github.com/Qiskit/qiskit-terra/pull/8447.

I am investigating in the first part of the issue. The hinton plot currently plots the matrix transversely. I am not sure if this is the expected behavior.

from qiskit.quantum_info import DensityMatrix
from qiskit.tools.visualization import plot_state_hinton

state = DensityMatrix(
    [
        [1,1],
        [-1,-0.5] 
    ])
plot_state_hinton(state)

produces

image
dimple12M commented 2 years ago

The first part of the issue I think its related with the elements displayed on the hinton plot As seen from the density matrix, the elements of the real part is displayed as shown :

from qiskit import QuantumCircuit
from qiskit.quantum_info import DensityMatrix
from qiskit.visualization import plot_state_hinton

qc = QuantumCircuit(2)
qc.h(0)

state = DensityMatrix.from_instruction(qc)
print(state)

Screenshot 2022-08-10 at 3 55 35 PM

dimple12M commented 2 years ago

This the second example specific : elements related to real as well as imaginary section. I think, how are the elements are displaced is confusing . Still will look into it. Maybe we have can small description for the same.


from qiskit import QuantumCircuit
from qiskit.quantum_info import DensityMatrix
from qiskit.visualization import plot_state_hinton
![Screenshot 2022-08-10 at 4 10 46 PM](https://user-images.githubusercontent.com/65215560/183850058-45173b26-bbb1-4fa4-8186-e534dd6b726f.png)

state=DensityMatrix([[0.5+0.j, 0.+0.j, 0. -0.5j, 0. +0.j],
               [0.5+0.j, 0.+0.j, 0. -0.5j, 0. +0.j],
               [0.5 +0.j, 0. +0.j, 0. -0.5j, 0.+ 0.j],
               [0.5 +0.j, 0. +0.j, 0. -0.5j, 0. +0.j]])

plot_state_hinton(state)

Screenshot 2022-08-10 at 4 14 49 PM