purity

purity(state, validate=True)[source]

Calculate the purity of a quantum state.

The purity of a density matrix \(\rho\) is

..code:

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

Parameters
  • state (Statevector or DensityMatrix) – a quantum state.

  • validate (bool) – check if input state is valid [Default: True]

Returns

the purity \(\Tr[\rho^2]\).

Return type

float

Raises

QiskitError – if the input isn’t a valid quantum state.