Add just-in-time DEM slice stitching - #664
Draft
qciaran wants to merge 13 commits into
Draft
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.
Summary
Adds the representation, PECOS-native extraction, assembly, and first production integration layer for just-in-time detector error models:
DemSlicetemplates with checked temporal horizonsDemSliceCachewhose key policy remains with the physical-template providerDemSliceInstanceDetectorErrorModelthat preserves independent contributions, Y decompositions, and arbitrary source-frame component listsDagFaultInfluenceMapidentities, with partial and unattributed ownership rejectedDemSliceRoundSchedulederivation from detector[x, y, round]coordinates and physical DAG gate ownership annotationsDemSliceTemplateCompilerthat extracts selected owner rounds without retaining an algorithm-length modelDemSliceTemplatehandles andDemSliceRoundSchedule.from_templates(...)compositiondem_slice_roundannotation for every gate generated by the surfaceLogicalCircuitBuilderDemStitcherassembly for commit-plus-buffer decoding windows with explicit hard/soft forward boundariesThis remains a draft because repeated logical-gate composition, the correct bounded mid-cycle fold-transversal SZ/SZdg circuit, broader multi-patch families, and the anti-snake logical-subgraph window decoder remain follow-ups. Full-circuit source-tracked models remain independent equivalence oracles, not the intended online algorithm path.
Motivation and design
Windowed decoding should not need to regenerate and filter a global DEM for every window. Under a bounded detector-correlation horizon, constant-depth physical operation templates can be compiled once and instantiated using relative detector addresses.
The API separates physical cache identity from scheduling state. Absolute rounds, detector-stream routing, patch placement, and output labels live on instances, so relabel-only operations do not multiply cached templates. Non-emitting temporal ports let asymmetric boundary slices refer to detectors owned by adjacent slices.
DemSlice::from_detector_error_modelconsumes PECOS's existing structured model and requires explicit mappings for everyD<n>,L<n>, andTP<n>identity.from_detector_error_model_for_locationsselects complete physical sources using influence-map location IDs. A correlated source may not be split across slices, and source components are checked to XOR to the complete effect.For surface circuits,
DemSliceRoundSchedule::from_annotated_circuitderives mappings and ownership automatically. Detector streams are ordered from the earliest full syndrome round, preserving the physical syndrome-bit order even when initialization has only a boundary subset. Integer detector time coordinates provide rounds, and each influence-map location inherits its owner from thedem_slice_roundattribute on its DAG gate. Missing, non-integral, or inconsistent metadata fails loudly.DemSliceTemplateCompilerturns a bounded annotated physical model into independently reusable owner-round slices. A three-SEC-round surface-memory fixture supplies four distinct families: initialization, stationary bulk SEC, pre-terminal SEC, and terminal data measurement. A six-round logical-gate fixture supplies initialization, ordinary pre-gate bulk, the pre-gate boundary round, the gate plus first post-gate SEC round, ordinary post-gate bulk, pre-terminal, and terminal families.The production providers follow PECOS's existing
functools.cachestyle. Physical cache identity includes geometry, orientation, boundary bases, and noise parameters, while excluding requested memory lengths, patch labels, qubit offsets, and coordinate placement. Those instance-only properties are applied while composing the schedule. Requests of different lengths therefore reuse the same bounded templates, and stitched memory and H results remain byte-for-byte identical to independent full DEMs.The transversal-CX provider extends this to two matching patch shapes. Its gate-boundary family retains native correlated two-patch sources and hyperedges. Canonical detector streams are partitioned by patch and translated independently at instantiation, so arbitrary control and target placements reuse the same physical templates. The common registered/memory/CX order is supported; mismatched shapes, shallow boundaries, and noncanonical ordering retain full-model fallback.
The current standalone SZ/SZdg emitter is deliberately not cached. Its detector span grows with the entire preceding memory segment (3, 5, and 9 rounds for pre-gate depths 3, 5, and 9), violating the bounded-correlation requirement. The documented paper protocol instead embeds a fold-transversal S operation midway through one syndrome-extraction round. Implementing that physical S-SE circuit is a prerequisite to a sound SZ/SZdg JIT provider; including memory depth in the cache key would only disguise the violation.
The window assembler assigns dense local
D<n>identifiers deterministically. It accepts a bounded source halo at the hard backward boundary, distinguishes soft sliding boundaries from hard terminal boundaries, and refuses to truncate a correlation that crosses the commit region and the entire buffer.required_buffer_roundscomputes the exact required look-ahead.Python callers can compile
DetectorErrorModel.round_schedule(...)once, extract opaque cached templates, compose new schedules withDemSliceRoundSchedule.from_templates(...), and reusestitch(...)across windows.build_algorithm_descriptor,build_dem, andbuild_sampler_and_decoderuse an eligible cached provider and fall back to the reusable structured provider otherwise. A local segment DEM may overlap the following detector round for correlation context, while itsnum_detectorsmetadata remains the non-overlapping input-syndrome partition expected by the streaming decoder.This follows the general slicing/stitching architecture in arXiv:2608.11719. The static-Tanner/prior-only optimization discussed in arXiv:2608.25027 remains a possible fast path when topology is actually unchanged; it is not assumed by the general stitcher.
Verification
origin/devinto the branchcargo test -p pecos-qec(816 unit tests: 810 passed, 6 expected ignored; all integration tests; 57 doc tests)cargo clippy -p pecos-qec -p pecos-rslib --all-targets -- -D warningscargo fmt --all -- --checkjust docs-build, andgit diff --checkFollow-ups