-
Notifications
You must be signed in to change notification settings - Fork 121
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
Conversation
…and QubitMapping data structures, and implement the swap update algorithm
…UpdateTransformer
…nd add test coverage for previously untested public functions
…nhattan distance in the swap updater
There was a problem hiding this 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.
recirq/quantum_chess/swap_updater.py
Outdated
# 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). |
There was a problem hiding this comment.
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?)
There was a problem hiding this comment.
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.
recirq/quantum_chess/swap_updater.py
Outdated
# 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 :)
this makes the swap updater work on devices that aren't regular grids and fixes #149