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 ReverseEstimatorGradient for partial gradients #9491

Merged
merged 3 commits into from
Jan 31, 2023

Conversation

Cryoris
Copy link
Contributor

@Cryoris Cryoris commented Jan 31, 2023

Summary

The ReverseEstimatorGradient did a lot of unnecessary copies if the circuit contained many gates with respect to whose parameter we didn't derive. That meant that e.g. computing all derivatives of a 100-parameter circuit was faster than computing only a single derivative.

Details and comments

The circuit splitting used

subcircuit.data += [instruction]

instead of just subcircuit.append. The first seems to copy all circuit instructions, which gets very expensive if called many times.

Here's a profiling for computing 7 of ~100 parameters in an EfficientSU2 circuit before the fix:
image
and after
image

@Cryoris Cryoris added stable backport potential The bug might be minimal and/or import enough to be port to stable performance Changelog: Bugfix Include in the "Fixed" section of the changelog labels Jan 31, 2023
@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:

Copy link
Contributor

@ElePT ElePT left a comment

Choose a reason for hiding this comment

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

The PR LGTM, I know that the low performance has been an issue to run certain experiments, and it's great that you fixed it so fast!!!

Copy link
Member

@jakelishman jakelishman left a comment

Choose a reason for hiding this comment

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

Absolutely lol at that performance, haha. It happens because there's no __iadd__ method defined for QuantumCircuitData, so the whole list gets copied and reassigned by +=.

It's a shooting offence to mutate QuantumCircuit.data directly.

@mergify mergify bot merged commit 729f7d1 into Qiskit:main Jan 31, 2023
mergify bot pushed a commit that referenced this pull request Jan 31, 2023
…#9491)

* Use append over +=

* add reno

(cherry picked from commit 729f7d1)
mergify bot added a commit that referenced this pull request Jan 31, 2023
…#9491) (#9492)

* Use append over +=

* add reno

(cherry picked from commit 729f7d1)

Co-authored-by: Julien Gacon <gaconju@gmail.com>
@Cryoris Cryoris deleted the fix-partial-reverse branch January 31, 2023 14:04
@coveralls
Copy link

Pull Request Test Coverage Report for Build 4053970489

  • 7 of 7 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 85.264%

Totals Coverage Status
Change from base Build 4028718413: 0.0%
Covered Lines: 67013
Relevant Lines: 78595

💛 - Coveralls

ElePT pushed a commit to ElePT/qiskit that referenced this pull request Jun 27, 2023
ElePT pushed a commit to ElePT/qiskit-algorithms-test that referenced this pull request Jul 17, 2023
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 performance stable backport potential The bug might be minimal and/or import enough to be port to stable
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants