relative_entropy(state0, state1, base=None, check_state=False, c_dtype='complex128')[source]

Compute the quantum relative entropy of one state with respect to another.

\[S(\rho\,\|\,\sigma)=-\text{Tr}(\rho\log\sigma)-S(\rho)=\text{Tr}(\rho\log\rho)-\text{Tr}(\rho\log\sigma) =\text{Tr}(\rho(\log\rho-\log\sigma))\]

Roughly speaking, quantum relative entropy is a measure of distinguishability between two quantum states. It is the quantum mechanical analog of relative entropy.

Each state can be given as a state vector in the computational basis or as a density matrix.

  • state0 (tensor_like) – (2**N) state vector or (2**N, 2**N) density matrix.

  • state1 (tensor_like) – (2**N) state vector or (2**N, 2**N) density matrix.

  • base (float) – Base for the logarithm. If None, the natural logarithm is used.

  • check_state (bool) – If True, the function will check the state validity (shape and norm).

  • c_dtype (str) – Complex floating point precision type.


Quantum relative entropy of state0 with respect to state1

Return type



The relative entropy between two equal states is always zero:

>>> x = np.array([1, 0])
>>> qml.math.relative_entropy(x, x)

and the relative entropy between two non-equal pure states is always infinity:

>>> y = np.array([1, 1]) / np.sqrt(2)
>>> qml.math.relative_entropy(x, y)

The quantum states can be provided as density matrices, allowing for computation of relative entropy between mixed states:

>>> rho = np.array([[0.3, 0], [0, 0.7]])
>>> sigma = np.array([[0.5, 0], [0, 0.5]])
>>> qml.math.relative_entropy(rho, sigma)
tensor(0.08228288, requires_grad=True)

It is also possible to change the log base:

>>> qml.math.relative_entropy(rho, sigma, base=2)
tensor(0.1187091, requires_grad=True)