Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Sabre extended set population order #10651

Merged
merged 2 commits into from
Nov 29, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Visit runs of 1Q gates before next 2Q.
  • Loading branch information
kevinhartman committed Nov 27, 2023
commit 43f016711f2dc47f231035917b363c06bafd78f5
33 changes: 21 additions & 12 deletions crates/accelerate/src/sabre_swap/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,21 +172,30 @@ fn populate_extended_set(
IndexMap::with_hasher(ahash::RandomState::default());
let mut i = 0;
while i < to_visit.len() && extended_set.len() < EXTENDED_SET_SIZE {
for edge in dag.dag.edges_directed(to_visit[i], Direction::Outgoing) {
let successor_node = edge.target();
let successor_index = successor_node.index();
*decremented.entry(successor_index).or_insert(0) += 1;
required_predecessors[successor_index] -= 1;
if required_predecessors[successor_index] == 0 {
if !dag.dag[successor_node].directive
&& !dag.node_blocks.contains_key(&successor_index)
{
if let [a, b] = dag.dag[successor_node].qubits[..] {
extended_set.push([a.to_phys(layout), b.to_phys(layout)]);
// Visit runs of non-2Q gates fully before moving on to children
// of 2Q gates. This way, traversal order is a BFS of 2Q gates rather
// than of all gates.
let mut visit_now = vec![to_visit[i]];
kevinhartman marked this conversation as resolved.
Show resolved Hide resolved
let mut j = 0;
while let Some(node) = visit_now.get(j) {
for edge in dag.dag.edges_directed(*node, Direction::Outgoing) {
let successor_node = edge.target();
let successor_index = successor_node.index();
*decremented.entry(successor_index).or_insert(0) += 1;
required_predecessors[successor_index] -= 1;
if required_predecessors[successor_index] == 0 {
if !dag.dag[successor_node].directive
&& !dag.node_blocks.contains_key(&successor_index) {
if let [a, b] = dag.dag[successor_node].qubits[..] {
extended_set.push([a.to_phys(layout), b.to_phys(layout)]);
to_visit.push(successor_node);
continue;
}
}
visit_now.push(successor_node);
}
to_visit.push(successor_node);
}
j += 1;
}
i += 1;
}
Expand Down