Beispiel #1
0
    def test_add_connections(self):
        a = Host('A')

        a.add_connection('B')
        self.assertEqual(len(a.classical_connections), 1)
        self.assertEqual(len(a.quantum_connections), 1)

        a.add_c_connection('C')
        self.assertEqual(len(a.classical_connections), 2)
        self.assertEqual(len(a.quantum_connections), 1)

        a.add_q_connection('D')
        self.assertEqual(len(a.classical_connections), 2)
        self.assertEqual(len(a.quantum_connections), 2)

        a.add_connections(['E', 'F'])
        self.assertEqual(len(a.classical_connections), 4)
        self.assertEqual(len(a.quantum_connections), 4)

        a.add_c_connections(['G', 'H'])
        self.assertEqual(len(a.classical_connections), 6)
        self.assertEqual(len(a.quantum_connections), 4)

        a.add_q_connections(['I', 'J'])
        self.assertEqual(len(a.classical_connections), 6)
        self.assertEqual(len(a.quantum_connections), 6)
Beispiel #2
0
def main():
    network = Network.get_instance()
    nodes = ['A', 'B', 'C', 'D', 'E']
    network.start(nodes)

    host_A = Host('A')
    host_A.add_connections(['B', 'C', 'D', 'E'])
    host_A.start()
    host_B = Host('B')
    host_B.add_c_connections(['C', 'D', 'E'])
    host_B.start()
    host_C = Host('C')
    host_C.add_c_connections(['B', 'D', 'E'])
    host_C.start()
    host_D = Host('D')
    host_D.add_c_connections(['B', 'C', 'E'])
    host_D.start()
    host_E = Host('E')
    host_E.add_c_connections(['B', 'C', 'D'])
    host_E.start()

    network.add_hosts([host_A, host_B, host_C, host_D, host_E])

    for i in range(10):
        # The ID of the generated secret EPR pair has to be agreed upon in advance
        epr_id = '123'
        host_A.run_protocol(distribute, ([host_B.host_id, host_C.host_id, host_D.host_id, host_E.host_id],))
        host_B.run_protocol(node, (host_A.host_id,))
        host_C.run_protocol(node, (host_A.host_id,))
        host_D.run_protocol(sender, (host_A.host_id, host_E.host_id, epr_id))
        host_E.run_protocol(receiver, (host_A.host_id, host_D.host_id, epr_id), blocking=True)
        time.sleep(0.5)
    network.stop(True)
Beispiel #3
0
def main():
    network = Network.get_instance()
    network.start()
    network.delay = 0.0

    host_A = Host('A')
    host_A.add_c_connection('C')
    host_A.delay = 0
    host_A.start()

    host_B = Host('B')
    host_B.add_c_connection('C')
    host_B.delay = 0
    host_B.start()

    host_C = Host('C')
    host_C.add_c_connections(['A', 'B'])
    host_C.delay = 0
    host_C.start()

    network.add_host(host_C)

    # To generate entanglement
    host_A.add_connection('B')
    host_B.add_connection('A')

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

    # strategy = 'CLASSICAL'
    strategy = 'QUANTUM'

    host_A.delay = 0.0
    host_B.delay = 0.0
    host_C.delay = 0.0

    print('Starting game. Strategy: %s' % strategy)
    if strategy == 'QUANTUM':
        print('Generating initial entanglement...')
        for i in range(PLAYS):
            host_A.send_epr('B', await_ack=True)
            print('created %d EPR pairs' % (i + 1))
        print('Done generating initial entanglement')
    else:
        network.delay = 0.0

    network.draw_classical_network()
    # Remove the connection from Alice and Bob
    host_A.remove_connection('B')
    host_B.remove_connection('A')

    # Play the game classically
    if strategy == 'CLASSICAL':
        host_A.run_protocol(alice_classical, (host_C.host_id, ))
        host_B.run_protocol(
            bob_classical,
            (host_C.host_id, ),
        )

    # Play the game quantumly
    if strategy == 'QUANTUM':
        host_A.run_protocol(alice_quantum, (host_C.host_id, host_B.host_id))
        host_B.run_protocol(bob_quantum, (host_C.host_id, host_A.host_id))

    host_C.run_protocol(referee, (host_A.host_id, host_B.host_id),
                        blocking=True)

    network.stop(True)
    # network.draw_quantum_network()
    network.draw_classical_network()