コード例 #1
0
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)
コード例 #2
0
def main():
    network = Network.get_instance()
    nodes = ["Alice", "Bob", "Eve"]
    network.start(nodes)
    network.delay = 0.1

    host_alice = Host('Alice')
    host_alice.add_connection('Bob')
    host_alice.start()

    host_bob = Host('Bob')
    host_bob.add_connections(['Alice', 'Eve'])
    host_bob.start()

    host_eve = Host('Eve')
    host_eve.add_connection('Bob')
    host_eve.start()

    network.add_hosts([host_alice, host_bob, host_eve])

    host_bob.q_relay_sniffing = True
    host_bob.q_relay_sniffing_fn = bob_sniffing_quantum

    host_bob.c_relay_sniffing = True
    host_bob.c_relay_sniffing_fn = bob_sniffing_classical

    t1 = host_alice.run_protocol(alice)
    t2 = host_eve.run_protocol(eve)

    t1.join()
    t2.join()

    network.stop(True)
    exit()
コード例 #3
0
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()
コード例 #4
0
ファイル: q_udp.py プロジェクト: witt-designs/QuNetSim
def main():
    network = Network.get_instance()

    nodes = ["Alice", "Bob"]
    network.x_error_rate = 0
    network.delay = 0.5
    network.start(nodes)

    host_alice = Host('Alice')
    host_alice.add_connection('Bob')
    host_alice.max_ack_wait = 10
    host_alice.delay = 0.2
    host_alice.start()

    host_bob = Host('Bob')
    host_bob.max_ack_wait = 10
    host_bob.delay = 0.2
    host_bob.add_connection('Alice')
    host_bob.start()

    network.add_host(host_alice)
    network.add_host(host_bob)

    q_size = 6

    host_alice.run_protocol(qudp_sender, (q_size, host_bob.host_id))
    host_bob.run_protocol(qudp_receiver, (q_size, host_alice.host_id))

    start_time = time.time()
    while time.time() - start_time < 50:
        pass

    network.stop(stop_hosts=True)
コード例 #5
0
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()
コード例 #6
0
def main():
    network = Network.get_instance()
    nodes = ['Alice', 'Bob', 'Eve']
    network.delay = 0.2
    network.start(nodes)

    host_alice = Host('Alice')
    host_bob = Host('Bob')
    host_eve = Host('Eve')

    host_alice.add_connection('Bob')
    host_bob.add_connection('Alice')
    host_bob.add_connection('Eve')
    host_eve.add_connection('Bob')

    host_alice.start()
    host_bob.start()
    host_eve.start()

    network.add_host(host_alice)
    network.add_host(host_bob)
    network.add_host(host_eve)

    q = Qubit(host_alice)
    q.X()

    host_alice.send_teleport('Eve', q, await_ack=True)
    q_eve = host_eve.get_data_qubit(host_alice.host_id, q.id, wait=5)

    assert q_eve is not None
    print('Eve measures: %d' % q_eve.measure())
コード例 #7
0
ファイル: test_single_hop.py プロジェクト: h-oll/QuNetSim
    def test_epr(self):

        hosts = {'alice': Host('Alice'),
                 'bob': Host('Bob')}

        self.hosts = hosts

        # A <-> B
        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)

        q_id = hosts['alice'].send_epr(hosts['bob'].host_id)
        q1 = hosts['alice'].get_epr(hosts['bob'].host_id, q_id)
        i = 0
        while q1 is None and i < TestOneHop.MAX_WAIT:
            q1 = hosts['alice'].get_epr(hosts['bob'].host_id, q_id)
            i += 1
            time.sleep(1)

        self.assertIsNotNone(q1)
        i = 0
        q2 = hosts['bob'].get_epr(hosts['alice'].host_id, q_id)
        while q2 is None and i < TestOneHop.MAX_WAIT:
            q2 = hosts['bob'].get_epr(hosts['alice'].host_id, q_id)
            i += 1
            time.sleep(1)

        self.assertIsNotNone(q2)
        self.assertEqual(q1.measure(), q2.measure())
