Skip to content

Commit eff646d

Browse files
author
Bart van der Vecht
committed
Add AnyBell depolarising distributor
1 parent 2401399 commit eff646d

File tree

4 files changed

+108
-17
lines changed

4 files changed

+108
-17
lines changed

examples/stack/teleport/config.yaml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,13 @@ stacks:
2525
host_qnos_latency: 1e5
2626

2727
link_cfg: &link_cfg
28-
length_A: 0.01
29-
length_B: 0.01
30-
full_cycle: 1e6
31-
cycle_time: 1e3
32-
alpha: 0.9
28+
fidelity: 0.8
29+
prob_success: 0.01
30+
t_cycle: 1.e+6
3331

3432
links:
3533
- stack1: sender
3634
stack2: receiver
37-
typ: nv
35+
typ: depolarise_any_bell
3836
cfg:
3937
<<: *link_cfg

examples/stack/teleport/example_teleport.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,16 @@
11
from __future__ import annotations
22

3-
import math
43
import os
54
from typing import Any, Dict, Generator, List
65

76
import netsquid as ns
87
from netqasm.lang.ir import BreakpointAction, BreakpointRole
98
from netqasm.sdk.qubit import Qubit
109
from netqasm.sdk.toolbox import set_qubit_state
11-
from netsquid.qubits import ketstates, operators, qubit, qubitapi
10+
from netsquid.qubits import operators, qubitapi
1211

