diff --git a/integration_tests/test_backend.py b/integration_tests/test_backend.py index ac79b130..3750cb20 100644 --- a/integration_tests/test_backend.py +++ b/integration_tests/test_backend.py @@ -40,9 +40,7 @@ def test_epr_generation(self): # Test multiple times to eliminate probabilistic effects for _ in range(5): - q1 = backend.create_EPR(alice.host_id, bob.host_id) - q2 = backend.receive_epr( - bob.host_id, alice.host_id, q_id=q1.id) + q1, q2 = backend.create_EPR(alice.host_id, bob.host_id) self.assertEqual(q1.id, q2.id) self.assertEqual(backend.measure(q1, False), backend.measure(q2, False)) @@ -87,9 +85,7 @@ def test_density_operator_qutip(self): network.add_host(alice) network.add_host(bob) - q1 = backend.create_EPR(alice.host_id, bob.host_id) - q2 = backend.receive_epr( - bob.host_id, alice.host_id, q_id=q1.id) + q1, q2 = backend.create_EPR(alice.host_id, bob.host_id) density_operator = backend.density_operator(q1) expected = np.diag([0.5, 0.5]) @@ -116,9 +112,7 @@ def test_density_operator(self): network.add_host(alice) network.add_host(bob) - q1 = backend.create_EPR(alice.host_id, bob.host_id) - q2 = backend.receive_epr( - bob.host_id, alice.host_id, q_id=q1.id) + q1, q2 = backend.create_EPR(alice.host_id, bob.host_id) density_operator = backend.density_operator(q1) expected = np.diag([0.5, 0.5]) diff --git a/qunetsim/backends/backend.py b/qunetsim/backends/backend.py index 6cb723d2..dd6e4bb5 100644 --- a/qunetsim/backends/backend.py +++ b/qunetsim/backends/backend.py @@ -57,33 +57,16 @@ def send_qubit_to(self, qubit, from_host_id, to_host_id): raise (EnvironmentError("This is only an interface, not \ an actual implementation!")) - def create_EPR(self, host_a_id, host_b_id, q_id=None, block=False): + def create_EPR(self, host_id, q_id=None, block=False): """ - Creates an EPR pair for two qubits and returns one of the qubits. + Creates an EPR pair for two qubits and returns both of the qubits. Args: - host_a_id (String): ID of the first host who gets the EPR state. - host_b_id (String): ID of the second host who gets the EPR state. + host_id (String): ID of the host who creates the EPR state. q_id (String): Optional id which both qubits should have. block (bool): Determines if the created pair should be blocked or not. Returns: - Returns a qubit. The qubit belongs to host a. To get the second - qubit of host b, the receive_epr function has to be called. - """ - raise (EnvironmentError("This is only an interface, not \ - an actual implementation!")) - - def receive_epr(self, host_id, sender_id, q_id=None, block=False): - """ - Called after create EPR in the receiver, to receive the other EPR pair. - - Args: - host_id (String): ID of the first host who gets the EPR state. - sender_id (String): ID of the sender of the EPR pair. - q_id (String): Optional id which both qubits should have. - block (bool): Determines if the created pair should be blocked or not. - Returns: - Returns an EPR qubit with the other Host. + Returns both EPR qubits. """ raise (EnvironmentError("This is only an interface, not \ an actual implementation!")) diff --git a/qunetsim/backends/cqc_backend.py b/qunetsim/backends/cqc_backend.py index a2044c75..4d688066 100644 --- a/qunetsim/backends/cqc_backend.py +++ b/qunetsim/backends/cqc_backend.py @@ -46,23 +46,6 @@ def __init__(self): CQCBackend.CQCConnections.__instance = self SafeDict.__init__(self) - class EntanglementIDs(SafeDict): - # There only should be one instance of Hosts - __instance = None - - @staticmethod - def get_instance(): - if CQCBackend.EntanglementIDs.__instance is not None: - return CQCBackend.EntanglementIDs.__instance - else: - return CQCBackend.EntanglementIDs() - - def __init__(self): - if CQCBackend.EntanglementIDs.__instance is not None: - raise Exception("Call get instance to get this class!") - CQCBackend.EntanglementIDs.__instance = self - SafeDict.__init__(self) - # SimulaQron comes with an own network simulator # has to be kept in sync with QuNetSim network backend_network = None @@ -71,8 +54,6 @@ def __init__(self): def __init__(self): self._hosts = CQCBackend.Hosts.get_instance() self._cqc_connections = CQCBackend.CQCConnections.get_instance() - # keys are from : to, where from is the host calling create EPR - self._entaglement_ids = CQCBackend.EntanglementIDs.get_instance() self._stopped = False def start(self, **kwargs): @@ -139,7 +120,7 @@ def send_qubit_to(self, qubit, from_host_id, to_host_id): qubit.qubit = cqc_to_host.recvQubit() qubit.host = self._hosts.get_from_dict(to_host_id) - def create_EPR(self, host_a_id, host_b_id, q_id=None, block=False): + def create_EPR(self, host_id, q_id=None, block=False): """ Creates an EPR pair for two qubits and returns one of the qubits. @@ -152,50 +133,15 @@ def create_EPR(self, host_a_id, host_b_id, q_id=None, block=False): Returns a qubit. The qubit belongs to host a. To get the second qubit of host b, the receive_epr function has to be called. """ - cqc_host_a = self._cqc_connections.get_from_dict(host_a_id) - cqc_host_b = self._cqc_connections.get_from_dict(host_b_id) - host_a = self._hosts.get_from_dict(host_a_id) - q = cqc_host_a.createEPR(cqc_host_b.name) - qubit = Qubit(host_a, qubit=q, q_id=q_id, blocked=block) - # add the ID to a list, so the next returned qubit from recv EPR - # gets assigned the right id - self.store_ent_id(cqc_host_a, cqc_host_b, qubit) - return qubit - - def store_ent_id(self, cqc_host_a, cqc_host_b, qubit): - key = cqc_host_a.name + ':' + cqc_host_b.name - ent_list = self._entaglement_ids.get_from_dict(key) - if ent_list is not None: - ent_list.append(qubit.id) - else: - ent_list = [qubit.id] - self._entaglement_ids.add_to_dict(key, ent_list) - - def receive_epr(self, host_id, sender_id, q_id=None, block=False): - """ - Called after create EPR in the receiver, to receive the other EPR pair. - - Args: - host_id (String): ID of the first host who gets the EPR state. - sender_id (String): ID of the sender of the EPR pair. - q_id (String): Optional id which both qubits should have. - block (bool): Determines if the created pair should be blocked or not. - Returns: - Returns an EPR qubit with the other Host. - """ - cqc_host = self._cqc_connections.get_from_dict(host_id) host = self._hosts.get_from_dict(host_id) - q = cqc_host.recvEPR() - key = sender_id + ':' + cqc_host.name - ent_list = self._entaglement_ids.get_from_dict(key) - if ent_list is None: - raise Exception("Internal Error!") - id = None - id = ent_list.pop(0) - if q_id is not None and q_id != id: - raise ValueError("q_id doesn't match id!") - self._entaglement_ids.add_to_dict(key, ent_list) - return Qubit(host, qubit=q, q_id=id, blocked=block) + cqc_host = self._cqc_connections.get_from_dict(host_id) + q1 = cqc.qubit(cqc_host) + q2 = cqc.qubit(cqc_host) + q1.H() + q1.cnot(q2) + q1 = Qubit(host, qubit=q1, q_id=id, blocked=block) + q2 = Qubit(host, qubit=q2, q_id=id, blocked=block) + return q1, q2 def flush(self, host_id): """ diff --git a/qunetsim/backends/eqsn_backend.py b/qunetsim/backends/eqsn_backend.py index 57b1e368..7dcb8556 100644 --- a/qunetsim/backends/eqsn_backend.py +++ b/qunetsim/backends/eqsn_backend.py @@ -99,27 +99,8 @@ def __init__(self): EQSNBackend.Hosts.__instance = self SafeDict.__init__(self) - class EntanglementIDs(SafeDict): - # There only should be one instance of Hosts - __instance = None - - @staticmethod - def get_instance(): - if EQSNBackend.EntanglementIDs.__instance is not None: - return EQSNBackend.EntanglementIDs.__instance - else: - return EQSNBackend.EntanglementIDs() - - def __init__(self): - if EQSNBackend.EntanglementIDs.__instance is not None: - raise Exception("Call get instance to get this class!") - EQSNBackend.EntanglementIDs.__instance = self - SafeDict.__init__(self) - def __init__(self): self._hosts = EQSNBackend.Hosts.get_instance() - # keys are from : to, where from is the host calling create EPR - self._entaglement_qubits = EQSNBackend.EntanglementIDs.get_instance() self.eqsn = EQSN.get_instance() def start(self, **kwargs): @@ -170,64 +151,27 @@ def send_qubit_to(self, qubit, from_host_id, to_host_id): new_host = self._hosts.get_from_dict(to_host_id) qubit.host = new_host - def create_EPR(self, host_a_id, host_b_id, q_id=None, block=False): + def create_EPR(self, host_id, q_id=None, block=False): """ - Creates an EPR pair for two qubits and returns one of the qubits. + Creates an EPR pair for two qubits and returns both of the qubits. Args: - host_a_id (String): ID of the first host who gets the EPR state. - host_b_id (String): ID of the second host who gets the EPR state. + host_id (String): ID of the host who creates the EPR state. q_id (String): Optional id which both qubits should have. block (bool): Determines if the created pair should be blocked or not. Returns: - Returns a qubit. The qubit belongs to host a. To get the second - qubit of host b, the receive_epr function has to be called. + Returns both EPR qubits. """ uid1 = uuid.uuid4() uid2 = uuid.uuid4() - host_a = self._hosts.get_from_dict(host_a_id) - host_b = self._hosts.get_from_dict(host_b_id) + host = self._hosts.get_from_dict(host_id) self.eqsn.new_qubit(uid1) self.eqsn.new_qubit(uid2) self.eqsn.H_gate(uid1) self.eqsn.cnot_gate(uid2, uid1) - q1 = Qubit(host_a, qubit=uid1, q_id=q_id, blocked=block) - q2 = Qubit(host_b, qubit=uid2, q_id=q1.id, blocked=block) - self.store_ent_pair(host_a.host_id, host_b.host_id, q2) - return q1 - - def store_ent_pair(self, host_a, host_b, qubit): - key = host_a + ':' + host_b - ent_queue = self._entaglement_qubits.get_from_dict(key) - - if ent_queue is not None: - ent_queue.put(qubit) - else: - ent_queue = Queue() - ent_queue.put(qubit) - self._entaglement_qubits.add_to_dict(key, ent_queue) - - def receive_epr(self, host_id, sender_id, q_id=None, block=False): - """ - Called after create EPR in the receiver, to receive the other EPR pair. - - Args: - host_id (String): ID of the first host who gets the EPR state. - sender_id (String): ID of the sender of the EPR pair. - q_id (String): Optional id which both qubits should have. - block (bool): Determines if the created pair should be blocked or not. - Returns: - Returns an EPR qubit with the other Host. - """ - key = sender_id + ':' + host_id - ent_queue = self._entaglement_qubits.get_from_dict(key) - if ent_queue is None: - raise Exception("Internal Error!") - q = ent_queue.get() - self._entaglement_qubits.add_to_dict(key, ent_queue) - if q_id is not None and q_id != q.id: - raise ValueError("Qid doesent match id!") - return q + q1 = Qubit(host, qubit=uid1, q_id=q_id, blocked=block) + q2 = Qubit(host, qubit=uid2, q_id=q1.id, blocked=block) + return q1, q2 ########################## # Gate definitions # diff --git a/qunetsim/backends/projectq_backend.py b/qunetsim/backends/projectq_backend.py index 9996e5d8..7c0e6d07 100644 --- a/qunetsim/backends/projectq_backend.py +++ b/qunetsim/backends/projectq_backend.py @@ -15,30 +15,12 @@ class ProjectQBackend(object): def __init__(self): self._hosts = ProjectQBackend.Hosts.get_instance() - self._entaglement_pairs = ProjectQBackend.EntanglementPairs.get_instance() self.engine = projectq.MainEngine() self.measuring = False def __del__(self): self.engine.flush(deallocate_qubits=True) - class EntanglementPairs(SafeDict): - # There only should be one instance of Hosts - __instance = None - - @staticmethod - def get_instance(): - if ProjectQBackend.EntanglementPairs.__instance is not None: - return ProjectQBackend.EntanglementPairs.__instance - else: - return ProjectQBackend.EntanglementPairs() - - def __init__(self): - if ProjectQBackend.EntanglementPairs.__instance is not None: - raise Exception("Call get instance to get this class!") - ProjectQBackend.EntanglementPairs.__instance = self - SafeDict.__init__(self) - class Hosts(SafeDict): # There only should be one instance of Hosts __instance = None @@ -102,63 +84,27 @@ def send_qubit_to(self, qubit, from_host_id, to_host_id): """ qubit.host = self._hosts.get_from_dict(to_host_id) - def create_EPR(self, host_a_id, host_b_id, q_id=None, block=False): + def create_EPR(self, host_id, q_id=None, block=False): """ - Creates an EPR pair for two qubits and returns one of the qubits. + Creates an EPR pair for two qubits and returns both of the qubits. Args: - host_a_id (String): ID of the first host who gets the EPR state. - host_b_id (String): ID of the second host who gets the EPR state. + host_id (String): ID of the host who creates the EPR state. q_id (String): Optional id which both qubits should have. block (bool): Determines if the created pair should be blocked or not. Returns: - Returns a qubit. The qubit belongs to host a. To get the second - qubit of host b, the receive_epr function has to be called. + Returns both EPR qubits. """ - q1 = self.create_qubit(host_a_id) - q2 = self.create_qubit(host_b_id) + q1 = self.create_qubit(host_id) + q2 = self.create_qubit(host_id) projectq.ops.H | q1 projectq.ops.CNOT | (q1, q2) - host_a = self._hosts.get_from_dict(host_a_id) - host_b = self._hosts.get_from_dict(host_b_id) - qubit_b = Qubit(host_b, qubit=q2, q_id=q_id, blocked=block) - qubit = Qubit(host_a, qubit=q1, q_id=q_id, blocked=block) - self.store_ent_pair(host_a.host_id, host_b.host_id, qubit_b) - return qubit - - def store_ent_pair(self, host_a, host_b, qubit): - key = host_a + ':' + host_b - ent_queue = self._entaglement_pairs.get_from_dict(key) - - if ent_queue is not None: - ent_queue.put(qubit) - else: - ent_queue = Queue() - ent_queue.put(qubit) - self._entaglement_pairs.add_to_dict(key, ent_queue) - - def receive_epr(self, host_id, sender_id, q_id=None, block=False): - """ - Called after create EPR in the receiver, to receive the other EPR pair. - - Args: - host_id (String): ID of the first host who gets the EPR state. - sender_id (String): ID of the sender of the EPR pair. - q_id (String): Optional id which both qubits should have. - block (bool): Determines if the created pair should be blocked or not. - Returns: - Returns an EPR qubit with the other Host. - """ - key = sender_id + ':' + host_id - ent_queue = self._entaglement_pairs.get_from_dict(key) - if ent_queue is None: - raise Exception("Internal Error!") - qubit = ent_queue.get() - if q_id is not None and q_id != qubit.id: - raise ValueError("Qid doesn't match id!") - return qubit + host = self._hosts.get_from_dict(host_id) + qubit_b = Qubit(host, qubit=q2, q_id=q_id, blocked=block) + qubit = Qubit(host, qubit=q1, q_id=q_id, blocked=block) + return qubit, qubit_b ########################## # Gate definitions # diff --git a/qunetsim/backends/qutip_backend.py b/qunetsim/backends/qutip_backend.py index 7a3d4de6..4fb91984 100644 --- a/qunetsim/backends/qutip_backend.py +++ b/qunetsim/backends/qutip_backend.py @@ -127,26 +127,8 @@ def __init__(self): QuTipBackend.Hosts.__instance = self SafeDict.__init__(self) - class EntanglementIDs(SafeDict): - # There only should be one instance of Hosts - __instance = None - - @staticmethod - def get_instance(): - if QuTipBackend.EntanglementIDs.__instance is not None: - return QuTipBackend.EntanglementIDs.__instance - else: - return QuTipBackend.EntanglementIDs() - - def __init__(self): - if QuTipBackend.EntanglementIDs.__instance is not None: - raise Exception("Call get instance to get this class!") - QuTipBackend.EntanglementIDs.__instance = self - SafeDict.__init__(self) - def __init__(self): self._hosts = QuTipBackend.Hosts.get_instance() - self._entaglement_qubits = QuTipBackend.EntanglementIDs.get_instance() def start(self, **kwargs): """ @@ -195,66 +177,29 @@ def send_qubit_to(self, qubit, from_host_id, to_host_id): new_host = self._hosts.get_from_dict(to_host_id) qubit.host = new_host - def create_EPR(self, host_a_id, host_b_id, q_id=None, block=False): + def create_EPR(self, host_id, q_id=None, block=False): """ - Creates an EPR pair for two qubits and returns one of the qubits. + Creates an EPR pair for two qubits and returns both of the qubits. Args: - host_a_id (String): ID of the first host who gets the EPR state. - host_b_id (String): ID of the second host who gets the EPR state. + host_id (String): ID of the host who creates the EPR state. q_id (String): Optional id which both qubits should have. block (bool): Determines if the created pair should be blocked or not. Returns: - Returns a qubit. The qubit belongs to host a. To get the second - qubit of host b, the receive_epr function has to be called. + Returns both EPR qubits. """ name1 = str(uuid.uuid4()) name2 = str(uuid.uuid4()) - host_a = self._hosts.get_from_dict(host_a_id) - host_b = self._hosts.get_from_dict(host_b_id) + host = self._hosts.get_from_dict(host_id) qubit1 = (QuTipBackend.QubitCollection(name1), name1) qubit2 = (QuTipBackend.QubitCollection(name2), name2) qubit1[0].apply_single_gate(snot(), qubit1[1]) qubit1[0].add_qubit(qubit2[0]) qubit2 = (qubit1[0], name2) qubit1[0].apply_double_gate(cnot(), qubit1[1], qubit2[1]) - q1 = Qubit(host_a, qubit=qubit1, q_id=q_id, blocked=block) - q2 = Qubit(host_b, qubit=qubit2, q_id=q1.id, blocked=block) - self.store_ent_pair(host_a.host_id, host_b.host_id, q2) - return q1 - - def store_ent_pair(self, host_a, host_b, qubit): - key = host_a + ':' + host_b - ent_queue = self._entaglement_qubits.get_from_dict(key) - - if ent_queue is not None: - ent_queue.put(qubit) - else: - ent_queue = Queue() - ent_queue.put(qubit) - self._entaglement_qubits.add_to_dict(key, ent_queue) - - def receive_epr(self, host_id, sender_id, q_id=None, block=False): - """ - Called after create EPR in the receiver, to receive the other EPR pair. - - Args: - host_id (String): ID of the first host who gets the EPR state. - sender_id (String): ID of the sender of the EPR pair. - q_id (String): Optional id which both qubits should have. - block (bool): Determines if the created pair should be blocked or not. - Returns: - Returns an EPR qubit with the other Host. - """ - key = sender_id + ':' + host_id - ent_queue = self._entaglement_qubits.get_from_dict(key) - if ent_queue is None: - raise Exception("Internal Error!") - q = ent_queue.get() - self._entaglement_qubits.add_to_dict(key, ent_queue) - if q_id is not None and q_id != q.id: - raise ValueError("Qid doesent match id!") - return q + q1 = Qubit(host, qubit=qubit1, q_id=q_id, blocked=block) + q2 = Qubit(host, qubit=qubit2, q_id=q1.id, blocked=block) + return q1, q2 ########################## # Gate definitions # diff --git a/qunetsim/backends/safe_dict.py b/qunetsim/backends/safe_dict.py index c4a9e7f5..6961af1b 100644 --- a/qunetsim/backends/safe_dict.py +++ b/qunetsim/backends/safe_dict.py @@ -24,3 +24,10 @@ def get_from_dict(self, key): ret = self.dict[key] self.lock.release_read() return ret + + def keys(self): + ret = None + self.acquire_read() + ret = self.dict.keys() + self.release_read() + return ret diff --git a/qunetsim/components/network.py b/qunetsim/components/network.py index 3fc2dade..0be054c3 100644 --- a/qunetsim/components/network.py +++ b/qunetsim/components/network.py @@ -319,7 +319,7 @@ def get_classical_route(self, source, dest): """ return self.classical_routing_algo(self.classical_network, source, dest) - def _entanglement_swap(self, sender, receiver, route, q_id, o_seq_num, blocked): + def _entanglement_swap(self, sender, receiver, route, o_seq_num, epr_qubit): """ Performs a chain of entanglement swaps with the hosts between sender and receiver to create a shared EPR pair between sender and receiver. @@ -332,10 +332,27 @@ def _entanglement_swap(self, sender, receiver, route, q_id, o_seq_num, blocked): o_seq_num (int): The original sequence number blocked (bool): If the pair being distributed is blocked or not """ + q_id = epr_qubit.id + blocked = epr_qubit.blocked host_sender = self.get_host(sender) def establish_epr(net, s, r): - if not net.shares_epr(s, r): + """ + Establishes EPR betweem s and r. + + Args: + net (Network): The network object. + s (Host): The sender host. + r (Host): The receiver host. + """ + if s == route[0]: + # use the existing EPR Qubit + host_sender.send_qubit(r, epr_qubit, await_ack=True) + q = self.get_host(r).get_data_qubit(s, q_id=q_id, wait=Constants.WAIT_TIME) + if q is None: + Logger.get_instance().error("Error in Entanglement Swap.") + self.get_host(r).add_epr(s, q) + elif not net.shares_epr(s, r): self.get_host(s).send_epr(r, q_id, await_ack=True) else: old_id = self.get_host(s).change_epr_qubit_id(r, q_id) @@ -376,34 +393,9 @@ def establish_epr(net, s, r): host.send_teleport(route[i + 2], None, await_ack=True, payload=data, generate_epr_if_none=False) - # Change in the storage that the EPR qubit is shared with the receiver - q2 = host_sender.get_epr(route[1], q_id=q_id) - host_sender.add_epr(receiver, q2, q_id, blocked) Logger.get_instance().log('Entanglement swap was successful for pair with id ' + q_id + ' between ' + sender + ' and ' + receiver) - def _establish_epr(self, sender, receiver, q_id, o_seq_num, blocked): - """ - Instead doing an entanglement swap, for efficiency we establish EPR pairs - directly for simulation, if an entanglement swap would have been possible. - - Args: - sender (Host): Sender of the EPR pair - receiver (Host): Receiver of the EPR pair - q_id (str): Qubit ID of the sent EPR pair - o_seq_num (int): The original sequence number - blocked (bool): If the pair being distributed is blocked or not - """ - host_sender = self.get_host(sender) - host_receiver = self.get_host(receiver) - q1 = Qubit(host_sender) - q2 = Qubit(host_sender) - q1.H() - q1.cnot(q2) - host_sender.add_epr(receiver, q1, q_id, blocked) - host_receiver.add_epr(sender, q2, q_id, blocked) - host_receiver.send_ack(sender, o_seq_num) - def _route_quantum_info(self, sender, receiver, qubits): """ Routes qubits from sender to receiver. @@ -494,32 +486,16 @@ def _process_queue(self): elif len(route) == 2: if packet.protocol != Constants.RELAY: - if packet.protocol == Constants.REC_EPR: - host_sender = self.get_host(sender) - q = host_sender \ - .backend \ - .create_EPR(host_sender.host_id, - receiver, - q_id=packet.payload['q_id'], - block=packet.payload['blocked']) - host_sender.add_epr(receiver, q) self.ARP[receiver].rec_packet(packet) else: self.ARP[receiver].rec_packet(packet.payload) else: - if packet.protocol == Constants.REC_EPR: - q_id = packet.payload['q_id'] - blocked = packet.payload['blocked'] + if packet.protocol == Constants.REC_EPR and self.use_ent_swap: q_route = self.get_quantum_route(sender, receiver) - if self.use_ent_swap: - DaemonThread(self._entanglement_swap, - args=(sender, receiver, q_route, q_id, - packet.seq_num, blocked)) - else: - DaemonThread(self._establish_epr, - args=(sender, receiver, q_id, - packet.seq_num, blocked)) + DaemonThread(self._entanglement_swap, + args=(sender, receiver, q_route, + packet.seq_num, packet.payload)) else: network_packet = self._encode(route, packet) diff --git a/qunetsim/components/protocols.py b/qunetsim/components/protocols.py index f5358dfa..6ea17020 100644 --- a/qunetsim/components/protocols.py +++ b/qunetsim/components/protocols.py @@ -294,7 +294,16 @@ def _send_epr(packet): Args: packet (Packet): The packet in which to transmit. """ + sender = packet.sender + receiver = packet.receiver + host_sender = network.get_host(sender) + q1, q2 = host_sender.backend.create_EPR(host_sender.host_id, + q_id=packet.payload['q_id'], + block=packet.payload['blocked']) + host_sender.add_epr(receiver, q1) + packet.payload = q2 packet.protocol = Constants.REC_EPR + packet.payload_type = Constants.QUANTUM network.send(packet) @@ -313,11 +322,7 @@ def _rec_epr(packet): receiver = packet.receiver sender = packet.sender host_receiver = network.get_host(receiver) - q = host_receiver.backend.receive_epr(host_receiver.host_id, - sender_id=sender, - q_id=payload['q_id'], - block=payload['blocked']) - host_receiver.add_epr(sender, q) + host_receiver.add_epr(sender, payload) # Send an ACK if sequence number is not -1 if packet.seq_num != -1: _send_ack(sender, receiver, packet.seq_num)