qml.expval¶
- expval(op)[source]¶
Expectation value of the supplied observable.
Example:
dev = qml.device("default.qubit", wires=2) @qml.qnode(dev) def circuit(x): qml.RX(x, wires=0) qml.Hadamard(wires=1) qml.CNOT(wires=[0, 1]) return qml.expval(qml.Y(0))
Executing this QNode:
>>> circuit(0.5) -0.4794255386042029
- Parameters
op (Union[Observable, MeasurementValue]) – a quantum observable object. To get expectation values for mid-circuit measurements,
op
should be aMeasurementValue
.- Returns
measurement process instance
- Return type
code/api/pennylane.expval
Download Python script
Download Notebook
View on GitHub