2
$\begingroup$

Let's say I am running this code and I obtain picture below using Qiskit DensityMatrix class.

from qiskit.quantum_info import DensityMatrix
from qiskit.visualization import plot_state_city
qc2 = QuantumCircuit(2,2)
qc2.h(0)
qc2.cx(0,1)
qc2.draw('mpl')
state2 = DensityMatrix.from_instruction(qc2)
plot_state_city(state2.data)

How may I interpret this 'DensityMartix' chart? For what cases is it useful?

I have searched in Qiskit Documentation but did not find something beginner could digest. Will be grateful for any hints and directions.

enter image description here

$\endgroup$
1
$\begingroup$

The bars represent the amplitude of the elements in the desnity matrix, $\rho$.

So for instance, this particular plot

enter image description here

tell us that the element $\rho_{0,0} = \rho_{0,3} = \rho_{3,0} = \rho_{3,3} = 1/2$ and the rest are zero. That is, it meant to represent this matrix:

$$ \rho = \begin{pmatrix} \rho_{0,0} & \rho_{0,1} & \rho_{0,2} & \rho_{0,3}\\ \rho_{1,0} & \rho_{1,1} & \rho_{1,2} & \rho_{1,3}\\ \rho_{2,0} & \rho_{2,1} &\rho_{2,2} & \rho_{2,3}\\ \rho_{3,0} & \rho_{3,1} & \rho_{3,2} & \rho_{3,3}\end{pmatrix}= \begin{pmatrix} \rho_{0} & \rho_{1} & \rho_{2} & \rho_{3}\\ \rho_{4} & \rho_{5} & \rho_{6} & \rho_{7}\\ \rho_{8} & \rho_{9} &\rho_{10} & \rho_{11}\\ \rho_{12} & \rho_{13} & \rho_{14} & \rho_{15}\end{pmatrix}= \begin{pmatrix} 1/2 & 0 & 0 & 1/2\\ 0 & 0 & 0 & 0\\ 0 & 0 & 0 & 0\\ 1/2 & 0 & 0 & 1/2 \end{pmatrix} $$

Note that on the graph, the state $0000$ corresponds to the element $\rho_{0,0}$ which is the $0th$ element of $\rho$.

The state $0011$ corresponds to the $3rd$ element of the density matrix which is the element $\rho_{0,3}$. You can see the binary value $0011$ converts to $3$ in decimal.

Similarly, $1100$ converts to $12$ which corresponds to the $12th$ element of $\rho$ which is the element $\rho_{3,0}$.

And lastly, $1111$ converts to $15$ which is the last element of $\rho$, which is also $\rho_{3,3}$.

enter image description here

So in conclusion, the bars in the graph just to represent the amplitude of the density matrix $\rho$. And the size of the grid indicate how big your system is. The examples you gave all have matrix of size $4 \times 4$, hence it is a two qubit system. But if you have a 3 qubit system then your grid would be $8 \times 8$.


Another point to note is that the matrix

$$ \rho = \begin{pmatrix} 1/2 & 0 & 0 & 1/2\\ 0 & 0 & 0 & 0\\ 0 & 0 & 0 & 0\\ 1/2 & 0 & 0 & 1/2 \end{pmatrix} $$

can be constructed from taking the outer product of the state $|\psi \rangle = \dfrac{|00\rangle + |11 \rangle}{\sqrt{2}} = \begin{pmatrix} 1/\sqrt{2} \\ 0 \\ 0 \\ 1/\sqrt{2} \end{pmatrix}$.

That is,

$$\rho = |\psi \rangle \langle \psi | = \begin{pmatrix} 1/\sqrt{2} \\ 0 \\ 0 \\ 1/\sqrt{2} \end{pmatrix} \begin{pmatrix} 1/\sqrt{2} & 0 & 0 & 1/\sqrt{2} \end{pmatrix} = \begin{pmatrix} 1/2 & 0 & 0 & 1/2\\ 0 & 0 & 0 & 0\\ 0 & 0 & 0 & 0\\ 1/2 & 0 & 0 & 1/2 \end{pmatrix}$$

notice that the state $|\psi \rangle$ is precisely the state you created with your circuit.

qc2 = QuantumCircuit(2,2)
qc2.h(0)
qc2.cx(0,1)
$\endgroup$
2
  • $\begingroup$ thank you for this very educative and comprehensive answer! $\endgroup$
    – ertogrul
    May 20 at 7:49
  • $\begingroup$ @ertogrul you are welcome. glad I was able to help. $\endgroup$
    – KAJ226
    May 20 at 14:54

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.