Hello, I was trying to check density matrix for CZ gate after it being applied to state 11 but in density matrix i don’t see any phase flip. Why? what’s the formula that pennylane is using for density matrix?
# dev_cz = qml.device("lightning.qubit", wires=2)
@qml.qnode(dev_cz, interface="autograd")
def CZ(input_state):
qml.StatePrep(input_state, wires=[0, 1])
qml.CZ(wires=[0, 1])
return qml.density_matrix(wires=[0, 1])
input_state = np.array([0, 0, 0, 1], dtype=complex)
print(CZ(input_state))
If you want help with diagnosing an error, please put the full error message below:
I want to know why I am not seeing the phase shift here? in the density matrix shouldn’t it be |11\rangle -\langle 11| ?
Hi @Rayhan740 ,
Since you don’t have any noise in your circuit you actually have a pure state instead of a mixed state, so the density operator will be \rho = |\psi \rangle \langle \psi |. Since your initial state is |\psi \rangle = |11 \rangle then CZ|\psi \rangle = -|11 \rangle. Hence
\rho = \begin{bmatrix}0 &0 & 0 & 0\\0 & 0 & 0 & 0\\0 & 0 & 0 & 0\\0 & 0 & 0 & 1\end{bmatrix}
This is in fact the output that PennyLane is providing.
Since you don’t have any noise I’m wondering whether you really need density matrices here. If you’re planning on adding noise in the future you will need the "default.mixed" device instead of the "lightning.qubit" one.
Note: We actually have a really good PennyLane Codebook module on Noisy Quantum theory. I found it very helpful so I hope you do too!