Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix math rendering in some docsstrings of the quantum_info module #1441

Merged
merged 11 commits into from
Sep 13, 2024
2 changes: 1 addition & 1 deletion doc/source/api-reference/qibo.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2382,7 +2382,7 @@ Hellinger fidelity
Hellinger shot error
""""""""""""""""""""

.. autofunction:: qibo.quantum_info.hellinger_fidelity
.. autofunction:: qibo.quantum_info.hellinger_shot_error


Haar integral
Expand Down
7 changes: 5 additions & 2 deletions src/qibo/gates/channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
40 changes: 21 additions & 19 deletions src/qibo/quantum_info/basis.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ 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
representation. Default is ``False``.
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
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``.
Expand Down Expand Up @@ -148,15 +148,12 @@ 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.
For a definition of vectorization, see :func:`qibo.quantum_info.vectorization`.

Example:
.. code-block:: python
Expand All @@ -174,13 +171,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``.
Expand Down Expand Up @@ -237,20 +234,25 @@ 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.
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``.
Expand Down
4 changes: 2 additions & 2 deletions src/qibo/quantum_info/entropies.py
Original file line number Diff line number Diff line change
Expand Up @@ -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) \\, .

Expand Down Expand Up @@ -680,7 +680,7 @@ def relative_renyi_entropy(
This is known as the `min-relative entropy <https://arxiv.org/abs/1310.7178>`_.

.. 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.
Expand Down
34 changes: 20 additions & 14 deletions src/qibo/quantum_info/superoperator_transformations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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}

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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}`
Expand All @@ -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.
Expand Down Expand Up @@ -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)``
Expand Down Expand Up @@ -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)``
Expand Down