Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix snapshot wire order when simulation indices different than device wires #6461

Merged
merged 9 commits into from
Oct 30, 2024

Conversation

albi3ro
Copy link
Contributor

@albi3ro albi3ro commented Oct 28, 2024

Context:

Internally, default qubit only performs the simulation with the wires that it needs for apply the operation. Any wires only present in measurements are only added in at the very end. This can be substantially more memory and time efficient in certain edge cases.

Unfortunately, this can cause confusion about the snapshotted state taken mid-simulation. Mid simulation we have fewer wires and a different wire order.

Description of the Change:

  1. Add a map_wires method to snapshot to allow us to map the wires
  2. Fill in device wires on Snapshots during validate_device_wires.
  3. Allow StateMP.process_state to add in blank subsystems when the measurement has wires not present in the state's wire order.

These three steps are sufficient to make sure that snapshots always match the device's wire order.

Benefits:

Less Confusion

Possible Drawbacks:

It's no longer the state being used during the simulation at that point. We are hiding away the fact we are working with a different state during the simulation.

Related GitHub Issues:

Fixes #6427 [sc-76515]

Copy link
Contributor

Hello. You may have forgotten to update the changelog!
Please edit doc/releases/changelog-dev.md with:

  • A one-to-two sentence description of the change. You may include a small working example for new features.
  • A link back to this PR.
  • Your name (or GitHub username) in the contributors section.

@lillian542 lillian542 self-requested a review October 28, 2024 19:49
Copy link
Contributor

@lillian542 lillian542 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

pennylane/devices/preprocess.py Show resolved Hide resolved
@mudit2812 mudit2812 added this to the v0.39 milestone Oct 29, 2024
@albi3ro albi3ro requested a review from astralcai October 29, 2024 22:05
Copy link

codecov bot commented Oct 30, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Please upload report for BASE (v0.39.0-rc0@41a3b8a). Learn more about missing BASE report.

Additional details and impacted files
@@              Coverage Diff               @@
##             v0.39.0-rc0    #6461   +/-   ##
==============================================
  Coverage               ?   99.38%           
==============================================
  Files                  ?      452           
  Lines                  ?    42819           
  Branches               ?        0           
==============================================
  Hits                   ?    42557           
  Misses                 ?      262           
  Partials               ?        0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@astralcai astralcai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One suggestion, otherwise LGTM!

tests/measurements/test_state.py Outdated Show resolved Hide resolved
tests/measurements/test_state.py Outdated Show resolved Hide resolved
JerryChen97 and others added 2 commits October 30, 2024 15:13
This is dealing with a hardcoded testcases, so it should be safe to replace the redundancy with suggestions.

Co-authored-by: Astral Cai <astral.cai@xanadu.ai>
Co-authored-by: Astral Cai <astral.cai@xanadu.ai>
@JerryChen97 JerryChen97 enabled auto-merge (squash) October 30, 2024 19:15
@JerryChen97 JerryChen97 merged commit d5d3c2b into v0.39.0-rc0 Oct 30, 2024
35 checks passed
@JerryChen97 JerryChen97 deleted the snapshots-wire-order branch October 30, 2024 19:31
@albi3ro albi3ro mentioned this pull request Nov 4, 2024
1 task
Sign up for free to 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.

5 participants