-
Notifications
You must be signed in to change notification settings - Fork 131
Use marginal_distribution() instead of marginal_counts() #1144
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
Use marginal_distribution() instead of marginal_counts() #1144
Conversation
This commit updates the Qiskit marginalization function used in qiskit-experiments. Qiskit has 2 different function available for marginalizing counts: `marginal_counts()` [1] which is designed to work with `Counts` or `Result` objects and does **not** respect ordering of the indices passed in. The other is `marginal_distribution()` [2] which is designed to work with `Counts`, `Probabilities`, `QuasiProbabilities`, or a dictionary with string keys and integer or float values that respects the order of the indices passed in (so it can be used to permute the bits). In general if you're not working with a `Result` object it is better to use `marginal_distribution()` because it is written primarily in Rust and 10-100x faster than `marginal_counts()`. [1] https://qiskit.org/documentation/stubs/qiskit.result.marginal_counts.html [2] https://qiskit.org/documentation/stubs/qiskit.result.marginal_distribution.html
The other function which I thought we added for experiments but I didn't see anything that looked similar through some quick grepping is |
Oh interesting it's failing because the value type is |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Matthew. This looks good to me. In my local profiling with a composite curve analysis for parallel 27 qubit Rabi experiment, this PR reduces total processing time from 15.0s to 9.26s (roughly 40% time reduction). This is awesome improvement.
Since Qiskit/qiskit#9976 is going to be merged, do you want to remove safety typecast and turn this into on hold until next Terra release? Otherwise I'll merge.
I guess it depends on whether you think we should backport this for a potential 0.5.1 or not? If you want to include it for 0.5.1 and backport it we should leave it as is. But if you just want to save it for 0.6.0 lets just wait for the terra release when we can bump the minimum qiskit-terra version to 0.24.0 and remove the type cast. |
I think this should be released with 0.6 because this |
Ok, then I'll mark this as on hold then. I'll update this after the 0.24.0 release in a a couple of weeks to remove the type cast and update the minimum terra version to 0.24.0 |
We decided to include this in the 0.5.2 release since users have been asking for more performance improvements on large experiments. Once Terra 0.24 is released and this is updated and merged I'll tag the patch release. Can you also add a release note when you update this @mtreinish? |
I think for a patch release you probably don't want to bump the minimum qiskit-terra version for this (unless you need to for other reasons) just so you're not requiring people to bump their installed terra version to get the fixes in 0.5.2. |
The key behavioral difference for the marginal_distribution() function is that the input order of the bits of interest is significant and the bits are passed in out of order this will permute the output from the marginalization function. In the process tomography case the bits of interest aren't always in order and if they're out of order the output doesn't match the expected format. To correct this prior to calling marginal_distribution() this commit sorts the bits of interest to ensure the output order is as expected by the fitter.
@mtreinish You're right, I got mixed up there, our decision was actually to include this in the 0.5.2 release without bumping the required terra version to 0.24. @nkanazawa1989 are you ok with merging this as is? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please merge this for patch release. Once we bump terra version we should remove the typecast logic (it is another slight performance regression).
### Summary This commit updates the Qiskit marginalization function used in qiskit-experiments. Qiskit has 2 different function available for marginalizing counts: `marginal_counts()` [1] which is designed to work with `Counts` or `Result` objects and does **not** respect ordering of the indices passed in. The other is `marginal_distribution()` [2] which is designed to work with `Counts`, `Probabilities`, `QuasiProbabilities`, or a dictionary with string keys and integer or float values that respects the order of the indices passed in (so it can be used to permute the bits). In general if you're not working with a `Result` object it is better to use `marginal_distribution()` because it is written primarily in Rust and 10-100x faster than `marginal_counts()`. ### Details and comments [1] https://qiskit.org/documentation/stubs/qiskit.result.marginal_counts.html [2] https://qiskit.org/documentation/stubs/qiskit.result.marginal_distribution.html (cherry picked from commit 10b6182)
) (#1166) This is an automatic backport of pull request #1144 done by [Mergify](https://mergify.com). Co-authored-by: Matthew Treinish <[email protected]>
Summary
This commit updates the Qiskit marginalization function used in qiskit-experiments. Qiskit has 2 different function available for marginalizing counts:
marginal_counts()
[1] which is designed to work withCounts
orResult
objects and does not respect ordering of the indices passed in. The other ismarginal_distribution()
[2] which is designed to work withCounts
,Probabilities
,QuasiProbabilities
, or a dictionary with string keys and integer or float values that respects the order of the indices passed in (so it can be used to permute the bits). In general if you're not working with aResult
object it is better to usemarginal_distribution()
because it is written primarily in Rust and 10-100x faster thanmarginal_counts()
.Details and comments
[1] https://qiskit.org/documentation/stubs/qiskit.result.marginal_counts.html
[2] https://qiskit.org/documentation/stubs/qiskit.result.marginal_distribution.html