コード例 #8
0
def main():
    backend = EQSNBackend()
    network = Network.get_instance()
    nodes = ["Alice", "Bob", "Eve", "Dean"]
    network.start(nodes, backend)
    network.delay = 0.0

    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)

    ack_received_1 = hosts['alice'].send_classical(hosts['bob'].host_id,
                                                   'hello bob one',
                                                   await_ack=True)
    hosts['alice'].max_ack_wait = 0.0
    ack_received_2 = hosts['alice'].send_classical(hosts['bob'].host_id,
                                                   'hello bob one',
                                                   await_ack=True)
    assert ack_received_1
    assert not ack_received_2
    print("All tests succesfull!")
    network.stop(True)
    exit()
コード例 #9
0
def main():
    network = Network.get_instance()
    network.delay = 0.1
    nodes = ["Alice", "Bob", "Eve"]
    network.start(nodes)

    host_alice = Host('Alice', )
    host_alice.add_connection('Bob')
    host_alice.start()

    host_bob = Host('Bob')
    host_bob.add_connection('Alice')
    host_bob.add_connection('Eve')
    host_bob.start()

    host_eve = Host('Eve')
    host_eve.add_connection('Bob')
    host_eve.start()

    network.add_host(host_alice)
    network.add_host(host_bob)
    network.add_host(host_eve)

    host_alice.send_superdense('Eve', '11')
    host_alice.send_superdense('Eve', '10')
    host_alice.send_superdense('Eve', '00')

    time.sleep(5)
    messages = host_eve.get_classical('Alice')

    for m in messages:
        print('----')
        print(m)
        print('----')
コード例 #10
0
def main():
    backend = CQCBackend()
    network = Network.get_instance()
    nodes = ["Alice", "Bob", "Eve", "Dean"]
    network.start(nodes, backend)
    network.delay = 0.0
    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()

    hosts['alice'].send_teleport(hosts['bob'].host_id, q)

    q2 = hosts['bob'].get_data_qubit(hosts['alice'].host_id)
    i = 0
    while q2 is None and i < 5:
        q2 = hosts['bob'].get_data_qubit(hosts['alice'].host_id)
        i += 1
        time.sleep(1)

    assert q2 is not None
    assert q2.measure() == 1
    print("All tests succesfull!")
    network.stop(True)
    exit()
コード例 #11
0
ファイル: test_single_hop.py プロジェクト: h-oll/QuNetSim
    def test_packet_loss_classical(self):

        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)
コード例 #12
0
ファイル: q_money.py プロジェクト: witt-designs/QuNetSim
def main():
    # Initialize a network
    network = Network.get_instance()

    nodes = ['Alice', 'Bob', 'Eve']
    network.delay = 0.0
    network.start(nodes)

    host_alice = Host('Alice')
    host_alice.add_connection('Bob')
    host_alice.start()

    host_bob = Host('Bob')
    host_bob.add_connection('Alice')
    host_bob.add_connection('Eve')
    host_bob.start()

    host_eve = Host('Eve')
    host_eve.add_connection('Bob')
    host_eve.start()

    network.add_host(host_alice)
    network.add_host(host_bob)
    network.add_host(host_eve)

    print('Starting transfer')
    t1 = host_alice.run_protocol(banker_protocol, (host_eve.host_id, ))
    t2 = host_eve.run_protocol(customer_protocol, (host_alice.host_id, ))

    t1.join()
    t2.join()

    network.stop(True)
コード例 #13
0
ファイル: test_single_hop.py プロジェクト: h-oll/QuNetSim
    def test_send_qubit_bob_to_alice(self):

        hosts = {'alice': Host('Alice'),
                 'bob': Host('Bob')}

        self.hosts = hosts

        # A <-> B
        hosts['bob'].add_connection('00000000')

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

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

        q = Qubit(hosts['bob'])
        q.X()

        q_id = hosts['bob'].send_qubit(hosts['alice'].host_id, q)

        i = 0
        rec_q = hosts['alice'].get_data_qubit(hosts['bob'].host_id, q_id)
        while i < TestOneHop.MAX_WAIT and rec_q is None:
            rec_q = hosts['alice'].get_data_qubit(hosts['bob'].host_id, q_id)
            i += 1
            time.sleep(1)

        self.assertIsNotNone(rec_q)
        self.assertEqual(rec_q.measure(), 1)
