Skip to content

Commit

Permalink
update test_sabre_looping()
Browse files Browse the repository at this point in the history
  • Loading branch information
changsookim committed Jul 29, 2024
1 parent aae31dd commit 2c426db
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
9 changes: 2 additions & 7 deletions src/qibo/transpiler/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -922,13 +922,8 @@ def _shortest_path_routing(self):
)

# Q1 is moved
swaps = [
(
self.circuit.physical_to_logical(shortest_path[i]),
self.circuit.physical_to_logical(shortest_path[i + 1]),
)
for i in range(len(shortest_path) - 2)
]
shortest_path = [self.circuit.physical_to_logical(q) for q in shortest_path[:-1]]
swaps = list(zip(shortest_path[:-1], shortest_path[1:]))

for swap in swaps:
self.circuit.update(swap)
Expand Down
14 changes: 7 additions & 7 deletions tests/test_transpiler_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,10 @@ def test_sabre_looping():

placer = Trivial(connectivity=chip)
initial_layout = placer(loop_circ)
router_old = Sabre(connectivity=chip, swap_threshold=np.inf) # Old
router_new = Sabre(connectivity=chip) # New
routed_circuit_old, _ = router_old(loop_circ, initial_layout=initial_layout)
routed_circuit_new, _ = router_new(loop_circ, initial_layout=initial_layout)
router_no_threshold = Sabre(connectivity=chip, swap_threshold=np.inf) # Without reset
router_threshold = Sabre(connectivity=chip) # With reset
routed_no_threshold, _ = router_no_threshold(loop_circ, initial_layout=initial_layout)
routed_threshold, _ = router_threshold(loop_circ, initial_layout=initial_layout)

def count_swaps(circuit):
count = 0
Expand All @@ -214,10 +214,10 @@ def count_swaps(circuit):
count += 1
return count

count_old = count_swaps(routed_circuit_old)
count_new = count_swaps(routed_circuit_new)
count_no_threshold = count_swaps(routed_no_threshold)
count_threshold = count_swaps(routed_threshold)

assert count_new < count_old
assert count_no_threshold > count_threshold


def test_sabre_shortest_path_routing():
Expand Down

0 comments on commit 2c426db

Please sign in to comment.