Skip to content

Commit b53ce52

Browse files
authored
Merge pull request #1456 from qiboteam/negativity
Add `negativity` to `quantum_info.entanglement`
2 parents 2144add + 01a37bd commit b53ce52

File tree

3 files changed

+66
-1
lines changed

3 files changed

+66
-1
lines changed

doc/source/api-reference/qibo.rst

+6
Original file line numberDiff line numberDiff line change
@@ -1704,6 +1704,12 @@ Entanglement of formation
17041704
.. autofunction:: qibo.quantum_info.entanglement_of_formation
17051705

17061706

1707+
Negativity
1708+
""""""""""
1709+
1710+
.. autofunction:: qibo.quantum_info.negativity
1711+
1712+
17071713
Entanglement fidelity
17081714
"""""""""""""""""""""
17091715

src/qibo/quantum_info/entanglement.py

+38-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44

55
from qibo.backends import _check_backend
66
from qibo.config import PRECISION_TOL, raise_error
7-
from qibo.quantum_info.linalg_operations import partial_trace
7+
from qibo.quantum_info.linalg_operations import (
8+
matrix_power,
9+
partial_trace,
10+
partial_transpose,
11+
)
812
from qibo.quantum_info.metrics import fidelity, purity
913

1014

@@ -116,6 +120,39 @@ def entanglement_of_formation(
116120
return ent_of_form
117121

118122

123+
def negativity(state, bipartition, backend=None):
124+
"""Calculates the negativity of a bipartite quantum state.
125+
126+
Given a bipartite state :math:`\\rho \\in \\mathcal{H}_{A} \\otimes \\mathcal{H}_{B}`,
127+
the negativity :math:`\\operatorname{Neg}(\\rho)` is given by
128+
129+
.. math::
130+
\\operatorname{Neg}(\\rho) = \\frac{1}{2} \\,
131+
\\left( \\norm{\\rho_{B}}_{1} - 1 \\right) \\, ,
132+
133+
where :math:`\\rho_{B}` is the reduced density matrix after tracing out qubits in
134+
partition :math:`A`, and :math:`\\norm{\\cdot}_{1}` is the Schatten :math:`1`-norm
135+
(also known as nuclear norm or trace norm).
136+
137+
Args:
138+
state (ndarray): statevector or density matrix.
139+
bipartition (list or tuple or ndarray): qubits in the subsystem to be traced out.
140+
backend (:class:`qibo.backends.abstract.Backend`, optional): backend to be used
141+
in the execution. If ``None``, it uses :class:`qibo.backends.GlobalBackend`.
142+
Defaults to ``None``.
143+
144+
Returns:
145+
float: Negativity :math:`\\operatorname{Neg}(\\rho)` of state :math:`\\rho`.
146+
"""
147+
backend = _check_backend(backend)
148+
149+
reduced = partial_transpose(state, bipartition, backend)
150+
reduced = backend.np.conj(reduced.T) @ reduced
151+
norm = backend.np.trace(matrix_power(reduced, 1 / 2, backend))
152+
153+
return float(backend.np.real((norm - 1) / 2))
154+
155+
119156
def entanglement_fidelity(
120157
channel, nqubits: int, state=None, check_hermitian: bool = False, backend=None
121158
):

tests/test_quantum_info_entanglement.py

+22
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
entanglement_of_formation,
1010
entangling_capability,
1111
meyer_wallach_entanglement,
12+
negativity,
1213
)
1314
from qibo.quantum_info.random_ensembles import random_density_matrix, random_statevector
1415

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

6869

70+
@pytest.mark.parametrize("p", [1 / 5, 1 / 3 + 0.01, 1.0])
71+
def test_negativity(backend, p):
72+
# werner state
73+
zero, one = np.array([1, 0]), np.array([0, 1])
74+
psi = (np.kron(zero, one) - np.kron(one, zero)) / np.sqrt(2)
75+
psi = np.outer(psi, psi.T)
76+
psi = backend.cast(psi)
77+
state = p * psi + (1 - p) * backend.identity_density_matrix(2, normalize=True)
78+
79+
neg = negativity(state, [0], backend=backend)
80+
81+
if p == 1 / 5:
82+
target = 0.0
83+
elif p == 1.0:
84+
target = 1 / 2
85+
else:
86+
target = 3 / 400
87+
88+
backend.assert_allclose(neg, target, atol=1e-10)
89+
90+
6991
@pytest.mark.parametrize("check_hermitian", [False, True])
7092
@pytest.mark.parametrize("nqubits", [4, 6])
7193
@pytest.mark.parametrize("channel", [gates.DepolarizingChannel])

0 commit comments

Comments
 (0)