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

Add negativity to quantum_info.entanglement #1456

Merged
merged 26 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
53d7693
function
renatomello Sep 19, 2024
99830c2
Merge branch 'master' into negativity
renatomello Sep 19, 2024
0b8bf4a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 19, 2024
1e9f1e3
api ref
renatomello Sep 19, 2024
a004231
Merge branch 'master' into negativity
renatomello Sep 20, 2024
4dd7ca0
Merge branch 'master' into negativity
renatomello Sep 20, 2024
9c5260c
Merge branch 'master' into negativity
renatomello Sep 20, 2024
ea7bf28
Merge branch 'master' into negativity
renatomello Sep 23, 2024
68e9799
backup
renatomello Sep 23, 2024
3764f76
Merge branch 'partial_transpose' into negativity
renatomello Sep 23, 2024
bc4b7c7
remove prints
renatomello Sep 23, 2024
625870c
tests
renatomello Sep 23, 2024
8ed5b54
Merge branch 'master' into negativity
renatomello Sep 24, 2024
52f2f81
Merge branch 'master' into negativity
renatomello Oct 2, 2024
a9925c0
Merge branch 'master' into negativity
renatomello Oct 2, 2024
6a0bfbc
Merge branch 'master' into negativity
renatomello Oct 4, 2024
3d4b480
Merge branch 'master' into negativity
renatomello Oct 7, 2024
527c12d
Merge branch 'master' into negativity
renatomello Oct 7, 2024
e0ea04a
function
renatomello Sep 19, 2024
541e0f8
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 19, 2024
342234a
api ref
renatomello Sep 19, 2024
123d624
backup
renatomello Sep 23, 2024
3caeab7
remove prints
renatomello Sep 23, 2024
176a224
tests
renatomello Sep 23, 2024
f5da5d8
Merge branch 'negativity' of github.com:qiboteam/qibo into negativity
renatomello Oct 7, 2024
01a37bd
Merge branch 'master' into negativity
renatomello Oct 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions doc/source/api-reference/qibo.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1704,6 +1704,12 @@ Entanglement of formation
.. autofunction:: qibo.quantum_info.entanglement_of_formation


Negativity
""""""""""

.. autofunction:: qibo.quantum_info.negativity


Entanglement fidelity
"""""""""""""""""""""

Expand Down
39 changes: 38 additions & 1 deletion src/qibo/quantum_info/entanglement.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@

from qibo.backends import _check_backend
from qibo.config import PRECISION_TOL, raise_error
from qibo.quantum_info.linalg_operations import partial_trace
from qibo.quantum_info.linalg_operations import (
matrix_power,
partial_trace,
partial_transpose,
)
from qibo.quantum_info.metrics import fidelity, purity


Expand Down Expand Up @@ -116,6 +120,39 @@ def entanglement_of_formation(
return ent_of_form


def negativity(state, bipartition, backend=None):
"""Calculates the negativity of a bipartite quantum state.

Given a bipartite state :math:`\\rho \\in \\mathcal{H}_{A} \\otimes \\mathcal{H}_{B}`,
the negativity :math:`\\operatorname{Neg}(\\rho)` is given by

.. math::
\\operatorname{Neg}(\\rho) = \\frac{1}{2} \\,
\\left( \\norm{\\rho_{B}}_{1} - 1 \\right) \\, ,

where :math:`\\rho_{B}` is the reduced density matrix after tracing out qubits in
partition :math:`A`, and :math:`\\norm{\\cdot}_{1}` is the Schatten :math:`1`-norm
(also known as nuclear norm or trace norm).

Args:
state (ndarray): statevector or density matrix.
bipartition (list or tuple or ndarray): qubits in the subsystem to be traced out.
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``.

Returns:
float: Negativity :math:`\\operatorname{Neg}(\\rho)` of state :math:`\\rho`.
"""
backend = _check_backend(backend)

reduced = partial_transpose(state, bipartition, backend)
reduced = backend.np.conj(reduced.T) @ reduced
renatomello marked this conversation as resolved.
Show resolved Hide resolved
norm = backend.np.trace(matrix_power(reduced, 1 / 2, backend))

return float(backend.np.real((norm - 1) / 2))


def entanglement_fidelity(
channel, nqubits: int, state=None, check_hermitian: bool = False, backend=None
):
Expand Down
22 changes: 22 additions & 0 deletions tests/test_quantum_info_entanglement.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
entanglement_of_formation,
entangling_capability,
meyer_wallach_entanglement,
negativity,
)
from qibo.quantum_info.random_ensembles import random_density_matrix, random_statevector

Expand Down Expand Up @@ -66,6 +67,27 @@ def test_concurrence_and_formation(backend, bipartition, base, check_purity):
backend.assert_allclose(ent_form, 0.0, atol=PRECISION_TOL)


@pytest.mark.parametrize("p", [1 / 5, 1 / 3 + 0.01, 1.0])
def test_negativity(backend, p):
# werner state
zero, one = np.array([1, 0]), np.array([0, 1])
psi = (np.kron(zero, one) - np.kron(one, zero)) / np.sqrt(2)
psi = np.outer(psi, psi.T)
psi = backend.cast(psi)
state = p * psi + (1 - p) * backend.identity_density_matrix(2, normalize=True)

neg = negativity(state, [0], backend=backend)

if p == 1 / 5:
target = 0.0
elif p == 1.0:
target = 1 / 2
else:
target = 3 / 400

backend.assert_allclose(neg, target, atol=1e-10)


@pytest.mark.parametrize("check_hermitian", [False, True])
@pytest.mark.parametrize("nqubits", [4, 6])
@pytest.mark.parametrize("channel", [gates.DepolarizingChannel])
Expand Down