Multi qubit expectation values

Hi everyone!

I have a bit of theoretical curiosity relating to multi-qubit projective measurement (let’s say with PauliZ). For a two-qubit circuit, from my understanding, the measurement matrix will look something like this: Z⊗Z, and the shape of the output is (1,1) or a singular value. In PennyLane, there’s an option to measure each qubit separately, so for this particular circuit, the output shape will be something like (1,2) or two distinct values for the two qubits.

For the second case (i.e., measuring multiple qubits separately), what is the math underneath, especially in terms of matrices?

Is it something like this:

  • For qubit 1: Z⊗I
  • For qubit 2: I⊗Z

Also, if the measurement happens one qubit after the other, how does PennyLane handle “wavefunction collapse”?

Hi @Nabil_Anan_Orka ,

Could you please share the code you’re using? I just want to make sure I’m understanding your question correctly.

Please visit the following post for more clarification:

Explanation post and code

A dummy code:

def my_quantum_function(x, y):
    qml.RZ(x, wires=0)
    qml.CNOT(wires=[0, 1])
    qml.RY(y, wires=1)
    return [qml.expval(qml.PauliZ(i)) for i in range(2)]

Here, how are the two expvals are calculated theoretically?

Thanks for adding the code here @Nabil_Anan_Orka . Let me get back to you on this very soon.

Really good question :smile:

Theoretically what is done is to generate the state from the gates of the circuit. Imagine then that you want to calculate the expected value with respect to the observable Z in the ith qubit. What we do is to calculate the probability of obtaining 0 and 1 respectively in that qubit and we calculate P(0) - P(1).
Why P(0)- P(1)? Because the eigenvalue of |0\rangle is 1 and that of |1\rangle is -1.

If you had the observable ZxZ, the expected value would be P(00) - P(01) - P(10) + P(11), since the eigenvalues of |00\rangle, |01\rangle, |10\rangle and |11\rangle are 1,-1,-1 and 1 respectively.

if you define an arbitrary state |\phi\rangle = (\alpha_1, \alpha_2, \alpha_3, \alpha_4) and do the math (\langle \phi | Z\otimes Z |\phi \rangle ), you will see that this is what I said before :rocket:

I hope that helps!

2 Likes

Thank you for your clarification:

However, I still have some questions regarding the circuit:

After performing the quantum operations, the resulting state is |ψ⟩ = a|00⟩ + b|01⟩ + c|10⟩ + d|11⟩.

Here, |ψ⟩ is a column vector (matrix) of shape (4,1). I need to calculate the probabilities:

  1. Pr(0) = ⟨0|ψ⟩
  2. Pr(1) = ⟨1|ψ⟩

How do I calculate these probabilities and then find the difference Pr(0) - Pr(1) in this context, especially considering ⟨0| and ⟨1| are row vectors (matrices) of shape (1,2)?

Given |\psi\rangle we can calculate P(|00\rangle) = a^2, P(|01\rangle) = b^2, P(|10\rangle) = c^2 and P(|11\rangle) = d^2 :slight_smile:
Does this solve your issue?

Are P(|0>) and P(|00>) the same, for the circuit above?

Consider a three-qubit circuit with the state (|ψ⟩ = a|000⟩ + b|001⟩ + c|010⟩ + d|011⟩ + e|100⟩ + f|101⟩ + g|110⟩ + h|111⟩). What would the probabilities (Pr(0)) and (Pr(1)) look like for this state? For each qubit in this three-qubit circuit, is the expected value with respect to the Pauli-Z operator (Pr(0) - Pr(1))?

We know that measuring a qubit in a circuit changes the state of the system. What will happen to the remaining qubits if we measure the first qubit using (Pr(0) - Pr(1))? Will this measurement violate any quantum rules?

The probability of getting 0 in the first qubit in the above case would be the sum of all the separate amplitudes that meet that. In this case:
|a|^2 + |b|^2 + |c|^2 + |d|^2

To give another example, the probability of obtaining 0 in the second qubit is:

|a|^2 + |b|^2 + |e|^2 + |f|^2