Entropy measures#
Set of functions to calculate entropy measures.
Shannon entropy#
- qibo.quantum_info.shannon_entropy(prob_dist, base=2, backend=None)[source]#
Calculate the Shannon entropy of a probability array \(\mathbf{p}\), which is given by
\[H(\mathbf{p}) = - \sum_{k = 0}^{d^{2} - 1} \, p_{k} \, \log_{b}(p_{k}) \, ,\]where \(d = \text{dim}(\mathcal{H})\) is the dimension of the Hilbert space \(\mathcal{H}\), \(b\) is the log base (default 2), and \(0 \log_{b}(0) \equiv 0\).
- Parameters:
prob_dist (ArrayLike) – a probability array \(\mathbf{p}\).
base (float) – the base of the log. Defaults to \(2\).
backend (
qibo.backends.abstract.Backend, optional) – backend to be used in the execution. IfNone, it uses the current backend. Defaults toNone.
- Returns:
Shannon entropy \(H(\mathcal{p})\).
- Return type:
Classical relative entropy#
- qibo.quantum_info.classical_relative_entropy(prob_dist_p, prob_dist_q, base=2, backend=None)[source]#
Calculates the relative entropy between two discrete probability distributions.
For probabilities \(\mathbf{p}\) and \(\mathbf{q}\), it is defined as
\[D(\mathbf{p} \, \| \, \mathbf{q}) = \sum_{x} \, \mathbf{p}(x) \, \log\left( \frac{\mathbf{p}(x)}{\mathbf{q}(x)} \right) \, .\]The classical relative entropy is also known as the Kullback-Leibler (KL) divergence.
- Parameters:
prob_dist_p (ArrayLike) – discrete probability distribution \(p\).
prob_dist_q (ArrayLike) – discrete probability distribution \(q\).
base (float) – the base of the log. Defaults to \(2\).
backend (
qibo.backends.abstract.Backend, optional) – backend to be used in the execution. IfNone, it uses the current backend. Defaults toNone.
- Returns:
Classical relative entropy between \(\mathbf{p}\) and \(\mathbf{q}\).
- Return type:
Classical mutual information#
- qibo.quantum_info.classical_mutual_information(prob_dist_joint, prob_dist_p, prob_dist_q, base=2, backend=None)[source]#
Calculates the classical mutual information of two random variables.
Given two random variables \((X, \, Y)\), their mutual information is given by
\[I(X, \, Y) \equiv H(p(x)) + H(q(y)) - H(p(x, \, y)) \, ,\]where \(p(x, \, y)\) is the joint probability distribution of \((X, Y)\), \(p(x)\) is the marginal probability distribution of \(X\), \(q(y)\) is the marginal probability distribution of \(Y\), and \(H(\cdot)\) is the
qibo.quantum_info.entropies.shannon_entropy().- Parameters:
prob_dist_joint (ArrayLike) – joint probability distribution \(p(x, \, y)\).
prob_dist_p (ArrayLike) – marginal probability distribution \(p(x)\).
prob_dist_q (ArrayLike) – marginal probability distribution \(q(y)\).
base (float) – the base of the log. Defaults to \(2\).
backend (
qibo.backends.abstract.Backend, optional) – backend to be used in the execution. IfNone, it uses the current backend. Defaults toNone.
- Returns:
Mutual information \(I(X, \, Y)\).
- Return type:
Classical Rényi entropy#
- qibo.quantum_info.classical_renyi_entropy(prob_dist, alpha, base=2, backend=None)[source]#
Calculates the classical Rényi entropy \(H_{\alpha}\) of a discrete probability distribution.
For \(\alpha \in (0, \, 1) \cup (1, \, \infty)\) and probability distribution \(\mathbf{p}\), the classical Rényi entropy is defined as
\[H_{\alpha}(\mathbf{p}) = \frac{1}{1 - \alpha} \, \log\left( \sum_{x} \, \mathbf{p}^{\alpha}(x) \right) \, .\]A special case is the limit \(\alpha \to 1\), in which the classical Rényi entropy coincides with the
qibo.quantum_info.entropies.shannon_entropy().Another special case is the limit \(\alpha \to 0\), where the function is reduced to \(\log\left(|\mathbf{p}|\right)\), with \(|\mathbf{p}|\) being the support of \(\mathbf{p}\). This is known as the Hartley entropy (also known as Hartley function or max-entropy).
In the limit \(\alpha \to \infty\), the function reduces to \(-\log(\max_{x}(\mathbf{p}(x)))\), which is called the min-entropy.
- Parameters:
prob_dist (ArrayLike) – discrete probability distribution.
base (float) – the base of the log. Defaults to \(2\).
backend (
qibo.backends.abstract.Backend, optional) – backend to be used in the execution. IfNone, it uses the current backend. Defaults toNone.
- Returns:
Classical Rényi entropy \(H_{\alpha}\).
- Return type:
Classical Rényi relative entropy#
- qibo.quantum_info.classical_relative_renyi_entropy(prob_dist_p, prob_dist_q, alpha, base=2, backend=None)[source]#
Calculates the classical relative Rényi entropy between two discrete probability distributions.
This function is also known as Rényi divergence.
For \(\alpha \in (0, \, 1) \cup (1, \, \infty)\) and probability distributions \(\mathbf{p}\) and \(\mathbf{q}\), the classical relative Rényi entropy is defined as
\[H_{\alpha}(\mathbf{p} \, \| \, \mathbf{q}) = \frac{1}{\alpha - 1} \, \log\left( \sum_{x} \, \frac{\mathbf{p}^{\alpha}(x)} {\mathbf{q}^{\alpha - 1}(x)} \right) \, .\]A special case is the limit \(\alpha \to 1\), in which the classical Rényi divergence coincides with the
qibo.quantum_info.entropies.classical_relative_entropy().Another special case is the limit \(\alpha \to 1/2\), where the function is reduced to \(-2 \log\left(\sum_{x} \, \sqrt{\mathbf{p}(x) \, \mathbf{q}(x)} \right)\). The sum inside the \(\log\) is known as the Bhattacharyya coefficient.
In the limit \(\alpha \to \infty\), the function reduces to \(\log(\max_{x}(\mathbf{p}(x) \, \mathbf{q}(x))\).
- Parameters:
prob_dist_p (ArrayLike) – discrete probability distribution \(p\).
prob_dist_q (ArrayLike) – discrete probability distribution \(q\).
base (float) – the base of the log. Defaults to \(2\).
backend (
qibo.backends.abstract.Backend, optional) – backend to be used in the execution. IfNone, it uses the current backend. Defaults toNone.
- Returns:
Classical relative Rényi entropy \(H_{\alpha}(\mathbf{p} \, \| \, \mathbf{q})\).
- Return type:
Classical Tsallis entropy#
- qibo.quantum_info.classical_tsallis_entropy(prob_dist, alpha, base=2, backend=None)[source]#
Calculates the classical Tsallis entropy for a discrete probability distribution.
This is defined as
\[S_{\alpha}(\mathbf{p}) = \frac{1}{\alpha - 1} \, \left(1 - \sum_{x} \, \mathbf{p}^{\alpha}(x) \right)\]- Parameters:
prob_dist (ArrayLike) – discrete probability distribution.
base (float) – the base of the log. Used when
alpha=1.0. Defaults to \(2\).backend (
qibo.backends.abstract.Backend, optional) – backend to be used in the execution. IfNone, it uses the current backend. Defaults toNone.
- Returns:
Classical Tsallis entropy \(S_{\alpha}(\mathbf{p})\).
- Return type:
Classical Tsallis relative entropy#
- qibo.quantum_info.classical_relative_tsallis_entropy(prob_dist_p, prob_dist_q, alpha, base=2, backend=None)[source]#
Calculate the classical relative Tsallis entropy between two discrete probability distributions.
Given a discrete random variable \(\chi\) that has values \(x\) in the set \(\mathcal{X}\) with probability \(\mathrm{p}(x)\) and a discrete random variable \(\upsilon\) that has the values \(x\) in the same set \(\mathcal{X}\) with probability \(\mathrm{q}(x)\), their relative Tsallis entropy is given by
\[D_{\alpha}^{\text{ts}}(\chi \, \| \, \upsilon) = \sum_{x \in \mathcal{X}} \, \mathrm{p}^{\alpha}(x) \, \ln_{\alpha} \left( \frac{\mathrm{p}(x)}{\mathrm{q}(x)} \right) \, ,\]where \(\ln_{\alpha}(x) \equiv \frac{x^{1 - \alpha} - 1}{1 - \alpha}\) is the so-called \(\alpha\)-logarithm. When \(\alpha = 1\), it reduces to
qibo.quantum_info.entropies.classical_relative_entropy.- Parameters:
prob_dist_p (ArrayLike) – discrete probability distribution \(p\).
prob_dist_q (ArrayLike) – discrete probability distribution \(q\).
alpha (float) – entropic index.
base (float) – the base of the log used when \(\alpha = 1\). Defaults to \(2\).
backend (
qibo.backends.abstract.Backend, optional) – backend to be used in the execution. IfNone, it uses the current backend. Defaults toNone.
- Returns:
Tsallis relative entropy \(D_{\alpha}^{\text{ts}}\).
- Return type:
von Neumann entropy#
- qibo.quantum_info.von_neumann_entropy(state, base=2, return_spectrum=False, backend=None)[source]#
Calculate the von-Neumann entropy \(S(\rho)\) of a quantum
state\(\rho\).It is given by
\[S(\rho) = - \text{tr}\left(\rho \, \log(\rho)\right)\]- Parameters:
state (ArrayLike) – statevector or density matrix.
base (float, optional) – the base of the log. Defaults to \(2\).
return_spectrum (bool) – if
True, returnsentropyand \(-\log_{\textup{b}}(\textup{eigenvalues})\), where \(b\) isbase. IfFalse, returns onlyentropy. Default isFalse.backend (
qibo.backends.abstract.Backend, optional) – backend to be used in the execution. IfNone, it uses the current backend. Defaults toNone.
- Returns:
The von-Neumann entropy \(S\) of
state\(\rho\).- Return type:
Relative von Neumann entropy#
- qibo.quantum_info.relative_von_neumann_entropy(state, target, base=2, backend=None)[source]#
Calculates the relative von Neumann entropy between two quantum states.
Also known as quantum relative entropy, \(S(\rho \, \| \, \sigma)\) is given by
\[S(\rho \, \| \, \sigma) = \text{tr}\left(\rho \, \log(\rho)\right) - \text{tr}\left(\rho \, \log(\sigma)\right)\]where
state\(\rho\) andtarget\(\sigma\) are two quantum states.- Parameters:
state (ArrayLike) – statevector or density matrix \(\rho\).
target (ArrayLike) – statevector or density matrix \(\sigma\).
base (float, optional) – the base of the log. Defaults to \(2\).
backend (
qibo.backends.abstract.Backend, optional) – backend to be used in the execution. IfNone, it uses the current backend. Defaults toNone.
- Returns:
Relative von-Neumann entropy \(S(\rho \, \| \, \sigma)\).
- Return type:
Mutual information#
- qibo.quantum_info.mutual_information(state, partition, base=2, backend=None)[source]#
Calculates the mutual information of a bipartite state.
Given a qubit
partition\(A\), the mutual information of state \(\rho\) is given by\[I(\rho) \equiv S(\rho_{A}) + S(\rho_{B}) - S(\rho) \, ,\]where \(B\) is the remaining qubits that are not in partition \(A\), and \(S(\cdot)\) is the
qibo.quantum_info.von_neumann_entropy().- Parameters:
state (ArrayLike) – statevector or density matrix.
partition (Union[List[int], Tuple[int]]) – indices of qubits in partition \(A\).
base (float, optional) – the base of the log. Defaults to \(2\).
backend (
qibo.backends.abstract.Backend, optional) – backend to be used in the execution. IfNone, it uses the current backend. Defaults toNone.
- Returns:
Mutual information \(I(\rho)\) of
state\(\rho\).- Return type:
Rényi entropy#
- qibo.quantum_info.renyi_entropy(state, alpha, base=2, backend=None)[source]#
Calculates the Rényi entropy \(H_{\alpha}\) of a quantum state \(\rho\).
For \(\alpha \in (0, \, 1) \cup (1, \, \infty)\), the Rényi entropy is defined as
\[H_{\alpha}(\rho) = \frac{1}{1 - \alpha} \, \log\left( \rho^{\alpha} \right) \, .\]A special case is the limit \(\alpha \to 1\), in which the Rényi entropy coincides with the
qibo.quantum_info.entropies.entropy().Another special case is the limit \(\alpha \to 0\), where the function is reduced to \(\log\left(d\right)\), with \(d = 2^{n}\) being the dimension of the Hilbert space in which
state\(\rho\) lives in. This is known as the Hartley entropy (also known as Hartley function or max-entropy).In the limit \(\alpha \to \infty\), the function reduces to \(-\log(\|\rho\|_{\infty})\), with \(\|\cdot\|_{\infty}\) being the spectral norm. This is known as the min-entropy.
- Parameters:
state (ArrayLike) – statevector or density matrix.
base (float) – the base of the log. Defaults to \(2\).
backend (
qibo.backends.abstract.Backend, optional) – backend to be used in the execution. IfNone, it uses the current backend. Defaults toNone.
- Returns:
Rényi entropy \(H_{\alpha}\).
- Return type:
Relative Rényi entropy#
- qibo.quantum_info.relative_renyi_entropy(state, target, alpha, base=2, backend=None)[source]#
Calculates the relative Rényi entropy between two quantum states.
For \(\alpha \in (0, \, 1) \cup (1, \, \infty)\) and quantum states \(\rho\) and \(\sigma\), the relative Rényi entropy is defined as
\[H_{\alpha}(\rho \, \| \, \sigma) = \frac{1}{\alpha - 1} \, \log\left( \textup{tr}\left( \rho^{\alpha} \, \sigma^{1 - \alpha} \right) \right) \, .\]A special case is the limit \(\alpha \to 1\), in which the Rényi entropy coincides with the
qibo.quantum_info.entropies.relative_von_neumann_entropy().In the limit \(\alpha \to \infty\), the function reduces to \(-2 \, \log(\|\sqrt{\rho} \, \sqrt{\sigma}\|_{1})\), with \(\|\cdot\|_{1}\) being the Schatten 1-norm. This is known as the min-relative entropy.
Note
Function raises
NotImplementedErrorwhentarget\(\sigma\) is a pure state and \(\alpha > 1\). This is due to the fact that it is not possible to calculate \(\sigma^{1 - \alpha}\) when \(\alpha > 1\) and \(\sigma\) is a projector, i.e. a singular matrix.- Parameters:
state (ArrayLike) – statevector or density matrix \(\rho\).
target (ArrayLike) – statevector or density matrix \(\sigma\).
base (float) – the base of the log. Defaults to \(2\).
backend (
qibo.backends.abstract.Backend, optional) – backend to be used in the execution. IfNone, it uses the current backend. Defaults toNone.
- Returns:
Relative Rényi entropy \(H_{\alpha}(\rho \, \| \, \sigma)\).
- Return type:
Tsallis entropy#
- qibo.quantum_info.tsallis_entropy(state, alpha, base=2, backend=None)[source]#
Calculates the Tsallis entropy of a quantum state.
\[S_{\alpha}(\rho) = \frac{1}{1 - \alpha} \, \left( \text{tr}(\rho^{\alpha}) - 1 \right)\]When \(\alpha = 1\), the functions defaults to
qibo.quantum_info.entropies.entropy().- Parameters:
state (ArrayLike) – statevector or density matrix.
base (float, optional) – the base of the log. Used when
alpha=1.0. Defaults to \(2\).backend (
qibo.backends.abstract.Backend, optional) – backend to be used in the execution. IfNone, it uses the current backend. Defaults toNone.
- Returns:
Tsallis entropy \(S_{\alpha}(\rho)\).
- Return type:
Relative Tsallis entropy#
- qibo.quantum_info.relative_tsallis_entropy(state, target, alpha, base=2, backend=None)[source]#
Calculate the relative Tsallis entropy between two quantum states.
For \(\alpha \in [0, \, 2]\) and quantum states \(\rho\) and \(\sigma\), the relative Tsallis entropy is defined as
\[\Delta_{\alpha}^{\text{ts}}(\rho, \, \sigma) = \frac{1 - \text{tr}\left(\rho^{\alpha} \, \sigma^{1 - \alpha}\right)}{1 - \alpha} \, .\]A special case is the limit \(\alpha \to 1\), in which the Tsallis entropy coincides with the
qibo.quantum_info.entropies.relative_von_neumann_entropy().- Parameters:
state (ArrayLike) – statevector or density matrix \(\rho\).
target (ArrayLike) – statevector or density matrix \(\sigma\).
alpha (float or int) – entropic index \(\alpha \in [0, \, 2]\).
base (float, optional) – the base of the log used when \(\alpha = 1\). Defaults to \(2\).
backend (
qibo.backends.abstract.Backend, optional) – backend to be used in the execution. IfNone, it usesqibo.backends.GlobalBackend. Defaults toNone.
- Returns:
Relative Tsallis entropy \(\Delta_{\alpha}^{\text{ts}}\).
- Return type:
References
1. S. Abe, Nonadditive generalization of the quantum Kullback-Leibler divergence for measuring the degree of purification, Phys. Rev. A 68, 032302.
2. S. Furuichi, K. Yanagi, and K. Kuriyama, Fundamental properties of Tsallis relative entropy, J. Math. Phys., Vol. 45, Issue 12, pp. 4868-4877 (2004) .
Entanglement entropy#
- qibo.quantum_info.entanglement_entropy(state, bipartition, base=2, return_spectrum=False, backend=None)[source]#
Calculates the entanglement entropy \(S\) of bipartition \(A\) of
state\(\rho\). This is given by\[S(\rho_{A}) = -\text{tr}(\rho_{A} \, \log(\rho_{A})) \, ,\]where \(\rho_{A} = \text{tr}_{B}(\rho)\) is the reduced density matrix calculated by tracing out the
bipartition\(B\).- Parameters:
state (ArrayLike) – statevector or density matrix.
bipartition (list or tuple or ArrayLike) – qubits in the subsystem to be traced out.
base (float, optional) – the base of the log. Defaults to :math: 2.
return_spectrum (bool) – if
True, returnsentropyand eigenvalues ofstate. IfFalse, returns onlyentropy. Default isFalse.backend (
qibo.backends.abstract.Backend, optional) – backend to be used in the execution. IfNone, it uses the current backend. Defaults toNone.
- Returns:
Entanglement entropy \(S\) of
state\(\rho\).- Return type: