qml.math.purity¶
- purity(state, indices, check_state=False, c_dtype='complex128')[source]¶
Computes the purity of a density matrix.
γ=Tr(ρ2)where ρ is the density matrix. The purity of a normalized quantum state satisfies 1d≤γ≤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