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

Add support for mid-circuit measurement program capture #6015

Merged
merged 33 commits into from
Aug 2, 2024
Merged

Conversation

mudit2812
Copy link
Contributor

@mudit2812 mudit2812 commented Jul 18, 2024

Context:
This PR is following up on the new program capture effort by adding support for capturing mid-circuit measurements. Currently, mid-circuit measurements can be captured, classically processed, and executed, with specific constraints, but cannot be used with qml.cond

Description of the Change:

  • Add primitive for capturing qml.measure. This primitive's concrete implementation is basically the same as the original, where it queues a MidMeasureMP and returns a MeasurementValue, but its abstract eval returns a boolean integer tracer. Follow up work will take advantage of this.

Benefits:

  • Mid-circuit measurements can be captured
  • Arbitrary classical processing of MCMs can be captured. This includes functionality that is already available, as well as new functionality such as operations like jnp.sin(m), jnp.array([m1, m2]), and even jnp.max(jnp.array([m1, m2])! All of this can be captured, but not executed.
  • Using mid-circuit measurements as gate parameters, eg. qml.RX(m, 0), can be captured, but not executed.
  • Circuits containing mid-circuit measurements can be executed with qml.capture.enable(). This only works when the circuit does not classically process MCMs or applies qml.cond with MCMs in the predicate.
  • Circuits collecting statistics on mid-circuit measurements or sequences of mid-circuit measurements can be captured and executed.

@mudit2812
Copy link
Contributor Author

mudit2812 commented Jul 18, 2024

[sc-66783] [sc-69204] [sc-69668] [sc-69206] [sc-70055]

Copy link

codecov bot commented Jul 18, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.66%. Comparing base (0b0e212) to head (2959d55).
Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6015      +/-   ##
==========================================
+ Coverage   99.52%   99.66%   +0.13%     
==========================================
  Files         430      430              
  Lines       41835    41452     -383     
==========================================
- Hits        41637    41312     -325     
+ Misses        198      140      -58     

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

@mudit2812 mudit2812 marked this pull request as ready for review July 29, 2024 22:11
Copy link
Contributor

@PietropaoloFrisoni PietropaoloFrisoni left a comment

Choose a reason for hiding this comment

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

Seems pretty good! Just a few questions for my own understanding

doc/releases/changelog-dev.md Show resolved Hide resolved
doc/releases/changelog-dev.md Show resolved Hide resolved
pennylane/workflow/qnode.py Show resolved Hide resolved
Copy link
Contributor

@PietropaoloFrisoni PietropaoloFrisoni left a comment

Choose a reason for hiding this comment

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

LGTM

@mudit2812 mudit2812 requested review from albi3ro and removed request for albi3ro August 2, 2024 14:23
Copy link
Contributor

@dime10 dime10 left a comment

Choose a reason for hiding this comment

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

Nice work 💯

I'm guessing you abandoned cond(m, fun)()?

I also vaguely remember at the start you told me that other primitives that have been implemented didn't work with measure yet because it didn't exist, and that you would need to update those. Was that just the measurement processes of mcms or do you remember if there was anything else?

@mudit2812
Copy link
Contributor Author

mudit2812 commented Aug 2, 2024

I'm guessing you abandoned cond(m, fun)()?

@dime10 That's in a different PR #6058 (though that needs to be updated as well)

I also vaguely remember at the start you told me that other primitives that have been implemented didn't work with measure yet because it didn't exist, and that you would need to update those. Was that just the measurement processes of mcms or do you remember if there was anything else?

It was just the measurement processes of MCMs, which is working in this PR.

@mudit2812 mudit2812 enabled auto-merge (squash) August 2, 2024 16:13
@mudit2812 mudit2812 merged commit 4641975 into master Aug 2, 2024
40 checks passed
@mudit2812 mudit2812 deleted the capture-mcm1 branch August 2, 2024 16:51
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.

6 participants