From ca20f93c4a91d01843c53dd5e7b4666ee5a6f8a2 Mon Sep 17 00:00:00 2001 From: Renato Mello Date: Tue, 10 Sep 2024 14:08:38 +0400 Subject: [PATCH 01/10] fix math rendering --- src/qibo/quantum_info/entropies.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qibo/quantum_info/entropies.py b/src/qibo/quantum_info/entropies.py index 05bf3f823f..0ee7250008 100644 --- a/src/qibo/quantum_info/entropies.py +++ b/src/qibo/quantum_info/entropies.py @@ -78,7 +78,7 @@ def classical_relative_entropy(prob_dist_p, prob_dist_q, base: float = 2, backen For probabilities :math:`\\mathbf{p}` and :math:`\\mathbf{q}`, it is defined as - ..math:: + .. math:: D(\\mathbf{p} \\, \\| \\, \\mathbf{q}) = \\sum_{x} \\, \\mathbf{p}(x) \\, \\log\\left( \\frac{\\mathbf{p}(x)}{\\mathbf{q}(x)} \\right) \\, . From 6e800d8256c2f9c8d65cfaf636c3327235f14ba4 Mon Sep 17 00:00:00 2001 From: Renato Mello Date: Tue, 10 Sep 2024 14:25:03 +0400 Subject: [PATCH 02/10] fix note --- src/qibo/quantum_info/entropies.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qibo/quantum_info/entropies.py b/src/qibo/quantum_info/entropies.py index 0ee7250008..c9c889b603 100644 --- a/src/qibo/quantum_info/entropies.py +++ b/src/qibo/quantum_info/entropies.py @@ -680,7 +680,7 @@ def relative_renyi_entropy( This is known as the `min-relative entropy `_. .. note:: - Function raises ``NotImplementedError`` when ``target`` :math:`sigma` + Function raises ``NotImplementedError`` when ``target`` :math:`\\sigma` is a pure state and :math:`\\alpha > 1`. This is due to the fact that it is not possible to calculate :math:`\\sigma^{1 - \\alpha}` when :math:`\\alpha > 1` and :math:`\\sigma` is a projector, i.e. a singular matrix. From 028bb098341a8940cc49ee2fb76e37d96ee45f6f Mon Sep 17 00:00:00 2001 From: Renato Mello Date: Tue, 10 Sep 2024 15:31:18 +0400 Subject: [PATCH 03/10] fix `qibo.rst` --- doc/source/api-reference/qibo.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/api-reference/qibo.rst b/doc/source/api-reference/qibo.rst index 1b254088b3..5d013b103a 100644 --- a/doc/source/api-reference/qibo.rst +++ b/doc/source/api-reference/qibo.rst @@ -2382,7 +2382,7 @@ Hellinger fidelity Hellinger shot error """""""""""""""""""" -.. autofunction:: qibo.quantum_info.hellinger_fidelity +.. autofunction:: qibo.quantum_info.hellinger_shot_error Haar integral From a3f23682f3df6e2ebcd4de6864aa0bdf651ce328 Mon Sep 17 00:00:00 2001 From: Renato Mello Date: Tue, 10 Sep 2024 15:32:28 +0400 Subject: [PATCH 04/10] disable lint error --- src/qibo/ui/mpldrawer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qibo/ui/mpldrawer.py b/src/qibo/ui/mpldrawer.py index 778a429fe2..cac3759be3 100644 --- a/src/qibo/ui/mpldrawer.py +++ b/src/qibo/ui/mpldrawer.py @@ -601,7 +601,7 @@ def _process_gates(array_gates): item += ("q_" + str(qbit),) gates_plot.append(item) elif init_label == "ENTANGLEMENTENTROPY": - for qbit in list(range(circuit.nqubits)): + for qbit in list(range(circuit.nqubits)): # pylint: disable=E0602 item = (init_label,) item += ("q_" + str(qbit),) gates_plot.append(item) From 4f2c03d1e2c937bc98e757b9194ff49a40cf9fd6 Mon Sep 17 00:00:00 2001 From: Renato Mello Date: Wed, 11 Sep 2024 13:03:07 +0400 Subject: [PATCH 05/10] docstrings in `basis` --- src/qibo/quantum_info/basis.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/qibo/quantum_info/basis.py b/src/qibo/quantum_info/basis.py index 5ea541bca0..2378027618 100644 --- a/src/qibo/quantum_info/basis.py +++ b/src/qibo/quantum_info/basis.py @@ -29,14 +29,14 @@ def pauli_basis( all Pauli matrices. If ``True``, retuns an array where every row is a vectorized Pauli matrix. Defaults to ``False``. sparse (bool, optional) If ``True``, retuns Pauli basis in a sparse - representation. Default is ``False``. + representation. Defaults to ``False``. order (str, optional): If ``"row"``, vectorization of Pauli basis is performed row-wise. If ``"column"``, vectorization is performed column-wise. If ``"system"``, system-wise vectorization is performed. If ``vectorization=False``, then ``order=None`` is - forced. Default is ``None``. + forced. Defaults to ``None``. pauli_order (str, optional): corresponds to the order of 4 single-qubit - Pauli elements. Default is "IXYZ". + Pauli elements. Defaults to ``"IXYZ"``. backend (:class:`qibo.backends.abstract.Backend`, optional): backend to be used in the execution. If ``None``, it uses :class:`qibo.backends.GlobalBackend`. Defaults to ``None``. @@ -174,13 +174,13 @@ def comp_basis_to_pauli( normalize (bool, optional): If ``True``, converts to the Pauli basis. Defaults to ``False``. sparse (bool, optional): If ``True``, returns unitary matrix in - sparse representation. Default is ``False``. + sparse representation. Defaults to ``False``. order (str, optional): If ``"row"``, vectorization of Pauli basis is performed row-wise. If ``"column"``, vectorization is performed column-wise. If ``"system"``, system-wise vectorization is - performed. Default is ``"row"``. + performed. Defaults to ``"row"``. pauli_order (str, optional): corresponds to the order of 4 single-qubit - Pauli elements. Default is "IXYZ". + Pauli elements. Defaults to ``"IXYZ"``. backend (:class:`qibo.backends.abstract.Backend`, optional): backend to be used in the execution. If ``None``, it uses :class:`qibo.backends.GlobalBackend`. Defaults to ``None``. @@ -244,13 +244,13 @@ def pauli_to_comp_basis( normalize (bool, optional): If ``True``, converts to the Pauli basis. Defaults to ``False``. sparse (bool, optional): If ``True``, returns unitary matrix in - sparse representation. Default is ``False``. + sparse representation. Defaults to ``False``. order (str, optional): If ``"row"``, vectorization of Pauli basis is performed row-wise. If ``"column"``, vectorization is performed column-wise. If ``"system"``, system-wise vectorization is - performed. Default is ``"row"``. + performed. Defaults to ``"row"``. pauli_order (str, optional): corresponds to the order of 4 single-qubit - Pauli elements. Default is "IXYZ". + Pauli elements. Defaults to ``"IXYZ"``. backend (:class:`qibo.backends.abstract.Backend`, optional): backend to be used in the execution. If ``None``, it uses :class:`qibo.backends.GlobalBackend`. Defaults to ``None``. From e69315554af9db3c0f8cb138c03aaa146b2c7450 Mon Sep 17 00:00:00 2001 From: Renato Mello Date: Wed, 11 Sep 2024 13:05:46 +0400 Subject: [PATCH 06/10] missing colon --- src/qibo/quantum_info/basis.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qibo/quantum_info/basis.py b/src/qibo/quantum_info/basis.py index 2378027618..efd8bdfe86 100644 --- a/src/qibo/quantum_info/basis.py +++ b/src/qibo/quantum_info/basis.py @@ -28,7 +28,7 @@ def pauli_basis( vectorize (bool, optional): If ``False``, returns a nested array with all Pauli matrices. If ``True``, retuns an array where every row is a vectorized Pauli matrix. Defaults to ``False``. - sparse (bool, optional) If ``True``, retuns Pauli basis in a sparse + sparse (bool, optional): If ``True``, retuns Pauli basis in a sparse representation. Defaults to ``False``. order (str, optional): If ``"row"``, vectorization of Pauli basis is performed row-wise. If ``"column"``, vectorization is performed From 5473a5a91f1b1d2cef47440de77afa0a788a3ff1 Mon Sep 17 00:00:00 2001 From: Renato Mello Date: Wed, 11 Sep 2024 13:30:09 +0400 Subject: [PATCH 07/10] `comp_basis_to_pauli` --- src/qibo/quantum_info/basis.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/qibo/quantum_info/basis.py b/src/qibo/quantum_info/basis.py index efd8bdfe86..cc22f268c6 100644 --- a/src/qibo/quantum_info/basis.py +++ b/src/qibo/quantum_info/basis.py @@ -148,15 +148,11 @@ def comp_basis_to_pauli( The unitary :math:`U` is given by .. math:: - U = \\sum_{k = 0}^{d^{2} - 1} \\, \\ketbra{k}{P_{k}} \\,\\, , + U = \\sum_{k = 0}^{d^{2} - 1} \\, |k)(P_{k}| \\,\\, , - where :math:`\\ket{P_{k}}` is the system-vectorization of the :math:`k`-th - Pauli operator :math:`P_{k}`, and :math:`\\ket{k}` is the computational - basis element. - - When converting a state :math:`\\ket{\\rho}` to its Pauli-Liouville - representation :math:`\\ket{\\rho'}`, one should use ``order="system"`` - in :func:`vectorization`. + where :math:`|P_{k})` is the vectorization of the :math:`k`-th + Pauli operator :math:`P_{k}`, and :math:`|k)` is the vectorization + of the :math:`k`-th computational basis element. Example: .. code-block:: python From c1d5e09ffc7f168bfb51d30c9f974f75d59a2baa Mon Sep 17 00:00:00 2001 From: Renato Mello Date: Wed, 11 Sep 2024 16:26:08 +0400 Subject: [PATCH 08/10] improve docstring --- src/qibo/quantum_info/basis.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/qibo/quantum_info/basis.py b/src/qibo/quantum_info/basis.py index cc22f268c6..e3bf042a60 100644 --- a/src/qibo/quantum_info/basis.py +++ b/src/qibo/quantum_info/basis.py @@ -153,6 +153,7 @@ def comp_basis_to_pauli( where :math:`|P_{k})` is the vectorization of the :math:`k`-th Pauli operator :math:`P_{k}`, and :math:`|k)` is the vectorization of the :math:`k`-th computational basis element. + For a definition of vectorization, see :func:`qibo.quantum_info.vectorization`. Example: .. code-block:: python @@ -233,7 +234,12 @@ def pauli_to_comp_basis( The unitary :math:`U` is given by .. math:: - U = \\sum_{k = 0}^{d^{2} - 1} \\, \\ketbra{P_{k}}{b_{k}} \\, . + U = \\sum_{k = 0}^{d^{2} - 1} \\, |P_{k})(b_{k}| \\, , + + where :math:`|P_{k})` is the vectorization of the :math:`k`-th + Pauli operator :math:`P_{k}`, and :math:`|k)` is the vectorization + of the :math:`k`-th computational basis element. + For a definition of vectorization, see :func:`qibo.quantum_info.vectorization`. Args: nqubits (int): number of qubits. From 4b62f5268c4f78ab850566666dfd29a2290ff2ec Mon Sep 17 00:00:00 2001 From: Renato Mello Date: Thu, 12 Sep 2024 13:41:07 +0400 Subject: [PATCH 09/10] unifying notation --- src/qibo/gates/channels.py | 7 ++-- .../superoperator_transformations.py | 34 +++++++++++-------- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/src/qibo/gates/channels.py b/src/qibo/gates/channels.py index bde8c50273..bdab7ee552 100644 --- a/src/qibo/gates/channels.py +++ b/src/qibo/gates/channels.py @@ -48,8 +48,11 @@ def to_choi(self, nqubits: Optional[int] = None, order: str = "row", backend=Non of the Kraus channel :math:`\\{K_{\\alpha}\\}_{\\alpha}`. .. math:: - \\mathcal{E} = \\sum_{\\alpha} \\, |K_{\\alpha}\\rangle\\rangle - \\langle\\langle K_{\\alpha}| + \\mathcal{E} = \\sum_{\\alpha} \\, |K_{\\alpha})(K_{\\alpha}| \\, , + + where :math:`|K_{\\alpha})` is the vectorization of the Kraus operator + :math:`K_{\\alpha}`. + For a definition of vectorization, see :func:`qibo.quantum_info.vectorization`. Args: nqubits (int, optional): total number of qubits to be considered diff --git a/src/qibo/quantum_info/superoperator_transformations.py b/src/qibo/quantum_info/superoperator_transformations.py index 73bce85f97..7fbe0a36cc 100644 --- a/src/qibo/quantum_info/superoperator_transformations.py +++ b/src/qibo/quantum_info/superoperator_transformations.py @@ -14,18 +14,17 @@ def vectorization(state, order: str = "row", backend=None): - """Returns state :math:`\\rho` in its Liouville - representation :math:`|\\rho\\rangle\\rangle`. + """Returns state :math:`\\rho` in its Liouville representation :math:`|\\rho)`. If ``order="row"``, then: .. math:: - |\\rho\\rangle\\rangle = \\sum_{k, l} \\, \\rho_{kl} \\, \\ket{k} \\otimes \\ket{l} + |\\rho) = \\sum_{k, l} \\, \\rho_{kl} \\, \\ket{k} \\otimes \\ket{l} If ``order="column"``, then: .. math:: - |\\rho\\rangle\\rangle = \\sum_{k, l} \\, \\rho_{kl} \\, \\ket{l} \\otimes \\ket{k} + |\\rho) = \\sum_{k, l} \\, \\rho_{kl} \\, \\ket{l} \\otimes \\ket{k} Args: state: state vector or density matrix. @@ -88,12 +87,12 @@ def vectorization(state, order: str = "row", backend=None): def unvectorization(state, order: str = "row", backend=None): """Returns state :math:`\\rho` from its Liouville - representation :math:`|\\rho\\rangle\\rangle`. This operation is + representation :math:`|\\rho)`. This operation is the inverse function of :func:`vectorization`, i.e. .. math:: \\begin{align} - \\rho &= \\text{unvectorization}(|\\rho\\rangle\\rangle) \\nonumber \\\\ + \\rho &= \\text{unvectorization}(|\\rho)) \\nonumber \\\\ &= \\text{unvectorization}(\\text{vectorization}(\\rho)) \\nonumber \\end{align} @@ -152,9 +151,9 @@ def to_choi(channel, order: str = "row", backend=None): """Converts quantum ``channel`` :math:`U` to its Choi representation :math:`\\Lambda`. .. math:: - \\Lambda = | U \\rangle\\rangle \\langle\\langle U | \\, , + \\Lambda = | U ) ( U | \\, , - where :math:`| \\cdot \\rangle\\rangle` is the :func:`qibo.quantum_info.vectorization` + where :math:`| \\cdot )` is the :func:`qibo.quantum_info.vectorization` operation. Args: @@ -376,7 +375,9 @@ def choi_to_kraus( .. math:: \\Lambda = \\sum_{\\alpha} \\, \\lambda_{\\alpha}^{2} \\, - |\\tilde{K}_{\\alpha}\\rangle\\rangle \\langle\\langle \\tilde{K}_{\\alpha}| \\, . + |\\tilde{K}_{\\alpha})(\\tilde{K}_{\\alpha}| \\, . + + where :math:`|\\cdot)` is the :func:`qibo.quantum_info.vectorization` operation. This is the spectral decomposition of :math:`\\Lambda`, Hence, the set :math:`\\{\\lambda_{\\alpha}, \\, \\tilde{K}_{\\alpha}\\}_{\\alpha}` @@ -385,7 +386,7 @@ def choi_to_kraus( .. math:: K_{\\alpha} = \\lambda_{\\alpha} \\, - \\text{unvectorization}(|\\tilde{K}_{\\alpha}\\rangle\\rangle) \\, . + \\text{unvectorization}(|\\tilde{K}_{\\alpha})) \\, . If :math:`\\mathcal{E}` is not CP, then spectral composition is replaced by a singular value decomposition (SVD), i.e. @@ -638,7 +639,11 @@ def kraus_to_choi(kraus_ops, order: str = "row", backend=None): of quantum channel to its Choi representation :math:`\\Lambda`. .. math:: - \\Lambda = \\sum_{\\alpha} \\, |K_{\\alpha}\\rangle\\rangle \\langle\\langle K_{\\alpha}| + \\Lambda = \\sum_{\\alpha} \\, |K_{\\alpha})( K_{\\alpha}| + + where :math:`|K_{\\alpha})` is the vectorization of the Kraus operator + :math:`K_{\\alpha}`. + For a definition of vectorization, see :func:`qibo.quantum_info.vectorization`. Args: kraus_ops (list): List of Kraus operators as pairs ``(qubits, Ak)`` @@ -757,10 +762,11 @@ def kraus_to_chi( of quantum channel to its :math:`\\chi`-matrix representation. .. math:: - \\chi = \\sum_{\\alpha} \\, |c_{\\alpha}\\rangle\\rangle \\langle\\langle c_{\\alpha}|, + \\chi = \\sum_{\\alpha} \\, |c_{\\alpha})( c_{\\alpha}|, - where :math:`|c_{\\alpha}\\rangle\\rangle \\cong |K_{\\alpha}\\rangle\\rangle` - in Pauli-Liouville basis. + where :math:`|c_{\\alpha}) \\cong |K_{\\alpha})` in Pauli-Liouville basis, + and :math:`| \\cdot )` is the :func:`qibo.quantum_info.vectorization` + operation. Args: kraus_ops (list): List of Kraus operators as pairs ``(qubits, Ak)`` From 5a7fe1e50cee1d2e8453e79ee0b1ceff032e1292 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 12 Sep 2024 09:41:34 +0000 Subject: [PATCH 10/10] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/qibo/gates/channels.py | 2 +- src/qibo/quantum_info/superoperator_transformations.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qibo/gates/channels.py b/src/qibo/gates/channels.py index bdab7ee552..be43678318 100644 --- a/src/qibo/gates/channels.py +++ b/src/qibo/gates/channels.py @@ -50,7 +50,7 @@ def to_choi(self, nqubits: Optional[int] = None, order: str = "row", backend=Non .. math:: \\mathcal{E} = \\sum_{\\alpha} \\, |K_{\\alpha})(K_{\\alpha}| \\, , - where :math:`|K_{\\alpha})` is the vectorization of the Kraus operator + where :math:`|K_{\\alpha})` is the vectorization of the Kraus operator :math:`K_{\\alpha}`. For a definition of vectorization, see :func:`qibo.quantum_info.vectorization`. diff --git a/src/qibo/quantum_info/superoperator_transformations.py b/src/qibo/quantum_info/superoperator_transformations.py index 7fbe0a36cc..dbdb136ad1 100644 --- a/src/qibo/quantum_info/superoperator_transformations.py +++ b/src/qibo/quantum_info/superoperator_transformations.py @@ -641,7 +641,7 @@ def kraus_to_choi(kraus_ops, order: str = "row", backend=None): .. math:: \\Lambda = \\sum_{\\alpha} \\, |K_{\\alpha})( K_{\\alpha}| - where :math:`|K_{\\alpha})` is the vectorization of the Kraus operator + where :math:`|K_{\\alpha})` is the vectorization of the Kraus operator :math:`K_{\\alpha}`. For a definition of vectorization, see :func:`qibo.quantum_info.vectorization`.