Skip to content

refactor(gpu): drop the unused observable expectations - #301

Merged
rafaelha merged 1 commit into
mainfrom
refactor/gpu-drop-expectations
Nov 13, 2026
Merged

rafaelha merged 1 commit into
mainfrom
refactor/gpu-drop-expectations

Conversation

@rafaelha

Copy link
Copy Markdown
Collaborator

Nothing in Tsim asks the Metal sampler for observable expectations: sample_accepted(expectations=True) served only tests. This drops the feature and the plumbing around it (about 310 lines).

Changes

  • gpu/tape.py: tapes no longer compute expectations: no ev argument, observables map or weight bookkeeping. tape_kernel loses num_detectors, and tape_function loses observables.
  • gpu/noise.py: split loses observables_from.
  • metal/kernels.py: the tape kernel loses its expectations buffer, so deviation moves from buffer 7 to 6. The gather_float kernel is gone.
  • metal/sampler.py:
    • sample_accepted and _sample_call merge into the private _accepted, which always takes columns. direct_bools passes every output.
    • Slots, shares and the noise split are no longer keyed by expectations. The split is computed when the module compiles.
    • _select no longer commits an empty command buffer when it has nothing to dispatch.
  • Tests: the expectation tests are gone. test_metal_unmasked_expectations_after_a_masked_call becomes a rows-only check of the same buffer reuse.

Testing

  • pytest test/unit test/integration/test_metal_sampler.py on Linux: 2254 passed, 103 skipped (the Metal tests skip without a Mac).
  • Not run on Apple hardware. On Linux the sampler ran against a fake Metal runtime. Every kernel dispatch (kernel, arguments, grid) for 30 circuits, with and without masks, packed and boolean, matches main, apart from the dropped values argument and the empty command buffers that are no longer committed.
  • The changed MSL has not been compiled. Please run the Metal tests on a Mac before merging.

PR #219 (CUDA) leaves this shared code alone and will drop its own use of the old signatures once this lands.

🤖 Generated with Claude Code

Nothing in Tsim asks the Metal sampler for observable expectations: they
served only tests. Remove them from the shared tape and noise split and from
the Metal kernels and sampler, and merge sample_accepted into the private
_accepted, which always takes columns. _select no longer commits an empty
command buffer when it dispatches nothing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-13T20:00:57.129343Z fd01f89 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.

rafaelha added a commit that referenced this pull request Nov 13, 2026
The removal of expectations from the shared tape, the noise split and the
Metal sampler moves to its own PR (#301). CUDA keeps its own simplification:
it asks the shared tape for no observables, so its tapes compute none.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Nov 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@github-actions

Copy link
Copy Markdown
Contributor

☂️ Code Coverage

current status: ✅

Overall Coverage

Statements Covered Coverage Threshold Status
6194 5174 84% 0% 🟢

New Files

No new covered files...

Modified Files

File Coverage Status
src/tsim/statevector/gpu/noise.py 96% 🟢
src/tsim/statevector/gpu/tape.py 99% 🟢
src/tsim/statevector/metal/kernels.py 69% 🟢
src/tsim/statevector/metal/sampler.py 30% 🟢
TOTAL 74% 🟢

updated for commit: fd01f89 by action🐍

@rafaelha
rafaelha merged commit c010c34 into main Nov 13, 2026
14 checks passed
@rafaelha
rafaelha deleted the refactor/gpu-drop-expectations branch November 13, 2026 20:27
rafaelha added a commit that referenced this pull request Nov 17, 2026
CUDA takes the shared tape's new signatures (#301): tape_kernel has no
num_detectors, and the tape kernel no expectations pointer.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
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.

1 participant