Skip to content

Commit

Permalink
Fix some more issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Takishima committed Oct 24, 2019
1 parent fdc881d commit 25beef4
Showing 1 changed file with 6 additions and 19 deletions.
25 changes: 6 additions & 19 deletions projectq/cengines/_graphmapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ class GraphMapper(BasicMapperEngine):
Args:
graph (networkx.Graph) : Arbitrary connected graph
storage (int) Number of gates to temporarily store
storage (int): Approximate number of gates to temporarily store
add_qubits_to_mapping (function or str): Function called when
new qubits are to be added to the current mapping.
Special possible string values:
Expand All @@ -307,7 +307,7 @@ class GraphMapper(BasicMapperEngine):
Attributes:
current_mapping: Stores the mapping: key is logical qubit id, value
is mapped qubit id from 0,...,self.num_qubits
storage (int): Number of gate it caches before mapping.
storage (int): Approximate number of gate it caches before mapping.
num_qubits(int): number of qubits
num_mappings (int): Number of times the mapper changed the mapping
depth_of_swaps (dict): Key are circuit depth of swaps, value is the
Expand All @@ -327,7 +327,7 @@ def __init__(self,
Args:
graph (networkx.Graph): Arbitrary connected graph representing
Qubit connectivity
storage (int): Number of gates to temporarily store
storage (int): Approximate number of gates to temporarily store
add_qubits_to_mapping (function or str): Function called
when new qubits are to be added to the current
mapping.
Expand Down Expand Up @@ -584,14 +584,6 @@ def _run(self):
# to the temporary internal reverse mapping with invalid ids
new_internal_mapping[backend_id] = -1

# Calculate reverse internal mapping
new_internal_mapping = deepcopy(self._reverse_current_mapping)

# Add missing entries with invalid id to be able to process the
# swaps operations
for backend_id in not_allocated_ids:
new_internal_mapping[backend_id] = -1

# Send swap operations to arrive at the new mapping
for bqb0, bqb1 in swaps:
qb0 = WeakQubitRef(engine=self, idx=bqb0)
Expand All @@ -608,14 +600,9 @@ def _run(self):
# Register statistics:
self.num_mappings += 1
depth = return_swap_depth(swaps)
if depth not in self.depth_of_swaps:
self.depth_of_swaps[depth] = 1
else:
self.depth_of_swaps[depth] += 1
if len(swaps) not in self.num_of_swaps_per_mapping:
self.num_of_swaps_per_mapping[len(swaps)] = 1
else:
self.num_of_swaps_per_mapping[len(swaps)] += 1
self.depth_of_swaps[depth] = self.depth_of_swaps.get(depth, 0) + 1
self.num_of_swaps_per_mapping[len(
swaps)] = self.num_of_swaps_per_mapping.get(len(swaps), 0) + 1

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

0 comments on commit 25beef4

Please sign in to comment.