コード例 #14
0
ファイル: test_single_hop.py プロジェクト: h-oll/QuNetSim
    def test_superdense(self):

        hosts = {'alice': Host('Alice'),
                 'bob': Host('Bob')}
        self.hosts = hosts

        # A <-> B
        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)

        hosts['alice'].send_superdense(hosts['bob'].host_id, '01')

        messages = hosts['bob'].classical
        i = 0
        while i < TestOneHop.MAX_WAIT and len(messages) == 0:
            messages = hosts['bob'].classical
            i += 1
            time.sleep(1)

        self.assertIsNotNone(messages)
        self.assertTrue(len(messages) > 0)
        self.assertEqual(messages[0]['sender'], hosts['alice'].host_id)
        self.assertEqual(messages[0]['message'], '01')
コード例 #15
0
ファイル: test_single_hop.py プロジェクト: h-oll/QuNetSim
    def test_teleport(self):

        hosts = {'alice': Host('Alice'),
                 'bob': Host('Bob')}

        self.hosts = hosts

        # A <-> B
        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)

        q = Qubit(hosts['alice'])
        q.X()

        hosts['alice'].send_teleport(hosts['bob'].host_id, q)

        q2 = hosts['bob'].get_data_qubit(hosts['alice'].host_id)
        i = 0
        while q2 is None and i < TestOneHop.MAX_WAIT:
            q2 = hosts['bob'].get_data_qubit(hosts['alice'].host_id)
            i += 1
            time.sleep(1)

        self.assertIsNotNone(q2)
        self.assertEqual(q2.measure(), 1)
コード例 #16
0
ファイル: protocol_send_EPR.py プロジェクト: h-oll/QuNetSim
def main():
    network = Network.get_instance()
    nodes = ['A', 'B', 'C']
    network.start(nodes)
    network.delay = 0.1

    host_A = Host('A')
    host_A.add_connection('B')
    host_A.start()

    host_B = Host('B')
    host_B.add_connection('A')
    host_B.add_connection('C')
    host_B.start()

    host_C = Host('C')
    host_C.add_connection('B')
    host_C.start()

    network.add_host(host_A)
    network.add_host(host_B)
    network.add_host(host_C)

    host_A.run_protocol(protocol_1, (host_C.host_id,))
    host_C.run_protocol(protocol_2, (host_A.host_id,))
コード例 #17
0
def main():
    network = Network.get_instance()
    nodes = ["Alice", "Bob", "Eve", "Dean"]
    back = ProjectQBackend()
    network.start(nodes, back)

    network.delay = 0.1

    host_alice = Host('Alice', back)
    host_alice.add_connection('Bob')
    host_alice.add_connection('Eve')
    host_alice.start()

    host_bob = Host('Bob', back)
    host_bob.add_connection('Alice')
    host_bob.add_connection('Eve')
    host_bob.start()

    host_eve = Host('Eve', back)
    host_eve.add_connection('Bob')
    host_eve.add_connection('Dean')
    host_eve.add_connection('Alice')
    host_eve.start()

    host_dean = Host('Dean', back)
    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)

    share_list = ["Bob", "Eve", "Dean"]
    q_id1 = host_alice.send_ghz(share_list, no_ack=True)

    q1 = host_alice.get_ghz('Alice', q_id1, wait=10)
    q2 = host_bob.get_ghz('Alice', q_id1, wait=10)
    q3 = host_eve.get_ghz('Alice', q_id1, wait=10)
    q4 = host_dean.get_ghz('Alice', q_id1, wait=10)

    if q1 is None:
        raise ValueError("Q1 is none")
    if q2 is None:
        raise ValueError("Q2 is none")
    if q3 is None:
        raise ValueError("Q3 is none")
    if q4 is None:
        raise ValueError("Q4 is none")

    m1 = q1.measure()
    m2 = q2.measure()
    m3 = q3.measure()
    m4 = q4.measure()

    print("results of measurements are %d, %d, %d, and %d." % (m1, m2, m3, m4))

    network.stop(True)
    exit()
