qml.var

var(op)[source]

Variance of the supplied observable.

Parameters

op (Union[Operator, MeasurementValue]) – a quantum observable object. To get variances for mid-circuit measurements, op should be a MeasurementValue.

Returns

Measurement process instance

Return type

VarianceMP

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.var(qml.Y(0))

Executing this QNode:

>>> circuit(0.5)
0.7701511529340698

Contents

Using PennyLane

Release news

Development

API

Internals