Skip to content

Commit

Permalink
Remove branching from extended-set scoring
Browse files Browse the repository at this point in the history
On modern hardware, branching is typically more expensive than a simple
floating-point addition that can be pipelined in.  This removes the
branch in favour of removing the duplication from the scoring at the end
by dividing by two.
  • Loading branch information
jakelishman committed Sep 20, 2023
1 parent 4e44644 commit 0475b3b
Showing 1 changed file with 3 additions and 13 deletions.
16 changes: 3 additions & 13 deletions crates/accelerate/src/sabre_swap/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,21 +226,11 @@ impl ExtendedSet {
self.qubits
.iter()
.enumerate()
.map(move |(a_index, others)| {
others
.iter()
.map(|b| {
let b_index = b.index();
if a_index <= b_index {
dist[[a_index, b_index]]
} else {
0.0
}
})
.sum::<f64>()
.flat_map(move |(a_index, others)| {
others.iter().map(move |b| dist[[a_index, b.index()]])
})
.sum::<f64>()
/ self.len as f64
/ (2.0 * self.len as f64) // Factor of two is to remove double-counting of each gate.
}

/// Clear all nodes from the extended set.
Expand Down

0 comments on commit 0475b3b

Please sign in to comment.