Skip to content

Commit

Permalink
Correctly apply selected layout on dag nodes
Browse files Browse the repository at this point in the history
This commit corrects a bug in the PR branch that was caused by applying
the selected initial layout in a trial to the swapped order node list.
This was causing unexpected results when applying the circuit because
the intent was to apply it only to the original input not the reversed
input.
  • Loading branch information
mtreinish committed Nov 14, 2022
1 parent 5dbd76b commit d98ef6c
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/sabre_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,11 @@ fn layout_trial(
std::mem::swap(&mut dag_nodes, &mut rev_dag_nodes);
}
}
let layout_dag = apply_layout(&dag_nodes, &initial_layout, num_physical_qubits, num_clbits);
// Reverse the circuit back to avoid replaying the circuit in reverse order.
// the output of the loop above will always have the reverse order nodes set
// to dag_nodes. So one more swap is needed to restore the original order
std::mem::swap(dag_nodes, &mut rev_dag_nodes);
let layout_dag = apply_layout(dag_nodes, &initial_layout, num_physical_qubits, num_clbits);
let mut final_layout = initial_layout.clone();
let (swap_map, gate_order) = build_swap_map_inner(
num_physical_qubits,
Expand Down

0 comments on commit d98ef6c

Please sign in to comment.