Skip to content

Commit 0118029

Browse files
Updating for PIP
1 parent fdc3b00 commit 0118029

File tree

12 files changed

+81
-73
lines changed

12 files changed

+81
-73
lines changed

build/lib/backends/eqsn_backend.py

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import eqsn
1+
from eqsn import EQSN
22
import uuid
33
from objects.qubit import Qubit
44
import threading
@@ -117,6 +117,7 @@ def __init__(self):
117117
self._hosts = EQSNBackend.Hosts.get_instance()
118118
# keys are from : to, where from is the host calling create EPR
119119
self._entaglement_qubits = EQSNBackend.EntanglementIDs.get_instance()
120+
self.eqsn = EQSN()
120121

121122
def start(self, **kwargs):
122123
"""
@@ -129,7 +130,7 @@ def stop(self):
129130
"""
130131
Stops Backends which are running in an own thread or process.
131132
"""
132-
eqsn.stop_all()
133+
self.eqsn.stop_all()
133134

134135
def add_host(self, host):
135136
"""
@@ -151,7 +152,7 @@ def create_qubit(self, host_id):
151152
Qubit of backend type.
152153
"""
153154
id = str(uuid.uuid4())
154-
eqsn.new_qubit(id)
155+
self.eqsn.new_qubit(id)
155156
return id
156157

157158
def send_qubit_to(self, qubit, from_host_id, to_host_id):
@@ -183,10 +184,10 @@ def create_EPR(self, host_a_id, host_b_id, q_id=None, block=False):
183184
uid2 = uuid.uuid4()
184185
host_a = self._hosts.get_from_dict(host_a_id)
185186
host_b = self._hosts.get_from_dict(host_b_id)
186-
eqsn.new_qubit(uid1)
187-
eqsn.new_qubit(uid2)
188-
eqsn.H_gate(uid1)
189-
eqsn.cnot_gate(uid2, uid1)
187+
self.eqsn.new_qubit(uid1)
188+
self.eqsn.new_qubit(uid2)
189+
self.eqsn.H_gate(uid1)
190+
self.eqsn.cnot_gate(uid2, uid1)
190191
q1 = Qubit(host_a, qubit=uid1, q_id=q_id, blocked=block)
191192
q2 = Qubit(host_b, qubit=uid2, q_id=q1.id, blocked=block)
192193
self.store_ent_pair(host_a.host_id, host_b.host_id, q2)
@@ -245,7 +246,7 @@ def X(self, qubit):
245246
Args:
246247
qubit (Qubit): Qubit on which gate should be applied to.
247248
"""
248-
eqsn.X_gate(qubit.qubit)
249+
self.eqsn.X_gate(qubit.qubit)
249250

250251
def Y(self, qubit):
251252
"""
@@ -254,7 +255,7 @@ def Y(self, qubit):
254255
Args:
255256
qubit (Qubit): Qubit on which gate should be applied to.
256257
"""
257-
eqsn.Y_gate(qubit.qubit)
258+
self.eqsn.Y_gate(qubit.qubit)
258259

259260
def Z(self, qubit):
260261
"""
@@ -263,7 +264,7 @@ def Z(self, qubit):
263264
Args:
264265
qubit (Qubit): Qubit on which gate should be applied to.
265266
"""
266-
eqsn.Z_gate(qubit.qubit)
267+
self.eqsn.Z_gate(qubit.qubit)
267268

268269
def H(self, qubit):
269270
"""
@@ -272,7 +273,7 @@ def H(self, qubit):
272273
Args:
273274
qubit (Qubit): Qubit on which gate should be applied to.
274275
"""
275-
eqsn.H_gate(qubit.qubit)
276+
self.eqsn.H_gate(qubit.qubit)
276277

277278
def K(self, qubit):
278279
"""
@@ -281,7 +282,7 @@ def K(self, qubit):
281282
Args:
282283
qubit (Qubit): Qubit on which gate should be applied to.
283284
"""
284-
eqsn.K_gate(qubit.qubit)
285+
self.eqsn.K_gate(qubit.qubit)
285286

