def receive_qubit(self, src, qubit): if not qubit.is_null: self.detector.get() if __name__ == "__main__": runtime = 10e12 tl = Timeline(runtime) # nodes and hardware node1 = SenderNode("node1", tl) node2 = ReceiverNode("node2", tl) qc = QuantumChannel("qc", tl, attenuation=0, distance=1e3) qc.set_ends(node1, node2) # counter counter = Counter() node2.detector.attach(counter) # schedule events time_bin = int(1e12 / FREQUENCY) process1 = Process(node1.memory, "update_state", [[complex(math.sqrt(1 / 2)), complex(math.sqrt(1 / 2))]]) process2 = Process(node1.memory, "excite", ["node2"]) for i in range(NUM_TRIALS): event1 = Event(i * time_bin, process1) event2 = Event(i * time_bin + (time_bin / 2), process2)
}, { "efficiency": 0.8, "dark_count": 1, "time_resolution": 10 }, { "efficiency": 0.8, "dark_count": 1, "time_resolution": 10 }] bob = QKDNode("bob", tl, encoding=time_bin, stack_size=1) for i in range(len(detector_params)): for name, param in detector_params[i].items(): bob.update_detector_params(i, name, param) qc0.set_ends(alice, bob) qc1.set_ends(bob, alice) cc0.set_ends(alice, bob) cc1.set_ends(bob, alice) # BB84 config pair_bb84_protocols(alice.protocol_stack[0], bob.protocol_stack[0]) # add parent protocol for monitoring pa = Parent(alice, keysize, "alice") pb = Parent(bob, keysize, "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])
def pair_protocol(p1: EntanglementProtocol, p2: EntanglementProtocol): p1.set_others(p2) p2.set_others(p1) tl = Timeline() node1 = EntangleGenNode('node1', tl) node2 = EntangleGenNode('node2', tl) bsm_node = BSMNode('bsm_node', tl, ['node1', 'node2']) bsm_node.bsm.update_detectors_params('efficiency', 1) qc1 = QuantumChannel('qc1', tl, attenuation=0, distance=1000) qc2 = QuantumChannel('qc2', tl, attenuation=0, distance=1000) qc1.set_ends(node1, bsm_node) qc2.set_ends(node2, bsm_node) nodes = [node1, node2, bsm_node] for i in range(3): for j in range(3): cc= ClassicalChannel('cc_%s_%s'%(nodes[i].name, nodes[j].name), tl, 1000, 1e8) cc.set_ends(nodes[i], nodes[j]) for i in range(1000): tl.time = tl.now() + 1e11 node1.create_protocol('bsm_node', 'node2') node2.create_protocol('bsm_node', 'node1') pair_protocol(node1.protocols[0], node2.protocols[0])
# Bob detector_params = [{ "efficiency": 0.8, "dark_count": 10, "time_resolution": 10, "count_rate": 50e6 }, { "efficiency": 0.8, "dark_count": 10, "time_resolution": 10, "count_rate": 50e6 }] bob = QKDNode("bob", tl, stack_size=1) 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) cc.set_ends(alice, bob) # BB84 config pair_bb84_protocols(alice.protocol_stack[0], bob.protocol_stack[0]) process = Process(alice.protocol_stack[0], "push", [256, math.inf, 6e12]) event = Event(0, process) tl.schedule(event) tl.init() tl.run()
# create all-to-all classical connections cc_delay = 1e9 node_list = [r1, r2, r3, m12, m23] for i, node1 in enumerate(node_list): for node2 in node_list[i + 1:]: cc = ClassicalChannel("cc_%s_%s" % (node1.name, node2.name), tl, 1e3, delay=cc_delay) cc.set_ends(node1, node2) # create quantum channels linking r1 and r2 to m1 qc_atten = 0 qc_dist = 1e3 qc1 = QuantumChannel("qc_r1_m12", tl, qc_atten, qc_dist) qc1.set_ends(r1, m12) qc2 = QuantumChannel("qc_r2_m12", tl, qc_atten, qc_dist) qc2.set_ends(r2, m12) # create quantum channels linking r2 and r3 to m2 qc3 = QuantumChannel("qc_r2_m23", tl, qc_atten, qc_dist) qc3.set_ends(r2, m23) qc4 = QuantumChannel("qc_r3_m23", tl, qc_atten, qc_dist) qc4.set_ends(r3, m23) tl.init() # load rules rule1 = Rule(10, eg_rule_action_f1_1, eg_rule_condition_f1) r1.resource_manager.load(rule1) rule2 = Rule(10, eg_rule_action_f1_2, eg_rule_condition_f1) r2.resource_manager.load(rule2)
def test_NetworkManager(): tl = Timeline(1e10) n1 = FakeNode("n1", tl, 50) n2 = FakeNode("n2", tl, 50) n3 = FakeNode("n3", tl, 20) m1 = BSMNode("m1", tl, ["n1", "n2"]) m2 = BSMNode("m2", tl, ["n2", "n3"]) cc0 = ClassicalChannel("cc_n1_n2", tl, 10, delay=1e5) cc1 = ClassicalChannel("cc_n2_n1", tl, 10, delay=1e5) cc2 = ClassicalChannel("cc_n1_m1", tl, 10, delay=1e5) cc3 = ClassicalChannel("cc_n2_m1", tl, 10, delay=1e5) cc4 = ClassicalChannel("cc_n2_n3", tl, 10, delay=1e5) cc5 = ClassicalChannel("cc_n3_n2", tl, 10, delay=1e5) cc6 = ClassicalChannel("cc_n2_m2", tl, 10, delay=1e5) cc7 = ClassicalChannel("cc_n3_m2", tl, 10, delay=1e5) cc0.set_ends(n1, n2) cc1.set_ends(n2, n1) cc2.set_ends(n1, m1) cc3.set_ends(n2, m1) cc4.set_ends(n2, n3) cc5.set_ends(n3, n2) cc6.set_ends(n2, m2) cc7.set_ends(n3, m2) qc = QuantumChannel("qc_n1_m1", tl, 0, 10) qc.set_ends(n1, m1) qc = QuantumChannel("qc_n2_m1", tl, 0, 10) qc.set_ends(n2, m1) qc = QuantumChannel("qc_n2_m2", tl, 0, 10) qc.set_ends(n2, m2) qc = QuantumChannel("qc_n3_m2", tl, 0, 10) qc.set_ends(n3, m2) n1.network_manager.protocol_stack[0].add_forwarding_rule("n2", "n2") n1.network_manager.protocol_stack[0].add_forwarding_rule("n3", "n2") n2.network_manager.protocol_stack[0].add_forwarding_rule("n1", "n1") n2.network_manager.protocol_stack[0].add_forwarding_rule("n3", "n3") n3.network_manager.protocol_stack[0].add_forwarding_rule("n1", "n2") n3.network_manager.protocol_stack[0].add_forwarding_rule("n2", "n2") tl.init() # approved request n1.network_manager.request("n3", 1e12, 2e12, 20, 0.9) tl.run() assert len(n1.send_log) == len(n1.receive_log) == 1 assert n1.send_log[0][0] == "n2" and n1.receive_log[0][0] == "n2" assert n1.send_log[0][1].payload.payload.msg_type == RSVPMsgType.REQUEST assert n1.receive_log[0][1].payload.payload.msg_type == RSVPMsgType.APPROVE assert len(n2.send_log) == len(n2.receive_log) == 2 assert n2.send_log[0][0] == "n3" and n2.receive_log[0][0] == "n1" assert n2.send_log[1][0] == "n1" and n2.receive_log[1][0] == "n3" assert len(n3.send_log) == len(n3.receive_log) == 1 assert n3.send_log[0][0] == "n2" and n3.receive_log[0][0] == "n2" n1.reset() n2.reset() n3.reset() # rejected request n1.network_manager.request("n3", 3e12, 4e12, 50, 0.9) tl.run() assert len(n1.send_log) == len(n1.receive_log) == 1 assert n1.send_log[0][0] == "n2" and n1.receive_log[0][0] == "n2" assert n1.send_log[0][1].payload.payload.msg_type == RSVPMsgType.REQUEST assert n1.receive_log[0][1].payload.payload.msg_type == RSVPMsgType.REJECT assert len(n2.send_log) == len(n2.receive_log) == 1 assert n2.send_log[0][0] == "n1" and n2.receive_log[0][0] == "n1" n1.reset() n2.reset() n3.reset() n1.network_manager.request("n3", 5e12, 6e12, 25, 0.9) tl.run() assert len(n1.send_log) == len(n1.receive_log) == 1 assert n1.send_log[0][0] == "n2" and n1.receive_log[0][0] == "n2" assert n1.send_log[0][1].payload.payload.msg_type == RSVPMsgType.REQUEST assert n1.receive_log[0][1].payload.payload.msg_type == RSVPMsgType.REJECT assert len(n2.send_log) == len(n2.receive_log) == 2 assert n2.send_log[0][0] == "n3" and n2.receive_log[0][0] == "n1" assert n2.send_log[1][0] == "n1" and n2.receive_log[1][0] == "n3" assert len(n3.send_log) == len(n3.receive_log) == 1 assert n3.send_log[0][0] == "n2" and n3.receive_log[0][0] == "n2"