-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Improve performance of CircuitData::__getitem__
#11842
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
The order of the variants in `SliceOrInt` determines which is tried first by the `FromPyObject` derivation. `Int` is more common in like 99.9+% of cases, so wants to be first.
jakelishman
added
stable backport potential
The bug might be minimal and/or import enough to be port to stable
performance
Changelog: None
Do not include in changelog
Rust
This PR or issue is related to Rust code in the repository
mod: circuit
Related to the core of the `QuantumCircuit` class or the circuit library
labels
Feb 20, 2024
One or more of the the following people are requested to review this:
|
mtreinish
approved these changes
Feb 20, 2024
Pull Request Test Coverage Report for Build 7978537934Details
💛 - Coveralls |
mergify bot
pushed a commit
that referenced
this pull request
Feb 20, 2024
The order of the variants in `SliceOrInt` determines which is tried first by the `FromPyObject` derivation. `Int` is more common in like 99.9+% of cases, so wants to be first. (cherry picked from commit 6a8bdb7)
mtreinish
added a commit
to mtreinish/qiskit-core
that referenced
this pull request
Feb 20, 2024
After doing some post-merge analysis on the impact of Qiskit#11842 it turns out the enum being modified in that PR was duplicated in the rust code unnecessarily. The same enum was already defined in the euler_one_qubit_decomposer module for it's custom 1 qubit gate sequence return type. This commit updates the code so it just use the one defined in the circuit data module that has the fix from Qiskit#11842 applied already.
github-merge-queue bot
pushed a commit
that referenced
this pull request
Feb 20, 2024
The order of the variants in `SliceOrInt` determines which is tried first by the `FromPyObject` derivation. `Int` is more common in like 99.9+% of cases, so wants to be first. (cherry picked from commit 6a8bdb7) Co-authored-by: Jake Lishman <jake.lishman@ibm.com>
github-merge-queue bot
pushed a commit
that referenced
this pull request
Feb 21, 2024
* Deduplicate SliceOrInt After doing some post-merge analysis on the impact of #11842 it turns out the enum being modified in that PR was duplicated in the rust code unnecessarily. The same enum was already defined in the euler_one_qubit_decomposer module for it's custom 1 qubit gate sequence return type. This commit updates the code so it just use the one defined in the circuit data module that has the fix from #11842 applied already. * Move enum to common location
mergify bot
pushed a commit
that referenced
this pull request
Feb 21, 2024
* Deduplicate SliceOrInt After doing some post-merge analysis on the impact of #11842 it turns out the enum being modified in that PR was duplicated in the rust code unnecessarily. The same enum was already defined in the euler_one_qubit_decomposer module for it's custom 1 qubit gate sequence return type. This commit updates the code so it just use the one defined in the circuit data module that has the fix from #11842 applied already. * Move enum to common location (cherry picked from commit 802ac51)
github-merge-queue bot
pushed a commit
that referenced
this pull request
Feb 21, 2024
* Deduplicate SliceOrInt After doing some post-merge analysis on the impact of #11842 it turns out the enum being modified in that PR was duplicated in the rust code unnecessarily. The same enum was already defined in the euler_one_qubit_decomposer module for it's custom 1 qubit gate sequence return type. This commit updates the code so it just use the one defined in the circuit data module that has the fix from #11842 applied already. * Move enum to common location (cherry picked from commit 802ac51) Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
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
mod: circuit
Related to the core of the `QuantumCircuit` class or the circuit library
performance
Rust
This PR or issue is related to Rust code in the repository
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
The order of the variants in
SliceOrInt
determines which is tried first by theFromPyObject
derivation.Int
is more common in like 99.9+% of cases, so wants to be first.Details and comments
For the microbenchmark:
I saw the timings go from ~350ns on my machine to ~280ns with the PR, which is a 20% improvement. That's not as impressive as Qiskit/rustworkx#1096 because we're doing more object-generation work here within the method, but still nothing to sneeze at for a one-line change.
edit: having looked closer - I made this in a big rush at the end of the day, having just spotted the problem on Rustworkx - there's no reason
__getitem__
should have shown a speedup here; it manually avoids usingSliceOrInt
(quite possibly for the exact reason of this PR). Running the numbers again just now (post merge) showed the same behaviour for both this PR and its parent, so it might just be I was tricked by thermal throttling the first time around. Still, this PR should improve__setitem__
and__delitem__
.