def main(): network = Network.get_instance() # backend = ProjectQBackend() backend = CQCBackend() nodes = ['A', 'B', 'C'] network.start(nodes, backend) network.delay = 0.1 host_A = Host('A', backend) host_A.add_connection('B') host_A.delay = 0 host_A.start() host_B = Host('B', backend) host_B.add_connections(['A', 'C']) host_B.delay = 0 host_B.start() host_C = Host('C', backend) host_C.add_connection('B') host_C.delay = 0 host_C.start() network.add_host(host_A) network.add_host(host_B) network.add_host(host_C) t1 = host_A.run_protocol(protocol_1, (host_C.host_id, )) t2 = host_C.run_protocol(protocol_2, (host_A.host_id, )) t1.join() t2.join() network.stop(True)
def main(): network = Network.get_instance() nodes = ["Alice", "Bob", "Eve", "Dean"] backend = CQCBackend() network.start(nodes, backend) network.delay = 0.7 hosts = {'alice': Host('Alice', backend), 'bob': Host('Bob', backend)} network.delay = 0 # A <-> B hosts['alice'].add_connection('Bob') hosts['bob'].add_connection('Alice') hosts['alice'].start() hosts['bob'].start() for h in hosts.values(): network.add_host(h) q1 = Qubit(hosts['alice']) hosts['alice'].send_qubit('Bob', q1, await_ack=True) q1 = Qubit(hosts['alice']) hosts['alice'].send_qubit('Bob', q1, await_ack=True) q1 = Qubit(hosts['alice']) hosts['alice'].send_qubit('Bob', q1, await_ack=True) q1 = Qubit(hosts['bob']) hosts['bob'].send_qubit('Alice', q1, await_ack=True) network.stop(True) exit()
def main(): backend = CQCBackend() network = Network.get_instance() nodes = ["Alice", "Bob", "Eve", "Dean"] network.start(nodes, backend) network.delay = 0.7 hosts = {'alice': Host('Alice', backend), 'bob': Host('Bob', backend)} # A <-> B hosts['alice'].add_connection('Bob') hosts['bob'].add_connection('Alice') hosts['alice'].start() hosts['bob'].start() for h in hosts.values(): network.add_host(h) q = Qubit(hosts['alice']) q.X() q_id = hosts['alice'].send_qubit(hosts['bob'].host_id, q) i = 0 rec_q = hosts['bob'].get_data_qubit(hosts['alice'].host_id, q_id) while i < 5 and rec_q is None: rec_q = hosts['bob'].get_data_qubit(hosts['alice'].host_id, q_id) i += 1 time.sleep(1) assert rec_q is not None assert rec_q.measure() == 1 print("All tests succesfull!") network.stop(True) exit()
def main(): backend = CQCBackend() network = Network.get_instance() nodes = ["Alice", "Bob", "Eve", "Dean"] network.start(nodes, backend) network.delay = 0.7 hosts = {'alice': Host('Alice', backend), 'bob': Host('Bob', backend)} # A <-> B hosts['alice'].add_connection('Bob') hosts['bob'].add_connection('Alice') hosts['alice'].start() hosts['bob'].start() for h in hosts.values(): network.add_host(h) hosts['alice'].send_superdense(hosts['bob'].host_id, '01') messages = hosts['bob'].classical i = 0 while i < 5 and len(messages) == 0: messages = hosts['bob'].classical i += 1 time.sleep(1) assert messages is not None assert len(messages) > 0 assert (messages[0].sender == hosts['alice'].host_id) assert (messages[0].content == '01') print("All tests succesfull!") network.stop(True) exit()
def test_ghz_ten_hops_cqc(benchmark): backend = CQCBackend() nodes = 2 network, hosts = setup_network(nodes, backend) ms = benchmark.pedantic(ghz, args=(hosts[0], hosts[1:]), rounds=1) for m in ms: assert (sum(m) == nodes - 1 or sum(m) == 0) network.stop(True)
def main(): backend = CQCBackend() network = Network.get_instance() nodes = ["Alice", "Bob", "Eve", "Dean"] network.start(nodes, backend) hosts = {'alice': Host('Alice', backend), 'bob': Host('Bob', backend)} network.delay = 0.1 # A <-> B hosts['alice'].add_connection('Bob') hosts['bob'].add_connection('Alice') hosts['alice'].storage_epr_limit = 1 hosts['bob'].storage_epr_limit = 1 hosts['alice'].start() hosts['bob'].start() for h in hosts.values(): network.add_host(h) hosts['alice'].max_ack_wait = 10 hosts['alice'].send_epr(hosts['bob'].host_id, await_ack=True) hosts['alice'].send_epr(hosts['bob'].host_id, await_ack=True) assert hosts['alice'].shares_epr(hosts['bob'].host_id) assert len(hosts['alice'].get_epr_pairs(hosts['bob'].host_id)) == 1 assert hosts['bob'].shares_epr(hosts['alice'].host_id) assert len(hosts['bob'].get_epr_pairs(hosts['alice'].host_id)) == 1 hosts['alice'].set_epr_memory_limit(2, hosts['bob'].host_id) hosts['bob'].set_epr_memory_limit(2) hosts['alice'].send_epr(hosts['bob'].host_id, await_ack=True) hosts['alice'].send_epr(hosts['bob'].host_id, await_ack=True) alice_pairs = hosts['alice'].get_epr_pairs(hosts['bob'].host_id) bob_pairs = hosts['bob'].get_epr_pairs(hosts['alice'].host_id) assert len(alice_pairs) == 2 assert len(bob_pairs) == 2 for q in alice_pairs: q.measure() for q in bob_pairs: q.measure() print("All tests succesfull!") network.stop(True) exit()
def main(): backend = CQCBackend() network = Network.get_instance() nodes = ["Alice", "Bob", "Eve", "Dean"] network.start(nodes, backend) network.delay = 0.7 hosts = {'alice': Host('Alice', backend), 'bob': Host('Bob', backend)} network.delay = 0 # A <-> B hosts['alice'].add_connection('Bob') hosts['bob'].add_connection('Alice') hosts['alice'].start() hosts['bob'].start() for h in hosts.values(): network.add_host(h) hosts['alice'].send_classical(hosts['bob'].host_id, 'Hello Bob', False) hosts['bob'].send_classical(hosts['alice'].host_id, 'Hello Alice', False) i = 0 bob_messages = hosts['bob'].classical while i < 5 and len(bob_messages) == 0: bob_messages = hosts['bob'].classical i += 1 time.sleep(1) i = 0 alice_messages = hosts['alice'].classical while i < 5 and len(alice_messages) == 0: alice_messages = hosts['alice'].classical i += 1 time.sleep(1) assert len(alice_messages) > 0 assert alice_messages[0].sender == hosts['bob'].host_id assert alice_messages[0].content == 'Hello Alice' assert (len(bob_messages) > 0) assert (bob_messages[0].sender == hosts['alice'].host_id) assert (bob_messages[0].content == 'Hello Bob') print("All tests succesfull!") network.stop(True) exit()
def main(): print("Skip test, this test has to be updated!") return backend = CQCBackend() network = Network.get_instance() nodes = ["Alice", "Bob", "Eve", "Dean"] network.start(nodes, backend) network.delay = 0.7 hosts = {'alice': Host('Alice', backend), 'bob': Host('Bob', backend)} network.delay = 0 # A <-> B hosts['alice'].add_connection('Bob') hosts['bob'].add_connection('Alice') hosts['alice'].start() hosts['bob'].start() for h in hosts.values(): network.add_host(h) # 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'].classical # print([m.seq_num for m in messages]) for m in messages: if m.content == Constants.ACK and m.seq_num == 0: saw_ack_1 = True if m.content == Constants.ACK and m.seq_num == 1: saw_ack_2 = True if saw_ack_1 and saw_ack_2: break assert saw_ack_1 assert saw_ack_2 print("All tests succesfull!") network.stop(True) exit()
def main(): backend = CQCBackend() network = Network.get_instance() nodes = ["Alice", "Bob", "Eve", "Dean"] network.start(nodes, backend) network.delay = 0.7 hosts = {'alice': Host('Alice', backend), 'bob': Host('Bob', backend)} # A <-> B hosts['alice'].add_connection('Bob') hosts['bob'].add_connection('Alice') hosts['alice'].start() hosts['bob'].start() for h in hosts.values(): network.add_host(h) q_id = hosts['alice'].send_epr(hosts['bob'].host_id) q1 = hosts['alice'].shares_epr(hosts['bob'].host_id) i = 0 while not q1 and i < MAX_WAIT: q1 = hosts['alice'].shares_epr(hosts['bob'].host_id) i += 1 time.sleep(1) i = 0 q2 = hosts['bob'].shares_epr(hosts['alice'].host_id) while not q2 and i < 5: q2 = hosts['bob'].shares_epr(hosts['alice'].host_id) i += 1 time.sleep(1) assert hosts['alice'].shares_epr(hosts['bob'].host_id) assert hosts['bob'].shares_epr(hosts['alice'].host_id) q_alice = hosts['alice'].get_epr(hosts['bob'].host_id, q_id) q_bob = hosts['bob'].get_epr(hosts['alice'].host_id, q_id) assert q_alice is not None assert q_bob is not None assert q_alice.measure() == q_bob.measure() assert not hosts['alice'].shares_epr(hosts['bob'].host_id) assert not hosts['bob'].shares_epr(hosts['alice'].host_id) print("All tests succesfull!") network.stop(True) exit()
def main(): print("Test maximum data qubit has been skipped.") return backend = CQCBackend() network = Network.get_instance() nodes = ["Alice", "Bob", "Eve", "Dean"] network.start(nodes, backend) network.delay = 0.7 hosts = {'alice': Host('Alice', backend), 'bob': Host('Bob', backend)} network.delay = 0 # A <-> B hosts['alice'].add_connection('Bob') hosts['bob'].add_connection('Alice') hosts['alice'].memory_limit = 1 hosts['bob'].memory_limit = 1 hosts['alice'].start() hosts['bob'].start() for h in hosts.values(): network.add_host(h) q_alice_id_1 = hosts['alice'].send_qubit(hosts['bob'].host_id, Qubit(hosts['alice'])) time.sleep(2) q_alice_id_2 = hosts['alice'].send_qubit(hosts['bob'].host_id, Qubit(hosts['alice'])) time.sleep(2) q_bob_id_1 = hosts['bob'].send_qubit(hosts['alice'].host_id, Qubit(hosts['bob'])) time.sleep(2) q_bob_id_2 = hosts['bob'].send_qubit(hosts['alice'].host_id, Qubit(hosts['bob'])) time.sleep(2) # Allow the network to process the requests # TODO: remove the need for this time.sleep(2) i = 0 while len(hosts['alice'].get_data_qubits( hosts['bob'].host_id)) < 1 and i < 5: time.sleep(1) i += 1 i = 0 while len(hosts['bob'].get_data_qubits( hosts['alice'].host_id)) < 1 and i < 5: time.sleep(1) i += 1 assert len(hosts['alice'].get_data_qubits(hosts['bob'].host_id)) == 1 assert hosts['alice'].get_data_qubit(hosts['bob'].host_id, q_bob_id_1).measure() == 0 assert hosts['alice'].get_data_qubit(hosts['bob'].host_id, q_bob_id_2) == None assert len(hosts['bob'].get_data_qubits(hosts['alice'].host_id)) == 1 assert hosts['bob'].get_data_qubit(hosts['alice'].host_id, q_alice_id_1).measure() == 0 assert hosts['bob'].get_data_qubit(hosts['alice'].host_id, q_alice_id_2) == None hosts['alice'].set_data_qubit_memory_limit(2, hosts['bob'].host_id) hosts['bob'].set_data_qubit_memory_limit(2) q_alice_id_1 = hosts['alice'].send_qubit(hosts['bob'].host_id, Qubit(hosts['alice'])) time.sleep(2) q_alice_id_2 = hosts['alice'].send_qubit(hosts['bob'].host_id, Qubit(hosts['alice'])) time.sleep(2) q_alice_id_3 = hosts['alice'].send_qubit(hosts['bob'].host_id, Qubit(hosts['alice'])) time.sleep(2) q_bob_id_1 = hosts['bob'].send_qubit(hosts['alice'].host_id, Qubit(hosts['bob'])) time.sleep(2) q_bob_id_2 = hosts['bob'].send_qubit(hosts['alice'].host_id, Qubit(hosts['bob'])) time.sleep(2) q_bob_id_3 = hosts['bob'].send_qubit(hosts['alice'].host_id, Qubit(hosts['bob'])) time.sleep(2) # Allow the network to process the requests time.sleep(3) i = 0 while len(hosts['alice'].get_data_qubits( hosts['bob'].host_id)) < 2 and i < 5: time.sleep(1) i += 1 i = 0 while len(hosts['bob'].get_data_qubits( hosts['alice'].host_id)) < 2 and i < 5: time.sleep(1) i += 1 assert len(hosts['alice'].get_data_qubits(hosts['bob'].host_id)) == 2 assert hosts['alice'].get_data_qubit(hosts['bob'].host_id, q_bob_id_1).measure() == 0 assert hosts['alice'].get_data_qubit(hosts['bob'].host_id, q_bob_id_2).measure() == 0 assert hosts['alice'].get_data_qubit(hosts['bob'].host_id, q_bob_id_3) == None assert len(hosts['bob'].get_data_qubits(hosts['alice'].host_id)) == 2 assert hosts['bob'].get_data_qubit(hosts['alice'].host_id, q_alice_id_1).measure() == 0 assert hosts['bob'].get_data_qubit(hosts['alice'].host_id, q_alice_id_2).measure() == 0 assert hosts['bob'].get_data_qubit(hosts['alice'].host_id, q_alice_id_3) == None print("All tests succesfull!") network.stop(True) exit()
def main(): global thread_1_return global thread_2_return network = Network.get_instance() nodes = ["Alice", "Bob", "Eve", "Dean"] back = CQCBackend() network.start(nodes, back) network.delay = 0.0 host_alice = Host('Alice', back) host_alice.add_connection('Bob') host_alice.max_ack_wait = 30 host_alice.delay = 0.0 host_alice.start() host_bob = Host('Bob', back) host_bob.max_ack_wait = 30 host_bob.delay = 0.0 host_bob.add_connection('Alice') host_bob.add_connection('Eve') host_bob.start() host_eve = Host('Eve', back) host_eve.max_ack_wait = 30 host_eve.delay = 0.0 host_eve.add_connection('Bob') host_eve.add_connection('Dean') host_eve.start() host_dean = Host('Dean', back) host_dean.max_ack_wait = 30 host_dean.delay = 0.0 host_dean.add_connection('Eve') host_dean.start() network.add_host(host_alice) network.add_host(host_bob) network.add_host(host_eve) network.add_host(host_dean) network.x_error_rate = 0 network.packet_drop_rate = 0 q_size = 6 checksum_per_qubit = 2 host_alice.run_protocol(qtcp_sender, (q_size, host_dean.host_id, checksum_per_qubit)) host_dean.run_protocol(qtcp_receiver, (q_size, host_alice.host_id, checksum_per_qubit)) while thread_1_return is None or thread_2_return is None: if thread_1_return is False or thread_2_return is False: print('TCP Connection not successful : EXITING') sys.exit(1) pass start_time = time.time() while time.time() - start_time < 150: pass network.stop(stop_hosts=True) exit()
def test_tele_ten_hops_cqc(benchmark): backend = CQCBackend() network, hosts = setup_network(11, backend) benchmark.pedantic(teleport, args=(hosts[0], hosts[-1]), rounds=30) network.stop(True)
def test_super_ten_hops_cqc(benchmark): backend = CQCBackend() network, hosts = setup_network(3, backend) benchmark.pedantic(superdense, args=(hosts[0], hosts[-1]), rounds=1) network.stop(True)