@@ -154,6 +154,19 @@ def check_qubit_from_host_exists(self, from_host_id, purpose=None):
154154 self .lock .release_write ()
155155 return False
156156
157+ def get_qubit_by_id (self , q_id ):
158+ """
159+ Return the qubit that has the id *q_id*
160+
161+ Args:
162+ q_id (str): The ID of the qubit
163+ Returns:
164+ (Qubit): The qubit with the id *q_id* or None if it does not exist
165+ """
166+ if q_id in self ._qubit_dict :
167+ return list (self ._qubit_dict [q_id ].values ())[0 ]
168+ return None
169+
157170 def change_qubit_id (self , from_host_id , new_id , old_id = None ):
158171 """
159172 Changes the ID of a qubit. If the ID is not given, a random
@@ -242,10 +255,10 @@ def get_all_qubits_from_host(self, from_host_id, purpose=None):
242255
243256 def _check_all_requests (self ):
244257 """
245- Checks if any of the pending requests is now fullfilled .
258+ Checks if any of the pending requests is now fulfilled .
246259
247260 Returns:
248- 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
249262 returns the qubit of this request.
250263 """
251264 for req_id , args in self ._pending_request_dict .items ():
@@ -351,7 +364,9 @@ def _get_qubit_from_host(self, from_host_id, q_id, purpose):
351364 return None
352365
353366 def _pop_qubit_with_id_and_host_from_qubit_dict (self , q_id , from_host_id , purpose = None ):
354- 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+
355370 if q_id not in self ._purpose_dict :
356371 return None
357372 pur = self ._purpose_dict [q_id ].pop (from_host_id , None )
@@ -361,7 +376,7 @@ def _pop_purpose_from_purpose_dict(q_id, from_host_id):
361376 return pur
362377 return None
363378
364- purp = _pop_purpose_from_purpose_dict (q_id , from_host_id )
379+ purp = _pop_purpose_from_purpose_dict ()
365380 if purp is not None :
366381 if purpose is None or purpose == purp :
367382 qubit = self ._qubit_dict [q_id ].pop (from_host_id , None )
@@ -376,15 +391,16 @@ def _pop_purpose_from_purpose_dict(q_id, from_host_id):
376391 return None
377392
378393 def _add_qubit_to_qubit_dict (self , qubit , purpose , from_host_id ):
379- def _add_purpose_to_purpose_dict (purpose , id , from_host_id ):
380- if id not in self ._purpose_dict :
381- self ._purpose_dict [id ] = {}
382- 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
383399
384400 if qubit .id not in self ._qubit_dict :
385401 self ._qubit_dict [qubit .id ] = {}
386402 self ._qubit_dict [qubit .id ][from_host_id ] = qubit
387- _add_purpose_to_purpose_dict (purpose , qubit .id , from_host_id )
403+ _add_purpose_to_purpose_dict (qubit .id )
388404
389405 def _add_new_host (self , host_id ):
390406 if host_id not in self ._host_dict :
@@ -396,6 +412,14 @@ def _add_new_host(self, host_id):
396412 def _check_qubit_in_system (self , qubit , from_host_id , purpose = None ):
397413 """
398414 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.
399423 """
400424 if qubit .id in self ._qubit_dict and \
401425 from_host_id in self ._qubit_dict [qubit .id ]:
0 commit comments