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 SwapUpdater precompute all the qubit-to-qubit shortest path lengths #151

Merged
merged 16 commits into from
Mar 31, 2021

Conversation

weinstein
Copy link
Contributor

this makes the swap updater work on devices that aren't regular grids and fixes #149

@weinstein weinstein requested review from wingers and dstrain115 March 2, 2021 02:15
@weinstein weinstein added the chess label Mar 2, 2021
@weinstein weinstein marked this pull request as ready for review March 2, 2021 02:16
@weinstein weinstein requested a review from cantwellc March 23, 2021 16:41
Copy link
Collaborator

@dstrain115 dstrain115 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with minor comments.

# the Floyd-Warshall algorithm which is O(v**3).
# This won't work if in the future we figure out a way to incorporate edge
# weights (for example in order to give negative preference to gates with poor
# calibration metrics).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional: should we put this comment into the docstring where it is more visibile?
(Or do you think it is so implementation-specific that it belongs in the code?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's worth adding a comment about the runtime complexity to the docstring, but I'd avoid adding more details about the implementation beyond that.

# Do BFS starting from each qubit and collect the shortest path lengths as
# we go.
# For device graphs where all edges are the same (where each edge can be
# treated as unit length) repeated BFS is O(v**2) and is faster than
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is exponential in the number of edges, should we consider aborting if the number of edges is above a sanity limit? If you believe the hype, we are not that far away from much larger qubit counts.

Copy link
Contributor Author

@weinstein weinstein Mar 31, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

each round of bfs visits each vertex and edge at most once so O(V+E), and we do bfs V times. That's O(V^2 + V E) ie quadratic in the number of edges and vertices, not exponential

Assuming with bigger devices qubits are still likely to be locally connected (like grids where the device graph is sparse and edges per vertex bounded by a constant) then E is O(V) and this function is O(V^2) overall. Not sure if that assumption will withstand the test of time, but at least on a graph of 'GridQubit' it seems like a safe assumption. Even a fully connected graph would have at most V^2 edges making repeated bfs cubic in the number of qubits O(V^3) not exponential.

We're precomputing O(V^2) vertex-to-vertex distance values so it is highly unlikely that we'll be able to do any better on sparse device graphs or grids :)

@weinstein weinstein merged commit 5842d9f into quantumlib:master Mar 31, 2021
@weinstein weinstein deleted the issue149 branch April 1, 2021 17:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update SwapUpdater to use computed shortest path length instead of Manhattan distance
2 participants