qml.math.relative_entropy¶
- 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 must be given as a density matrix. To find the relative entropy given a pure state, call
dm_from_state_vector()
first.- Parameters
state0 (tensor_like) –
(2**N, 2**N)
or(batch_dim, 2**N, 2**N)
density matrix.state1 (tensor_like) –
(2**N, 2**N)
or(batch_dim, 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.
- Returns
Quantum relative entropy of state0 with respect to state1
- Return type
float
Examples
The relative entropy between two equal states is always zero:
>>> x = np.array([1, 0]) >>> x = qml.math.dm_from_state_vector(x) >>> qml.math.relative_entropy(x, x) 0.0
and the relative entropy between two non-equal pure states is always infinity:
>>> y = np.array([1, 1]) / np.sqrt(2) >>> y = qml.math.dm_from_state_vector(y) >>> qml.math.relative_entropy(x, y) inf
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) 0.08228288
It is also possible to change the log base:
>>> qml.math.relative_entropy(rho, sigma, base=2) 0.1187091