Skip to content

Commit 33952a9

Browse files
committed
Fix some more issues
1 parent 5b2a96e commit 33952a9

File tree

1 file changed

+6
-19
lines changed

1 file changed

+6
-19
lines changed

projectq/cengines/_graphmapper.py

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ class GraphMapper(BasicMapperEngine):
286286
287287
Args:
288288
graph (networkx.Graph) : Arbitrary connected graph
289-
storage (int) Number of gates to temporarily store
289+
storage (int): Approximate number of gates to temporarily store
290290
add_qubits_to_mapping (function or str): Function called when
291291
new qubits are to be added to the current mapping.
292292
Special possible string values:
@@ -307,7 +307,7 @@ class GraphMapper(BasicMapperEngine):
307307
Attributes:
308308
current_mapping: Stores the mapping: key is logical qubit id, value
309309
is mapped qubit id from 0,...,self.num_qubits
310-
storage (int): Number of gate it caches before mapping.
310+
storage (int): Approximate number of gate it caches before mapping.
311311
num_qubits(int): number of qubits
312312
num_mappings (int): Number of times the mapper changed the mapping
313313
depth_of_swaps (dict): Key are circuit depth of swaps, value is the
@@ -327,7 +327,7 @@ def __init__(self,
327327
Args:
328328
graph (networkx.Graph): Arbitrary connected graph representing
329329
Qubit connectivity
330-
storage (int): Number of gates to temporarily store
330+
storage (int): Approximate number of gates to temporarily store
331331
add_qubits_to_mapping (function or str): Function called
332332
when new qubits are to be added to the current
333333
mapping.
@@ -584,14 +584,6 @@ def _run(self):
584584
# to the temporary internal reverse mapping with invalid ids
585585
new_internal_mapping[backend_id] = -1
586586

587-
# Calculate reverse internal mapping
588-
new_internal_mapping = deepcopy(self._reverse_current_mapping)
589-
590-
# Add missing entries with invalid id to be able to process the
591-
# swaps operations
592-
for backend_id in not_allocated_ids:
593-
new_internal_mapping[backend_id] = -1
594-
595587
# Send swap operations to arrive at the new mapping
596588
for bqb0, bqb1 in swaps:
597589
qb0 = WeakQubitRef(engine=self, idx=bqb0)
@@ -608,14 +600,9 @@ def _run(self):
608600
# Register statistics:
609601
self.num_mappings += 1
610602
depth = return_swap_depth(swaps)
611-
if depth not in self.depth_of_swaps:
612-
self.depth_of_swaps[depth] = 1
613-
else:
614-
self.depth_of_swaps[depth] += 1
615-
if len(swaps) not in self.num_of_swaps_per_mapping:
616-
self.num_of_swaps_per_mapping[len(swaps)] = 1
617-
else:
618-
self.num_of_swaps_per_mapping[len(swaps)] += 1
603+
self.depth_of_swaps[depth] = self.depth_of_swaps.get(depth, 0) + 1
604+
self.num_of_swaps_per_mapping[len(
605+
swaps)] = self.num_of_swaps_per_mapping.get(len(swaps), 0) + 1
619606

620607
# Calculate the list of "helper" qubits that need to be deallocated
621608
# and remove invalid entries

0 commit comments

Comments
 (0)