286287
def S(self, qubit):
287288
"""
@@ -290,7 +291,7 @@ def S(self, qubit):
290291
Args:
291292
qubit (Qubit): Qubit on which gate should be applied to.
292293
"""
293-
eqsn.S_gate(qubit.qubit)
294+
self.eqsn.S_gate(qubit.qubit)
294295

295296
def T(self, qubit):
296297
"""
@@ -299,7 +300,7 @@ def T(self, qubit):
299300
Args:
300301
qubit (Qubit): Qubit on which gate should be applied to.
301302
"""
302-
eqsn.T_gate(qubit.qubit)
303+
self.eqsn.T_gate(qubit.qubit)
303304

304305
def rx(self, qubit, phi):
305306
"""
@@ -309,7 +310,7 @@ def rx(self, qubit, phi):
309310
qubit (Qubit): Qubit on which gate should be applied to.
310311
phi (float): Amount of roation in Rad.
311312
"""
312-
eqsn.RX_gate(qubit.qubit, phi)
313+
self.eqsn.RX_gate(qubit.qubit, phi)
313314

314315
def ry(self, qubit, phi):
315316
"""
@@ -319,7 +320,7 @@ def ry(self, qubit, phi):
319320
qubit (Qubit): Qubit on which gate should be applied to.
320321
phi (float): Amount of roation in Rad.
321322
"""
322-
eqsn.RY_gate(qubit.qubit, phi)
323+
self.eqsn.RY_gate(qubit.qubit, phi)
323324

324325
def rz(self, qubit, phi):
325326
"""
@@ -329,7 +330,7 @@ def rz(self, qubit, phi):
329330
qubit (Qubit): Qubit on which gate should be applied to.
330331
phi (float): Amount of roation in Rad.
331332
"""
332-
eqsn.RZ_gate(qubit.qubit, phi)
333+
self.eqsn.RZ_gate(qubit.qubit, phi)
333334

334335
def cnot(self, qubit, target):
335336
"""
@@ -339,7 +340,7 @@ def cnot(self, qubit, target):
339340
qubit (Qubit): Qubit to control cnot.
340341
target (Qubit): Qubit on which the cnot gate should be applied.
341342
"""
342-
eqsn.cnot_gate(target.qubit, qubit.qubit)
343+
self.eqsn.cnot_gate(target.qubit, qubit.qubit)
343344

344345
def cphase(self, qubit, target):
345346
"""
@@ -349,7 +350,7 @@ def cphase(self, qubit, target):
349350
qubit (Qubit): Qubit to control cphase.
350351
target (Qubit): Qubit on which the cphase gate should be applied.
351352
"""
352-
eqsn.cphase_gate(target.qubit, qubit.qubit)
353+
self.eqsn.cphase_gate(target.qubit, qubit.qubit)
353354

354355
def measure(self, qubit, non_destructive):
355356
"""
@@ -362,7 +363,7 @@ def measure(self, qubit, non_destructive):
362363
Returns:
363364
The value which has been measured.
364365
"""
365-
return eqsn.measure(qubit.qubit, non_destructive)
366+
return self.eqsn.measure(qubit.qubit, non_destructive)
366367

367368
def release(self, qubit):
368369
"""
@@ -371,4 +372,4 @@ def release(self, qubit):
371372
Args:
372373
qubit (Qubit): The qubit which should be released.
373374
"""
374-
eqsn.measure(qubit.qubit)
375+
self.eqsn.measure(qubit.qubit)

build/lib/components/host.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from objects.quantum_storage import QuantumStorage
88
from objects.classical_storage import ClassicalStorage
99
from objects.message import Message
10-
from backends.cqc_backend import CQCBackend
10+
from backends.eqsn_backend import EQSNBackend
1111
import uuid
1212
import time
1313

@@ -35,7 +35,7 @@ def __init__(self, host_id, backend=None):
3535
self._classical_connections = []
3636
self._quantum_connections = []
3737
if backend is None:
38-
self._backend = CQCBackend()
38+
self._backend = EQSNBackend()
3939
else:
4040
self._backend = backend
4141
# add this host to the backend
@@ -359,6 +359,19 @@ def get_sequence_number(self, host):
359359

360360
return self._seq_number_sender[host]
361361

362+
def get_sequence_number_receiver(self, host):
363+
364+
'''
365+
366+
:param host:
367+
:return:
368+
'''
369+
370+
if host not in self._seq_number_receiver:
371+
return 0
372+
373+
return self._seq_number_receiver[host][1]
374+
362375
def _get_message_w_seq_num(self, sender_id, seq_num, wait=-1):
363376
"""
364377
Get a message from a sender with a specific sequence number.
@@ -476,8 +489,7 @@ def check_task(q, _sender, _seq_num, timeout, start_time):
476489
expected_seq += 1
477490
elif seq_num > expected_seq:
478491
self._seq_number_sender_ack[sender][0].append(seq_num)
479-
else:
480-
raise Exception("Should never happen!")
492+
481493
for t in self._ack_receiver_queue:
482494
res = check_task(*t)
483495
if res is True:
@@ -1118,7 +1130,7 @@ def add_checksum(self, qubits, size_per_qubit=2):
11181130
i = 0
11191131
check_qubits = []
11201132
while i < len(qubits):
1121-
check = Qubit(self.host_id)
1133+
check = Qubit(self)
11221134
j = 0
11231135
while j < size_per_qubit:
11241136
qubits[i + j].cnot(check)

build/lib/components/network.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
from objects.packet import Packet
1515
from objects.routing_packet import RoutingPacket
16-
from backends.cqc_backend import CQCBackend
16+
from backends.eqsn_backend import EQSNBackend
1717

1818

1919
# Network singleton
@@ -614,17 +614,16 @@ def stop(self, stop_hosts=False):
614614
self._stop_thread = True
615615
if self._backend is not None:
616616
self._backend.stop()
617-
except Exception:
618-
Logger.get_instance().error("Network stopped with errors")
617+
except Exception as e:
618+
Logger.get_instance().error(e)
619619

620620
def start(self, nodes=None, backend=None):
621621
"""
622622
Starts the network.
623623
624624
"""
625625
if backend is None:
626-
self._backend = CQCBackend()
627-
self.use_ent_swap = True
626+
self._backend = EQSNBackend()
628627
else:
629628
self._backend = backend
630629
if nodes is not None:

build/lib/objects/logger.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
logging.basicConfig(format=FORMAT)
55

66

7-
class Logger:
7+
class Logger():
88
__instance = None
99
DISABLED = True
1010

39.5 KB
Binary file not shown.

dist/qunetsim-0.0.10.tar.gz

30.3 KB
Binary file not shown.
-39.5 KB
Binary file not shown.

dist/qunetsim-0.0.9.tar.gz

-30.4 KB
Binary file not shown.

examples/CHSH/chsh.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,24 +113,21 @@ def referee(ref, alice_id, bob_id):
113113
def main():
114114
network = Network.get_instance()
115115

116-
backend = ProjectQBackend()
117-
# backend = EQSNBackend()
118-
119116
nodes = ['A', 'B', 'C']
120117
network.delay = 0.1
121-
network.start(nodes, backend)
118+
network.start(nodes)
122119

123-
host_A = Host('A', backend)
120+
host_A = Host('A')
124121
host_A.add_c_connection('C')
125122
host_A.delay = 0
126123
host_A.start()
127124

128-
host_B = Host('B', backend)
125+
host_B = Host('B')
129126
host_B.add_c_connection('C')
130127
host_B.delay = 0
131128
host_B.start()
132129

133-
host_C = Host('C', backend)
130+
host_C = Host('C')
134131
host_C.add_c_connections(['A', 'B'])
135132
host_C.delay = 0
136133
host_C.start()

examples/send_GHZ/send_ghz.py

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,34 @@
11
from components.host import Host
22
from components.network import Network
33
from objects.logger import Logger
4-
from backends.projectq_backend import ProjectQBackend
54

6-
Logger.DISABLED = False
5+
Logger.DISABLED = True
76

87

98
def main():
109
network = Network.get_instance()
1110
nodes = ["Alice", "Bob", "Eve", "Dean"]
12-
back = ProjectQBackend()
13-
network.start(nodes, back)
11+
network.start(nodes)
1412

1513
network.delay = 0.1
1614

17-
host_alice = Host('Alice', back)
15+
host_alice = Host('Alice')
1816
host_alice.add_connection('Bob')
1917
host_alice.add_connection('Eve')
2018
host_alice.start()
2119

22-
host_bob = Host('Bob', back)
20+
host_bob = Host('Bob')
2321
host_bob.add_connection('Alice')
2422
host_bob.add_connection('Eve')
2523
host_bob.start()
2624

27-
host_eve = Host('Eve', back)
25+
host_eve = Host('Eve')
2826
host_eve.add_connection('Bob')
2927
host_eve.add_connection('Dean')
3028
host_eve.add_connection('Alice')
3129
host_eve.start()
3230

33-
host_dean = Host('Dean', back)
31+
host_dean = Host('Dean')
3432
host_dean.add_connection('Eve')
3533
host_dean.start()
3634

@@ -40,30 +38,31 @@ def main():
4038
network.add_host(host_dean)
4139

4240
share_list = ["Bob", "Eve", "Dean"]
43-
q_id1, ack_received = host_alice.send_ghz(share_list, await_ack=True)
44-
45-
print("Alice received ACK from all? " + str(ack_received))
46-
47-
q1 = host_alice.get_ghz('Alice', q_id1, wait=10)
48-
q2 = host_bob.get_ghz('Alice', q_id1, wait=10)
49-
q3 = host_eve.get_ghz('Alice', q_id1, wait=10)
50-
q4 = host_dean.get_ghz('Alice', q_id1, wait=10)
51-
52-
if q1 is None:
53-
raise ValueError("Q1 is none")
54-
if q2 is None:
55-
raise ValueError("Q2 is none")
56-
if q3 is None:
57-
raise ValueError("Q3 is none")
58-
if q4 is None:
59-
raise ValueError("Q4 is none")
60-
61-
m1 = q1.measure()
62-
m2 = q2.measure()
63-
m3 = q3.measure()
64-
m4 = q4.measure()
65-
66-
print("results of measurements are %d, %d, %d, and %d." % (m1, m2, m3, m4))
41+
for _ in range(10):
42+
q_id1, ack_received = host_alice.send_ghz(share_list, await_ack=True)
43+
44+
print("Alice received ACK from all? " + str(ack_received))
45+
46+
q1 = host_alice.get_ghz('Alice', q_id1, wait=10)
47+
q2 = host_bob.get_ghz('Alice', q_id1, wait=10)
48+
q3 = host_eve.get_ghz('Alice', q_id1, wait=10)
49+
q4 = host_dean.get_ghz('Alice', q_id1, wait=10)
50+
51+
if q1 is None:
52+
raise ValueError("Q1 is none")
53+
if q2 is None:
54+
raise ValueError("Q2 is none")
55+
if q3 is None:
56+
raise ValueError("Q3 is none")
57+
if q4 is None:
58+
raise ValueError("Q4 is none")
59+
60+
m1 = q1.measure()
61+
m2 = q2.measure()
62+
m3 = q3.measure()
63+
m4 = q4.measure()
64+
65+
print("results of measurements are %d, %d, %d, and %d." % (m1, m2, m3, m4))
6766

6867
network.stop(True)
6968
exit()

0 commit comments

Comments
 (0)