Repository navigation
[P8-06] Avoid alias-table allocations for single CPU samples - #571
Merged
Merged
Conversation
Share full state validation with a scratch-free one-draw cumulative path across CPU layouts. Preserve repeated-draw alias behavior and noisy shot-seed/RNG advancement; record public paired timings, allocation profiles and remaining tiny-call overhead.
ruslan-splynx
marked this pull request as ready for review
October 13, 2026 20:45
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 #556.
Each noisy trajectory used to build six state-sized probability/alias buffers for one terminal draw. CPU AoS FP64, SoA FP64 and FP32 now fully validate the state without materializing probabilities, then use one cumulative draw; zero shots validate with no allocations/RNG consumption. Two or more shots keep the alias algorithm, allocation requirements and seeded mapping.
The single-shot seed-to-outcome mapping intentionally changes. Both algorithms consume one RNG u64, so absolute noisy shot seeds, gate/channel ordering and subsequent readout RNG position are preserved. Shared validation retains normalization budgets and FP32 widening, rejects late NaN/Inf and malformed layouts before drawing, skips zero bins and handles endpoint rounding with the last positive bin. No production unsafe code, dependency, fusion or noisy-worker/state-reuse change is introduced.
Paired Criterion A/B/B/A on Intel i5-13500, logical CPU0 / one Rayon worker, shared services untouched, two repeats × 10 samples per cell:
At n=20 single-shot, all CPU layouts drop from 7 allocations / 36 MiB scratch peak to 1 allocation / 8 result bytes. Full one-worker noisy n=20/8 additional live-heap peak drops 52 → 16 MiB; this is requested Rust heap, not RSS. Many-shot allocations match baseline exactly. Initial tiny 1024-shot regressions motivated an isolated
inline(never)low-shot helper; final tiny 2–4-shot cells retain up to 5.3% (roughly 3–6 ns) overhead. No many-shot speedup or wider optimal streaming threshold is claimed.Validation: 346 SV unit/property tests; six stored Aer noise/readout oracles; three noisy-driver tests; public analytic single/many-shot distributions through all three layouts; 1/2/4-worker noisy determinism with Pauli/Kraus/readout; million-shot convergence and FP32 equivalence. Workspace all-target clippy, final SV clippy, rustfmt and diff checks passed. Linux final release: all six noisy Aer oracles plus both public sampler/worker-invariance tests passed.
docs/perf/p8-06-single-shot-sampling.mddocuments seeds, limits, commands and noise-model identity. Data includes all 48 cases × 4 Criterion repeats with confidence intervals/raw samples, allocation counters, provenance and the valid initial helper campaign. An invalid shared-Cargo-target pilot returned identical binaries; allocation preflight caught it, pilot timings were discarded, and accepted builds use independent targets and distinct hashes. Benchmark/memory evidence is from actual public Rust APIs; no Python/GPU/Metal performance claim.Draft pending CI and final review. #557 trajectory reuse/concurrency/sparse results and draft #569 Metal timings remain separate.