-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQEuropeFunctions.py
executable file
·1687 lines (1348 loc) · 80.3 KB
/
QEuropeFunctions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python
#This file contains all the important functions for simulating a european quantum network
# Netsquid has to be installed
#Author : Raja Yehia (raja.yehia@gmail.com)
import netsquid as ns
import netsquid.components.instructions as instr
import netsquid.components.qprogram as qprog
import random
from scipy.stats import bernoulli
import logging
import math
import numpy as np
from netsquid.components import Channel, QuantumChannel, QuantumMemory, ClassicalChannel
from netsquid.components.models.qerrormodels import FibreLossModel, DepolarNoiseModel, DephaseNoiseModel
from netsquid.nodes import Node, DirectConnection
from netsquid.nodes.connections import Connection
from netsquid.protocols import NodeProtocol
from netsquid.components.models import DelayModel
from netsquid.components.models.delaymodels import FixedDelayModel, FibreDelayModel
from netsquid.components import QuantumMemory
from netsquid.qubits.state_sampler import StateSampler
from netsquid.components.qsource import QSource, SourceStatus
from netsquid.components.qprocessor import QuantumProcessor
from netsquid.nodes.network import Network
from netsquid.qubits import ketstates as ks
from netsquid.protocols.protocol import Signals
from netsquid.components.qprocessor import PhysicalInstruction
from netsquid.qubits import qubitapi as qapi
from netsquid.components.clock import Clock
from netsquid.qubits.dmtools import DenseDMRepr
import sys
from lossmodel import FreeSpaceLossModel, FixedSatelliteLossModel
#Qlient parameters
f_qubit_qlient = 100e6 #Qubit creation attempt frequency
Qlient_init_time = math.ceil(1e9/f_qubit_qlient) #time to create |0> in a Qlient node in ns
Qlient_init_succ = 0.008 #Probability that a a qubit creation succeed
Qlient_init_flip = 0 # probability that a qubit is flipped at its creation
Qlient_meas_succ= 0.95 #Probability that a measurement succeeds
Qlient_meas_flip = 1e-5 #Probability that the measurement outcome is flipped by the detectors
#Qonnector parameters
Max_Qlient = 5 #Number of simultaneous link that the Qonnector can create
f_qubit_qonn = 100e6 #Qubit creation attempt frequency in MHz
Qonnector_init_time = math.ceil(1e9/f_qubit_qonn) #time to create |0> in a Qonnector node in ns
Qonnector_init_succ = 1 #Probability that a qubit creation succeeds
Qonnector_init_flip = 0
Qonnector_meas_succ=0.85 #Probability that a measurement succeeds
Qonnector_meas_flip = 0 #Probability that the measurement outcome is flipped by the detectors
switch_succ=0.9 #probability that transmitting a qubit from a qlient to another succeeds
BSM_succ = 0.9 #probability that a Bell state measurement of 2 qubits succeeds
EPR_succ=1 #probability that an initialisation of an EPR pair succeeds
f_EPR = 80e6 #EPR pair creation attempt frequency in MHz
EPR_time = math.ceil(1e9/f_EPR) # time to create a bell pair in a Qonnector node (ns)
f_GHZ = 8e6 #GHZ state creation attempt frequency in MHz
GHZ3_time = math.ceil(1e9/f_GHZ) #time to create a GHZ3 state (ns)
GHZ3_succ = 2.5e-3 #probability that creating a GHZ3 state succeeds
GHZ4_time = math.ceil(1e9/f_GHZ) #time to create a GHZ4 state (ns)
GHZ4_succ = 3.6e-3 #probability that creating a GHZ4 state succeeds
GHZ5_time = math.ceil(1e9/f_GHZ) #time to create a GHZ5 state (ns)
GHZ5_succ = 9e-5 #probability that creating a GHZ5 state succeeds
#Detector noise parameters
DetectGate = 1e-10 #Detection gate window
DCRate = 100 #Dark count rate
BGRateDay = 5000 #Background Noise rate by day
BGRateNight = 500 #Background Noise rate by night
pdark = DCRate*DetectGate #Probability to get a dark count within the detection window
pbgday = BGRateDay*DetectGate*Qonnector_meas_succ #Probability to get a background click count within the detection window by day
pbgnight = BGRateNight*DetectGate*Qonnector_meas_succ #Probability to get a background click count within the detection window by night
pafterpulse = 0.05 #afterpulse probability
#Network parameter
fiber_coupling = 0.9 #Fiber coupling efficiency
fiber_loss=0.18 #Loss in fiber in dB/km
fiber_dephasing_rate = 0.02 #dephasing rate in the fiber (Hz)
#Satellite to Ground channel parameters
txDiv = 500e-6
sigmaPoint = 5e-6
rx_aperture_sat = 1
Cn2_sat = 0
#Free space channel parameter
wavelength = 1550*1e-9
W0 = wavelength/(txDiv*np.pi)
rx_aperture_drone = 0.3
rx_aperture_ground = 0.3
Cn2_drone_to_ground = 10e-16
Cn2_drone_to_drone = 10e-18
c = 299792.458 #speed of light in km/s
Tatm = 1
#Quantum operations accessible to the Qonnectors
qonnector_physical_instructions = [
PhysicalInstruction(instr.INSTR_INIT, duration=Qonnector_init_time),
PhysicalInstruction(instr.INSTR_H, duration=1, parallel=True, topology=[0]),
PhysicalInstruction(instr.INSTR_X, duration=1, parallel=True, topology=[0]),
PhysicalInstruction(instr.INSTR_Z, duration=1, parallel=True, topology=[0]),
PhysicalInstruction(instr.INSTR_S, duration=1, parallel=True, topology=[0]),
PhysicalInstruction(instr.INSTR_I, duration=1, parallel=True, topology=[0]),
PhysicalInstruction(instr.INSTR_CNOT, duration=4, parallel=True),
PhysicalInstruction(instr.INSTR_MEASURE, duration=1, parallel=True, topology=[0,1]),
PhysicalInstruction(instr.INSTR_MEASURE_BELL, duration = 1, parallel=True),
PhysicalInstruction(instr.INSTR_SWAP, duration = 1, parallel=True)
]
#Quantum operations accessible to the Qlient
qlient_physical_instructions = [
PhysicalInstruction(instr.INSTR_INIT, duration=Qlient_init_time),
PhysicalInstruction(instr.INSTR_H, duration=1, parallel=True, topology=[0]),
PhysicalInstruction(instr.INSTR_X, duration=1, parallel=True, topology=[0]),
PhysicalInstruction(instr.INSTR_Z, duration=1, parallel=True, topology=[0]),
PhysicalInstruction(instr.INSTR_S, duration=1, parallel=True, topology=[0]),
PhysicalInstruction(instr.INSTR_I, duration=1, parallel=True, topology=[0]),
PhysicalInstruction(instr.INSTR_MEASURE, duration=1, parallel=False, topology=[0])
]
class Qlient_node(Node):
"""A Qlient node
Parameters:
name: name of the Qlient
phys_instruction: list of physical instructions for the Qlient
keylist: list of bits for QKD
ports: list of two ports: one to send to Qonnector and one to receive
"""
def __init__(self, name, phys_instruction, keylist=None,listports=None):
super().__init__(name=name)
qmem = QuantumProcessor("QlientMemory{}".format(name), num_positions=1,
phys_instructions=phys_instruction)
self.qmemory = qmem
self.keylist=keylist
self.listports=listports
class Qonnector_node(Node):
"""A Qonnector node
Parameters:
QlientList: List of connected Qlients
QlientPorts: Dictionnary of the form {Qlient: [port_to_send, port_to_receive]}
QlientKeys : Dictionnary for QKD of the form {Qlient: [key]}
type : Type of connector. Can be "ground", "satellite" or "drone".
"""
def __init__(self, name, QlientList = None,
QlientPorts = None, QlientKeys = None, type = "ground"):
super().__init__(name=name)
self.QlientList = QlientList
self.QlientPorts = QlientPorts
self.QlientKeys = QlientKeys
self.type = type
class QEurope():
def __init__(self,name):
""" Initialisation of a Quantum network
Parameter:
name: name of the network (str) /!\ Expected name should start with 'Qonnector' /!\
"""
self.network = Network(name)
self.name=name
def Add_Qonnector(self, qonnectorname):
"""Method to add a Qonnector to the network
Parameter :
qonnectorname: name tof the Qonnector to add (str)
"""
Qonnector = Qonnector_node(qonnectorname, QlientList = [], QlientPorts = {}, QlientKeys = {})
self.network.add_node(Qonnector)
def Add_Qlient(self, qlientname, distance, qonnectorto):
""" Method to add a Qlient to the network. It creates a Quantum Processor at the Qonnector qonnectorto
that is linked to the new Qlient through a fiber.
Parameters :
qlientname: name of the qlient to add (str)
distance: distance from the Qonnector to the new node in km
qonnectorto: Name of the Qonnector to attach the Qlient to (str)
"""
network = self.network
# Check that the Qonnector has space for the new qlient
Qonnector = network.get_node(qonnectorto)
if len(Qonnector.QlientList)==Max_Qlient:
raise ValueError("You have reached the maximum Qlient capacity for this Qonnector.")
#creates a qlient and adds it to the network
Qlient = Qlient_node(qlientname,qlient_physical_instructions,keylist=[],listports=[])
network.add_node(Qlient)
#Create quantum channels and add them to the network
qchannel1 = QuantumChannel("QuantumChannelSto{}".format(qlientname),length=distance, delay=1,
models={"quantum_loss_model": FibreLossModel(p_loss_init=1-fiber_coupling,
p_loss_length=fiber_loss),
"quantum_noise_model":DephaseNoiseModel(dephase_rate = fiber_dephasing_rate,time_independent=True)})
qchannel2 = QuantumChannel("QuantumChannel{}toS".format(qlientname),length=distance, delay=1,
models={"quantum_loss_model": FibreLossModel(p_loss_init=1-fiber_coupling,
p_loss_length=fiber_loss),
"quantum_noise_model":DephaseNoiseModel(dephase_rate = fiber_dephasing_rate,time_independent=True)})
Qonn_send, Qlient_receive = network.add_connection(
qonnectorto, qlientname, channel_to=qchannel1, label="quantumS{}".format(qlientname))
Qlient_send, Qonn_receive = network.add_connection(
qlientname, qonnectorto, channel_to=qchannel2, label="quantum{}S".format(qlientname))
# Update the Qonnector's properties
qmem = QuantumProcessor( "QonnectorMemoryTo{}".format(qlientname), num_positions=2 ,
phys_instructions=qonnector_physical_instructions)
Qonnector.add_subcomponent(qmem)
Qonnector.QlientList.append(qlientname)
Qonnector.QlientPorts[qlientname] = [Qonn_send,Qonn_receive]
Qonnector.QlientKeys[qlientname] = []
#Update Qlient ports
Qlient.listports = [Qlient_send, Qlient_receive]
def route_qubits(msg):
target = msg.meta.pop('internal', None)
if isinstance(target, QuantumMemory):
if not target.has_supercomponent(Qonnector):
raise ValueError("Can't internally route to a quantummemory that is not a subcomponent.")
target.ports['qin'].tx_input(msg)
else:
Qonnector.ports[Qonn_send].tx_output(msg)
# Connect the Qonnector's ports
qmem.ports['qout'].bind_output_handler(route_qubits) #port to send to Qlient
Qonnector.ports[Qonn_receive].forward_input(qmem.ports["qin"]) #port to receive from Qlient
# Connect the Qlient's ports
Qlient.ports[Qlient_receive].forward_input(Qlient.qmemory.ports["qin"]) #port to receive from qonnector
Qlient.qmemory.ports["qout"].forward_output(Qlient.ports[Qlient_send]) #port to send to qonnector
#Classical channels on top of that
cchannel1 = ClassicalChannel("ClassicalChannelSto{}".format(qlientname),length=distance, delay=1)
cchannel2 = ClassicalChannel("ClassicalChannel{}toS".format(qlientname),length=distance, delay=1)
network.add_connection(qonnectorto, qlientname, channel_to=cchannel1,
label="ClassicalS{}".format(qlientname), port_name_node1="cout_{}".format(qlientname),
port_name_node2="cin")
network.add_connection(qlientname, qonnectorto, channel_to=cchannel2,
label="Classical{}S".format(qlientname), port_name_node1="cout",
port_name_node2="cin_{}".format(qlientname))
def connect_qonnectors(self, qonnector_1_name, qonnector_2_name, distance, loss_model):
# Create Qonnector objects
network = self.network
qonnector_1 = network.get_node(qonnector_1_name)
qonnector_2 = network.get_node(qonnector_2_name)
# Create dedicated processor at each Qonnector
q_mem_1 = QuantumProcessor("QonnectorMemoryTo{}".format(qonnector_2_name), num_positions = 2,
phys_instructions = qonnector_physical_instructions)
qonnector_1.add_subcomponent(q_mem_1)
q_mem_2 = QuantumProcessor("QonnectorMemoryTo{}".format(qonnector_1_name), num_positions = 2,
phys_instructions=qonnector_physical_instructions)
qonnector_2.add_subcomponent(q_mem_2)
# Create biderctional quantum channel
q_channel_1 = QuantumChannel("QonnectorChannelto{}".format(qonnector_1_name), length = distance, delay = 1,
models = {"quantum_loss_model": loss_model})
q_channel_2 = QuantumChannel("QonnectorChannelto{}".format(qonnector_2_name), length = distance, delay = 1,
models = {"quantum_loss_model": loss_model})
# Connect Qonnectors via the quantum channel
qonnector_1_send, qonnector_2_receive = network.add_connection(
qonnector_1, qonnector_2, channel_to = q_channel_1, label = "QonnectorChanTo{}".format(qonnector_2_name))
qonnector_2_send, qonnector_1_receive = network.add_connection(
qonnector_2, qonnector_1, channel_to = q_channel_2, label = "QonnectorChanTo{}".format(qonnector_1_name))
# Update Qonnector 1 properties
qonnector_1.QlientList.append(qonnector_2_name)
qonnector_1.QlientPorts[qonnector_2_name] = [qonnector_1_send, qonnector_1_receive]
qonnector_1.QlientKeys[qonnector_2_name] = []
# Update Qonnector 2 properties
qonnector_2.QlientList.append(qonnector_1_name)
qonnector_2.QlientPorts[qonnector_1_name] = [qonnector_2_send, qonnector_2_receive]
qonnector_2.QlientKeys[qonnector_1_name] = []
# Update Qonnector 1 ports
def route_qubits_1(msg):
target = msg.meta.pop('internal', None)
if isinstance(target, QuantumMemory):
if not target.has_supercomponent(qonnector_1):
raise ValueError("Can't internally route to a quantum memory that is not a subcomponent.")
target.ports['qin'].tx_input(msg)
else:
qonnector_1.ports[qonnector_1_send].tx_output(msg)
q_mem_1.ports['qout'].bind_output_handler(route_qubits_1)
qonnector_1.ports[qonnector_1_receive].forward_input(q_mem_1.ports["qin"])
# Update Qonnector 2 ports
def route_qubits_2(msg):
target = msg.meta.pop('internal', None)
if isinstance(target, QuantumMemory):
if not target.has_supercomponent(qonnector_2):
raise ValueError("Can't internally route to a quantum memory that is not a subcomponent.")
target.ports['qin'].tx_input(msg)
else:
qonnector_2.ports[qonnector_2_send].tx_output(msg)
q_mem_2.ports['qout'].bind_output_handler(route_qubits_2)
qonnector_2.ports[qonnector_2_receive].forward_input(q_mem_2.ports["qin"])
# Create biderectional classical channel
c_channel_1 = ClassicalChannel("ClassicalChannelto{}".format(qonnector_1), length = distance, delay=1)
c_channel_2 = ClassicalChannel("ClassicalChannelto{}".format(qonnector_2), length = distance, delay=1)
# Connect Qonnectors via the classical channel
network.add_connection(qonnector_2, qonnector_1, channel_to=c_channel_1,
label = "Classicalto{}".format(qonnector_1), port_name_node1 = "cout_{}".format(qonnector_1_name),
port_name_node2 = "cin_{}".format(qonnector_2_name))
network.add_connection(qonnector_1, qonnector_2, channel_to=c_channel_2,
label = "Classicalto{}".format(qonnector_2), port_name_node1 = "cout_{}".format(qonnector_2_name),
port_name_node2 = "cin_{}".format(qonnector_1_name))
def Connect_Qonnector(self, Qonnector1, Qonnector2, distmid1,distmid2,tsat1,tsat2, linktype):
"""Method to connect two Qonnectors. It creates dedicated quantum processor at each Qonnector.
### Parameters ###
Qonnector1: name of the first Qonnector (str)
Qonnector2: name of the second Qonnector (str)
distmid1: distance between Qonnector 1 and middle node (satellite) in km or height of the drones (drone)
distmid2: distance between Qonnector 2 and middle node (satellite) in km or distance between drones
tsat1 : atmospheric transmittance between Qonnector 1 and satellite or between Qonnectors and drones (drone)
tsat2 : atmospheric transmittance between Qonnector 2 and satellite or between the two drones (drone)
linktype: "drone" or "satellite". In the first case it creates a direct free space link between the two
Qonnectors. In the "satellite case", it creates a quantum processor (satellite) in the middle
connected to the two Qonnectors"""
network = self.network
#check the format of linktype
if not(linktype == "drone") and not (linktype == "satellite"):
raise NameError("Wrong link type, it should be drone or satellite")
#create dedicated quantum memories at each qonnector
Qonn1 = network.get_node(Qonnector1)
Qonn2 = network.get_node(Qonnector2)
#create channels depending on the link type
if linktype == "drone":
#create two drones
Drone1 = Qonnector_node("Drone{}".format(Qonnector1), QlientList=[],QlientPorts={},QlientKeys={})
network.add_node(Drone1)
Drone2 = Qonnector_node("Drone{}".format(Qonnector2), QlientList=[],QlientPorts={},QlientKeys={})
network.add_node(Drone2)
qmem3 = QuantumProcessor("DroneMemoryTo{}".format(Qonnector1), num_positions=2,
phys_instructions=qonnector_physical_instructions)
Drone1.add_subcomponent(qmem3)
qmem4 = QuantumProcessor("DroneMemoryTo{}".format(Drone2.name), num_positions=2,
phys_instructions=qonnector_physical_instructions)
Drone1.add_subcomponent(qmem4)
qmem5 = QuantumProcessor("DroneMemoryTo{}".format(Qonnector2), num_positions=2,
phys_instructions=qonnector_physical_instructions)
Drone2.add_subcomponent(qmem5)
qmem6 = QuantumProcessor("DroneMemoryTo{}".format(Drone1.name), num_positions=2,
phys_instructions=qonnector_physical_instructions)
Drone2.add_subcomponent(qmem6)
#create processor at each Qonnector
qmem1 = QuantumProcessor( "QonnectorMemoryTo{}".format(Drone1.name), num_positions=2 ,
phys_instructions=qonnector_physical_instructions)
Qonn1.add_subcomponent(qmem1)
qmem2 = QuantumProcessor( "QonnectorMemoryTo{}".format(Drone2.name), num_positions=2 ,
phys_instructions=qonnector_physical_instructions)
Qonn2.add_subcomponent(qmem2)
#connect the drone to their Qonnector
qchannel1 = QuantumChannel("DroneChannelto{}".format(Qonnector1), length = distmid1, delay = 1,
models={"quantum_loss_model":FreeSpaceLossModel(W0, rx_aperture_ground,
Cn2_drone_to_ground, wavelength, tsat1)})
qchannel2 = QuantumChannel("DroneChannelto{}".format(Drone1.name), length = distmid1, delay = 1,
models={"quantum_loss_model":FreeSpaceLossModel(W0, rx_aperture_drone,
Cn2_drone_to_ground, wavelength, tsat1)})
Drone1_send, Qonn1_receive = network.add_connection(
Drone1, Qonn1, channel_to = qchannel1, label="Drone1ChanTo{}".format(Qonnector1))
Qonn1_send, Drone1_receive = network.add_connection(
Qonn1, Drone1, channel_to = qchannel2, label="Drone1ChanTo{}".format(Drone1.name))
qchannel3 = QuantumChannel("DroneChannelto{}".format(Qonnector2), length = distmid1, delay = 1,
models={"quantum_loss_model":FreeSpaceLossModel(W0, rx_aperture_ground,
Cn2_drone_to_ground, wavelength, tsat1)})
qchannel4 = QuantumChannel("DroneChannelto{}".format(Drone2.name), length = distmid1, delay = 1,
models={"quantum_loss_model":FreeSpaceLossModel(W0, rx_aperture_drone,
Cn2_drone_to_ground, wavelength, tsat1)})
Drone2_send, Qonn2_receive = network.add_connection(
Drone2, Qonn2, channel_to = qchannel3, label="Drone2ChanTo{}".format(Qonnector2))
Qonn2_send, Drone2_receive = network.add_connection(
Qonn2, Drone2, channel_to = qchannel4, label="Drone2ChanTo{}".format(Drone2.name))
#Connect Drones
qchannel5 = QuantumChannel("DroneChannelto{}".format(Drone2.name), length = distmid2, delay = 1,
models={"quantum_loss_model":FreeSpaceLossModel(W0, rx_aperture_drone,
Cn2_drone_to_drone, wavelength, tsat2)})
qchannel6 = QuantumChannel("DroneChannelto{}".format(Drone1.name), length = distmid2, delay = 1,
models={"quantum_loss_model":FreeSpaceLossModel(W0, rx_aperture_drone,
Cn2_drone_to_drone, wavelength, tsat2)})
Drone1_sendtoDrone, Drone2_receivefromDrone = network.add_connection(
Drone1, Drone2, channel_to = qchannel5, label="Drone1ChanTo{}".format(Drone2.name))
Drone2_sendtoDrone, Drone1_receivefromDrone = network.add_connection(
Drone2, Drone1, channel_to = qchannel6, label="Drone2ChanTo{}".format(Drone1.name))
#Update node properties
Qonn1.QlientList.append(Drone1.name)
Qonn1.QlientPorts[Drone1.name] = [Qonn1_send,Qonn1_receive]
Qonn1.QlientKeys[Drone1.name] = []
Qonn2.QlientList.append(Drone2.name)
Qonn2.QlientPorts[Drone2.name] = [Qonn2_send,Qonn2_receive]
Qonn2.QlientKeys[Drone2.name] = []
Drone1.QlientList.append(Qonnector1)
Drone1.QlientPorts[Qonnector1]= [Drone1_send,Drone1_receive]
Drone1.QlientKeys[Qonnector1] = []
Drone1.QlientList.append(Drone2.name)
Drone1.QlientPorts[Drone2.name]= [Drone1_sendtoDrone,Drone1_receivefromDrone]
Drone1.QlientKeys[Drone2.name] = []
Drone2.QlientList.append(Qonnector2)
Drone2.QlientPorts[Qonnector2]= [Drone2_send,Drone2_receive]
Drone2.QlientKeys[Qonnector2] = []
Drone2.QlientList.append(Drone1.name)
Drone2.QlientPorts[Drone1.name]= [Drone2_sendtoDrone,Drone2_receivefromDrone]
Drone2.QlientKeys[Drone1.name] = []
#Connect the ports
#Drone1
def route_qubits3(msg):
target = msg.meta.pop('internal', None)
if isinstance(target, QuantumMemory):
if not target.has_supercomponent(Drone1):
raise ValueError("Can't internally route to a quantummemory that is not a subcomponent.")
target.ports['qin'].tx_input(msg)
else:
Drone1.ports[Drone1_send].tx_output(msg)
qmem3.ports['qout'].bind_output_handler(route_qubits3)
def route_qubits4(msg):
target = msg.meta.pop('internal', None)
if isinstance(target, QuantumMemory):
if not target.has_supercomponent(Drone1):
raise ValueError("Can't internally route to a quantummemory that is not a subcomponent.")
target.ports['qin'].tx_input(msg)
else:
Drone1.ports[Drone1_sendtoDrone].tx_output(msg)
qmem4.ports['qout'].bind_output_handler(route_qubits4)
Drone1.ports[Drone1_receive].forward_input(qmem3.ports["qin"])
Drone1.ports[Drone1_receivefromDrone].forward_input(qmem4.ports["qin"])
#Drone2
def route_qubits5(msg):
target = msg.meta.pop('internal', None)
if isinstance(target, QuantumMemory):
if not target.has_supercomponent(Drone2):
raise ValueError("Can't internally route to a quantummemory that is not a subcomponent.")
target.ports['qin'].tx_input(msg)
else:
Drone2.ports[Drone2_send].tx_output(msg)
qmem5.ports['qout'].bind_output_handler(route_qubits5)
def route_qubits6(msg):
target = msg.meta.pop('internal', None)
if isinstance(target, QuantumMemory):
if not target.has_supercomponent(Drone2):
raise ValueError("Can't internally route to a quantummemory that is not a subcomponent.")
target.ports['qin'].tx_input(msg)
else:
Drone2.ports[Drone2_sendtoDrone].tx_output(msg)
qmem6.ports['qout'].bind_output_handler(route_qubits6)
Drone2.ports[Drone2_receive].forward_input(qmem5.ports["qin"])
Drone2.ports[Drone2_receivefromDrone].forward_input(qmem6.ports["qin"])
#Qonnectors
def route_qubits7(msg):
target = msg.meta.pop('internal', None)
if isinstance(target, QuantumMemory):
if not target.has_supercomponent(Qonn1):
raise ValueError("Can't internally route to a quantummemory that is not a subcomponent.")
target.ports['qin'].tx_input(msg)
else:
Qonn1.ports[Qonn1_send].tx_output(msg)
qmem1.ports['qout'].bind_output_handler(route_qubits7)
Qonn1.ports[Qonn1_receive].forward_input(qmem1.ports["qin"])
def route_qubits8(msg):
target = msg.meta.pop('internal', None)
if isinstance(target, QuantumMemory):
if not target.has_supercomponent(Qonn2):
raise ValueError("Can't internally route to a quantummemory that is not a subcomponent.")
target.ports['qin'].tx_input(msg)
else:
Qonn2.ports[Qonn2_send].tx_output(msg)
qmem2.ports['qout'].bind_output_handler(route_qubits8)
Qonn2.ports[Qonn2_receive].forward_input(qmem2.ports["qin"])
#Classical channels on top of that
cchannel1 = ClassicalChannel("ClassicalChannelto{}".format(Qonnector1),length=distmid1, delay=1)
cchannel2 = ClassicalChannel("ClassicalChanneltoDrone1",length=distmid1, delay=1)
network.add_connection(Drone1, Qonn1, channel_to=cchannel1,
label="Classicalto{}".format(Qonnector1), port_name_node1="cout_{}".format(Qonnector1),
port_name_node2="cin_{}".format(Drone1.name))
network.add_connection(Qonn1, Drone1, channel_to=cchannel2,
label="ClassicaltoDrone1", port_name_node1="cout_{}".format(Drone1.name),
port_name_node2="cin_{}".format(Qonnector1))
cchannel3 = ClassicalChannel("ClassicalChannelto{}".format(Qonnector2),length=distmid1, delay=1)
cchannel4 = ClassicalChannel("ClassicalChanneltoDrone2",length=distmid1, delay=1)
network.add_connection(Drone2, Qonn2, channel_to=cchannel3,
label="Classicalto{}".format(Qonnector2), port_name_node1="cout_{}".format(Qonnector2),
port_name_node2="cin_{}".format(Drone2.name))
network.add_connection(Qonn2, Drone2, channel_to=cchannel4,
label="ClassicaltoDrone2", port_name_node1="cout_{}".format(Drone2.name),
port_name_node2="cin_{}".format(Qonnector2))
cchannel5 = ClassicalChannel("ClassicalChanneltoDrone1",length=distmid1, delay=1)
cchannel6 = ClassicalChannel("ClassicalChanneltoDrone2",length=distmid1, delay=1)
network.add_connection(Drone1, Drone2, channel_to=cchannel5,
label="Classicalto{}".format(Drone2.name), port_name_node1="cout_{}".format(Drone2.name),
port_name_node2="cin_{}".format(Drone1.name))
network.add_connection(Drone2, Drone1, channel_to=cchannel6,
label="Classicalto{}".format(Drone1.name), port_name_node1="cout_{}".format(Drone1.name),
port_name_node2="cin_{}".format(Drone2.name))
if linktype == "satellite":
#Create a satellite node with a quantum processor for each qonnector
Satellite = Qonnector_node("Satellite{}".format(Qonnector1+Qonnector2), QlientList=[],QlientPorts={},QlientKeys={})
network.add_node(Satellite)
qmem3 = QuantumProcessor( "SatelliteMemoryTo{}".format(Qonnector1), num_positions=2 ,
phys_instructions=qonnector_physical_instructions)
Satellite.add_subcomponent(qmem3)
qmem4 = QuantumProcessor( "SatelliteMemoryTo{}".format(Qonnector2), num_positions=2 ,
phys_instructions=qonnector_physical_instructions)
Satellite.add_subcomponent(qmem4)
qmem1 = QuantumProcessor( "QonnectorMemoryTo{}".format(Satellite.name), num_positions=2 ,
phys_instructions=qonnector_physical_instructions)
Qonn1.add_subcomponent(qmem1)
qmem2 = QuantumProcessor( "QonnectorMemoryTo{}".format(Satellite.name), num_positions=2 ,
phys_instructions=qonnector_physical_instructions)
Qonn2.add_subcomponent(qmem2)
#Connect Satellite with Qonn1 (only downlink)
qchannel1 = QuantumChannel("SatChannelto{}".format(Qonnector1),length=distmid1, delay=1,
models={"quantum_loss_model": FixedSatelliteLossModel(txDiv, sigmaPoint,
rx_aperture_sat, Cn2_sat, wavelength,tsat1)})
qchannel3 = QuantumChannel("SatChannelto{}".format(Satellite),length=distmid1, delay=1,
models={"quantum_loss_model": FixedSatelliteLossModel(txDiv, sigmaPoint,
rx_aperture_sat, Cn2_sat, wavelength,tsat1)})
#connect the channels to nodes
Sat1_send, Qonn1_receive = network.add_connection(
Satellite, Qonn1, channel_to=qchannel1, label="SatelliteChanTo{}".format(Qonnector1))
Qonn1_send, Sat1_rec = network.add_connection(
Qonn1, Satellite, channel_to=qchannel3, label="SatelliteChanTo{}".format(Satellite))
#update both node properties
Satellite.QlientList.append(Qonnector1)
Satellite.QlientPorts[Qonnector1] = [Sat1_send]
Satellite.QlientKeys[Qonnector1] = []
Qonn1.QlientList.append(Satellite.name)
Qonn1.QlientPorts[Satellite.name] = [Qonn1_send,Qonn1_receive]
Qonn1.QlientKeys[Satellite.name] = []
# Connect the Satellite and Qonnector's ports
def route_qubits3(msg):
target = msg.meta.pop('internal', None)
if isinstance(target, QuantumMemory):
if not target.has_supercomponent(Satellite):
raise ValueError("Can't internally route to a quantummemory that is not a subcomponent.")
target.ports['qin'].tx_input(msg)
else:
Satellite.ports[Sat1_send].tx_output(msg)
qmem3.ports['qout'].bind_output_handler(route_qubits3)
def route_qubits5(msg):
target = msg.meta.pop('internal', None)
if isinstance(target, QuantumMemory):
if not target.has_supercomponent(Qonn1):
raise ValueError("Can't internally route to a quantummemory that is not a subcomponent.")
target.ports['qin'].tx_input(msg)
else:
Qonn1.ports[Qonn1_send].tx_output(msg)
qmem1.ports['qout'].bind_output_handler(route_qubits5)
Qonn1.ports[Qonn1_receive].forward_input(qmem1.ports["qin"])
#Classical channels on top of that
cchannel1 = ClassicalChannel("ClassicalChannelto{}".format(Qonnector1),length=distmid1, delay=1)
cchannel2 = ClassicalChannel("ClassicalChanneltoSatellite",length=distmid1, delay=1)
network.add_connection(Satellite, Qonn1, channel_to=cchannel1,
label="Classicalto{}".format(Qonnector1), port_name_node1="cout_{}".format(Qonnector1),
port_name_node2="cin_{}".format(Satellite.name))
network.add_connection(Qonn1, Satellite, channel_to=cchannel2,
label="ClassicaltoSat".format(Qonnector1), port_name_node1="cout_{}".format(Satellite.name),
port_name_node2="cin_{}".format(Qonnector1))
#Do the same with Qonn2
qchannel2 = QuantumChannel("SatChannelto{}".format(Qonnector2),length=distmid2, delay=1,
models={"quantum_loss_model": FixedSatelliteLossModel(txDiv, sigmaPoint,
rx_aperture_sat, Cn2_sat, wavelength,tsat2)})
qchannel4 = QuantumChannel("SatChannelto{}".format(Satellite),length=distmid1, delay=1,
models={"quantum_loss_model": FixedSatelliteLossModel(txDiv, sigmaPoint,
rx_aperture_sat, Cn2_sat, wavelength,tsat2)})
#connect the channels to nodes
Sat2_send, Qonn2_receive = network.add_connection(
Satellite, Qonn2, channel_to=qchannel2, label="SatelliteChanTo{}".format(Qonnector2))
Qonn2_send, Sat2_receive = network.add_connection(
Qonn2, Satellite, channel_to=qchannel4, label="SatelliteChanTo{}".format(Satellite))
#update both node properties
Satellite.QlientList.append(Qonnector2)
Satellite.QlientPorts[Qonnector2] = [Sat2_send]
Satellite.QlientKeys[Qonnector2] = []
Qonn2.QlientList.append(Satellite.name)
Qonn2.QlientPorts[Satellite.name] = [Qonn2_send,Qonn2_receive]
Qonn2.QlientKeys[Satellite.name] = []
# Connect the Satellite and Qonnector's ports
def route_qubits4(msg):
target = msg.meta.pop('internal', None)
if isinstance(target, QuantumMemory):
if not target.has_supercomponent(Satellite):
raise ValueError("Can't internally route to a quantummemory that is not a subcomponent.")
target.ports['qin'].tx_input(msg)
else:
Satellite.ports[Sat2_send].tx_output(msg)
qmem4.ports['qout'].bind_output_handler(route_qubits4)
def route_qubits6(msg):
target = msg.meta.pop('internal', None)
if isinstance(target, QuantumMemory):
if not target.has_supercomponent(Qonn2):
raise ValueError("Can't internally route to a quantummemory that is not a subcomponent.")
target.ports['qin'].tx_input(msg)
else:
Qonn2.ports[Qonn2_send].tx_output(msg)
qmem2.ports['qout'].bind_output_handler(route_qubits6)
Qonn2.ports[Qonn2_receive].forward_input(qmem2.ports["qin"])
#Classical channels on top of that
cchannel3 = ClassicalChannel("ClassicalChannelto{}".format(Qonnector2),length=distmid2, delay=1)
cchannel4 = ClassicalChannel("ClassicalChanneltoSatellite",length=distmid2, delay=1)
network.add_connection(Satellite, Qonn2, channel_to=cchannel3,
label="Classicalto{}".format(Qonnector2), port_name_node1="cout_{}".format(Qonnector2),
port_name_node2="cin_{}".format(Satellite.name))
network.add_connection(Qonn2, Satellite, channel_to=cchannel4,
label="ClassicaltoSat".format(Qonnector2), port_name_node1="cout_{}".format(Satellite.name),
port_name_node2="cin_{}".format(Qonnector2))
class ReceiveProtocol(NodeProtocol):
"""Protocol performed by a node to receive a state a measure it. Saves the outputs as well as the
measurement basis and timestamps of reception in the list QlientKeys["name of the sending node"]
in the case of a Qonnector or in the list keylist in the case of a Qlient.
Parameters:
othernode: node from which a qubit is expected
measurement_succ: probability that the measurement succeeds
measurement_flip: probability that the detector flips the outcome (crosstalk)
BB84: boolean indicating if we perform BB84 measurement (random choice of measurement basis)"""
def __init__(self, othernode, measurement_succ, measurement_flip, BB84, node):
super().__init__(node=node)
self._othernode = othernode
self._measurement_succ=measurement_succ
self._BB84 = BB84
self._measurement_flip = measurement_flip
def run(self):
if self.node.name[0:9] == 'Qonnector' or self.node.name[0:5]=='Drone':
if self.node.name[0:9] == 'Qonnector':
mem = self.node.subcomponents["QonnectorMemoryTo{}".format(self._othernode.name)]
port = self.node.ports[self.node.QlientPorts[self._othernode.name][1]]
elif self.node.name[0:5]=='Drone':
mem = self.node.subcomponents["DroneMemoryTo{}".format(self._othernode.name)]
port = self.node.ports[self.node.QlientPorts[self._othernode.name][1]]
#print(port)
while True:
yield self.await_port_input(port)
t = self.node.ports["cin_{}".format(self._othernode.name)].rx_input()
b = bernoulli.rvs(self._measurement_succ)
if b ==1 :
if self._BB84: #in case we perform BB84
base = bernoulli.rvs(0.5) #choose a random basis
if base < 0.5:
mem.execute_instruction(instr.INSTR_H, [0], physical = False)
base = "plusmoins"
else:
mem.execute_instruction(instr.INSTR_I, [0],physical = False)
base = "zeroun"
else:
base = None
m,_,_ = mem.execute_instruction(instr.INSTR_MEASURE,[0],output_key="M1")
yield self.await_program(mem,await_done=True,await_fail=True)
flip = bernoulli.rvs(self._measurement_flip)
if (flip==1):
if m['M1'][0]==0:
m['M1'][0] =1
elif m['M1'][0]==1:
m['M1'][0]=0
if m['M1'] is not None and t is not None and base is not None:
self.node.QlientKeys[self._othernode.name].append(([t.items[0],base],m['M1'][0]))
elif m['M1'] is not None and t is not None:
self.node.QlientKeys[self._othernode.name].append((t.items,m['M1'][0]))
elif m['M1'] is not None:
self.node.QlientKeys[self._othernode.name].append(m['M1'][0])
mem.reset()
else:
mem = self.node.qmemory
port = self.node.ports[self.node.listports[1]]
while True:
yield self.await_port_input(port)
#print("qubit received")
#qubit, = mem.peek([0])
#print(mem.peek([0]))
t = self.node.ports["cin"].rx_input()
b = bernoulli.rvs(self._measurement_succ)
#print(b)
if b ==1 :
if self._BB84: #in case we perform BB84
base = bernoulli.rvs(0.5) #choose a random basis
if base < 0.5:
mem.execute_instruction(instr.INSTR_H, [0], physical = False)
base = "plusmoins"
else:
mem.execute_instruction(instr.INSTR_I, [0],physical = False)
base = "zeroun"
else:
base = None
if not(mem.busy):
m,_,_ = mem.execute_instruction(instr.INSTR_MEASURE,[0],output_key="M1")
yield self.await_program(mem,await_done=True,await_fail=True)
#print("qubit measured")
flip = bernoulli.rvs(self._measurement_flip)
if (flip==1):
if m['M1'][0]==0:
m['M1'][0] =1
elif m['M1'][0]==1:
m['M1'][0]=0
if m['M1'] is not None and t is not None and base is not None:
self.node.keylist.append(([t.items[0], base],m['M1'][0]))
elif m['M1'] is not None and t is not None:
self.node.keylist.append((t.items,m['M1'][0]))
elif m['M1'] is not None:
self.node.keylist.append(m['M1'][0])
mem.reset()
class TransmitProtocol(NodeProtocol):
"""Protocol performed by a Qonnector to transmit a qubit sent by a Qlient or a satellite to another Qlient
Parameters
Qlient_from: node from which a qubit is expected
Qlient_to: node to which transmit the qubit received
switch_succ: probability that the transmission succeeds"""
def __init__(self, Qlient_from, Qlient_to, switch_succ, node=None, name=None):
super().__init__(node=node, name=name)
self._Qlient_from = Qlient_from
self._Qlient_to = Qlient_to
self._switch_succ=switch_succ
def run(self):
rec_mem = self.node.subcomponents["QonnectorMemoryTo{}".format(self._Qlient_from.name)]
rec_port = self.node.ports[self.node.QlientPorts[self._Qlient_from.name][1]]
sen_mem = self.node.subcomponents["QonnectorMemoryTo{}".format(self._Qlient_to.name)]
#print(sen_mem)
while True:
rec_mem.reset()
sen_mem.reset()
yield self.await_port_input(rec_port)
#print("qubit received at qonnector" )
t = self.node.ports["cin_{}".format(self._Qlient_from.name)].rx_input()
rec_mem.pop([0], skip_noise=True, meta_data={'internal': sen_mem})
#print("qubit moved in qonnector's memory")
b = bernoulli.rvs(self._switch_succ)
if b ==1 :
qubit, = sen_mem.pop([0])
self.node.ports["cout_{}".format(self._Qlient_to.name)].tx_output(t)
#print("qubit sent to node")
class SendEPR(NodeProtocol):
"""Protocol performed by a Qonnector or a satellite node to create a send EPR pair to two nodes,
each getting one qubit.
Parameters:
Qlient1 : Name of the first receiving node (str)
Qlient2 : Name of the second receiving node (str)
EPR_succ : success probability of the creation of the EPR pair
"""
def __init__(self, Qlient_1, Qlient_2, EPR_succ, node = None, name = None):
super().__init__(node=node, name=name)
self._Qlient_1 = Qlient_1
self._Qlient_2 = Qlient_2
self._EPR_succ = EPR_succ
def run(self):
if self.node.name[0:9]== 'Satellite':
mem1 = self.node.subcomponents["SatelliteMemoryTo{}".format(self._Qlient_1.name)]
mem2 = self.node.subcomponents["SatelliteMemoryTo{}".format(self._Qlient_2.name)]
port1 = self.node.ports[self.node.QlientPorts[self._Qlient_1.name][0]]
else:
mem1 = self.node.subcomponents["QonnectorMemoryTo{}".format(self._Qlient_1.name)]
mem2 = self.node.subcomponents["QonnectorMemoryTo{}".format(self._Qlient_2.name)]
port1 = self.node.ports[self.node.QlientPorts[self._Qlient_1.name][1]]
state_sampler = StateSampler(qreprs=[ks.b11],
probabilities=[1])
qsource = QSource("qsource{}".format(self._Qlient_1.name+self._Qlient_2.name),
state_sampler=state_sampler,
num_ports=2,
timing_model=FixedDelayModel(delay=EPR_time),
status=SourceStatus.EXTERNAL)
clock = Clock(name="clock",
start_delay=0,
models={"timing_model": FixedDelayModel(delay=EPR_time)})
self.node.add_subcomponent(clock)
self.node.add_subcomponent(qsource)
clock.ports["cout"].connect(qsource.ports["trigger"])
qsource.ports["qout0"].connect(mem1.ports["qin"])
qsource.ports["qout1"].connect(mem2.ports["qin"])
clock.start()
while True:
yield self.await_port_input(mem1.ports["qin"]) and self.await_port_input(mem2.ports["qin"])
b = bernoulli.rvs(self._EPR_succ)
if b==1:
mem1.pop([0])
self.node.ports["cout_{}".format(self._Qlient_1.name)].tx_output(clock.num_ticks)
self.node.QlientKeys[self._Qlient_1.name].append(0)
mem2.pop([0])
self.node.ports["cout_{}".format(self._Qlient_2.name)].tx_output(clock.num_ticks)
self.node.QlientKeys[self._Qlient_2.name].append(0)
mem1.reset()
mem2.reset()
class SendBB84(NodeProtocol):
"""Protocol performed by a node to send a random BB84 qubit |0>, |1>, |+> or |-> .
Parameters:
othernode: name of the receiving node (str).
init_succ: probability that a qubit creation attempt succeeds.
init_flip : probability that a qubit created is flipped before the sending.
"""
def __init__(self,othernode, init_succ, init_flip,node):
super().__init__(node=node)
self._othernode = othernode
self._init_succ = init_succ
self._init_flip = init_flip
def run(self):
if self.node.name[0:9] == 'Qonnector' or self.node.name[0:9]== 'Satellite' or self.node.name[0:5]=='Drone':
if self.node.name[0:9]== 'Satellite':
mem = self.node.subcomponents["SatelliteMemoryTo{}".format(self._othernode.name)]
elif self.node.name[0:5]=='Drone':
mem = self.node.subcomponents["DroneMemoryTo{}".format(self._othernode.name)]
else:
mem = self.node.subcomponents["QonnectorMemoryTo{}".format(self._othernode.name)]
clock = Clock(name="clock",
start_delay=0,
models={"timing_model": FixedDelayModel(delay=Qonnector_init_time )})
self.node.add_subcomponent(clock)
clock.start()
while True:
mem.reset()
mem.execute_instruction(instr.INSTR_INIT,[0])
yield self.await_program(mem,await_done=True,await_fail=True)
#print("qubit created")
succ = bernoulli.rvs(self._init_succ)
if (succ == 1):
flip = bernoulli.rvs(self._init_flip)
if (flip == 1):
mem.execute_instruction(instr.INSTR_X, [0], physical = False)
base = bernoulli.rvs(0.5) #random choice of a basis
if base <0.5: