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

Update the state original tape device #1049

Merged
merged 3 commits into from
Jan 28, 2021
Merged

Update the state original tape device #1049

merged 3 commits into from
Jan 28, 2021

Conversation

antalszava
Copy link
Contributor

@antalszava antalszava commented Jan 28, 2021

Context:
With #1008 devices can be swapped under the hood to get the best differentiation method. This means that certain internal device data may be lost during the QNode call.

Description of the Change:
Updates the _pre_rotated_state and _state private attributes of the original device with the device that was actually used during execution.

Note: the way of how the state prior to rotations in being stored might not be completely unified between devices and is not a part of the shared device methods (not a member of QubitDevice). Therefore we are attempting to set the affected attributes, but if they do not exist then no change is done.

Benefits:
States are updated even if a different device is used under the hood.

Possible Drawbacks:
None, though might provide a reason to consider a unified name for storing states in statevector simulator devices.

Related GitHub Issues:
#1048

@antalszava antalszava changed the title Update the state Update the state original tape device Jan 28, 2021
@github-actions
Copy link
Contributor

Hello. You may have forgotten to update the changelog!
Please edit .github/CHANGELOG.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.

@codecov
Copy link

codecov bot commented Jan 28, 2021

Codecov Report

Merging #1049 (410c290) into master (61b4939) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1049   +/-   ##
=======================================
  Coverage   97.74%   97.75%           
=======================================
  Files         153      153           
  Lines       11508    11512    +4     
=======================================
+ Hits        11249    11253    +4     
  Misses        259      259           
Impacted Files Coverage Δ
pennylane/tape/qnode.py 99.23% <100.00%> (+0.01%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 61b4939...410c290. Read the comment docs.

Copy link
Contributor

@glassnotes glassnotes left a comment

Choose a reason for hiding this comment

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

Thanks for the quick fix! Verified this works with the original example, as well as the demo that uncovered the bug.

"""Test that the returned state is equal to the expected returned state for all of
PennyLane's built in statevector devices"""

dev = qml.device(device, wires=4)

@qnode(dev, diff_method="parameter-shift")
@qnode(dev, diff_method=diff_method)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

"best" may cover "backprop" too for relevant devices and tests the new behaviour.

@antalszava antalszava merged commit 5551f4b into master Jan 28, 2021
@antalszava antalszava deleted the dev_state_tape branch January 28, 2021 23:14
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

2 participants