qml.math.purity¶
- purity(state, indices, check_state=False, c_dtype='complex128')[source]¶
Computes the purity of a density matrix.
\[\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.
It is possible to compute the purity of a sub-system from a given state. To find the purity of the overall state, include all wires in the
indices
argument.- Parameters
state (tensor_like) – Density matrix of shape
(2**N, 2**N)
or(batch_dim, 2**N, 2**N)
indices (list(int)) – List of indices in the considered subsystem.
check_state (bool) – If
True
, the function will check the state validity (shape and norm).c_dtype (str) – Complex floating point precision type.
- Returns
Purity of the considered subsystem.
- Return type
float
Example
>>> x = [[1/2, 0, 0, 1/2], [0, 0, 0, 0], [0, 0, 0, 0], [1/2, 0, 0, 1/2]] >>> purity(x, [0, 1]) 1.0 >>> purity(x, [0]) 0.5
>>> x = [[1/2, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 1/2]] >>> purity(x, [0, 1]) 0.5
See also