2
$\begingroup$

If I have a one gate circuit like in the following image:

enter image description here

I can calculate the density matrix by following steps:

enter image description here

enter image description here

enter image description here

However, I want to do it for the Toffoli gate circuit:

enter image description here

and I am confused with the initial density matrix. How to write an initial density matrix for 3 qubits?

I used qiskit to compute it and I used the following code:

qc_AB = QuantumCircuit(3)
qc_AB.h(2)
qc_AB.cx(1,2)
qc_AB.tdg(2)
qc_AB.cx(0,2)
qc_AB.t(2)
qc_AB.cx(1,2)
qc_AB.tdg(2)
qc_AB.cx(0,2)
qc_AB.cx(0,1)
qc_AB.h(2)
qc_AB.t(0)
qc_AB.tdg(1)
qc_AB.cx(0,1)
qc_AB.draw()
rho_AB = qi.DensityMatrix.from_instruction(qc_AB)
rho_AB.draw('latex', prefix='\\rho_{AB} = ')

According the qiskit my initial density matrix is here:

enter image description here

How to calculate it by hand? I am not sure this initial density matrix is correct or not...

$\endgroup$
4
$\begingroup$

You just forgot to add the highlighted gates to your code: enter image description here

Add them and your code should work as expected.

Note that to add Toffoli gate to your circuit you can call toffoli method:

qc_AB.toffoli(0, 1, 2)
$\endgroup$
1
  • $\begingroup$ great, thank you very much for your help and yes I guess now I found what I wanted !. I cannot use toffoli gate directly because of some experimental part of the study ...:/ $\endgroup$
    – quest
    Jan 4 at 12:57
1
$\begingroup$

"How to calculate it by hand? I am not sure this initial density matrix is correct or not..."

If you initialize your states to $|000\rangle = |0\rangle\otimes |0\rangle \otimes|0\rangle$, and each $|0\rangle$ has a vector representation (in the "computational basis") of:

$$\tag{1} |0\rangle \equiv\begin{pmatrix} 1 \\ 0 \end{pmatrix}, $$

then the vector representation of your initial three qubits will be an 8-element vector where the first one is a 1 and the rest are all 0.

Now you need to do the outer product of this vector with itself. This will give you an 8x8 matrix in which the first element (row 1, column 1) is a 1 and the rest are all 0s.

I think this is even easier to verify with octave-online than with Python:

Zero = [1 ; 0];ZeroZeroZero = kron(kron(Zero,Zero),Zero)
ZeroZeroZero =

   1
   0
   0
   0
   0
   0
   0
   0

rho = ZeroZeroZero*ZeroZeroZero'
ans =

   1   0   0   0   0   0   0   0
   0   0   0   0   0   0   0   0
   0   0   0   0   0   0   0   0
   0   0   0   0   0   0   0   0
   0   0   0   0   0   0   0   0
   0   0   0   0   0   0   0   0
   0   0   0   0   0   0   0   0
   0   0   0   0   0   0   0   0
$\endgroup$
1
  • $\begingroup$ amazing thanks. I now know how to do it. UNfortunatel I cannot give 2 tick for different answer, the forum is not allow me to do it. thanks : )) $\endgroup$
    – quest
    Jan 4 at 12:58

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.