@@ -18,9 +18,11 @@ use qiskit_circuit::PhysicalQubit;
1818
1919use 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 {
4042impl 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 ( ) ] ] )
0 commit comments