Repository navigation
Conversation
classify_direct only accepted a single-output component whose classical Z spider carries exactly one error-basis parameter. Deterministic detectors of noiseless circuits reduce to the same two-vertex shape with no parameters, so each went through extract/decompose/compile and was sampled as its own JAX component (40 of them for the noiseless distillation circuit). Add classify_constant (sharing the structural check with classify_direct via _output_bit_phase) and a CompiledProgram.constant_bits field. Constants sit between the direct and the compiled outputs in output_order; the sampler broadcasts them in sample_program, scatters them in _compute_direct_outputs (so all-direct-or-constant programs still skip JAX), counts them as direct for postselection, and checks them in CompiledStateProbs.probability_of. Noiseless distillation.stim detector sampler: 41 -> 1 compiled components, 10k shots 2.7 s -> 1.3 s. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Contributor
|
Contributor
☂️ Code Coverage
Overall Coverage
New FilesNo new covered files... Modified Files
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
classify_directonly accepted a single-output component whose classical Z spider has exactly one error-basis parameter (len(phase.parameters) != 1returnedNone). Deterministic detectors of noiseless circuits reduce to the same two-vertex shape with no parameters, so each one went throughdecompose/compile_scalarsand was sampled as its own JAX component.This PR adds a constant path next to the direct path:
compile/pipeline.py:classify_constant(component)returns the output bit (phase.value == 1, the same convention as the direct flip). It shares the structural check (classical output, Hadamard edge, classical Z spider, phase 0/π) withclassify_directthrough the new_output_bit_phase.core/types.py: newCompiledProgram.constant_bitsfield.output_orderis now[direct..., constant..., compiled...], andoutput_reindexis computed from it as before.sampler.py:sample_programbroadcasts the constants into the concatenated result._compute_direct_outputsscatters them, so programs with only direct and constant outputs still skip JAX via_sample_direct. The all-direct gather path is unchanged, because scattering benchmarked 1.6–2.4× slower.CompiledStateProbs.probability_ofmultiplies by an indicator that the state matches the constants.reprreports the constant count.Effect
Noiseless
distillation.stim(from clifft-bench), detector sampler:sample(10_000)Behaviour changes
postselection_masknow discards every shot without running JAX (unlessuse_detector_reference_samplecancels it). Before, it fell back to full sampling.Tests
test/unit/compile/test_pipeline.py:T · T_DAG). It checks the number of compiled components,constant_bits,output_orderwith a non-identity reindex, and that sampled detectors equal the constants.sample_program, with and without reference samples.probability_ofwith constants.classify_constantaccept and reject cases.test/unit/test_postselection.py: postselection on a constant detector, with and without a reference sample.uv run pytest test/unit(1052 passed),uv run pytest test/integration(311 passed),uv run pyright src test(0 errors).mainon 300 random noisy Clifford+T circuits. Probabilities matched to 7.5e-9, and every sampler option (including postselection) gave the same constant and direct columns asmain. It also checked marginals against stim on 147 Clifford circuits.🤖 Generated with Claude Code