-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Avoid deepcopy in sabre_swap #5316
Merged
Merged
Conversation
This file contains 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
This commit changes the deepcopy usage in the sabreswap pass to a shallow copy. In sabre_swap the deepcopy was run on the DAGCircuit node when remapping it, however this was not necessary because it's not actually used where shared references matter. The output from the remapper is not used directly and instead a copy of the DAGNode object is just used as a container for the required args in apply_operation_back() where a new DAGNode is always created from the op, qargs, etc. The remapping just replaces the qargs parameter with the remapped one. So this commit changes the deepcopy to a shallow copy which won't have the performance overhead. Fixes Qiskit#5197
ajavadia
approved these changes
Nov 2, 2020
mergify bot
pushed a commit
that referenced
this pull request
Nov 2, 2020
This commit changes the deepcopy usage in the sabreswap pass to a shallow copy. In sabre_swap the deepcopy was run on the DAGCircuit node when remapping it, however this was not necessary because it's not actually used where shared references matter. The output from the remapper is not used directly and instead a copy of the DAGNode object is just used as a container for the required args in apply_operation_back() where a new DAGNode is always created from the op, qargs, etc. The remapping just replaces the qargs parameter with the remapped one. So this commit changes the deepcopy to a shallow copy which won't have the performance overhead. Fixes #5197 Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> (cherry picked from commit a506ba9)
mergify bot
added a commit
that referenced
this pull request
Nov 3, 2020
This commit changes the deepcopy usage in the sabreswap pass to a shallow copy. In sabre_swap the deepcopy was run on the DAGCircuit node when remapping it, however this was not necessary because it's not actually used where shared references matter. The output from the remapper is not used directly and instead a copy of the DAGNode object is just used as a container for the required args in apply_operation_back() where a new DAGNode is always created from the op, qargs, etc. The remapping just replaces the qargs parameter with the remapped one. So this commit changes the deepcopy to a shallow copy which won't have the performance overhead. Fixes #5197 Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> (cherry picked from commit a506ba9) Co-authored-by: Matthew Treinish <mtreinish@kortar.org> Co-authored-by: Luciano Bello <luciano.bello@ibm.com>
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.
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>
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
stable backport potential
The bug might be minimal and/or import enough to be port to stable
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
This commit changes the deepcopy usage in the sabreswap pass to a
shallow copy. In sabre_swap the deepcopy was run on the DAGCircuit node
when remapping it, however this was not necessary because it's not
actually used where shared references matter. The output from the
remapper is not used directly and instead a copy of the DAGNode object
is just used as a container for the required args in
apply_operation_back() where a new DAGNode is always created from the
op, qargs, etc. The remapping just replaces the qargs parameter with the
remapped one. So this commit changes the deepcopy to a shallow copy
which won't have the performance overhead.
Details and comments
Fixes #5197