What is the difference between qml.measure and qml.PauliZ?

Hey @nilserik! Great question.

Indeed, qml.expval(op=m0) averages over computational basis measurements (pauli Z basis), but in the 0/1 notation, not ±1 notation. You can see this with finite shots and sample:

device = qml.device('default.qubit', wires=1, shots=100)

@qml.qnode(device)
def circuit_measure():
    qml.Hadamard(0)
    measurement = qml.measure(wires=0)

    return qml.expval(op=measurement), qml.sample(measurement)

result_measurement = circuit_measure()
print(result_measurement)
(tensor(0.39, requires_grad=True), tensor([0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0,
        0, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0,
        1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0,
        0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0,
        1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1], requires_grad=True))

So, to answer your question, qml.expval(qml.Z(0)) and qml.expval(op=measurement) here are the exact same thing… up to a linear transformation of multiplying by 2 and substracting one :sweat_smile:.

This could definitely be clearer in the documentation for qml.measure. I’ll make sure to make this obvious!