コード例 #18
0
def main():

    Y = 2
    M = 2

    network = Network.get_instance()
    nodes = ['Alice','C0','Bob']
    network.use_ent_swap = True
    network.start(nodes)
#0.01549
    alice = Host('Alice')
    alice.add_connection('C0', 100)
    alice.coherence_time = 1
    alice.max_ack_wait = 5
    alice.start()

    repeater0 = Host('C0')
    repeater0.add_connection('Alice', 100)
    repeater0.add_connection('Bob', 100)
    repeater0.coherence_time = 1
    repeater0.max_ack_wait = 5
    repeater0.start()

    # repeater1 = Host('C1')
    # repeater1.add_connection('C0')
    # repeater1.add_connection('C2')
    # repeater1.max_ack_wait = 5
    # repeater1.start()

    # repeater2 = Host('C2')
    # repeater2.add_connection('C1')
    # repeater2.add_connection('Bob')
    # repeater2.max_ack_wait = 5
    # repeater2.start()

    bob = Host('Bob')
    bob.add_connection('C0', 100)
    bob.coherence_time = 1
    bob.max_ack_wait = 5
    bob.start()

    network.add_host(alice)
    network.add_host(repeater0)
    #network.add_host(repeater1)
    #network.add_host(repeater2)
    network.add_host(bob)
    
    t1 = alice.run_protocol(AliceProtocol, (repeater0.host_id, Y, M))
    t2 = repeater0.run_protocol(RepeaterProtocol, (alice.host_id, bob.host_id, 0, 1, Y, M))
    #repeater1.run_protocol(RepeaterProtocol, (repeater0.host_id, repeater2.host_id, 1, 2, Y, M))
    #repeater2.run_protocol(RepeaterProtocol, (repeater1.host_id, bob.host_id, 2, 2, Y, M))
    t3 = bob.run_protocol(BobProtocol, (repeater0.host_id, Y, M))

    t1.join()
    t2.join()
    t3.join()

    network.stop(True)
コード例 #19
0
ファイル: qkd_eqsn.py プロジェクト: witt-designs/QuNetSim
def main():
    # Initialize a network
    network = Network.get_instance()
    backend = EQSNBackend()

    # Define the host IDs in the network
    nodes = ['Alice', 'Bob']

    network.delay = 0.0

    # Start the network with the defined hosts
    network.start(nodes, backend)

    # Initialize the host Alice
    host_alice = Host('Alice', backend)

    # Add a one-way connection (classical and quantum) to Bob
    host_alice.add_connection('Bob')
    host_alice.delay = 0.0

    # Start listening
    host_alice.start()

    host_bob = Host('Bob', backend)
    # Bob adds his own one-way connection to Alice
    host_bob.add_connection('Alice')
    host_bob.delay = 0.0
    host_bob.start()

    # Add the hosts to the network
    # The network is: Alice <--> Bob
    network.add_host(host_alice)
    network.add_host(host_bob)

    # Generate random key
    key_size = 20  # the size of the key in bit
    secret_key = np.random.randint(2, size=key_size)

    # Concatentate functions
    def alice_func(alice):
        msg_buff = []
        alice_qkd(alice, msg_buff, secret_key, host_bob.host_id)
        alice_send_message(alice, secret_key, host_bob.host_id)

    def bob_func(eve):
        msg_buff = []
        eve_key = eve_qkd(eve, msg_buff, key_size, host_alice.host_id)
        eve_receive_message(eve, msg_buff, eve_key, host_alice.host_id)

    # Run Bob and Alice

    host_alice.run_protocol(alice_func, ())
    host_bob.run_protocol(bob_func, (), blocking=True)

    time.sleep(1)
    network.stop(True)
