|
4 | 4 | from typing import Any, Dict, List |
5 | 5 |
|
6 | 6 | import netsquid as ns |
| 7 | +import numpy as np |
| 8 | +from netsquid.qubits.ketstates import BellIndex |
| 9 | +from netsquid.qubits.state_sampler import StateSampler |
7 | 10 | from netsquid_magic.link_layer import ( |
8 | 11 | MagicLinkLayerProtocol, |
9 | 12 | MagicLinkLayerProtocolWithSignaling, |
|
12 | 15 | from netsquid_magic.magic_distributor import ( |
13 | 16 | DepolariseWithFailureMagicDistributor, |
14 | 17 | DoubleClickMagicDistributor, |
| 18 | + MagicDistributor, |
15 | 19 | PerfectStateMagicDistributor, |
16 | 20 | ) |
| 21 | +from netsquid_magic.state_delivery_sampler import HeraldedStateDeliverySamplerFactory |
17 | 22 | from netsquid_nv.magic_distributor import NVSingleClickMagicDistributor |
18 | 23 | from netsquid_physlayer.heralded_connection import MiddleHeraldedConnection |
19 | 24 |
|
20 | 25 | from squidasm.run.stack.build import build_generic_qdevice, build_nv_qdevice |
21 | 26 | from squidasm.run.stack.config import ( |
| 27 | + DepolariseAnyBellLinkConfig, |
22 | 28 | DepolariseLinkConfig, |
23 | 29 | GenericQDeviceConfig, |
24 | 30 | HeraldedLinkConfig, |
|
32 | 38 | from squidasm.sim.stack.stack import NodeStack, StackNetwork |
33 | 39 |
|
34 | 40 |
|
| 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 | + |
35 | 114 | def fidelity_to_prob_max_mixed(fid: float) -> float: |
36 | 115 | return (1 - fid) * 4.0 / 3.0 |
37 | 116 |
|
@@ -80,6 +159,17 @@ def _setup_network(config: StackNetworkConfig) -> StackNetwork: |
80 | 159 | prob_success=link_cfg.prob_success, |
81 | 160 | t_cycle=link_cfg.t_cycle, |
82 | 161 | ) |
| 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 | + ) |
83 | 173 | elif link.typ == "nv": |
84 | 174 | link_cfg = link.cfg |
85 | 175 | if not isinstance(link_cfg, NVLinkConfig): |
|
0 commit comments