Skip to content

Commit 2783e9a

Browse files
author
Stephen DiAdamo
committed
Fix the test case
1 parent d9077b1 commit 2783e9a

File tree

2 files changed

+25
-15
lines changed

2 files changed

+25
-15
lines changed

integration_tests/test_quantum_storage.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,9 @@ def test_get_qubit_by_id(self):
157157
q3 = FakeQubit()
158158

159159
storage = QuantumStorage()
160-
storage.add_qubit_from_host('T', Constants.DATA, q1)
161-
storage.add_qubit_from_host('T', Constants.EPR, q2)
162-
storage.add_qubit_from_host('T', Constants.GHZ, q3)
160+
storage.add_qubit_from_host(q1, from_host_id='S', purpose=Constants.DATA)
161+
storage.add_qubit_from_host(q2, from_host_id='T', purpose=Constants.EPR)
162+
storage.add_qubit_from_host(q3, from_host_id='V', purpose=Constants.GHZ)
163163

164164
self.assertEqual(q1, storage.get_qubit_by_id(q1.id))
165165
self.assertEqual(q2, storage.get_qubit_by_id(q2.id))

qunetsim/objects/quantum_storage.py

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,8 @@ def get_qubit_by_id(self, q_id):
163163
Returns:
164164
(Qubit): The qubit with the id *q_id* or None if it does not exist
165165
"""
166-
matching_qubits = [q for q_list in self._qubit_dict.values() for q in q_list if q.id == q_id]
167-
if len(matching_qubits) > 0:
168-
return matching_qubits[0]
166+
if q_id in self._qubit_dict:
167+
return list(self._qubit_dict[q_id].values())[0]
169168
return None
170169

171170
def change_qubit_id(self, from_host_id, new_id, old_id=None):
@@ -256,10 +255,10 @@ def get_all_qubits_from_host(self, from_host_id, purpose=None):
256255

257256
def _check_all_requests(self):
258257
"""
259-
Checks if any of the pending requests is now fullfilled.
258+
Checks if any of the pending requests is now fulfilled.
260259
261260
Returns:
262-
If a request is fullfilled, the request is handeled and the function
261+
If a request is fulfilled, the request is handled and the function
263262
returns the qubit of this request.
264263
"""
265264
for req_id, args in self._pending_request_dict.items():
@@ -365,7 +364,9 @@ def _get_qubit_from_host(self, from_host_id, q_id, purpose):
365364
return None
366365

367366
def _pop_qubit_with_id_and_host_from_qubit_dict(self, q_id, from_host_id, purpose=None):
368-
def _pop_purpose_from_purpose_dict(q_id, from_host_id):
367+
def _pop_purpose_from_purpose_dict():
368+
nonlocal q_id, from_host_id
369+
369370
if q_id not in self._purpose_dict:
370371
return None
371372
pur = self._purpose_dict[q_id].pop(from_host_id, None)
@@ -375,7 +376,7 @@ def _pop_purpose_from_purpose_dict(q_id, from_host_id):
375376
return pur
376377
return None
377378

378-
purp = _pop_purpose_from_purpose_dict(q_id, from_host_id)
379+
purp = _pop_purpose_from_purpose_dict()
379380
if purp is not None:
380381
if purpose is None or purpose == purp:
381382
qubit = self._qubit_dict[q_id].pop(from_host_id, None)
@@ -390,15 +391,16 @@ def _pop_purpose_from_purpose_dict(q_id, from_host_id):
390391
return None
391392

392393
def _add_qubit_to_qubit_dict(self, qubit, purpose, from_host_id):
393-
def _add_purpose_to_purpose_dict(purpose, id, from_host_id):
394-
if id not in self._purpose_dict:
395-
self._purpose_dict[id] = {}
396-
self._purpose_dict[id][from_host_id] = purpose
394+
def _add_purpose_to_purpose_dict(q_id):
395+
nonlocal purpose, from_host_id
396+
if q_id not in self._purpose_dict:
397+
self._purpose_dict[q_id] = {}
398+
self._purpose_dict[q_id][from_host_id] = purpose
397399

398400
if qubit.id not in self._qubit_dict:
399401
self._qubit_dict[qubit.id] = {}
400402
self._qubit_dict[qubit.id][from_host_id] = qubit
401-
_add_purpose_to_purpose_dict(purpose, qubit.id, from_host_id)
403+
_add_purpose_to_purpose_dict(qubit.id)
402404

403405
def _add_new_host(self, host_id):
404406
if host_id not in self._host_dict:
@@ -410,6 +412,14 @@ def _add_new_host(self, host_id):
410412
def _check_qubit_in_system(self, qubit, from_host_id, purpose=None):
411413
"""
412414
True if qubit with same parameters already in the systems
415+
416+
Args:
417+
qubit (Qubit): The qubit in question
418+
from_host_id (str): The ID of the sending host
419+
purpose (int): Qubit's purpose
420+
421+
Returns:
422+
(bool): If the qubit is in the system.
413423
"""
414424
if qubit.id in self._qubit_dict and \
415425
from_host_id in self._qubit_dict[qubit.id]:

0 commit comments

Comments
 (0)