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

Changes to readout mitigator tests #7482

Merged
merged 34 commits into from
Feb 17, 2022
Merged

Conversation

gadial
Copy link
Contributor

@gadial gadial commented Jan 5, 2022

Summary

  • Removing constant result data
  • Adding settings method
  • Bug fixes

Details and comments

This PR addresses the use of constants in the main class for testing the readout mitigators. This can be replaced by one the fly computation of the expected results.

A settings method is added to the mitigators to enable JSON encoding/decoding.

A bug in LocalReadoutMitigator.assignment_matrix is fixed.

@gadial gadial requested a review from a team as a code owner January 5, 2022 15:52
@coveralls
Copy link

coveralls commented Jan 5, 2022

Pull Request Test Coverage Report for Build 1858802700

  • 25 of 27 (92.59%) changed or added relevant lines in 2 files are covered.
  • 4 unchanged lines in 1 file lost coverage.
  • Overall coverage increased (+0.009%) to 83.332%

Changes Missing Coverage Covered Lines Changed/Added Lines %
qiskit/result/mitigation/correlated_readout_mitigator.py 8 9 88.89%
qiskit/result/mitigation/local_readout_mitigator.py 17 18 94.44%
Files with Coverage Reduction New Missed Lines %
qiskit/result/mitigation/utils.py 4 88.41%
Totals Coverage Status
Change from base Build 1858663772: 0.009%
Covered Lines: 52215
Relevant Lines: 62659

💛 - Coveralls

@gadial gadial changed the title [WIP] Changes to readout mitigator tests Changes to readout mitigator tests Jan 11, 2022
@ShellyGarion ShellyGarion self-requested a review January 12, 2022 04:36
ShellyGarion
ShellyGarion previously approved these changes Jan 12, 2022
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.

I'm not really well placed to review all of this, but here's a couple of things at a high level.

qiskit/result/mitigation/local_readout_mitigator.py Outdated Show resolved Hide resolved
test/python/result/test_mitigators.py Outdated Show resolved Hide resolved
Comment on lines +94 to +98
@property
def settings(self) -> Dict:
"""Return settings."""
return {"assignment_matrices": self._assignment_mats, "qubits": self._qubits}

Copy link
Member

Choose a reason for hiding this comment

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

Why not adding it to the super class BaseReadoutMitigator?

Copy link
Member

Choose a reason for hiding this comment

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

This is since the assignment matrix is a 2^n-by-2^n matrix (where n is the number of qubits), so it will not be possible to generate it for advanced mitigation methods (such as M3).

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.

What bug in assignment_matrix is fixed? If it's anything at all user-facing, it probably needs a release note.

test/python/result/test_mitigators.py Outdated Show resolved Hide resolved
)
mitigated_error = self.compare_results(counts_ideal, mitigated_probs)
self.assertTrue(
mitigated_error < unmitigated_error * 0.8,
Copy link
Member

Choose a reason for hiding this comment

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

Where does the factor of 0.8 come from? Is this absolutely 100% guaranteed to always succeed - is there any fuzziness to it at all?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I know of no general result here. This specific number was chosen because it works with the current data, allowing for detections of changes to the mitigators which make it fail on this specific data. This was done with the hard-coded numbers in mind; I agree that by relying on getting the numbers from the fake backend we introduce fuzziness.

test/python/result/test_mitigators.py Outdated Show resolved Hide resolved
test/python/result/test_mitigators.py Outdated Show resolved Hide resolved
test/python/result/test_mitigators.py Outdated Show resolved Hide resolved
test/python/result/test_mitigators.py Outdated Show resolved Hide resolved
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.

Shelly already approved previously, so from my side this is good now too.

expected_assignment_matrix = np.kron(
np.kron(assignment_matrices[2], assignment_matrices[1]), assignment_matrices[0]
)
expected_mitigation_matrix = np.linalg.inv(expected_assignment_matrix)
Copy link
Member

Choose a reason for hiding this comment

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

This is 100x better thanks - I can super clearly see what's going on, and it's obvious to me that this should be a valid mitigation strategy.

@jakelishman jakelishman added automerge Changelog: Bugfix Include in the "Fixed" section of the changelog stable backport potential The bug might be minimal and/or import enough to be port to stable labels Feb 17, 2022
@jakelishman jakelishman added this to the 0.19.3 milestone Feb 17, 2022
@mergify mergify bot merged commit ff267b5 into Qiskit:main Feb 17, 2022
mergify bot pushed a commit that referenced this pull request Feb 17, 2022
* Bugfix in local mitigator and a relevant test

* Name fix

* Refactoring mitigation tests

* Cleanup

* Linting

* Linting

* Small bugfix and a test for it

* Fix to rng usage

* Linting

* Changing test sensitivity

* Added settings property to mitigator to allow JSON encoding when given as experiment result

* Linting

* Linting

* Linting

* Release note relating to the bugfix

* Get the assignment matrices implicitly

* Using more specific assertions

* Removing magic constants

* Make initialization conform to settings

* Linting

* Removing testcase which might fail on some machines

* Removing testcase which might fail on some machines

* Linting

* Reword release note

* Reword release note

Co-authored-by: Jake Lishman <jake.lishman@ibm.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
(cherry picked from commit ff267b5)

# Conflicts:
#	test/python/result/test_mitigators.py
@jakelishman jakelishman removed the stable backport potential The bug might be minimal and/or import enough to be port to stable label Feb 17, 2022
@jakelishman jakelishman modified the milestones: 0.19.3, 0.20 Feb 17, 2022
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.

6 participants