Skip to content

🐛 Clear classical bits in resetSimulationState - #466

Open
rturrado wants to merge 1 commit into
munich-quantum-toolkit:mainfrom
rturrado:464
Open

🐛 Clear classical bits in resetSimulationState#466
rturrado wants to merge 1 commit into
munich-quantum-toolkit:mainfrom
rturrado:464

Conversation

@rturrado

Copy link
Copy Markdown
Contributor

Description

🤖 AI text below 🤖

resetSimulationState in src/backend/dd/DDSimDebug.cpp 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.

This PR iterates ddsim->variables with std::ranges::for_each over std::views::values after the quantum state rebuild and sets each boolValue back to false, matching how the quantum side is reset. Includes an end-to-end test that runs a program, verifies c[0] is true, calls resetSimulation, and verifies c[0] is false.

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

  • The pull request only contains commits that are focused and relevant to this change.
  • I have added appropriate tests that cover the new/changed functionality.
  • I have updated the documentation to reflect these changes.
  • The changes follow the project's style guidelines and introduce no new warnings.
  • The changes are fully tested and pass the CI checks.
  • I have reviewed my own code changes.

If PR contains AI-assisted content:

  • Any agent that created, edited, or submitted GitHub content was explicitly authorized for that scope, as required by our AI Usage Guidelines.
  • Every agent-authored or agent-edited public text body begins with the visible disclosure 🤖 *AI text below* 🤖 (titles are exempt).
  • I have disclosed AI assistance in the PR description.
  • I confirm that I have personally reviewed and understood all AI-generated content and accept full responsibility for it.

`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.
Closesmunich-quantum-toolkit#464.
Assisted-by: Claude Opus 4.7 via Claude Code
@rturrado

Copy link
Copy Markdown
ContributorAuthor

@coderabbitai full review

@coderabbitai

coderabbitaiBot commented Sep 8, 2026

Copy link
Copy Markdown
✅ Action performed

Full review finished.

@coderabbitai

coderabbitaiBot commented Sep 8, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Advanced

Run ID: 8accaf05-479d-413c-b81a-8bb7fb50c4e6

📥 Commits

Reviewing files that changed from the base of the PR and between 061ec7d and e077116.

📒 Files selected for processing (2)
  • src/backend/dd/DDSimDebug.cpp
  • test/test_custom_code.cpp

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Summary

Summary by CodeRabbit

  • Bug Fixes

    • Resetting a simulation now also clears all classical variables, setting them to false alongside the quantum state.
    • This ensures classical measurement results do not persist after a simulation reset.
  • Tests

    • Added coverage verifying that measured classical bits are cleared when the simulation is reset.

Walkthrough

The reset operation now clears all classical variables after rebuilding the quantum state. A regression test verifies that a measured classical bit returns to false.

Changes

Classical State Reset

Layer / File(s)Summary
Reset classical variables and verify behavior
src/backend/dd/DDSimDebug.cpp, test/test_custom_code.cpp
resetSimulationState sets every classical variable to false. The new test verifies this after a measurement.

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 e0771

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)
Check nameStatusExplanation
Linked Issues check✅ PassedThe implementation resets all classical bit values to false after rebuilding the quantum state, and the added end-to-end test verifies this behavior. These changes satisfy issue #464 and remain within…
Out of Scope Changes check✅ PassedThe source change and corresponding test are directly related to clearing classical bits during resetSimulationState. No unrelated changes are identified.
Docstring Coverage✅ PassedDocstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 2 files.
Title check✅ PassedThe title clearly and concisely identifies the main change: clearing classical bits in resetSimulationState.
Description check✅ PassedThe description explains the bug, motivation, implementation, linked issue, test coverage, AI assistance, and checklist status. It does not list dependencies explicitly, but this is non-critical and t…

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.

❤️ Share

A rabbit measured one,
Then watched the reset run.
The quantum state turned new,
Classical bits did too.
False now waits in every slot.
Reset leaves no stale thought.

Comment @coderabbitai help to get the list of available commands.

@rturrado
rturrado marked this pull request as ready for review September 8, 2026 15:36
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐛 Classical bits are not cleared by the CLI's reset command

1 participant

@rturrado