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

Add test for exceptional behavior when initializing PauliList.from_symplectic #13751

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

MattePalte
Copy link

Summary

Improve Test Coverage for PauliList Exceptional Behavior

This pull request addresses a testing gap in the PauliList object's from_symplectic method, which was introduced in a previous pull request (#13624). The new test ensures that the exceptional behavior is thoroughly tested, enhancing the overall reliability of the Qiskit library.

Details and Comments

To verify the effectiveness of this change, I have run the entire test suite locally and measured the test coverage using the following command (note that I also run the entire testing suite):

pytest --cov=$PWD/. --cov-report=xml test/python/quantum_info/operators/symplectic/test_pauli_list.py

The results demonstrate a notable improvement in test coverage:

Coverage Comparison

Before:
test_pr_13624_coverage_before
After:
test_pr_13624_coverage_after

Please let me know if there's anything else I can provide to facilitate the review of this pull request.

@MattePalte MattePalte requested a review from a team as a code owner January 28, 2025 14:29
@qiskit-bot qiskit-bot added the Community PR PRs from contributors that are not 'members' of the Qiskit repo label Jan 28, 2025
@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 following people are relevant to this code:

  • @Qiskit/terra-core

@CLAassistant
Copy link

CLAassistant commented Jan 28, 2025

CLA assistant check
All committers have signed the CLA.

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.

Thanks for the increased test coverage.

As a minor comment: it's great to be detail-oriented in the PR comment, but in some cases, less can be more. It's a lot of text and images to read for a PR whose logic is obvious - it's just more work for you to write and for us to read. A PR comment like

This addresses missed testing coverage of a failure path in PauliList.from_symplectic.

would have got across all the same information.

Comment on lines 228 to 232
try:
PauliList.from_symplectic(z, x, phase)
assert False, "Expected ValueError for 2D phase"
except ValueError as e:
assert str(e) == "phase should be at most 1D but has 2 dimensions."
Copy link
Member

Choose a reason for hiding this comment

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

Bare assert is rarely correct in a unittest-based test suite - in this case you want the self.assertRaisesRegex context manager.

Copy link
Author

Choose a reason for hiding this comment

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

Refactored thanks @jakelishman. I will also keep in mind to make more concise PR description thanks for the guideline.

@@ -221,6 +221,16 @@ def test_init_from_settings(self):
from_settings = PauliList(**pauli_list.settings)
self.assertEqual(pauli_list, from_settings)

def test_from_symplectic_phase_check(self):
Copy link
Member

Choose a reason for hiding this comment

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

You'll likely need a docstring on this function to satisfy the linter (though tbh, we'd disable the rule for the test suite if it was easier to give pytest different configurations based on file path).

Copy link
Author

Choose a reason for hiding this comment

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

Done. Thanks. Also checked locally to pass tox -elint.

@ShellyGarion ShellyGarion added the mod: quantum info Related to the Quantum Info module (States & Operators) label Jan 28, 2025
@coveralls
Copy link

coveralls commented Jan 28, 2025

Pull Request Test Coverage Report for Build 13013775255

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 11 unchanged lines in 3 files lost coverage.
  • Overall coverage increased (+0.01%) to 88.942%

Files with Coverage Reduction New Missed Lines %
crates/accelerate/src/unitary_synthesis.rs 1 92.97%
crates/qasm2/src/lex.rs 4 92.48%
crates/qasm2/src/parse.rs 6 97.61%
Totals Coverage Status
Change from base Build 13010967771: 0.01%
Covered Lines: 79688
Relevant Lines: 89595

💛 - Coveralls

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Community PR PRs from contributors that are not 'members' of the Qiskit repo mod: quantum info Related to the Quantum Info module (States & Operators)
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

6 participants