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”?

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

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:

Pr(0) = ⟨0|ψ⟩

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)?

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: