qml.purity

purity(wires)[source]

The purity of the system prior to measurement.

\[\gamma = \text{Tr}(\rho^2)\]

where \(\rho\) is the density matrix. The purity of a normalized quantum state satisfies \(\frac{1}{d} \leq \gamma \leq 1\), where \(d\) is the dimension of the Hilbert space. A pure state has a purity of 1.

Parameters

wires (Sequence[int] or int) – The wires of the subsystem

Returns

Measurement process instance

Return type

PurityMP

Example

dev = qml.device("default.mixed", wires=2)

@qml.qnode(dev)
def circuit_purity(p):
    qml.Hadamard(wires=0)
    qml.CNOT(wires=[0, 1])
    qml.BitFlip(p, wires=0)
    qml.BitFlip(p, wires=1)
    return qml.purity(wires=[0,1])
>>> circuit_purity(0.1)
array(0.7048)

Contents

Using PennyLane

Development

API

Internals