diff --git a/src/qibo/transpiler/router.py b/src/qibo/transpiler/router.py index 03cb66a7d5..943345b8a7 100644 --- a/src/qibo/transpiler/router.py +++ b/src/qibo/transpiler/router.py @@ -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) diff --git a/tests/test_transpiler_router.py b/tests/test_transpiler_router.py index 66e3a9bfdf..d76c7503e5 100644 --- a/tests/test_transpiler_router.py +++ b/tests/test_transpiler_router.py @@ -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 @@ -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():