Skip to content

Commit

Permalink
Track Sabre decay heuristic on physical qubits
Browse files Browse the repository at this point in the history
The custom `decay` heuristic is supposed to penalise increases in depth
in the output.  The output space of qubits are the physical qubits, so
the depth is defined in relation to those.  Since its introduction in
Qiskitgh-4537, this heuristic has instead been tracking the depth on the
virtual qubits, which due to the swaps is not necessarily related to the
depth in the output.

Notably, this commit actually makes the depth for routing large
volumetric circuits slightly _worse_ on average (at least for heavy-hex
topologies).  This may be because the effect on the heuristic is
overweighted, or that the depth tracking resets after each gate is
routed (and occasionally in between) to be flat across all qubits,
rather than reflecting the actual depth each qubit is subject to.
  • Loading branch information
jakelishman committed Sep 5, 2023
1 parent 1606ca3 commit 431b910
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
7 changes: 4 additions & 3 deletions crates/accelerate/src/sabre_swap/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,8 @@ fn swap_map_trial(
qubits_decay.fill(1.);
num_search_steps = 0;
} else {
qubits_decay[best_swap[0]] += DECAY_RATE;
qubits_decay[best_swap[1]] += DECAY_RATE;
qubits_decay[layout.logic_to_phys[best_swap[0]]] += DECAY_RATE;
qubits_decay[layout.logic_to_phys[best_swap[1]]] += DECAY_RATE;
}
}
// If we exceeded the number of allowed attempts without successfully routing a node, we
Expand Down Expand Up @@ -735,7 +735,8 @@ fn choose_best_swap(
+ EXTENDED_SET_WEIGHT * extended_set.score(swap, layout, dist)
}
Heuristic::Decay => {
qubits_decay[swap[0]].max(qubits_decay[swap[1]])
qubits_decay[layout.logic_to_phys[swap[0]]]
.max(qubits_decay[layout.logic_to_phys[swap[1]]])
* (absolute_score
+ layer.score(swap, layout, dist)
+ EXTENDED_SET_WEIGHT * extended_set.score(swap, layout, dist))
Expand Down
6 changes: 6 additions & 0 deletions releasenotes/notes/sabre-decay-physical-ad2f470cd45d69f3.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
fixes:
- |
The ``"decay"`` heuristic of :class:`.SabreSwap` and :class:`.SabreLayout` now tracks the depth
correctly on physical qubits rather than mistakenly tracking the "depth" of swaps on virtual
qubits.
2 changes: 1 addition & 1 deletion 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], [11, 10, 16, 5, 17])
self.assertEqual([layout[q] for q in circuit.qubits], [16, 7, 11, 12, 13])

def test_6q_circuit_20q_coupling(self):
"""Test finds layout for 6q circuit on 20q device."""
Expand Down

0 comments on commit 431b910

Please sign in to comment.