Skip to content

Commit a0f6808

Browse files
committed
Update documentation
1 parent 4eedef3 commit a0f6808

3 files changed

Lines changed: 17 additions & 18 deletions

File tree

crates/transpiler/src/passes/sabre/heuristic.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ impl BasicHeuristic {
8383
#[pyclass(module = "qiskit._accelerate.sabre", frozen, from_py_object)]
8484
#[derive(Clone, PartialEq, Debug)]
8585
pub struct LookaheadHeuristic {
86-
/// The relative weight of this heuristic. Typically this is defined relative to the
87-
/// :class:`.BasicHeuristic`, which generally has its weight set to 1.0.
86+
/// The relative weights of each sequential layer in this heuristic. Typically each of these is
87+
/// defined relative to the :class:`.BasicHeuristic`, which generally has its weight set to 1.0.
8888
weights: Vec<f64>,
89-
/// Dynamic scaling of the heuristic weight depending on the size of the layer.
89+
/// Dynamic scaling of the heuristic weight depending on the size of each layer.
9090
pub scale: SetScaling,
9191
}
9292
impl LookaheadHeuristic {

crates/transpiler/src/passes/sabre/layer.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ use qiskit_circuit::PhysicalQubit;
1818

1919
use super::vec_map::VecMap;
2020

21-
/// A container for the current non-routable parts of the front layer. This only ever holds
22-
/// two-qubit gates; the only reason a 0q- or 1q operation can be unroutable is because it has an
23-
/// unsatisfied 2q predecessor, which disqualifies it from being in the front layer.
21+
/// A container for 2q gates in a layer that are yet to be routed.
22+
///
23+
/// The graph nodes in this structure always refer to `TwoQ` entries, since `Synchronize` nodes do
24+
/// not impact the scoring; they only affect when nodes are eligible to move forwards a layer, or to
25+
/// become routed.
2426
///
2527
/// It would be more algorithmically natural for this struct to work in terms of virtual qubits,
2628
/// because then a swap insertion would not change the data contained. However, for each swap we
@@ -40,8 +42,8 @@ pub struct Layer {
4042
impl Layer {
4143
pub fn new(num_qubits: u32) -> Self {
4244
Layer {
43-
// This is the maximum capacity of the front layer, since each qubit must be one of a
44-
// pair, and can only have one gate in the layer.
45+
// This is the maximum capacity of the layer, since each qubit must be one of a pair,
46+
// and can only have one gate in the layer.
4547
nodes: IndexMap::with_capacity_and_hasher(
4648
num_qubits as usize / 2,
4749
::ahash::RandomState::default(),
@@ -61,15 +63,15 @@ impl Layer {
6163
&self.qubits
6264
}
6365

64-
/// Add a node into the front layer, with the two qubits it operates on.
66+
/// Add a node into the layer, with the two qubits it operates on.
6567
pub fn insert(&mut self, index: NodeIndex, qubits: [PhysicalQubit; 2]) {
6668
let [a, b] = qubits;
6769
self.qubits[a] = Some((index, b));
6870
self.qubits[b] = Some((index, a));
6971
self.nodes.insert(index, qubits);
7072
}
7173

72-
/// Remove a node from the front layer.
74+
/// Remove a node from the layer.
7375
pub fn remove(&mut self, index: &NodeIndex) {
7476
// The actual order in the indexmap doesn't matter as long as it's reproducible.
7577
// Swap-remove is more efficient than a full shift-remove.
@@ -98,12 +100,9 @@ impl Layer {
98100
/// Calculate the score _difference_ caused by this swap, compared to not making the swap.
99101
#[inline(always)]
100102
pub fn score(&self, swap: [PhysicalQubit; 2], dist: &ArrayView2<f64>) -> f64 {
101-
// At most there can be two affected gates in the front layer (one on each qubit in the
102-
// swap), since any gate whose closest path passes through the swapped qubit link has its
103-
// "virtual-qubit path" order changed, but not the total weight. In theory, we should
104-
// never consider the same gate in both `if let` branches, because if we did, the gate would
105-
// already be routable. It doesn't matter, though, because the two distances would be
106-
// equal anyway, so not affect the score.
103+
// At most there can be two affected gates in the layer (one on each qubit in the swap),
104+
// since any gate whose closest path passes through the swapped qubit link has its
105+
// "virtual-qubit path" order changed, but not the total weight.
107106
let [a, b] = swap;
108107
let mut total = 0.0;
109108
if let Some((_, c)) = self.qubits[a] {
@@ -118,7 +117,7 @@ impl Layer {
118117
total
119118
}
120119

121-
/// Calculate the total absolute of the current front layer on the given layer.
120+
/// Calculate the total absolute score of the layer for the set layout.
122121
pub fn total_score(&self, dist: &ArrayView2<f64>) -> f64 {
123122
self.iter()
124123
.map(|(_, &[a, b])| dist[[a.index(), b.index()]])

test/python/transpiler/test_sabre_swap.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ def test_do_not_reorder_measurements(self):
312312
def test_no_infinite_loop(self):
313313
"""Test that the 'release value' mechanisms allow SabreSwap to make progress even on
314314
circuits that get stuck in a stable local minimum of the lookahead parameters."""
315-
# This is an approximation to the "lookahaed" heuristic described by the original Sabre
315+
# This is an approximation to the "lookahead" heuristic described by the original Sabre
316316
# paper. For the particular circuit we're using, the layer-based lookahead Qiskit uses is
317317
# the same as the max-size depth-agnostic set of the original Sabre paper, since there's
318318
# only two (disjoint) gates that aren't in the front layer. We use this here because

0 commit comments

Comments
 (0)