Remove list searches in CouplingMap.distance()#5294
Merged
mergify[bot] merged 12 commits intoQiskit:masterfrom Dec 4, 2020
Merged
Remove list searches in CouplingMap.distance()#5294mergify[bot] merged 12 commits intoQiskit:masterfrom
mergify[bot] merged 12 commits intoQiskit:masterfrom
Conversation
Previously, the CouplingMap.distance() method was checking whether the qubit number was in the coupling graph by searching over a list for the coupling map indices. This search becomes a bottleneck at large qubit numbers because in the worst case it has to traverse the entire list to find a match. This also is unecessary because the coupling map indices are always an ordered range from 0 to n for n qubits. This commit fixes this bottleneck by updating the check to just error if the index is out of bounds for the size of the graph. Related to Qiskit#5197
mtreinish
added a commit
to mtreinish/qiskit-core
that referenced
this pull request
Nov 16, 2020
In sabre_swap the comprehension in _score_heuristic() with the basic heuristic starts to become a bottleneck as the size of the coupling map increases. This probably becomes the top bottleneck in a transpilation after Qiskit#5316, Qiskit#5183, Qiskit#5294, Qiskit#5267, and Qiskit#5272 are merged. This commit is an attempt to try and mitigate that a bit by using numpy native operations instead of a python comprehension in sum(). If this is insufficient we'll likely have to either avoid doing a sum like this or drop down to a lower level with cython or rust and operate on the array directly to remove this bottleneck.
kdk
reviewed
Nov 24, 2020
Member
kdk
left a comment
There was a problem hiding this comment.
Can you update the docstring to point out that qubit indices need to be consecutive, non-negative integers (e.g. that holes aren't supported, and indices omitted from the couplinglist will be implicitly added)?
Comment on lines
+178
to
+181
| if physical_qubit1 >= self.size(): | ||
| raise CouplingError("%s not in coupling graph" % physical_qubit1) | ||
| if physical_qubit2 >= self.size(): | ||
| raise CouplingError("%s not in coupling graph" % physical_qubit2) |
Member
There was a problem hiding this comment.
Would it make sense to likewise check if0 > physical_qubit1 here?
ajavadia
previously approved these changes
Nov 25, 2020
mergify Bot
added a commit
that referenced
this pull request
Nov 25, 2020
* Use numpy sum instead of comprehension in _score_heuristic In sabre_swap the comprehension in _score_heuristic() with the basic heuristic starts to become a bottleneck as the size of the coupling map increases. This probably becomes the top bottleneck in a transpilation after #5316, #5183, #5294, #5267, and #5272 are merged. This commit is an attempt to try and mitigate that a bit by using numpy native operations instead of a python comprehension in sum(). If this is insufficient we'll likely have to either avoid doing a sum like this or drop down to a lower level with cython or rust and operate on the array directly to remove this bottleneck. * Make distance matrix a coupling map property * Fix tests * Fix lint Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1ucian0
approved these changes
Dec 4, 2020
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Previously, the
CouplingMap.distance()method was checking whether thequbit number was in the coupling graph by searching over a list for the
coupling map indices. This search becomes a bottleneck at large qubit
numbers because in the worst case it has to traverse the entire list to
find a match. This also is unnecessary because the coupling map indices
are always an ordered range from 0 to n for n qubits. This commit fixes
this bottleneck by updating the check to just error if the index is out
of bounds for the size of the graph.
Details and comments
Related to #5197