Improve STN/MAST simulators: locality-ordered projection, prefix-tree sampling, qec-grade defaults, full Python exposure and docs - #523
Draft
ciaranra wants to merge 20 commits into
Draft
Conversation
…r-projection diagnostics
…act-disentangling fast path
…mmendation to StabMpsCompile
… for Mast; tri-state Python binding
…thon reads; uniform binding validation
… with tested examples, doc-test wiring
Member
Author
|
API-naming question for the owner (carried from the predecessor PR): the sampler pair is sample_bitstring (legacy, per-shot clone — kept for per-shot RNG-order reproducibility) and sample_bitstrings (prefix-tree, the documented primary). The ergonomics audit recommended renaming to sample_bitstrings_independent / sample_bitstrings_prefix_tree with deprecated aliases. Rename or keep as is? Status: draft while the deep-review fix program lands (deferred-correction physics fix per arXiv:2411.12482, amplitude_iterative determinism, reset reproducibility, binding-contract items). |
…covery; deterministic seeded reset; pure Mast getters; truncation-bound validation
…on-time corrections, forced projections) and the exact forced-projection phase-gauge, complement, and bitset defects
…rs; pin surface-example configurations
…ons; flush before disentangle; dense-oracle coverage with a triggering circuit
…, redetection scale relaxation, and the review doc sweep
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.
Improves the experimental STN/MAST simulators (exp/pecos-stab-tn) with techniques
validated against sibling implementations of the same representation, flips the general
defaults to the qec-grade posture, and closes the Python exposure gaps. Design notes,
cross-review record, and benchmarks live in the design vault; cross-implementation
correctness was verified against an independent oracle (all backends agree to 1e-16 on
identical small circuits).
Simulator improvements
Inputpreserves thelegacy order bit-for-bit including RNG consumption). Ancillas are projected by dynamic
frame locality, recomputed after every collapse. At the T=2N saturation regime
(32 data / 64 T), peak projection bond drops 64 -> <=2 and wall time 12.8 s -> 7 ms.
Verified by 5-sigma sampled-distribution tests against exact STN probabilities at
n=3..5, T=3..6. Per-projection diagnostics (
projection_records) included.numerical_flag_redetection): when thesymbolic disentangling-flag search misses, product sites are tested numerically at a
fixed 1e-12 tolerance and the existing verified fast path takes over. Detection only —
no new absorption algebra. Adversarial-regime fast-path rate improves 1.8% -> 6.2%
(deep 2q) and 16.4% -> 24.0% with mean bond 1.43 -> 1.23 (T-heavy 3q); research-target
regimes are unchanged (already optimal). Guarded off while lazy deferred ops are
pending (stored tensors differ from the effective state by the deferred Clifford).
sample_bitstrings): depth-first prefix tree overthe existing forced-projection sequence; each distinct measurement prefix is projected
once and shared across all shots taking that branch. At n=20 / 10k shots: 24 s -> 9 ms
vs the per-shot-clone sampler. Distribution equivalence verified at 5 sigma against
exact probabilities; original simulator state preserved; the existing
sample_bitstringis unchanged.
StabMpsCompile::advise): injection-mode recommendation(direct / immediate / deferred) with ancilla-budget feasibility (one fresh ancilla per
non-Clifford RZ under deferral), exact Angle64 injectable classification (a gate's
correction is Clifford iff its doubled angle is Clifford, matching the MAST
correction), and warnings as data.
SimulatorKindgainsMast;recommend()isunchanged for existing callers.
Defaults
StabMpsnow defaults to the qec-grade posture: max bond 128, adaptive truncation-errorbound 1e-8, merged same-qubit RZ.
MpsConfig::default()is aligned so StabMps, Mast,direct Mps use, and the sim_neo lane share one default posture. Every legacy behavior is
one explicit call away (
max_bond_dim(64),max_truncation_error(0.0)— the documenteddisable, verified by a dedicated test —
merge_rz(false),ProjectionOrder::Input).Tests that exercised legacy paths now pin those paths explicitly; no assertion was
weakened.
Python bindings (pecos-rslib-exp)
None= default, explicitTrue/Falseactually applies — previously
Falsewas silently ignored).svd_cutoff,numerical_flag_redetection; Mast gainsprojection_order("min_span" | "input") andnumerical_flag_redetection.sample_bitstrings,amplitude,amplitude_iterative,overlap_with_stabilizer,renyi_s2/s2_pce/s2_pcmps,disentangle,stats(), OFD telemetry (ofd_nullity,theoretical_min_bond_dim, ...),bond_cap_hits,apply_bit_flip/apply_phase_flip, Mast projection diagnostics,and a new
StabMpsCompileclass withrecommend()/advise().python/pecos-rslib-exp/tests/test_exposure.py(require a builtwheel; exercised in the comparison-harness environment).
API consistency and usability
From an audited ergonomics review of both API surfaces:
bits[q] == qubit qforprob_bitstring,amplitude,amplitude_iterative, and both samplers (previously the probability andamplitude APIs interpreted their argument reversed, so sampled rows fed back into
prob_bitstringsilently produced wrong values). Breaking change to those two APIs,documented at crate level and pinned by a sampler-to-probability round-trip
regression test.
deferred operations first, so results are never stale; status reads
(
is_state_exact,pragmatic_drift_count) deliberately do not flush. Rustflush()now materializes lazy deferred operations as well as pending RZs.
IndexError, malformedbitstrings / Pauli strings / probabilities raise
ValueErroracross all threeclasses; no Rust panic is reachable from bad Python arguments.
remaining_injections()(Rust and Python) plusconstructor docs for the capacity workflow;
advise()computes the requirement.(per-shot vs prefix-tree sampling, dense vs iterative amplitude), with Python
quickstart documentation under docs/ wired into the doc-test framework.
Breaking changes
For existing users of the experimental
pecos-stab-tncrate andpecos_rslib_expbindings (this crate carries no stability promise, but these change observable
behavior and are called out explicitly):
prob_bitstring,amplitude,amplitude_iterative: the bitstring argument is nowbits[q] == qubit q(previously reversed). Asymmetric bitstrings return differentvalues than before; the old convention produced silently wrong values when combined
with sampler output.
MpsConfig::default()andStabMpsBuilderdefaults: bond cap 64 -> 128, adaptivetruncation bound off -> 1e-8,
merge_rzoff -> on. The prior behavior ismax_bond_dim(64),max_truncation_error(0.0),merge_rz(false).Mastdefault projection order is nowMinSpan;ProjectionOrder::Inputrestoresthe legacy reverse-injection order.
(predetermined gadget outcomes, corrections applied at the injection point, forced
end-of-circuit projections). Seeded MAST RNG streams differ from prior releases;
prior MAST results on circuits with basis-changing Cliffords after injections were
incorrect.
amplitude_iterativepreviously returned 0 for a class of nonzero amplitudes; it isnow correct, so prior zeros may become nonzero.
reset()now deterministically replays the construction stream (previouslyreseeded from OS entropy);
reset()also clears runtime statistics.stab_mps()engine defaults follow the newStabMpsBuilderdefaults.Verification
--all-targets -D warnings) green on every commit; caches forced cold on changed code.independent dense oracle — statevector, Pauli expectation, and bitstring probability
agreement at ~1e-16 for both PECOS configurations.
headline numbers above reproduce on rerun.