Skip to content

Commit

Permalink
Only run a single inner routing trial for layout stage in SabreLayout (
Browse files Browse the repository at this point in the history
…Qiskit#10741)

* Only run a single inner routing trial for layout stage in SabreLayout

In the SabreLayout routing pass we internally run sabre swap multiple
times forward and backwards over the circuit and transform the layout
based on the swaps that would be inserted by the routing pass.
Previously we were running multiple routing trials for this internal
execution of routing and then selecting the routing result with the
least numbers of swaps inserted. However, this heuristic of least swaps
does not necessarily result in a better layout. When increasing the
number of swap trials used for sabre layout the output quality could
result in more swaps being necessary. This points to the heuristic for
the best routing output to use for a layout is not the minimal number of
swaps. Until a more suitable heuristic can be developed for selecting
the best routing output to use for an intermediate layout transform this
commit removes the use of multiple trials for layout purposes and only
runs a single trial. We still use multiple swap trials for the final
routing as the swap count heuristic works there, but for layout we only
run a single trial.

* Avoid rayon use when running a single routing trial
  • Loading branch information
mtreinish committed Aug 31, 2023
1 parent 48cfab6 commit dcec79e
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 52 deletions.
4 changes: 2 additions & 2 deletions crates/accelerate/src/sabre_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ fn layout_trial(
heuristic,
Some(seed),
&initial_layout,
num_swap_trials,
Some(run_swap_in_parallel),
1,
Some(false),
);
initial_layout = final_layout;
}
Expand Down
96 changes: 48 additions & 48 deletions test/python/transpiler/test_preset_passmanagers.py
Original file line number Diff line number Diff line change
Expand Up @@ -917,68 +917,68 @@ def test_layout_tokyo_fully_connected_cx(self, level):

sabre_layout = {
0: ancilla[0],
1: qr[4],
2: ancilla[1],
3: ancilla[2],
4: ancilla[3],
5: qr[1],
6: qr[0],
7: ancilla[4],
8: ancilla[5],
9: ancilla[6],
10: qr[2],
11: qr[3],
12: ancilla[7],
13: ancilla[8],
14: ancilla[9],
15: ancilla[10],
16: ancilla[11],
1: ancilla[1],
2: ancilla[2],
3: ancilla[3],
4: ancilla[4],
5: qr[2],
6: qr[1],
7: ancilla[6],
8: ancilla[7],
9: ancilla[8],
10: qr[3],
11: qr[0],
12: ancilla[9],
13: ancilla[10],
14: ancilla[11],
15: ancilla[5],
16: qr[4],
17: ancilla[12],
18: ancilla[13],
19: ancilla[14],
}

sabre_layout_lvl_2 = {
0: ancilla[0],
1: qr[4],
2: ancilla[1],
3: ancilla[2],
4: ancilla[3],
5: qr[1],
6: qr[0],
7: ancilla[4],
8: ancilla[5],
9: ancilla[6],
10: qr[2],
11: qr[3],
12: ancilla[7],
13: ancilla[8],
14: ancilla[9],
15: ancilla[10],
16: ancilla[11],
1: ancilla[1],
2: ancilla[2],
3: ancilla[3],
4: ancilla[4],
5: qr[2],
6: qr[1],
7: ancilla[6],
8: ancilla[7],
9: ancilla[8],
10: qr[3],
11: qr[0],
12: ancilla[9],
13: ancilla[10],
14: ancilla[11],
15: ancilla[5],
16: qr[4],
17: ancilla[12],
18: ancilla[13],
19: ancilla[14],
}

sabre_layout_lvl_3 = {
0: ancilla[0],
1: qr[4],
2: ancilla[1],
3: ancilla[2],
4: ancilla[3],
5: qr[1],
6: qr[0],
7: ancilla[4],
8: ancilla[5],
9: ancilla[6],
10: qr[2],
11: qr[3],
12: ancilla[7],
13: ancilla[8],
14: ancilla[9],
15: ancilla[10],
16: ancilla[11],
1: ancilla[1],
2: ancilla[2],
3: ancilla[3],
4: ancilla[4],
5: qr[2],
6: qr[1],
7: ancilla[6],
8: ancilla[7],
9: ancilla[8],
10: qr[3],
11: qr[0],
12: ancilla[9],
13: ancilla[10],
14: ancilla[11],
15: ancilla[5],
16: qr[4],
17: ancilla[12],
18: ancilla[13],
19: ancilla[14],
Expand Down
4 changes: 2 additions & 2 deletions test/python/transpiler/test_sabre_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def test_5q_circuit_20q_coupling(self):
pass_.run(dag)

layout = pass_.property_set["layout"]
self.assertEqual([layout[q] for q in circuit.qubits], [18, 11, 13, 12, 14])
self.assertEqual([layout[q] for q in circuit.qubits], [11, 10, 16, 5, 17])

def test_6q_circuit_20q_coupling(self):
"""Test finds layout for 6q circuit on 20q device."""
Expand Down Expand Up @@ -214,7 +214,7 @@ def test_layout_many_search_trials(self):
self.assertIsInstance(res, QuantumCircuit)
layout = res._layout.initial_layout
self.assertEqual(
[layout[q] for q in qc.qubits], [7, 19, 14, 18, 10, 6, 12, 16, 13, 20, 15, 21, 1, 17]
[layout[q] for q in qc.qubits], [22, 7, 2, 12, 1, 5, 14, 4, 11, 0, 16, 15, 3, 10]
)


Expand Down

0 comments on commit dcec79e

Please sign in to comment.