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

Fix performance of Sabre rust<->Python boundary (backport #10652) #10659

Merged
merged 1 commit into from Aug 17, 2023

Conversation

mergify[bot]
Copy link
Contributor

@mergify mergify bot commented Aug 17, 2023

This is an automatic backport of pull request #10652 done by Mergify.


Mergify commands and options

More conditions and actions can be found in the documentation.

You can also trigger Mergify actions by commenting on this pull request:

  • @Mergifyio refresh will re-evaluate the rules
  • @Mergifyio rebase will rebase this PR on its base branch
  • @Mergifyio update will merge the base branch into this PR
  • @Mergifyio backport <destination> will backport this PR on <destination> branch

Additionally, on Mergify dashboard you can:

  • look at your merge queues
  • generate the Mergify configuration with the config editor.

Finally, you can contact us on https://mergify.com

* Fix performance of Sabre rust<->Python boundary

In #10366 the SabreLayout and SabreSwap passes were refactored to
support nested control flow blocks. As part of that refactor a new
struct SabreResult was created to store the nested results for each
block. This new class however resulted in PyO3 cloning the full swap map
on every access. Since we have at least 1 access per gate in the circuit
(and another one for each swap) this extra clone() adds a lot of extra
overhead for deep circuits. In extreme cases this regression could be
quite extreme. To address this the result format is changed to be a
tuple (as it was originally), while this is less ergonomic the advantage
it provides is that for nested objects it moves the rust object to the
pyo3 interface so we avoid a copy as Python owns the object on the
return. However, for control flow blocks we're still using the
SabreResult class as it simplifies the internal implementation (which is
why #10366 introduced the struct). The potential impact of this is
mitigated by switching to only a single clone per control flow block,
by only accessing the SabreResult object's attribute on each recursive
call. However, if it is an issue in the future we can work on flattening
the nested structure before returning it to python to avoid any clones.

Fixes #10650

* Simplify recursive call logic in _apply_sabre_result

This commit simplifies the logic in the recursive call logic in
_apply_sabre_result to always use a tuple so we avoid an isinstance
check.

Co-authored-by: Kevin Hartman <kevin@hart.mn>

---------

Co-authored-by: Kevin Hartman <kevin@hart.mn>
(cherry picked from commit e6c431e)
@mergify mergify bot requested a review from a team as a code owner August 17, 2023 16:54
@qiskit-bot
Copy link
Collaborator

Thank you for opening a new pull request.

Before your PR can be merged it will first need to pass continuous integration tests and be reviewed. Sometimes the review process can be slow, so please be patient.

While you're waiting, please feel free to review other open PRs. While only a subset of people are authorized to approve pull requests for merging, everyone is encouraged to review open pull requests. Doing reviews helps reduce the burden on the core team and helps make the project's code better for everyone.

One or more of the the following people are requested to review this:

@mtreinish mtreinish added the Changelog: Bugfix Include in the "Fixed" section of the changelog label Aug 17, 2023
@mtreinish mtreinish added this to the 0.25.1 milestone Aug 17, 2023
@mtreinish mtreinish mentioned this pull request Aug 17, 2023
3 tasks
@mtreinish mtreinish added this pull request to the merge queue Aug 17, 2023
@coveralls
Copy link

Pull Request Test Coverage Report for Build 5893722836

  • 25 of 25 (100.0%) changed or added relevant lines in 3 files are covered.
  • 17 unchanged lines in 3 files lost coverage.
  • Overall coverage decreased (-0.01%) to 87.228%

Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/expr.rs 1 93.76%
crates/qasm2/src/lex.rs 4 90.89%
crates/qasm2/src/parse.rs 12 95.74%
Totals Coverage Status
Change from base Build 5893372895: -0.01%
Covered Lines: 74091
Relevant Lines: 84939

💛 - Coveralls

Merged via the queue into stable/0.25 with commit 8f4bc5e Aug 17, 2023
15 checks passed
@mergify mergify bot deleted the mergify/bp/stable/0.25/pr-10652 branch August 17, 2023 19:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: Bugfix Include in the "Fixed" section of the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants