def test_BB84_time_bin(): tl = Timeline(1e12) # stop time is 1 s alice = QKDNode("alice", tl, encoding=time_bin, stack_size=1) bob = QKDNode("bob", tl, encoding=time_bin, stack_size=1) pair_bb84_protocols(alice.protocol_stack[0], bob.protocol_stack[0]) qc = QuantumChannel("qc", tl, distance=10e3, polarization_fidelity=0.99, attenuation=0.00002) qc.set_ends(alice, bob) cc = ClassicalChannel("cc", tl, distance=10e3) cc.set_ends(alice, bob) # Parent pa = Parent(alice, 128, "alice") pb = Parent(bob, 128, "bob") alice.protocol_stack[0].upper_protocols.append(pa) pa.lower_protocols.append(alice.protocol_stack[0]) bob.protocol_stack[0].upper_protocols.append(pb) pb.lower_protocols.append(bob.protocol_stack[0]) process = Process(pa, "push", []) event = Event(0, process) tl.schedule(event) tl.init() tl.run() assert pa.counter == pb.counter == 10
def test_cascade_run(): KEYSIZE = 512 KEYNUM = 10 tl = Timeline(1e11) alice = QKDNode("alice", tl) bob = QKDNode("bob", tl) pair_bb84_protocols(alice.protocol_stack[0], bob.protocol_stack[0]) pair_cascade_protocols(alice.protocol_stack[1], bob.protocol_stack[1]) qc0 = QuantumChannel("qc0", tl, distance=1e3, attenuation=2e-5, polarization_fidelity=0.97) qc1 = QuantumChannel("qc1", tl, distance=1e3, attenuation=2e-5, polarization_fidelity=0.97) qc0.set_ends(alice, bob) qc1.set_ends(bob, alice) cc0 = ClassicalChannel("cc0", tl, distance=1e3) cc1 = ClassicalChannel("cc1", tl, distance=1e3) cc0.set_ends(alice, bob) cc1.set_ends(bob, alice) # Parent pa = Parent(alice, KEYSIZE, KEYNUM) pb = Parent(bob, KEYSIZE, KEYNUM) alice.protocol_stack[1].upper_protocols.append(pa) pa.lower_protocols.append(alice.protocol_stack[1]) bob.protocol_stack[1].upper_protocols.append(pb) pb.lower_protocols.append(bob.protocol_stack[1]) process = Process(pa, "push", []) event = Event(0, process) tl.schedule(event) tl.init() tl.run() assert pa.counter == pb.counter == KEYNUM for k1, k2 in zip(pa.keys, pb.keys): assert k1 == k2 assert k1 < 2**KEYSIZE # check that key is not too large assert alice.protocol_stack[1].error_bit_rate == 0
# open file to store experiment results # Path("results/timebin").mkdir(parents=True, exist_ok=True) # filename = "results/timebin/distance_cascade.log" # fh = open(filename, 'w') for distance in distances: tl = Timeline(runtime) tl.seed(1) tl.show_progress = True qc = QuantumChannel("qc", tl, distance=distance * 1e3, attenuation=0.0002) cc = ClassicalChannel("cc", tl, distance=distance * 1e3) # Alice ls_params = {"frequency": 2e6, "mean_photon_num": 0.1} alice = QKDNode("alice", tl, encoding=time_bin) for name, param in ls_params.items(): alice.update_lightsource_params(name, param) # Bob detector_params = [{"efficiency": 0.072, "dark_count": dark_count, "time_resolution": 10}, {"efficiency": 0.072, "dark_count": dark_count, "time_resolution": 10}, {"efficiency": 0.072, "dark_count": dark_count, "time_resolution": 10}] bob = QKDNode("bob", tl, encoding=time_bin) for i in range(len(detector_params)): for name, param in detector_params[i].items(): bob.update_detector_params(i, name, param) qc.set_ends(alice, bob)