fix: add RNGadvance support to legacy Python CVM#330
Conversation
There was a problem hiding this comment.
Pull request overview
Adds relative RNG stream movement (RNGadvance(delta)) to the Python PECOS CVM RNG model, including deterministic rewind behavior by reconstructing from the active seed, and expands unit coverage to validate forward/backward advances and reseed/count semantics.
Changes:
- Implement
RNGadvanceviaset_relative_index(delta)with support for negative deltas (rewind by reseeding + replaying to target index). - Fix RNGModel initialization to avoid overwriting
seedwithNone, and resetcounton reseed to keep stream position tracking consistent. - Extend Python unit tests to cover forward advance, backward advance, reseed semantics, and
counttracking.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| python/quantum-pecos/src/pecos/engines/cvm/rng_model.py | Adds relative index movement (RNGadvance) and updates seed/count handling + argument parsing for signed integers. |
| python/quantum-pecos/tests/pecos/unit/test_rng.py | Adds unit tests validating forward/backward relative movement, reseed behavior, and count consistency. |
| julia/PECOS.jl/src/Simulator.jl | Adjusts field docstring formatting for MeasurementResult. |
| julia/PECOS.jl/src/Decoder.jl | Adjusts field docstring formatting for DecodingResult. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Claude's review: Reviewed the RNG changes. The Python One scoping note for follow-up: Minor: in |
Consolidated review (Claude + Codex)Two-model review of the RNG changes. Net: the core algorithm is sound, but the What's correct
Blocking: per-shot
|
|
@ciaranra could you review again? |
Sign-off: fix verified, mergeable (Claude + Codex)Re-reviewed The round-1 blocker is closedThe per-shot A bound-change-within-shot rewind also round-trips. The Area 2 loop fix What was checked
Non-blocking follow-ups
LGTM. Reviewed by Claude Opus 4.8 and Codex (gpt-5.5) — adversarial cross-review. |
|
@ciaranra I can't merge, I am seeing:
|
|
Huh, weird... Maybe it is some added security I added... I'll try merging |
Summary
RNGadvance(delta)support to the legacy Python CVM RNG path, including backward replay through historical bound sequencescountdirectlyRNGseed,RNGindex, andRNGnumbehavior while tightening RNG argument validation and stream bookkeepingReviewer Notes
python/quantum-pecos/src/pecos/engines/cvm/rng_model.pyand the legacy caller inpython/quantum-pecos/src/pecos/engines/hybrid_engine_old.py.RNGadvancenow replays from an explicit replay base: reseeds reset that base, and each shot snapshots the current RNG state so rewinds stay correct even when the stream continues across shots.RngPcg.clone()only to snapshot the current generator state for shot-local replay.Validation
uv run maturin develop --manifest-path python/pecos-rslib/Cargo.tomluv run --frozen pytest python/quantum-pecos/tests/pecos/unit/test_rng.pyuv run --frozen ruff check python/quantum-pecos/src/pecos/engines/cvm/rng_model.py python/quantum-pecos/src/pecos/engines/hybrid_engine_old.py python/quantum-pecos/tests/pecos/unit/test_rng.py