Documentation of expval

Hey @IanDavis! Welcome to the forum :smile:

Thank you for your feedback :slight_smile:. I think the main source of confusion here is the distinction between qml.expval on its own versus when it’s returned from a QNode. Let me explain what’s going on under the hood at a high level.

If I just print out qml.expval(qml.PauliZ(0)), here’s what I get:

>>> import pennylane as qml
>>> qml.expval(qml.PauliZ(0))
expval(PauliZ(wires=[0]))
>>> type(qml.expval(qml.PauliZ(0)))
<class 'pennylane.measurements.expval.ExpectationMP'>

In that sense, the documentation for expval is correct: it’s returning a measurement process instance — expval(PauliZ(wires=[0])) — whose type is ExpectationMP.

However, a measurement process instance has no meaning / value on its own — it’s simply a process. A value is associated to the process when there’s something to inject into the process: a quantum state generated by a quantum circuit! So, in the context of being returned from a QNode — pennylane’s lingo for a quantum circuit — the measurement is assigned a value whose type is a pennylane.numpy.tensor.tensor, as you said.

Side note: pennylane.numpy.tensor.tensor really just means a NumPy array :slight_smile:.

Let me know if this helps!

1 Like