コード例 #20
0
ファイル: checksum.py プロジェクト: witt-designs/QuNetSim
def main():
    network = Network.get_instance()
    nodes = ["Alice", "Bob", "Eve", "Dean"]
    network.start(nodes)
    network.delay = 0.5

    host_alice = Host('Alice')
    host_alice.add_connection('Bob')
    host_alice.max_ack_wait = 30
    host_alice.delay = 0.2
    host_alice.start()

    host_bob = Host('Bob')
    host_bob.max_ack_wait = 30
    host_bob.delay = 0.2
    host_bob.add_connection('Alice')
    host_bob.add_connection('Eve')
    host_bob.start()

    host_eve = Host('Eve')
    host_eve.max_ack_wait = 30
    host_eve.delay = 0.2
    host_eve.add_connection('Bob')
    host_eve.add_connection('Dean')
    host_eve.start()

    host_dean = Host('Dean')
    host_dean.max_ack_wait = 30
    host_dean.delay = 0.2
    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(checksum_sender,
                            (q_size, host_dean.host_id, checksum_per_qubit))
    host_dean.run_protocol(checksum_receiver,
                           (q_size, host_alice.host_id, checksum_per_qubit))

    start_time = time.time()
    while time.time() - start_time < 150:
        pass

    network.stop(stop_hosts=True)
    exit()
コード例 #21
0
def qunetsim():
    from components.host import Host
    from components.network import Network
    from objects.qubit import Qubit

    network = Network.get_instance()
    nodes = ["Alice", "Bob", "Eve", "Dean"]
    network.start(nodes)
    network.delay = 0.1

    host_alice = Host('Alice')
    host_alice.add_connection('Bob')
    host_alice.start()

    host_bob = Host('Bob')
    host_bob.add_connection('Alice')
    host_bob.add_connection('Eve')
    host_bob.start()

    host_eve = Host('Eve')
    host_eve.add_connection('Bob')
    host_eve.add_connection('Dean')
    host_eve.start()

    host_dean = Host('Dean')
    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)

    from mappings.qunetsim import mapping

    #return host_alice, host_bob, host_eve, network

    def source_protocol(source_host, target_host_id):
        _ = qpz_atomics.lib(mapping, source_host)
        for i in range(5):
            q = _.PREP()
            q = _.H(q)
            print("sending"), _.DISP(q)
            _.SEND(q, target_host_id)

    def target_protocol(target_host, source_host_id):
        _ = qpz_atomics.lib(mapping, target_host)
        for i in range(5):
            print(source_host_id)
            q = _.RECV(source_host_id)
            print("recieved"), _.DISP(q)

    host_alice.run_protocol(source_protocol, (host_bob.host_id, ))
    host_bob.run_protocol(target_protocol, (host_alice.host_id, ))
コード例 #22
0
def main():
    # network.classical_routing_algo = routing_algorithm
    nodes = ['A', 'node_1', 'node_2', 'B']
    network.use_hop_by_hop = False
    network.set_delay = 0.1
    network.start(nodes)

    A = Host('A')
    A.add_connection('node_1')
    A.add_connection('node_2')
    A.start()

    node_1 = Host('node_1')
    node_1.add_connection('A')
    node_1.add_connection('B')
    node_1.start()

    node_2 = Host('node_2')
    node_2.add_connection('A')
    node_2.add_connection('B')
    node_2.start()

    B = Host('B')
    B.add_connection('node_1')
    B.add_connection('node_2')
    B.start()

    hosts = [A, node_1, node_2, B]
    for h in hosts:
        network.add_host(h)

    node_1.run_protocol(generate_entanglement)
    node_2.run_protocol(generate_entanglement)

    print('---- BUILDING ENTANGLEMENT   ----')
    # Let the network build up entanglement
    for i in range(10):
        print('building...')
        time.sleep(1)
    print('---- DONE BUILDING ENTANGLEMENT   ----')

    network.quantum_routing_algo = routing_algorithm
    choices = ['00', '11', '10', '01']
    for _ in range(5):
        print('----  sending superdense  ----')
        A.send_superdense(B.host_id, random.choice(choices), await_ack=True)
        time.sleep(1)

    print('stopping')
    try:
        network.stop(stop_hosts=True)
    except Exception:
        print('')
コード例 #23
0
 def setUpClass(cls):
     global network
     global hosts
     nodes = ["Alice", "Bob"]
     backend = EQSNBackend()
     network.start(nodes=nodes, backend=backend)
     hosts = {'alice': Host('Alice', backend), 'bob': Host('Bob', backend)}
     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)
コード例 #24
0
def test_multiple_backends(backend_generator):
    print("Starting multiple backends test...")
    backend1 = backend_generator()
    backend2 = backend_generator()
    assert backend1._cqc_connections == backend2._cqc_connections
    network = Network.get_instance()
    network.start(["Alice", "Bob"], backend1)
    alice = Host('Alice', backend2)
    bob = Host('Bob', backend1)
    assert str(backend1._cqc_connections) == str(backend2._cqc_connections)
    assert str(backend1._hosts) == str(backend2._hosts)
    network.stop(True)
    print("Test was successfull!")
コード例 #25
0
def main():
    global thread_1_return
    global thread_2_return

    network = Network.get_instance()
    nodes = ["Alice", "Bob", "Eve", "Dean"]
    network.start(nodes)
    network.delay = 0.5

    host_alice = Host('alice')
    host_alice.add_connection('bob')
    host_alice.max_ack_wait = 30
    host_alice.delay = 0.2
    host_alice.start()

    host_bob = Host('bob')
    host_bob.max_ack_wait = 30
    host_bob.delay = 0.2
    host_bob.add_connection('alice')
    host_bob.add_connection('eve')
    host_bob.start()

    host_eve = Host('eve')
    host_eve.max_ack_wait = 30
    host_eve.delay = 0.2
    host_eve.add_connection('bob')
    host_eve.add_connection('dean')
    host_eve.start()

    host_dean = Host('dean')
    host_dean.max_ack_wait = 30
    host_dean.delay = 0.2
    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)

    host_alice.run_protocol(retransmission_sender,
                            (host_dean.host_id, MAX_TRIAL_NUM))
    host_dean.run_protocol(retransmission_receiver,
                           (host_alice.host_id, MAX_TRIAL_NUM))

    start_time = time.time()
    while time.time() - start_time < 150:
        pass

    network.stop(stop_hosts=True)
    exit()
コード例 #26
0
ファイル: key_sharing.py プロジェクト: witt-designs/QuNetSim
def main():
    # Initialize a network
    network = Network.get_instance()
    # Define the host IDs in the network
    nodes = ['Alice', 'Bob', 'Eve']
    network.delay = 0.0
    # Start the network with the defined hosts
    network.start(nodes)
    # Initialize the host Alice
    host_alice = Host('Alice')
    # Add a one-way connection (classical and quantum) to Bob
    host_alice.add_connection('Bob')
    # Start listening
    host_alice.start()

    host_bob = Host('Bob')
    # Bob adds his own one-way connection to Alice and Eve
    host_bob.add_connection('Alice')
    host_bob.add_connection('Eve')
    host_bob.start()

    host_eve = Host('Eve')
    host_eve.add_connection('Bob')
    host_eve.start()

    # Add the hosts to the network
    # The network is: Alice <--> Bob <--> Eve
    network.add_host(host_alice)
    network.add_host(host_bob)
    network.add_host(host_eve)

    # Generate random key
    key_size = 8  # the size of the key in bit
    hosts = {'Alice': host_alice, 'Bob': host_bob, 'Eve': host_eve}

    # Run Alice and Eve
    host_alice.send_key(host_eve.host_id, key_size)

    start_time = time.time()
    while time.time() - start_time < 60:
        pass

    print('SENDER KEYS')
    print(host_alice.qkd_keys)

    print('RECEIVER KEYS')
    print(host_eve.qkd_keys)

    for h in hosts.values():
        h.stop()
    network.stop()
コード例 #27
0
def main():
    network = Network.get_instance()
    nodes = ["Alice", "Bob", "Eve", "Dean"]
    backend = CQCBackend()
    network.start(nodes, backend)
    network.delay = 0.2
    network.packet_drop_rate = 0
    print('')

    host_alice = Host('Alice', backend)
    host_alice.add_connection('Bob')
    host_alice.start()

    host_bob = Host('Bob', backend)
    host_bob.add_connection('Alice')
    host_bob.add_connection('Eve')
    host_bob.start()

    host_eve = Host('Eve', backend)
    host_eve.add_connection('Bob')
    host_eve.add_connection('Dean')
    host_eve.start()

    host_dean = Host('Dean', backend)
    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)

    print('alice sends message')

    host_alice.send_classical('Bob', 'hello1')
    host_alice.send_classical('Bob', 'hello2')
    host_alice.send_classical('Bob', 'hello3')
    host_alice.send_classical('Bob', 'hello4')
    host_alice.send_classical('Bob', 'hello5')
    host_alice.send_classical('Bob', 'hello6')
    host_alice.send_classical('Bob', 'hello7')
    host_alice.send_classical('Bob', 'hello8')
    host_alice.send_classical('Bob', 'hello9')
    host_alice.send_classical('Bob', 'hello10')

    start_time = time.time()
    while time.time() - start_time < 10:
        pass

    network.stop(True)
    exit()
コード例 #28
0
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 == protocols.ACK and m.seq_num == 0:
            saw_ack_1 = True
        if m.content == protocols.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()
コード例 #29
0
def main():
    network = Network.get_instance()
    nodes = ["Alice", "Bob", "Eve", "Dean"]
    network.start(nodes)
    network.delay = 0.1

    host_alice = Host('Alice')
    host_alice.add_connection('Bob')
    host_alice.start()

    host_bob = Host('Bob')
    host_bob.add_connection('Alice')
    host_bob.add_connection('Eve')
    host_bob.start()

    host_eve = Host('Eve')
    host_eve.add_connection('Bob')
    host_eve.add_connection('Dean')
    host_eve.start()

    host_dean = Host('Dean')
    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)

    # Create a qubit owned by Alice
    q = Qubit(host_alice)
    # Put the qubit in the excited state
    q.X()
    # Send the qubit and await an ACK from Dean
    q_id, _ = host_alice.send_qubit('Dean', q, await_ack=True)

    # Get the qubit on Dean's side from Alice
    q_rec = host_dean.get_data_qubit('Alice', q_id)

    # Ensure the qubit arrived and then measure and print the results.
    if q_rec is not None:
        m = q_rec.measure()
        print("Results of the measurements for q_id are ", str(m))
    else:
        print('q_rec is none')

    network.stop(True)
    exit()
コード例 #30
0
def main():
    network = Network.get_instance()
    nodes = ["Alice", "Bob", "Eve", "Dean"]
    network.start(nodes)
    network.delay = 0.1

    host_alice = Host('Alice')
    host_alice.add_connection('Bob')
    host_alice.start()

    host_bob = Host('Bob')
    host_bob.add_connection('Alice')
    host_bob.add_connection('Eve')
    host_bob.start()

    host_eve = Host('Eve')
    host_eve.add_connection('Bob')
    host_eve.add_connection('Dean')
    host_eve.start()

    host_dean = Host('Dean')
    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)

    q_id1, _ = host_alice.send_epr('Dean', await_ack=True)

    q1 = host_alice.get_epr('Dean', q_id1)
    q2 = host_dean.get_epr('Alice', q_id1)

    if q1 is not None and q2 is not None:
        m1 = q1.measure()
        m2 = q2.measure()
        print("Results of the measurements for the entangled pair are %d %d" %
              (m1, m2))
    else:
        if q1 is None:
            print('q1 is none')
        if q2 is None:
            print('q2 is none')

    network.stop(True)
    exit()