Hello,
qml.measure
measures the qubit in the computational basis, which is the Pauli Z basis, I would say. But why do I get different results with qml.expval(op=measurement)
and qml.expval(qml.PauliZ(wires=0)
?
Below you can find a minimal working example:
import pennylane as qml
from pennylane import numpy as np
device = qml.device('default.qubit', wires=1)
@qml.qnode(device)
def circuit_pauli_z(params):
qml.RX(params, wires=0)
return qml.expval(qml.PauliZ(wires=0))
@qml.qnode(device)
def circuit_measure(params):
qml.RX(params, wires=0)
measurement = qml.measure(wires=0)
return qml.expval(op=measurement)
params = 0.75 * np.pi
result_pauli_z = circuit_pauli_z(params)
result_measurement = circuit_measure(params)
print(result_pauli_z)
print(result_measurement)
which gives:
-0.7071067811865475
0.8535533905932737
From my understanding, the first result is the expected one. But what is the second output (the one from qml.measure
?