Understanding Expected Value Measurements in PennyLane

Hello,

I have a question about measuring expected values using PauliZ in a quantum computing context (as shown above). Here’s an example of the code:

  return [qml.expval(qml.PauliZ(i)) for i in range(2)]

In this case, we are measuring the expected values for each qubit. I want to understand the theory behind this measurement. Is the calculation or math behind it as follows?

  • For Qubit 1: ⟨ψ|(Z ⊗ I)|ψ⟩
  • For Qubit 2: ⟨ψ|(I ⊗ Z)|ψ⟩

Additionally, I have seen ⟨ψ|(Z ⊗ Z)|ψ⟩ as a solution in some cases. My understanding is that this provides only one expectation value, whereas the code above generates two values for two qubits. Could you clarify this for me?

Hi @Nabil_Anan_Orka , thank you for your question. Is this the same question as you asked in this other topic? It looks very similar so if it’s more or less the same it’s best to keep it in the same topic. Or if there’s a subtlety that I’m maybe not seeing here please let me know. I’ll get back to you with an answer in the other thread very soon.

Hi!

Yes, it’s the same. I have just provided a bit more context in this post for more clarity.

Thanks for clarifying @Nabil_Anan_Orka !

We’ve had a big flux of questions recently but I’ll be back with an answer very soon!

For anyone following this thread, my colleague Guillermo answered in the other thread :heart: