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)
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()