Skip to content

Test the untested branches of the statevector backend - #224

Open
rafaelha wants to merge 1 commit into
mainfrom
test/statevector-coverage
Open

rafaelha wants to merge 1 commit into
mainfrom
test/statevector-coverage

Conversation

@rafaelha

Copy link
Copy Markdown
Collaborator

Adds unit tests for the branches of tsim.statevector that no test reached. Tests only; no source changes.

Coverage of src/tsim/statevector

CI's coverage runs with JIT on, so it can't see inside numba kernels: shared.py shows 35% there. To get the real figure I combined a JIT-on run with a NUMBA_DISABLE_JIT=1 run, using pure-Python stand-ins for the ctpop/bitcast intrinsics (local only, not committed).

file before after
pbc.py 13 missed 1 missed
plan.py 1 0
schedule.py 1 0
shots.py 3 2
shared.py 1 (+ the intrinsic's codegen) 1
total ~98% ~99.7%

New tests:

  • read_pauli_ops rejects a component with an input.
  • _Relations rejects contradicting equalities, an equality that reduces to 0 = 1, and a sign left after reducing. It also handles a sign of one variable.
  • _rotation_axes rejects a component with no flow.
  • _frame accepts a dependent postselection that holds with certainty and rejects one of probability 0.
  • Commutant measurements skip a candidate that anticommutes with one already chosen.
  • The planner drops a rotation about a dormant Z.
  • The scheduler still runs expansions after the last measurement.
  • ShotSampler rejects a big-endian host.

Still uncovered (left on purpose)

These need contrived setups:

  • pbc.py:289: an output touching a quantum spider. zxparam's add_edge refuses to create that edge.
  • shared.py:595: a hash-probe collision in lane grouping.
  • shared.py:701: pruning before the first action, which needs an f-only postselected output inside a quantum component.
  • shots.py:409: a nonzero deviation in a call split into parts.
  • shots.py:438: an empty part.

Follow-up option: add pure-Python fallbacks for the numba intrinsics under numba.config.DISABLE_JIT and a JIT-off coverage pass to CI, so Codecov reports the kernels honestly.

🤖 Generated with Claude Code

Cover the rejection paths of the Pauli-op reader (an input, contradicting
or non-stochastic classical parts, no flow, a dependent postselection of
probability 0), commutant measurements that would anticommute, a rotation
about a dormant Z, expansions after the last measurement, and a big-endian
host.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings October 28, 2026 04:22
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-28T04:23:51.594089Z c913a54 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

Copy link
Copy Markdown
Contributor
PR Preview Action v1.8.2

QR code for preview link

🚀 View preview at
https://queracomputing.github.io/tsim/pr-preview/pr-224/

Built to branch gh-pages at 2026-10-28 04:24 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The test fixture cannot detect removal of the pairwise-commutation guard because Z1 is already rejected by the independent-X check.

1 open issue
What changed in this PR

This tests-only PR expands coverage of previously untested statevector backend branches without changing production code.

Changes:

  • Adds tests for Pauli-operation validation, relation reduction, postselection, and commutant measurements.
  • Covers dormant-Z rotation removal and scheduling expansions after the last measurement.
  • Verifies that shot sampling rejects big-endian hosts.
File Description
test/​unit/​statevector/​test_shots.py Tests rejection of big-endian hosts.
test/​unit/​statevector/​test_schedule.py Tests expansions after the final measurement.
test/​unit/​statevector/​test_plan.py Tests removal of dormant-Z rotations.
test/​unit/​statevector/​test_pbc.py Adds validation, relation, flow, postselection, and commutation tests.

Review effort: Balanced

Comment on lines +90 to +93
# NOTE: X1 and Z1 both commute with a rotation about Z0, but not with each other.
ops = PauliOps(
kind=np.array([ROTATION], dtype=np.uint8),
x=np.array([[0, 0]], dtype=bool),
@github-actions

Copy link
Copy Markdown
Contributor

☂️ Code Coverage

current status: ✅

Overall Coverage

Statements Covered Coverage Threshold Status
4483 3902 87% 0% 🟢

New Files

No new covered files...

Modified Files

No covered modified files...

updated for commit: c913a54 by action🐍

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants