diff --git a/crates/accelerate/src/sabre_swap/mod.rs b/crates/accelerate/src/sabre_swap/mod.rs index 16176b5a6a85..2d4dc40481e1 100644 --- a/crates/accelerate/src/sabre_swap/mod.rs +++ b/crates/accelerate/src/sabre_swap/mod.rs @@ -171,11 +171,12 @@ fn populate_extended_set( let mut decremented: IndexMap = IndexMap::with_hasher(ahash::RandomState::default()); let mut i = 0; + let mut visit_now: Vec = Vec::new(); while i < to_visit.len() && extended_set.len() < EXTENDED_SET_SIZE { // 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]]; + visit_now.push(to_visit[i]); let mut j = 0; while let Some(node) = visit_now.get(j) { for edge in dag.dag.edges_directed(*node, Direction::Outgoing) { @@ -185,7 +186,8 @@ fn populate_extended_set( required_predecessors[successor_index] -= 1; if required_predecessors[successor_index] == 0 { if !dag.dag[successor_node].directive - && !dag.node_blocks.contains_key(&successor_index) { + && !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); @@ -197,6 +199,7 @@ fn populate_extended_set( } j += 1; } + visit_now.clear(); i += 1; } for (node, amount) in decremented.iter() {