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 shots argument of local_readout_mitigator #9155

Merged
merged 14 commits into from
Nov 24, 2022

Conversation

peendebak
Copy link
Contributor

Summary

  • The LocalReadoutMitigator.quasi_probabilities method has an argument shots which is not used in the method. The docstring us updated for this
  • The method returns an object of type QuasiDistribution. The number of shots is set on that object
  • The documentation on the return type of counts_probability_vector is updated.

Fixes #9154

Details and comments

@peendebak peendebak requested a review from a team as a code owner November 17, 2022 15:33
@qiskit-bot qiskit-bot added the Community PR PRs from contributors that are not 'members' of the Qiskit repo label Nov 17, 2022
@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:

  • @Qiskit/terra-core

@coveralls
Copy link

coveralls commented Nov 17, 2022

Pull Request Test Coverage Report for Build 3544051628

  • 6 of 6 (100.0%) changed or added relevant lines in 2 files are covered.
  • 7 unchanged lines in 3 files lost coverage.
  • Overall coverage increased (+0.05%) to 84.556%

Files with Coverage Reduction New Missed Lines %
qiskit/extensions/quantum_initializer/squ.py 2 79.78%
src/sabre_swap/layer.rs 2 98.95%
src/vf2_layout.rs 3 94.74%
Totals Coverage Status
Change from base Build 3542917032: 0.05%
Covered Lines: 62843
Relevant Lines: 74321

💛 - Coveralls

Copy link
Contributor

@Cryoris Cryoris left a comment

Choose a reason for hiding this comment

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

I'm not an expert here, but I'm not sure this makes sense: in QuasiDistribution the number of shots is provided as integer. Here it is a boolean? It seems like either the argument type here should also be an integer, otherwise it cannot be safely passed to the QuasiDistribution.

@peendebak
Copy link
Contributor Author

I'm not an expert here, but I'm not sure this makes sense: in QuasiDistribution the number of shots is provided as integer. Here it is a boolean? It seems like either the argument type here should also be an integer, otherwise it cannot be safely passed to the QuasiDistribution.

The argument shots of the quasi_probabilities method is annotated as a boolean, but it is was not used at all. In the base class it is indeed annotated as an int. I modified the PR to set the number of shots as an int.

If the value of shots is not None, then it is used as is, otherwise it is calculated as:

probs_vec, shots = counts_probability_vector(
            data, qubit_index=self._qubit_index, clbits=clbits, qubits=qubits
        )

I am not sure what the value of a non-default value for the shots argument is. @ShellyGarion You introduced this code in #6485. Why do we need the shots argument in the quasi_probabilities method?

@ShellyGarion
Copy link
Member

@gadial
Copy link
Contributor

gadial commented Nov 21, 2022

I'm not sure I understand what user-supplied shots actually mean in this context. The number of shots can be computed (as you do) from the counts data; passing other shots value not consistent with the count data cannot yield meaningful results, unless I'm missing something.

Currently I think the parameter should simply be omitted.

@peendebak
Copy link
Contributor Author

@gadial @ShellyGarion I will remove the shots argument, as it can be calculated from the data and any other value would not make sense.

Should we remove it altogether, or add a deprecation warning?

@ShellyGarion
Copy link
Member

If you remove shots then it will require a deprecation warning, since it's part of the API:
https://qiskit.org/documentation/stubs/qiskit.result.LocalReadoutMitigator.quasi_probabilities.html#qiskit.result.LocalReadoutMitigator.quasi_probabilities

However, I am not sure if the number of shots can always be calculated from the counts, as the Counts object does not necessarily have to be a dictionary of integers (it can also contain probabilities or quasi-probabilities, I think).

@peendebak
Copy link
Contributor Author

If you remove shots then it will require a deprecation warning, since it's part of the API: https://qiskit.org/documentation/stubs/qiskit.result.LocalReadoutMitigator.quasi_probabilities.html#qiskit.result.LocalReadoutMitigator.quasi_probabilities

However, I am not sure if the number of shots can always be calculated from the counts, as the Counts object does not necessarily have to be a dictionary of integers (it can also contain probabilities or quasi-probabilities, I think).

Ok, in that case I will leave keep the argument (just update the typing from bool to int)

@ShellyGarion ShellyGarion self-requested a review November 21, 2022 15:55
@ShellyGarion
Copy link
Member

@peendebak - thanks for fixing this!
Perhaps it's worth to add a test to check that shots is handled OK now?
The tests are located here: https://github.com/Qiskit/qiskit-terra/blob/main/test/python/result/test_mitigators.py

@ShellyGarion ShellyGarion added this to the 0.23.0 milestone Nov 23, 2022
@ShellyGarion ShellyGarion self-requested a review November 24, 2022 15:19
ShellyGarion
ShellyGarion previously approved these changes Nov 24, 2022
Copy link
Member

@ShellyGarion ShellyGarion left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for fixing this!

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.

Please could we add a bugfix release note as well?

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.

Perfect, thanks!

@jakelishman jakelishman added Changelog: Bugfix Include in the "Fixed" section of the changelog automerge labels Nov 24, 2022
@mergify mergify bot merged commit 11eb891 into Qiskit:main Nov 24, 2022
Cryoris pushed a commit to Cryoris/qiskit-terra that referenced this pull request Jan 12, 2023
* fix shots argument of local_readout_mitigator

* fix correlated_readout_mitigator as well

* add test

* docstring

* black

* lint

* add release notes

* Fix up release note

Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
Co-authored-by: Jake Lishman <jake.lishman@ibm.com>
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 Community PR PRs from contributors that are not 'members' of the Qiskit repo
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

LocalReadoutMitigator.quasi_probabilities incorrectly handles the shots argument
8 participants