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

Make dense layout algorithm deterministic when run in parallel (backport #13133) #13190

Merged
merged 1 commit into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 7 additions & 2 deletions crates/accelerate/src/dense_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ struct SubsetResult {
pub error: f64,
pub map: Vec<usize>,
pub subgraph: Vec<[usize; 2]>,
pub index: usize,
}

fn bfs_sort(adj_matrix: ArrayView2<f64>, start: usize, num_qubits: usize) -> Vec<usize> {
Expand Down Expand Up @@ -190,6 +191,7 @@ pub fn best_subset_inner(
error,
map: bfs,
subgraph,
index: k,
}
};

Expand All @@ -199,17 +201,20 @@ pub fn best_subset_inner(
map: Vec::new(),
error: f64::INFINITY,
subgraph: Vec::new(),
index: usize::MAX,
}
};

let reduce_fn = |best: SubsetResult, curr: SubsetResult| -> SubsetResult {
if use_error {
if curr.count >= best.count && curr.error < best.error {
if (curr.count >= best.count && curr.error < best.error)
|| (curr.count == best.count && curr.error == best.error && curr.index < best.index)
{
curr
} else {
best
}
} else if curr.count > best.count {
} else if curr.count > best.count || (curr.count == best.count && curr.index < best.index) {
curr
} else {
best
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
fixes:
- |
Fixed a potential source of non-determinism in :class:`~.DenseLayout` (and
by extension :class:`~.SabreLayout`) when targeting a
:class:`.CouplingMap` or :class:`.Target` that has more than one subgraph
with the same degree of connectivity. In these case the exact output
layout from the pass could previously fluctuate based on the number of
local CPUs and thread execution speed.
Loading