Consolidate DEM batch sampling onto SampleBatch with bulk accessors - #452
Merged
Conversation
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.
Closes #448.
What changed
DemSamplerexposed two near-identically named batch-sampling methods with swapped semantics:sample_batchreturned raw Python lists whilegenerate_samplesreturned the Rust-heldSampleBatch. This PR consolidates them:sample_batch(num_shots, seed=None) -> SampleBatchon bothDemSamplerandParsedDem.generate_samplesis removed (all call sites migrated; zero references remain).sample_batch_with_pauli_masksalso returns aSampleBatchnow.SampleBatch:detector_events()andobservable_flips()return shots-majorlist[list[bool]], correct past 64 observables. These replace the old raw-tuple return; a formerdet, obs = sampler.sample_batch(...)becomes a batch call followed by the two accessors.SampleBatchconstructor takes keyword-onlynum_observables; a mask bit at or above it is aValueError. When omitted, width is inferred from the highest set bit (documented, including the all-zero-masks case).sample_batchon a raw-measurements-mode sampler returns a batch whose rows are measurements, not detector events. Data accessors work; every decode path — the six methods onSampleBatchand the five decoder objects that accept one (LogicalSubgraphDecoder.decode_count/decode_count_parallel,WindowedLogicalSubgraphDecoder.decode_count,LogicalAlgorithmDecoder.decode_count,LogicalCircuitDecoder.decode_count) — rejects such batches with aValueErrorinstead of silently decoding measurements as syndromes.pecos_rslib.pyigains coverage for thepecos_rslib.qecsubmodule (previously absent entirely).docs/user-guide/dem-from-guppy.mdcovering sampling into a batch, bulk extraction, and the decoder-comparison methods (decode_count,decode_each,decode_stats). Escaped-backtick artifacts removed from touched docstrings.Breaking changes
DemSampler.generate_samples/ParsedDemraw-tuplesample_batchare gone; old tuple-unpack call sites fail loudly with aTypeError.sample_batchnow uses the geometric columnar sampling path (previouslygenerate_samples' path), so fixed-seed results differ from the prior release; the distribution is unchanged.Tests
get_observable_mask_wide(no truncation).error(1.0) D0 D2 L0must yield[True, False, True]rows), so a column-mapping bug cannot pass by symmetric misreading.PauliFrameLookup.compute_mask_xor.SampleBatchmethod and a decoder-object path.Verification
just build-debugclean;python/quantum-pecos/tests/qec/1147 passed, 1 skipped, 1 xfailed;python/quantum-pecos/tests/docs/247 passed with only the two pre-existingtest_qec_guppy_block_9/10failures (present on dev before this change, tracked separately);just lintclean with clippy cold on the changed crate.Deferred follow-ups (numpy-shaped accessors, stub packaging/
py.typed, the pre-existing doc-test failures) are recorded on #448. Note for #420: its docs examples usegenerate_samples; whichever merges second needs a small alignment pass.