🐛 Clear classical bits in resetSimulationState - #466
Conversation
`resetSimulationState` rebuilt the quantum state on `reset` but left `ddsim->variables` (the map of classical bit values) untouched. After a first `run` followed by `reset`, reading `c[k]` returned the value from the previous run rather than the initial `false`, and the next `measure` on the same bit looked like a no-op because the bit already held the value it would receive. Iterate `ddsim->variables` with `std::ranges::for_each` over `std::views::values` after the quantum state rebuild and set each `boolValue` back to `false`, matching how the quantum side is reset. Closes munich-quantum-toolkit#464. Assisted-by: Claude Opus 4.7 via Claude Code
|
@coderabbitai full review |
✅ Action performedFull review finished. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Advanced Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review. 📝 SummarySummary by CodeRabbit
WalkthroughThe reset operation now clears all classical variables after rebuilding the quantum state. A regression test verifies that a measured classical bit returns to ChangesClassical State Reset
Priority: ➖ Normal — Schedule the reset fix because it restores classical bits to false for the CLI reset command and adds regression coverage for this medium-severity issue. Estimated code review effort: 1 (Trivial) | ~5 minutes Severity of issue fixed: Medium Merge Risk: ⚪ Minimal · up to Simulation reset now restores classical bits to false alongside quantum state, with regression coverage confirming a measured true bit is cleared. The change is ready to merge. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. A rabbit measured one, Comment |
DRovara
left a comment
There was a problem hiding this comment.
LGTM, thanks a lot! This is an interesting little slip.
Since we have been working on the VSCode integration of the Debugger that constantly displays the classical values, it's actually surprising that we never noticed this.
Description
🤖 AI text below 🤖
resetSimulationStateinsrc/backend/dd/DDSimDebug.cpprebuilt the quantum state onresetbut leftddsim->variables(the map of classical bit values) untouched. After a firstrunfollowed byreset, readingc[k]returned the value from the previous run rather than the initialfalse, and the nextmeasureon the same bit looked like a no-op because the bit already held the value it would receive.This PR iterates
ddsim->variableswithstd::ranges::for_eachoverstd::views::valuesafter the quantum state rebuild and sets eachboolValueback tofalse, matching how the quantum side is reset. Includes an end-to-end test that runs a program, verifiesc[0]istrue, callsresetSimulation, and verifiesc[0]isfalse.AI assistance
Commit messages, code changes, and this PR body were drafted with Claude Opus 4.7 via Claude Code. All content was reviewed and edited manually before submission.
Fixes #464.
Checklist
If PR contains AI-assisted content:
🤖 *AI text below* 🤖(titles are exempt).