# How does Pennylane compute expected values of single-qubit operators over real hardware?

Imagine I have a quantum circuit of n qubits and I want to measure the expected value of a single-qubit operator (let's say PauliZ) for each qubit. This is easily done in Pennylane with the following line:

return [qml.expval(qml.PauliZ(wires=i)) for i in range(n_qubits)]


Running this on real quantum hardware, how is this measurement done? Does it measure $$H=ZIII...I$$ first, $$H=IZII...I$$ afterwards and so forth, does it sample the circuit in computational basis and compute each qubit's expected value out of the odds, or it is something else?

1. For any wire that is not measured in the computational basis, the wire is rotated into the computational basis prior to measurement by appending $$\mathcal{O}(1)$$ single qubit gates (for example, for $$\langle X_i \rangle$$, a Hadamard gate would be appended to wire $$i$$).
3. Finally, the (approximate) expectation value is computed via $$\sum_i \lambda_i \mathbb{P}_i$$, where $$\lambda_i$$ are the eigenvalues of the observable being measured, and $$\mathbb{P}_i$$ are the (potentially rotated) probabilities from step (2). Note that, if we are restricted to Pauli terms as observables, the eigenvalues are known in advance and will simply be in the set $$\{-1, 1\}$$.