Skip to content

Commit 074c4e4

Browse files
authored
Entanglement fidelity of a quantum channel (#4158)
1 parent 7065c6d commit 074c4e4

File tree

4 files changed

+65
-1
lines changed

4 files changed

+65
-1
lines changed

cirq-core/cirq/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@
334334
density_matrix,
335335
density_matrix_from_state_vector,
336336
dirac_notation,
337+
entanglement_fidelity,
337338
eye_tensor,
338339
fidelity,
339340
kraus_to_channel_matrix,

cirq-core/cirq/qis/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from cirq.qis.clifford_tableau import CliffordTableau
2525

2626
from cirq.qis.measures import (
27+
entanglement_fidelity,
2728
fidelity,
2829
von_neumann_entropy,
2930
)

cirq-core/cirq/qis/measures.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import numpy as np
1919
import scipy
2020

21-
from cirq import value
21+
from cirq import protocols, value
2222
from cirq.qis.states import (
2323
QuantumState,
2424
infer_qid_shape,
@@ -273,3 +273,28 @@ def von_neumann_entropy(
273273
if validate:
274274
_ = quantum_state(state, qid_shape=qid_shape, copy=False, validate=True, atol=atol)
275275
return 0.0
276+
277+
278+
def entanglement_fidelity(operation: 'cirq.SupportsChannel') -> float:
279+
r"""Returns entanglement fidelity of a given quantum channel.
280+
281+
Entanglement fidelity $F_e$ of a quantum channel $E: L(H) \to L(H)$ is the overlap between
282+
the maximally entangled state $|\phi\rangle = \frac{1}{\sqrt{dim H}} \sum_i|i\rangle|i\rangle$
283+
and the state obtained by sending one half of $|\phi\rangle$ through the channel $E$, i.e.
284+
285+
$$
286+
F_e = \langle\phi|(E \otimes I)(|\phi\rangle\langle\phi|)|\phi\rangle
287+
$$
288+
289+
where $I: L(H) \to L(H)$ is the identity map.
290+
291+
Args:
292+
operation: Quantum channel whose entanglement fidelity is to be computed.
293+
Returns:
294+
Entanglement fidelity of the channel represented by operation.
295+
"""
296+
f = 0.0
297+
for k in protocols.channel(operation):
298+
f += np.abs(np.trace(k)) ** 2
299+
n_qubits = protocols.num_qubits(operation)
300+
return float(f / 4 ** n_qubits)

cirq-core/cirq/qis/measures_test.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,3 +222,40 @@ def test_von_neumann_entropy():
222222
)
223223
== 0
224224
)
225+
226+
227+
@pytest.mark.parametrize(
228+
'gate, expected_entanglement_fidelity',
229+
(
230+
(cirq.I, 1),
231+
(cirq.X, 0),
232+
(cirq.Y, 0),
233+
(cirq.Z, 0),
234+
(cirq.S, 1 / 2),
235+
(cirq.CNOT, 1 / 4),
236+
(cirq.TOFFOLI, 9 / 16),
237+
),
238+
)
239+
def test_entanglement_fidelity_of_unitary_channels(gate, expected_entanglement_fidelity):
240+
assert np.isclose(cirq.entanglement_fidelity(gate), expected_entanglement_fidelity)
241+
242+
243+
@pytest.mark.parametrize('p', (0, 0.1, 0.2, 0.5, 0.8, 0.9, 1))
244+
@pytest.mark.parametrize(
245+
'channel_factory, entanglement_fidelity_formula',
246+
(
247+
# Each Pauli error turns the maximally entangled state into an orthogonal state, so only
248+
# the error-free term, whose pre-factor is 1 - p, contributes to entanglement fidelity.
249+
(cirq.depolarize, lambda p: 1 - p),
250+
(lambda p: cirq.depolarize(p, n_qubits=2), lambda p: 1 - p),
251+
(lambda p: cirq.depolarize(p, n_qubits=3), lambda p: 1 - p),
252+
# See e.g. https://quantumcomputing.stackexchange.com/questions/16074 for average fidelity,
253+
# then use Horodecki formula F_avg = (N F_e + 1) / (N + 1) to find entanglement fidelity.
254+
(cirq.amplitude_damp, lambda gamma: 1 / 2 - gamma / 4 + np.sqrt(1 - gamma) / 2),
255+
),
256+
)
257+
def test_entanglement_fidelity_of_noisy_channels(p, channel_factory, entanglement_fidelity_formula):
258+
channel = channel_factory(p)
259+
actual_entanglement_fidelity = cirq.entanglement_fidelity(channel)
260+
expected_entanglement_fidelity = entanglement_fidelity_formula(p)
261+
assert np.isclose(actual_entanglement_fidelity, expected_entanglement_fidelity)

0 commit comments

Comments
 (0)