Skip to content

Commit

Permalink
Merge branch 'master' into new_gates
Browse files Browse the repository at this point in the history
  • Loading branch information
renatomello committed Aug 10, 2023
2 parents bcb304c + fff4c99 commit 935835a
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 13 deletions.
2 changes: 1 addition & 1 deletion doc/source/api-reference/qibo.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1351,7 +1351,7 @@ Bures distance
Entanglement fidelity
"""""""""""""""""""""

.. autofunction::qibo.quantum_info.entanglement_fidelity
.. autofunction:: qibo.quantum_info.entanglement_fidelity


Process fidelity
Expand Down
28 changes: 20 additions & 8 deletions src/qibo/quantum_info/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@


def purity(state):
"""Purity of a quantum state :math:`\\rho`, which is given by :math:`\\text{tr}(\\rho^{2})`.
"""Purity of a quantum state :math:`\\rho`, which is given by
.. math::
\\text{purity}(\\rho) = \\text{tr}(\\rho^{2}) \\, .
Args:
state (ndarray): statevector or density matrix.
Expand Down Expand Up @@ -247,8 +250,8 @@ def entanglement_entropy(
check_hermitian: bool = False,
backend=None,
):
"""Calculates the entanglement entropy :math:`S` of ``state`` :math:`\\rho`,
which is given by
"""Calculates the entanglement entropy :math:`S` of bipartition :math:`A`
of``state`` :math:`\\rho`. This is given by
.. math::
S(\\rho_{A}) = -\\text{tr}(\\rho_{A} \\, \\log(\\rho_{A})) \\, ,
Expand Down Expand Up @@ -585,7 +588,7 @@ def bures_distance(state, target, check_hermitian: bool = False, backend=None):
and a ``target`` state :math:`\\sigma`. This is given by
.. math::
D_{B}(\\rho, \\, \\sigma) = \\sqrt{2 \\, (1 - \\sqrt{F(\\rho, \\, \\sigma)})}
D_{B}(\\rho, \\, \\sigma) = \\sqrt{2 \\, \\left(1 - \\sqrt{F(\\rho, \\, \\sigma)}\\right)}
where :math:`F(\\rho, \\sigma)` is the :func:`qibo.quantum_info.fidelity`
between `state` and `target`.
Expand Down Expand Up @@ -616,9 +619,10 @@ def entanglement_fidelity(
:math:`\\rho`, which is given by
.. math::
\\begin{align*}
\\begin{align}
F_{\\mathcal{E}} &= \\text{fidelity}(\\rho_{f}, \\rho) \\nonumber \\\\
&= \\text{tr}(\\rho_{f} \\, \\rho)
&= \\text{tr}(\\rho_{f} \\, \\rho) \\nonumber
\\end{align}
where
Expand Down Expand Up @@ -856,8 +860,16 @@ def gate_error(channel, target=None, check_unitary: bool = False, backend=None):

def diamond_norm(channel, target=None, **kwargs):
"""Calculates the diamond norm :math:`\\|\\mathcal{E}\\|_{\\diamond}` of
``channel`` :math:`\\mathcal{E}`. If a ``target`` channel :math:`\\Lambda`
is specified, then it calculates :math:`\\| \\mathcal{E} - \\Lambda\\|_{\\diamond}`.
``channel`` :math:`\\mathcal{E}`, which is given by
.. math::
\\|\\mathcal{E}\\|_{\\diamond} = \\max_{\\rho} \\, \\| \\left(\\mathcal{E} \\bigotimes I_{d^{2}}\\right)(\\rho) \\| \\, ,
where :math:`I_{d^{2}}` is the :math:`d^{2} \\times d^{2}` Identity operator,
:math:`d = 2^{n}`, and :math:`n` is the number of qubits.
If a ``target`` channel :math:`\\Lambda` is specified,
then it calculates :math:`\\| \\mathcal{E} - \\Lambda\\|_{\\diamond}`.
Example:
Expand Down
15 changes: 13 additions & 2 deletions src/qibo/quantum_info/random_ensembles.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def random_hermitian(


def random_unitary(dims: int, measure: Optional[str] = None, seed=None, backend=None):
"""Returns a random Unitary operator :math:`U`,, i.e.
"""Returns a random Unitary operator :math:`U`, i.e.
a random operator such that :math:`U^{-1} = U^{\\dagger}`.
Args:
Expand Down Expand Up @@ -374,7 +374,18 @@ def random_density_matrix(
seed=None,
backend=None,
):
"""Creates a random density matrix :math:`\\rho`.
"""Creates a random density matrix :math:`\\rho`. If ``pure=True``,
.. math::
\\rho = \\ketbra{\\psi}{\\psi} \\, ,
where :math:`\\ket{\\psi}` is a :func:`qibo.quantum_info.random_statevector`.
If ``pure=False``, then
.. math::
\\rho = \\sum_{k} \\, p_{k} \\, \\ketbra{\\psi_{k}}{\\psi_{k}} \\, .
is a mixed state.
Args:
dims (int): dimension of the matrix.
Expand Down
2 changes: 1 addition & 1 deletion src/qibo/quantum_info/superoperator_transformations.py
Original file line number Diff line number Diff line change
Expand Up @@ -1671,7 +1671,7 @@ def stinespring_to_choi(
to its Choi representation :math:`\\Lambda`.
.. math::
\\Lambda = \\text{kraus_to_choi}(\\text{stinespring_to_kraus}(U_{0}}))
\\Lambda = \\text{kraus_to_choi}(\\text{stinespring_to_kraus}(U_{0}))
Args:
stinespring (ndarray): quantum channel in the Stinespring representation.
Expand Down
2 changes: 1 addition & 1 deletion src/qibo/quantum_info/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def hamming_weight(bitstring, return_indexes: bool = False):

def hadamard_transform(array, implementation: str = "fast", backend=None):
"""Calculates the (fast) Hadamard Transform :math:`\\text{HT}` of a
:math:`2^{n}`-dimensional vector or :math:`2^{n} \times 2^{n}` matrix :math:`A`,
:math:`2^{n}`-dimensional vector or :math:`2^{n} \\times 2^{n}` matrix :math:`A`,
where :math:`n` is the number of qubits in the system. If :math:`A` is a vector, then
.. math::
Expand Down

0 comments on commit 935835a

Please sign in to comment.