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

transpose wire ordering for state results after transpile #4793

Merged
merged 6 commits into from Nov 9, 2023

Conversation

albi3ro
Copy link
Contributor

@albi3ro albi3ro commented Nov 6, 2023

Context:

The transpile transform changes the wires of everything after the necessary SWAP gates. Unfortunately, we have classes of measurements in PennyLane that are sensitive to the wire order but do not store the wire order on the measurement process.

dev = qml.device("default.qubit", wires = 4)

coupling_map=[(1, 2), (0, 2), (1, 3)]

@qml.transforms.transpile(coupling_map=coupling_map)
@qml.qnode(dev)
def circuit():
  qml.Hadamard(wires = 0)
  qml.CNOT(wires = [0,1])
  return qml.state()

Description of the Change:

  • The transpile transform now takes the device as a keyword argument
  • If the device is default mixed and the measurement is StateMP, we convert it to DensityMatrixMP
  • If the measurement process does not have wires and is not a StateMP, we update the measurement to give it the device wires
  1. If any of the measurements are StateMP, the post-processing function transposes the state result

Benefits:

The output of the qnode will look the same with and without the transpile transform

Possible Drawbacks:

  • Transposition of state result could potentially be classically expensive for larger systems

Related GitHub Issues:

Copy link
Contributor

github-actions bot commented Nov 6, 2023

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.

@albi3ro
Copy link
Contributor Author

albi3ro commented Nov 6, 2023

[sc-49570]

@albi3ro albi3ro requested a review from a team November 6, 2023 19:55
@trbromley
Copy link
Contributor

Thanks @albi3ro! Is a device-independent bugfix infeasible?

@albi3ro
Copy link
Contributor Author

albi3ro commented Nov 7, 2023

Thanks @albi3ro! Is a device-independent bugfix infeasible?

Probably not impossible, but I don't know how to do it. I'm willing to take suggestions. In my mind, a device independent fix would require deeper architectural changes to how we handle wire orders.

Copy link
Contributor

@timmysilv timmysilv left a comment

Choose a reason for hiding this comment

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

i will address the overlapping code in StateMP and simulate.py in a follow-up PR. this looks good!

Copy link

codecov bot commented Nov 9, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (deaf387) 99.64% compared to head (16c48c7) 99.63%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4793      +/-   ##
==========================================
- Coverage   99.64%   99.63%   -0.02%     
==========================================
  Files         381      381              
  Lines       34336    34115     -221     
==========================================
- Hits        34214    33990     -224     
- Misses        122      125       +3     
Files Coverage Δ
pennylane/transforms/transpile.py 100.00% <100.00%> (ø)

... and 43 files with indirect coverage changes

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

@albi3ro albi3ro enabled auto-merge (squash) November 9, 2023 21:00
@albi3ro albi3ro merged commit d2ad6af into master Nov 9, 2023
33 checks passed
@albi3ro albi3ro deleted the transpile-fix branch November 9, 2023 21:19
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.

None yet

4 participants