Skip to content

Commit

Permalink
Merge pull request #48 from tqsd/seq-num-for-get-classical
Browse files Browse the repository at this point in the history
Seq num for get classical
  • Loading branch information
stephendiadamo authored Jun 24, 2020
2 parents c528ce0 + 4a1f645 commit 7ffed57
Show file tree
Hide file tree
Showing 12 changed files with 320 additions and 233 deletions.
Binary file modified docs/_build/.doctrees/components/host.doctree
Binary file not shown.
Binary file modified docs/_build/.doctrees/components/network.doctree
Binary file not shown.
Binary file modified docs/_build/.doctrees/environment.pickle
Binary file not shown.
160 changes: 116 additions & 44 deletions docs/_build/components/host.html

Large diffs are not rendered by default.

5 changes: 1 addition & 4 deletions docs/_build/components/network.html
Original file line number Diff line number Diff line change
Expand Up @@ -506,10 +506,7 @@ <h1>Network<a class="headerlink" href="#network" title="Permalink to this headli
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>whether the sender and receiver share an EPR pair.</p>
</dd>
<dt class="field-odd">Return type</dt>
<dd class="field-odd"><p>boolean</p>
<dd class="field-even"><p>(bool) whether the sender and receiver share an EPR pair.</p>
</dd>
</dl>
</dd></dl>
Expand Down
8 changes: 8 additions & 0 deletions docs/_build/genindex.html
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,10 @@ <h2 id="P">P</h2>
<h2 id="Q">Q</h2>
<table style="width: 100%" class="indextable genindextable"><tr>
<td style="width: 33%; vertical-align: top;"><ul>
<li><a href="components/host.html#qunetsim.components.host.Host.q_relay_sniffing">q_relay_sniffing() (qunetsim.components.host.Host property)</a>
</li>
<li><a href="components/host.html#qunetsim.components.host.Host.q_relay_sniffing_fn">q_relay_sniffing_fn() (qunetsim.components.host.Host property)</a>
</li>
<li><a href="components/host.html#qunetsim.components.host.Host.quantum_connections">quantum_connections() (qunetsim.components.host.Host property)</a>
</li>
<li><a href="components/host.html#qunetsim.components.host.Host.quantum_relay_sniffing_function">quantum_relay_sniffing_function() (qunetsim.components.host.Host method)</a>
Expand Down Expand Up @@ -602,6 +606,8 @@ <h2 id="R">R</h2>
<li><a href="objects/routing_packet.html#qunetsim.objects.routing_packet.RoutingPacket.receiver">(qunetsim.objects.routing_packet.RoutingPacket property)</a>
</li>
</ul></li>
<li><a href="components/host.html#qunetsim.components.host.Host.relay_sniffing_function">relay_sniffing_function() (qunetsim.components.host.Host method)</a>
</li>
<li><a href="objects/qubit.html#qunetsim.objects.qubit.Qubit.release">release() (qunetsim.objects.qubit.Qubit method)</a>
</li>
<li><a href="objects/quantum_storage.html#qunetsim.objects.quantum_storage.QuantumStorage.release_storage">release_storage() (qunetsim.objects.quantum_storage.QuantumStorage method)</a>
Expand All @@ -617,6 +623,8 @@ <h2 id="R">R</h2>
<li><a href="components/network.html#qunetsim.components.network.Network.remove_host">remove_host() (qunetsim.components.network.Network method)</a>
</li>
<li><a href="components/host.html#qunetsim.components.host.Host.remove_q_connection">remove_q_connection() (qunetsim.components.host.Host method)</a>
</li>
<li><a href="components/host.html#qunetsim.components.host.Host.reset_sequence_numbers">reset_sequence_numbers() (qunetsim.components.host.Host method)</a>
</li>
<li><a href="objects/quantum_storage.html#qunetsim.objects.quantum_storage.QuantumStorage.reset_storage">reset_storage() (qunetsim.objects.quantum_storage.QuantumStorage method)</a>
</li>
Expand Down
Binary file modified docs/_build/objects.inv
Binary file not shown.
2 changes: 1 addition & 1 deletion docs/_build/searchindex.js

Large diffs are not rendered by default.

37 changes: 34 additions & 3 deletions integration_tests/test_multi_hop.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,14 @@ def setUp(self):
hosts['bob'].set_data_qubit_memory_limit(-1)
hosts['eve'].set_data_qubit_memory_limit(-1)

def tearDown(self):
hosts['alice'].max_ack_wait = -1
hosts['bob'].max_ack_wait = -1
hosts['eve'].max_ack_wait = -1
hosts['alice'].empty_classical()
hosts['bob'].empty_classical()
hosts['eve'].empty_classical()

def tearDown(self):
pass

# @unittest.skip('')
def test_send_classical(self):
hosts['alice'].send_classical(hosts['eve'].host_id, 'testing123')
Expand All @@ -85,6 +86,36 @@ def test_send_classical(self):
self.assertEqual(messages[0].sender, hosts['alice'].host_id)
self.assertEqual(messages[0].content, 'testing123')

# @unittest.skip('')
def test_send_classical_w_seq_number(self):
hosts['alice'].reset_sequence_numbers()
hosts['bob'].reset_sequence_numbers()
hosts['eve'].reset_sequence_numbers()

hosts['alice'].send_classical(hosts['eve'].host_id, 'M0', await_ack=True)
hosts['alice'].send_classical(hosts['eve'].host_id, 'M1', await_ack=True)
hosts['alice'].send_classical(hosts['eve'].host_id, 'M2', await_ack=True)

eve_messages = hosts['eve'].classical
self.assertTrue(len(eve_messages) == 3)
for i in eve_messages:
print(i)

m0 = hosts['eve'].get_classical(hosts['alice'].host_id, seq_num=0)
m1 = hosts['eve'].get_classical(hosts['alice'].host_id, seq_num=1)
m2 = hosts['eve'].get_classical(hosts['alice'].host_id, seq_num=2)

self.assertTrue(m0.seq_num == 0)
self.assertTrue(m1.seq_num == 1)
self.assertTrue(m2.seq_num == 2)

self.assertTrue(m0.content == 'M0')
self.assertTrue(m1.content == 'M1')
self.assertTrue(m2.content == 'M2')

hosts['eve'].empty_classical()
self.assertTrue(len(hosts['eve'].classical) == 0)

# @unittest.skip('')
def test_full_network_routing(self):
network.use_hop_by_hop = False
Expand Down
142 changes: 33 additions & 109 deletions integration_tests/test_single_hop.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,13 @@ def setUp(self):
hosts['alice'].set_data_qubit_memory_limit(-1)
hosts['bob'].set_data_qubit_memory_limit(-1)

def tearDown(self):
global hosts
hosts['alice'].max_ack_wait = -1
hosts['bob'].max_ack_wait = -1
hosts['alice'].empty_classical()
hosts['bob'].empty_classical()

def tearDown(self):
pass

# @unittest.skip('')
def test_shares_epr(self):
q_id = hosts['alice'].send_epr(hosts['bob'].host_id)
Expand Down Expand Up @@ -87,10 +88,8 @@ def test_shares_epr(self):

# @unittest.skip('')
def test_send_classical(self):
hosts['alice'].send_classical(
hosts['bob'].host_id, 'Hello Bob', await_ack=False)
hosts['bob'].send_classical(
hosts['alice'].host_id, 'Hello Alice', await_ack=False)
hosts['alice'].send_classical(hosts['bob'].host_id, 'Hello Bob', await_ack=False)
hosts['bob'].send_classical(hosts['alice'].host_id, 'Hello Alice', await_ack=False)
i = 0
bob_messages = hosts['bob'].classical

Expand All @@ -114,73 +113,32 @@ def test_send_classical(self):
self.assertEqual(bob_messages[0].sender, hosts['alice'].host_id)
self.assertEqual(bob_messages[0].content, 'Hello Bob')

@unittest.skip('')
def test_await_ack(self):
global hosts

# print(f"ack test - SEND CLASSICAL - started at {time.strftime('%X')}")
hosts['alice'].send_classical(
hosts['bob'].host_id, 'hello bob one', await_ack=True)
hosts['alice'].send_classical(
hosts['bob'].host_id, 'hello bob two', await_ack=True)
# print(f"ack test - SEND CLASSICAL - finished at {time.strftime('%X')}")

saw_ack_1 = False
saw_ack_2 = False
messages = hosts['alice'].get_classical('bob')
print(messages)
for m in messages:
if m.content == Constants.ACK and m.seq_num == 1:
saw_ack_1 = True
if m.content == Constants.ACK and m.seq_num == 2:
saw_ack_2 = True
if saw_ack_1 and saw_ack_2:
break

self.assertTrue(saw_ack_1)
self.assertTrue(saw_ack_2)

# print(f"ack test - SEND SUPERDENSE - started at {time.strftime('%X')}")
hosts['alice'].send_superdense(
hosts['bob'].host_id, '00', await_ack=True)
# print(f"ack test - SEND SUPERDENSE - finished at {time.strftime('%X')}")

saw_ack = False
messages = hosts['alice'].get_classical('bob')
for m in messages:
if m.content == Constants.ACK and m.seq_num == 3:
saw_ack = True
break

self.assertTrue(saw_ack)

q = Qubit(hosts['alice'])
# @unittest.skip('')
def test_send_classical_w_seq_number(self):
hosts['alice'].reset_sequence_numbers()
hosts['bob'].reset_sequence_numbers()

