Fast deterministic detector sampling#78
Conversation
…ng for components determined by single f-variables.
☂️ Python Coverage
Overall Coverage
New FilesNo new covered files... Modified Files
|
|
…faelha/fast_deterministic_detector_sampling
…faelha/fast_deterministic_detector_sampling
…faelha/fast_deterministic_detector_sampling
|
Hi! Could you add a bit more context to this issue? A description of the expected behavior, use case, or any relevant details would help us prioritize and implement it. Thanks! |
6197df5 to
400766b
Compare
…faelha/fast_deterministic_detector_sampling
☂️ Code Coverage
Overall Coverage
New FilesNo new covered files... Modified Files
|
- Introduced a zero-copy fast path in `_CompiledSamplerBase` to optimize sampling when direct f-indices are contiguous, without flips or reindexing. - Updated `compile_program` to consolidate direct entries into a single list, enhancing clarity and efficiency in handling direct components. - Simplified the logic for sorting direct entries and adjusted the output order to align with the original layout, reducing potential reindexing at sample time. - Enhanced the `transform_error_basis` function to streamline the detection of phase variables, improving overall graph processing efficiency.
- Added a new test for the detector sampler that verifies it returns empty arrays when no detectors are present, both with and without a reference sample. - Removed outdated test cases that were previously causing crashes due to empty concatenation.
|
@codex review again |
There was a problem hiding this comment.
Pull request overview
This PR adds a fast path for detector sampling when connected components are deterministically given by a single error-basis variable (f_i), avoiding the JAX compilation + autoregressive sampling pipeline for those components. This targets faster detector sampling on low-noise surface-code-like circuits (per the linked paper).
Changes:
- Detect “direct” connected components (single output equal to one
fvariable, optionally flipped) and represent them explicitly inCompiledProgram. - Add a pure-NumPy sampling fast path for programs consisting only of direct components, plus precomputed output reindexing to avoid per-sample
argsort. - Add a unit test for reference sampling with zero detectors, a benchmark-style test, and documentation/changelog updates.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
src/tsim/core/graph.py |
Adds direct-component classification and prioritizes output-adjacent parameter vertices during error-basis transform. |
src/tsim/compile/pipeline.py |
Splits compilation into direct vs compiled components; precomputes output permutation (output_reindex). |
src/tsim/core/types.py |
Extends CompiledProgram to carry direct_f_indices, direct_flips, and output_reindex. |
src/tsim/sampler.py |
Uses direct bits in sample_program; adds NumPy-only _sample_direct fast path; updates probability_of. |
src/tsim/circuit.py |
Documents the new detector-sampler fast path behavior. |
test/unit/test_sampler.py |
Adds regression test for use_detector_reference_sample=True with no detectors. |
test/integration/test_sampler.py |
Updates CompiledProgram construction to include new required fields. |
test/unit/benchmarks/test_classical_detector_sampling.py |
Adds a performance threshold test (currently problematic for CI). |
CHANGELOG.md |
Documents the new detector-sampler fast path under Unreleased. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Codex Review: Didn't find any major issues. Another round soon, please! ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Code reviewFound 1 issue:
tsim/test/unit/benchmarks/test_classical_detector_sampling.py Lines 8 to 36 in 746b41f 🤖 Generated with Claude Code - If this code review was useful, please react with 👍. Otherwise, react with 👎. |
This PR contains the Clifford detector sampling fast path used in https://arxiv.org/pdf/2604.01059
Instead of compiling graphs into parametric expressions, one can read of the Tanner graph directly for deterministic detectors.
This significantly speeds up Clifford-only circuits (non-Clifford circuits are only slightly sped up). For example, for the circuits from the Clifft paper I got the following updated numbers:
Note that r=1 coherent noise circuits from Clifft become Clifford-only circuits after ZX reduction in the Tsim compilation step.