The Pauli matrices are both Hermitian and unitary, which means that they can be thought of as both an observable and a gate.

Let’s take PauliZ as an example. As a gate, its action can be understood on the Bloch sphere as a rotation of 180 degrees about the z axis. Instead, if we measure PauliZ as an observable, we project the qubit state into the eigenbasis of PauliZ, which is |0> and |1> (the computational basis). We would observe the value 1 if our state is projected into |0> and -1 if our state is projected into |1>. The expectation value of PauliZ is then just the average of 1’s and -1’s.

In other words, measuring the expectation value of PauliZ can be thought of as measuring in the usual computational basis and then using that to calculate an average. This is something we often want to do in quantum circuits, and hence we often have return qml.expval(qml.PauliZ(wire)).

The Pauli gates and rotation gates are closely linked. I recommend checking out some standard material such as Quantum Computation and Quantum Information for a better theoretical understanding. Practically, you can think of, e.g., the PauliZ gate as a special case of the RZ gate with a fixed rotation (up to a global phase) - in other words, the rotation gates give you access to a controllable rotation parameter which can be used for ML/optimization - so generally I’d use RZ as a gate in a variational circuit.

By reading the diagonal elements of the Pauli-Z matrix, we can see that
Z has two eigenvectors, |0⟩ and |1⟩ ,with corresponding eigenvalues
±1. Thus, if we measure the qubit and obtain Zero (corresponding to the state |0⟩), we know that the state of our qubit is a +1 eigenstate of the Z
operator and vice versa.

But PauliX also has the same eigen vectors. What makes Z different?

Also I found these table ? Can you explain these?

Pauli Measurement

Unitary transformation

Z

1

X

H

Y

HS†

That is, using this language, “measure Y” is equivalent to applying
HS†.

What does these mean? Also how many values expval takes for average for single wire?

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 Operation:

In [3]: qml.PauliX(0).diagonalizing_gates()
Out[3]: [Hadamard(wires=[0])]

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

Just one thing: You told that : The right column in the table that you have linked lists the unitary transformations ( U ) to be applied for each Pauli

But why identity to Z and H to X?
Is there any proof or Intuitive explanation for this?

Also If I do like:

return qml.expval(PauliX()) – Do I need to use Hadamard somewhere or is it inbuilt
since
return qml.expval(PauliZ()) has identity and so it will be same if we put or not, right?

Also both or all three X, Y or Z should give same answer right, since it all means measuring same state using different substitution for finding the hermitian operator.

But why identity to Z and H to X?
Is there any proof or Intuitive explanation for this?

The table above gives the unitary transforms to transform the given observable to the Pauli Z matrix. The most intuitive way to see this is via matrix multiplication

For example, consider the expression U^\dagger O U for various observables O (left column in the table) and unitary transformations U (right column).

With O=Z, U=I, it is slightly more intuitive, since we can directly see that I^\dagger ZI=Z without performing the matrix multiplication (since any matrix multiplied by the identity is unchanged).