# print(f"ack test - SEND TELEPORT - started at {time.strftime('%X')}")
hosts['alice'].send_teleport(hosts['bob'].host_id, q, await_ack=True)
# print(f"ack test - SEND TELEPORT - finished at {time.strftime('%X')}")
hosts['alice'].send_classical(hosts['bob'].host_id, 'M0', await_ack=True)
hosts['alice'].send_classical(hosts['bob'].host_id, 'M1', await_ack=True)
hosts['alice'].send_classical(hosts['bob'].host_id, 'M2', await_ack=True)

saw_ack = False
messages = hosts['alice'].get_classical('bob')
for m in messages:
if m.content == Constants.ACK and m.seq_num == 4:
saw_ack = True
break
bob_messages = hosts['bob'].classical
self.assertTrue(len(bob_messages) == 3)

self.assertTrue(saw_ack)
m0 = hosts['bob'].get_classical(hosts['alice'].host_id, seq_num=0)
m1 = hosts['bob'].get_classical(hosts['alice'].host_id, seq_num=1)
m2 = hosts['bob'].get_classical(hosts['alice'].host_id, seq_num=2)

# print(f"ack test - SEND EPR - started at {time.strftime('%X')}")
hosts['alice'].send_epr(hosts['bob'].host_id, await_ack=True)
# print(f"ack test - SEND EPR - finished at {time.strftime('%X')}")
self.assertTrue(m0.seq_num == 0)
self.assertTrue(m1.seq_num == 1)
self.assertTrue(m2.seq_num == 2)

saw_ack = False
messages = hosts['alice'].get_classical('bob')
for m in messages:
if m['message'] == Constants.ACK and m['sequence_number'] == 5:
saw_ack = True
break
self.assertTrue(m0.content == 'M0')
self.assertTrue(m1.content == 'M1')
self.assertTrue(m2.content == 'M2')

self.assertTrue(saw_ack)
hosts['bob'].empty_classical()
self.assertTrue(len(hosts['bob'].classical) == 0)

# @unittest.skip('')
def test_max_wait_for_ack(self):
Expand Down Expand Up @@ -214,6 +172,8 @@ def test_epr(self):
time.sleep(1)

self.assertIsNotNone(q2)
assert q1 is not None
assert q2 is not None
self.assertEqual(q1.measure(), q2.measure())

# @unittest.skip('')
Expand All @@ -228,7 +188,7 @@ def test_ghz(self):
self.assertIsNotNone(q_bob)
self.assertEqual(q_alice.measure(), q_bob.measure())

@unittest.skip('')
# @unittest.skip('')
def test_teleport(self):
global hosts

Expand All @@ -245,6 +205,7 @@ def test_teleport(self):
time.sleep(1)

self.assertIsNotNone(q2)
assert q2 is not None
self.assertEqual(q2.measure(), 1)

# @unittest.skip('')
Expand Down Expand Up @@ -331,6 +292,7 @@ def test_teleport_superdense_combination(self):
self.assertEqual(messages[0].content, '11')

self.assertIsNotNone(q2)
assert q2 is not None
self.assertEqual(q2.measure(), 1)

@unittest.skip('')
Expand Down Expand Up @@ -467,13 +429,13 @@ def test_maximum_data_qubit_limit(self):
def test_get_before_send(self):
global hosts

def alice_do(alice):
def alice_do(s):
q = Qubit(hosts['alice'])
q.X()
time.sleep(1)
_ = hosts['alice'].send_qubit(hosts['bob'].host_id, q)

def bob_do(bob):
def bob_do(s):
rec_q = hosts['bob'].get_data_qubit(
hosts['alice'].host_id, wait=-1)
self.assertIsNotNone(rec_q)
Expand All @@ -484,41 +446,3 @@ def bob_do(bob):

t1.join()
t2.join()

@unittest.skip('')
def test_packet_loss_classical(self):
global hosts
hosts = {'alice': Host('Alice'),
'bob': Host('Bob')}

self.network.packet_drop_rate = 0.75
self.network.delay = 0
self.hosts = hosts

hosts['alice'].add_connection('Bob')
hosts['bob'].add_connection('Alice')

hosts['alice'].start()
hosts['bob'].start()

for h in hosts.values():
self.network.add_host(h)

# ACKs for 1 hop take at most 2 seconds
hosts['alice'].max_ack_wait = 3
num_acks = 0
num_messages = 15
for _ in range(num_messages):
ack = hosts['alice'].send_classical(
hosts['bob'].host_id, 'Hello Bob', await_ack=True)
if ack:
num_acks += 1

num_messages_bob_received = len(hosts['bob'].classical)
self.assertTrue(num_acks != num_messages)
self.assertTrue(num_acks < num_messages)
self.assertTrue(num_messages_bob_received < num_messages)

# ACKs can also get dropped
self.assertTrue(num_messages_bob_received > num_acks)
self.assertTrue(float(num_acks) / num_messages < 0.9)
Loading

0 comments on commit 7ffed57

Please sign in to comment.