Fix lint errors, most_likely() tie-breaking bug, and expand test coverage to 36 tests#11
Fix lint errors, most_likely() tie-breaking bug, and expand test coverage to 36 tests#11
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Co-authored-by: blackboxprogramming <118287761+blackboxprogramming@users.noreply.github.com>
…rage) Co-authored-by: blackboxprogramming <118287761+blackboxprogramming@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR addresses CI quality/correctness gaps in the quantum circuit simulator by aligning MeasurementResult.most_likely() behavior with its documented tie-breaking rule, cleaning up lint issues, and expanding test coverage.
Changes:
- Fix
MeasurementResult.most_likely()to break ties by choosing the lexicographically smallest bitstring. - Resolve a Ruff E741 lint issue by renaming an ambiguous variable in tests and add new tests for edge cases and additional circuits.
- (Unintended) adds a
.coverageartifact file to the repository.
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
quantum_simulator.py |
Removes unused typing imports and corrects most_likely() tie-breaking logic to match the docstring. |
tests/test_quantum_simulator.py |
Fixes an ambiguous variable name and adds additional tests to improve coverage across edge cases and circuits. |
.coverage |
Adds a local coverage data artifact (should not be committed). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
| def test_bell_state_qubit1_collapses_qubit0(self): | ||
| """Measuring qubit 0 of a Bell state collapses qubit 1 to the same value.""" | ||
| circuit = QuantumCircuit(2) |
There was a problem hiding this comment.
Test name and docstring disagree: the function name says qubit1 collapses qubit0, but the test measures qubit 0 and asserts the full state collapses accordingly. Rename the test to match the behavior being validated to avoid confusion when reading failures.
The repo had three correctness/quality gaps: lint failures blocking CI, a behavioural mismatch between
most_likely()'s documented and actual tie-breaking behaviour, and only 28 tests despite the README advertising "35+".Fixes
quantum_simulator.pyIterableandListfromtypingmost_likely()tie-breaking — was returning the lexicographically largest bitstring on ties; now correctly returns the smallest as documented:tests/test_quantum_simulator.pyI→identity(E741)TestEmptyQubitsprobabilities(qubits=[])early-return path;measure(qubits=[])full-state collapseTestNonSquareUnitary_apply_unitaryTestMostLikelyTieBreakingTestAdditionalCircuitsOriginal prompt
🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.