Assume we have a one qubit state | \psi \rangle and are curious about the expectation value \langle \psi | O| \psi \rangle, where O is an Hermitian operator. It turns out that we can find a unitary U such that O can be expressed using U and PauliZ as follows: O=U^\dagger ZU. Using this, we can formulate calculating the expectation value \langle \psi | O| \psi \rangle, as finding a U unitary, such that \langle \psi | U^\dagger Z U |\psi \rangle.
Given such a U unitary, we can then calculate \langle \psi | O| \psi \rangle as follows:
Apply U to the state |\psi \rangle, such that |\phi \rangle = U|\psi \rangle
Calculate the expectation value \langle \phi | Z | \phi \rangle
Internally we use this logic in PennyLane to carry out measurements for simulators.
The right column in the table that you have linked lists the unitary transformations (U) to be applied for each Pauli. As Nathan mentioned on Slack, this would correspond to the unitary being absorbed into the variational circuit pre-measurement. For example, for PauliZ, we can simply apply the identity whereas, in the case of PauliX, we use the Hadamard gate:
\langle \psi | X |\psi \rangle = \langle \psi | U^\dagger Z U |\psi \rangle = \langle \psi | H^\dagger Z H |\psi \rangle = \langle \phi | Z |\phi \rangle
where H stands for the Hadamard gate.
In PennyLane, gates are accessible through calling the
diagonalizing_gates method of an
In : qml.PauliX(0).diagonalizing_gates()
As for your question on the number of values used for an expectation value, one can specify the number of
shots for a device in PennyLane. This will determine the number of samples obtained through executing the quantum circuit that are being averaged over (provided that the
analytic attribute is set to
False for the device):
dev = qml.device('default.qubit', shots=100, wires=1, analytic=False)
Hope this helps!