1312
from pydynaa import EventExpression
14-
from squidasm.run.stack.config import (
15-
GenericQDeviceConfig,
16-
LinkConfig,
17-
StackConfig,
18-
StackNetworkConfig,
19-
)
13+
from squidasm.run.stack.config import StackNetworkConfig
2014
from squidasm.run.stack.run import run
2115
from squidasm.sim.stack.common import LogManager
2216
from squidasm.sim.stack.csocket import ClassicalSocket
@@ -154,6 +148,5 @@ def do_teleportation(
154148

155149
link.cfg["fidelity"] = 0.8
156150

157-
for _ in range(2):
158-
fidelities = do_teleportation(cfg, num_times=10, theta=0, phi=0)
159-
print(fidelities)
151+
fidelities = do_teleportation(cfg, num_times=10, theta=0, phi=0)
152+
print(fidelities)

squidasm/run/stack/config.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,16 @@ def from_file(cls, path: str) -> DepolariseLinkConfig:
134134
return _from_file(path, DepolariseLinkConfig)
135135

136136

137+
class DepolariseAnyBellLinkConfig(BaseModel):
138+
fidelity: float
139+
prob_success: float
140+
t_cycle: float
141+
142+
@classmethod
143+
def from_file(cls, path: str) -> DepolariseAnyBellLinkConfig:
144+
return _from_file(path, DepolariseAnyBellLinkConfig)
145+
146+
137147
class NVLinkConfig(BaseModel):
138148
length_A: float
139149
length_B: float

squidasm/run/stack/run.py

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
from typing import Any, Dict, List
55

66
import netsquid as ns
7+
import numpy as np
8+
from netsquid.qubits.ketstates import BellIndex
9+
from netsquid.qubits.state_sampler import StateSampler
710
from netsquid_magic.link_layer import (
811
MagicLinkLayerProtocol,
912
MagicLinkLayerProtocolWithSignaling,
@@ -12,13 +15,16 @@
1215
from netsquid_magic.magic_distributor import (
1316
DepolariseWithFailureMagicDistributor,
1417
DoubleClickMagicDistributor,
18+
MagicDistributor,
1519
PerfectStateMagicDistributor,
1620
)
21+
from netsquid_magic.state_delivery_sampler import HeraldedStateDeliverySamplerFactory
1722
from netsquid_nv.magic_distributor import NVSingleClickMagicDistributor
1823
from netsquid_physlayer.heralded_connection import MiddleHeraldedConnection
1924

2025
from squidasm.run.stack.build import build_generic_qdevice, build_nv_qdevice
2126
from squidasm.run.stack.config import (
27+
DepolariseAnyBellLinkConfig,
2228
DepolariseLinkConfig,
2329
GenericQDeviceConfig,
2430
HeraldedLinkConfig,
@@ -32,6 +38,79 @@
3238
from squidasm.sim.stack.stack import NodeStack, StackNetwork
3339

3440

41+
class DepolariseWithFailureAnyBellStateSamplerFactory(
42+
HeraldedStateDeliverySamplerFactory
43+
):
44+
def __init__(self):
45+
super().__init__(func_delivery=self._delivery_func)
46+
47+
@staticmethod
48+
def _delivery_func(prob_max_mixed, prob_success, **kwargs):
49+
bell00 = np.array(
50+
[[0.5, 0, 0, 0.5], [0, 0, 0, 0], [0, 0, 0, 0], [0.5, 0, 0, 0.5]],
51+
dtype=np.complex,
52+
)
53+
bell01 = np.array(
54+
[[0, 0, 0, 0], [0, 0.5, 0.5, 0], [0, 0.5, 0.5, 0], [0, 0, 0, 0]],
55+
dtype=np.complex,
56+
)
57+
bell10 = np.array(
58+
[[0, 0, 0, 0], [0, 0.5, -0.5, 0], [0, -0.5, 0.5, 0], [0, 0, 0, 0]],
59+
dtype=np.complex,
60+
)
61+
bell11 = np.array(
62+
[[0.5, 0, 0, -0.5], [0, 0, 0, 0], [0, 0, 0, 0], [-0.5, 0, 0, 0.5]],
63+
dtype=np.complex,
64+
)
65+
maximally_mixed = np.array(
66+
[[0.25, 0, 0, 0], [0, 0.25, 0, 0], [0, 0, 0.25, 0], [0, 0, 0, 0.25]],
67+
dtype=np.complex,
68+
)
69+
bell00_noisy = (1 - prob_max_mixed) * bell00 + prob_max_mixed * maximally_mixed
70+
bell01_noisy = (1 - prob_max_mixed) * bell01 + prob_max_mixed * maximally_mixed
71+
bell10_noisy = (1 - prob_max_mixed) * bell10 + prob_max_mixed * maximally_mixed
72+
bell11_noisy = (1 - prob_max_mixed) * bell11 + prob_max_mixed * maximally_mixed
73+
return (
74+
StateSampler(
75+
qreprs=[bell00_noisy, bell01_noisy, bell10_noisy, bell11_noisy],
76+
probabilities=[0.25, 0.25, 0.25, 0.25],
77+
labels=[
78+
BellIndex.PHI_PLUS,
79+
BellIndex.PSI_PLUS,
80+
BellIndex.PSI_MINUS,
81+
BellIndex.PHI_MINUS,
82+
],
83+
),
84+
prob_success,
85+
)
86+
87+
88+
class DepolariseWithFailureAnyBellMagicDistributor(MagicDistributor):
89+
def __init__(self, nodes, prob_max_mixed, prob_success, **kwargs):
90+
self.prob_max_mixed = prob_max_mixed
91+
self.prob_success = prob_success
92+
super().__init__(
93+
delivery_sampler_factory=DepolariseWithFailureAnyBellStateSamplerFactory(),
94+
nodes=nodes,
95+
**kwargs,
96+
)
97+
98+
def add_delivery(self, memory_positions, **kwargs):
99+
return super().add_delivery(
100+
memory_positions=memory_positions,
101+
prob_max_mixed=self.prob_max_mixed,
102+
prob_success=self.prob_success,
103+
**kwargs,
104+
)
105+
106+
def get_bell_state(self, midpoint_outcome):
107+
try:
108+
status, label = midpoint_outcome
109+
except ValueError:
110+
raise ValueError("Unknown midpoint outcome {}".format(midpoint_outcome))
111+
return label
112+
113+
35114
def fidelity_to_prob_max_mixed(fid: float) -> float:
36115
return (1 - fid) * 4.0 / 3.0
37116

@@ -80,6 +159,17 @@ def _setup_network(config: StackNetworkConfig) -> StackNetwork:
80159
prob_success=link_cfg.prob_success,
81160
t_cycle=link_cfg.t_cycle,
82161
)
162+
elif link.typ == "depolarise_any_bell":
163+
link_cfg = link.cfg
164+
if not isinstance(link_cfg, DepolariseAnyBellLinkConfig):
165+
link_cfg = DepolariseAnyBellLinkConfig(**link.cfg)
166+
prob_max_mixed = fidelity_to_prob_max_mixed(link_cfg.fidelity)
167+
link_dist = DepolariseWithFailureAnyBellMagicDistributor(
168+
nodes=[stack1.node, stack2.node],
169+
prob_max_mixed=prob_max_mixed,
170+
prob_success=link_cfg.prob_success,
171+
t_cycle=link_cfg.t_cycle,
172+
)
83173
elif link.typ == "nv":
84174
link_cfg = link.cfg
85175
if not isinstance(link_cfg, NVLinkConfig):

0 commit comments

Comments
 (0)