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

Raise an error for MCMs nested in Conditionals #7027

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

lillian542
Copy link
Contributor

Context:
The current methods for of mid-circuit measurement processing don't support applying a mid-circuit measurement conditionally. This was not within the scope of the implementation for any of these methods, so we don't expect it to work - however, we would prefer to return clear error messages, and we don't want to be returning incorrect results.

Currently, qml.cond(m, qml.measure)(wire) either raises a difficult to parse error (in the case of deferred measurements and analytical execution), or returns incorrect results (in the case of tree-traversal, one-shot, and deferred measurements with shots).

Description of the Change:

We add validation in the midcircuit_measurements transform, checking for conditional mcms and raising an error. Specific mcm_methods can be made to pass this validation check in the future if support for conditional mcms are added to the method; for now, we disallow it completely.

Benefits:
We don't return incorrect results or raise cryptic errors.

Possible Drawbacks:
It adds one more iteration over the operations for validation 🤷‍♀️

Related GitHub Issues:
None, but sc stories [sc-84177] and [sc-84178]

This comment was marked as resolved.

@lillian542 lillian542 marked this pull request as ready for review February 28, 2025 20:29
Copy link

codecov bot commented Feb 28, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.60%. Comparing base (9b45754) to head (d67b42b).
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #7027   +/-   ##
=======================================
  Coverage   99.60%   99.60%           
=======================================
  Files         484      484           
  Lines       46305    46312    +7     
=======================================
+ Hits        46122    46129    +7     
  Misses        183      183           

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

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.

1 participant