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

Move defer_measurements out of QNode construction #4432

Merged
merged 15 commits into from
Aug 18, 2023
Merged

Conversation

mudit2812
Copy link
Contributor

@mudit2812 mudit2812 commented Aug 2, 2023

Context:
Currently QNode unconditionally applies the defer_measurements transform during construction. This should change so that devices that support native mid-circuit measurements can use their capabilities.

Description of the Change:

  • Removed application of defer_measurements transform from QNode.construct.
  • Added defer_measurements transform step to qml.Device.batch_transform for devices that don't support mid-circuit measurements natively.

Benefits:

  • defer_measurements is not applied unconditionally, allowing devices with native mid-circuit measurement support to define the behaviour without being able to use it.

Possible Drawbacks:

Related GitHub Issues:

@mudit2812
Copy link
Contributor Author

[sc-42758]

pennylane/_device.py Outdated Show resolved Hide resolved
@mudit2812 mudit2812 added this to the v0.32 milestone Aug 14, 2023
@mudit2812 mudit2812 marked this pull request as ready for review August 16, 2023 15:32
@mudit2812 mudit2812 requested a review from a team August 16, 2023 15:32
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.

what's the status for the new device API?

pennylane/_device.py Show resolved Hide resolved
@mudit2812
Copy link
Contributor Author

mudit2812 commented Aug 17, 2023

what's the status for the new device API?

The new device API already calls defer_measurements in preprocess, which is called from qml.execute. I added a small integration test to check that defer_measurements is called with the new device.

@mudit2812 mudit2812 requested review from timmysilv and a team August 17, 2023 14:50
@codecov
Copy link

codecov bot commented Aug 17, 2023

Codecov Report

Merging #4432 (113011f) into master (c2995b6) will not change coverage.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master    #4432   +/-   ##
=======================================
  Coverage   99.71%   99.71%           
=======================================
  Files         378      378           
  Lines       34242    34242           
=======================================
  Hits        34144    34144           
  Misses         98       98           
Files Changed Coverage Δ
pennylane/qnode.py 100.00% <ø> (ø)
pennylane/_device.py 99.70% <100.00%> (+<0.01%) ⬆️

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.

looks great! the new device docs are pretty straightforward with when this is run, and new devices will provide their own preprocessing function if they want to support mid-circuit measurements

@mudit2812 mudit2812 requested a review from a team August 17, 2023 21:08
tests/test_qnode.py Outdated Show resolved Hide resolved
@mudit2812 mudit2812 requested review from albi3ro and a team August 18, 2023 17:50
Copy link
Contributor

@albi3ro albi3ro left a comment

Choose a reason for hiding this comment

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

👍

@mudit2812 mudit2812 enabled auto-merge (squash) August 18, 2023 18:37
@mudit2812 mudit2812 merged commit e88fe8c into master Aug 18, 2023
40 checks passed
@mudit2812 mudit2812 deleted the move-defer branch August 18, 2023 20:16
mlxd pushed a commit that referenced this pull request Aug 23, 2023
* Moved defer_measurements to device

* Updated changelog

* Update pennylane/_device.py

* Fix error

* Added test

* Linting

* Fixed tests

* Updated tests

* Added small integration test

* [skip ci] Added new test

* [skip ci] linting

---------

Co-authored-by: Christina Lee <christina@xanadu.ai>
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

3 participants