def __init__(self, name, tl): Node.__init__(self, name, tl) self.memory_array = MemoryArray(name + ".MemoryArray", tl, num_memories=50) self.memory_array.owner = self self.resource_manager = ResourceManager(self)
def test_QuantumChannel_set_ends(): tl = Timeline() qc = QuantumChannel("qc", tl, attenuation=0.0002, distance=1e4) end1 = Node("end1", tl) end2 = Node("end2", tl) assert len(end1.qchannels) == len(end2.qchannels) == 0 qc.set_ends(end1, end2) assert len(end1.qchannels) == len(end2.qchannels) == 1 assert end1 in qc.ends and end2 in qc.ends assert end1.name in end2.qchannels and end2.name in end1.qchannels
def test_ClassicalChannel_set_ends(): tl = Timeline() cc = ClassicalChannel("cc", tl, 1e3) n1 = Node('n1', tl) n2 = Node('n2', tl) assert len(n1.cchannels) == 0 and len(n2.cchannels) == 0 cc.set_ends(n1, n2) assert 'n1' in n2.cchannels and 'n2' in n1.cchannels assert n1.cchannels["n2"] == n2.cchannels["n1"] == cc
def test_generation_expire(): class DumbBSM(): def __init__(self): pass def get(self, qubit): pass tl = Timeline(1e12) e0 = Node("e0", tl) e1 = Node("e1", tl) m0 = FakeNode("m0", tl) qc0 = QuantumChannel("qc_e0m0", tl, 0, 1e3) qc1 = QuantumChannel("qc_e1m0", tl, 0, 1e3) qc0.set_ends(e0, m0) qc1.set_ends(e1, m0) cc0 = ClassicalChannel("cc_e0m0", tl, 1e3, delay=1e12) cc1 = ClassicalChannel("cc_e1m0", tl, 1e3, delay=1e12) cc2 = ClassicalChannel("cc_e0e1", tl, 2e3, delay=1e9) cc3 = ClassicalChannel("cc_e1e0", tl, 2e3, delay=1e9) cc0.set_ends(e0, m0) cc1.set_ends(e1, m0) cc2.set_ends(e0, e1) cc3.set_ends(e1, e0) e0.memory_array = MemoryArray("e0mem", tl, coherence_time=1) e1.memory_array = MemoryArray("e1mem", tl, coherence_time=1) e0.memory_array.owner = e0 e1.memory_array.owner = e1 m0.bsm = DumbBSM() tl.init() protocol0 = EntanglementGenerationA(e0, "e0prot", middle="m0", other="e1", memory=e0.memory_array[0]) protocol1 = EntanglementGenerationA(e1, "e1prot", middle="m0", other="e0", memory=e1.memory_array[0]) protocol0.primary = True e0.protocols.append(protocol0) e1.protocols.append(protocol1) protocol0.set_others(protocol1) protocol1.set_others(protocol0) process = Process(protocol0, "start", []) event = Event(0, process) tl.schedule(event) process = Process(protocol1, "start", []) event = Event(0, process) tl.schedule(event) tl.run() assert e0.memory_array[0].expiration_event.time > 1e12
def test_generation_receive_message(): tl = Timeline() node = Node("e1", tl) m0 = FakeNode("m1", tl) qc = QuantumChannel("qc_nodem1", tl, 0, 1e3) qc.set_ends(node, m0) node.memory_array = MemoryArray("", tl) node.assign_cchannel(ClassicalChannel("", tl, 0, delay=1), "m1") eg = EntanglementGenerationA(node, "EG", middle="m1", other="e2", memory=node.memory_array[0]) eg.qc_delay = 1 # negotiate message msg = EntanglementGenerationMessage(GenerationMsgType.NEGOTIATE_ACK, "EG", emit_time=0) assert eg.received_message("e2", msg) is True assert eg.expected_time == 1 assert len(tl.events.data) == 2 # excite and next start time
def __init__(self, name, tl): Node.__init__(self, name, tl) self.memory_array = MemoryArray(name + ".MemoryArray", tl) self.resource_manager = ResourceManager(self) self.send_log = []
def __init__(self, name, tl, **kwargs): Node.__init__(self, name, tl) self.msg_log = [] self.resource_manager = FakeResourceManager(self)
def __init__(self, name, tl): Node.__init__(self, name, tl) self.log = []
def __init__(self, name, tl, **kwargs): Node.__init__(self, name, tl, **kwargs) self.msgs = []
def __init__(self, name, tl, ls): Node.__init__(self, name, tl) self.lightsource = ls self.lightsource.owner = self
def init(self): pass def received_message(self, src: str, message: Message): assert message.msg_type == MsgType.PING print("node {} received ping message at time {}".format( self.own.name, self.own.timeline.now())) new_msg = Message(MsgType.PONG, self.other_name) self.own.send_message(self.other_node, new_msg) if __name__ == "__main__": tl = Timeline(1e12) node1 = Node("node1", tl) node2 = Node("node2", tl) cc = ClassicalChannel("cc", tl, 1e3, 1e9) cc.set_ends(node1, node2) pingp = PingProtocol(node1, "pingp", "pongp", "node2") pongp = PongProtocol(node2, "pongp", "pingp", "node1") process = Process(pingp, "start", []) event = Event(0, process) tl.schedule(event) tl.init() tl.run()
def test_Node_assign_cchannel(): tl = Timeline() node = Node("node1", tl) cc = ClassicalChannel("cc", tl, 1e3) node.assign_cchannel(cc, "node2") assert "node2" in node.cchannels and node.cchannels["node2"] == cc
def test_Node_assign_qchannel(): tl = Timeline() node = Node("node1", tl) qc = QuantumChannel("qc", tl, 2e-4, 1e3) node.assign_qchannel(qc, "node2") assert "node2" in node.qchannels and node.qchannels["node2"] == qc