Skip to content

Conversation

mtreinish
Copy link
Member

Summary

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
with sabre 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.

Details and comments

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.
@mtreinish mtreinish added on hold Can not fix yet performance labels Nov 16, 2020
@mtreinish mtreinish requested a review from a team as a code owner November 16, 2020 21:15
@mtreinish
Copy link
Member Author

Still need to benchmark this to see if it actually makes a difference or not. Since to really see the bottleneck we need a bunch of PRs at once I'll have to setup an environment to benchmark this reliably.

Copy link
Contributor

@itoko itoko left a comment

Choose a reason for hiding this comment

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

LGTM. Just a tiny comment.

Comment on lines 318 to 320
if self.coupling_map._dist_matrix is None:
self.coupling_map._compute_distance_matrix()
return self.coupling_map._dist_matrix[
Copy link
Contributor

Choose a reason for hiding this comment

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

It might be better to put these lines to dist_matrix property in CouplingMap class (if we don't mind one function call).

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, that's a good idea. I made this change in: 8df570f

@mtreinish mtreinish removed the on hold Can not fix yet label Nov 18, 2020
@mergify mergify bot merged commit 2a40c62 into Qiskit:master Nov 25, 2020
@mtreinish mtreinish deleted the use-numpy-sum-sabre branch November 26, 2020 15:53
@kdk kdk added the Changelog: None Do not include in changelog label Mar 31, 2021
@mtreinish mtreinish mentioned this pull request Jun 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: None Do not include in changelog performance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants