-
Notifications
You must be signed in to change notification settings - Fork 603
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
MeasurementValue raises an error when used as boolean #6386
Conversation
…/PennyLaneAI/pennylane into fix-measurement-value-truthiness
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #6386 +/- ##
==========================================
- Coverage 99.71% 99.39% -0.32%
==========================================
Files 448 448
Lines 42466 42472 +6
==========================================
- Hits 42346 42217 -129
- Misses 120 255 +135 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the fix!
[sc-76023] |
**Context:** Users might be able to do: ``` @qml.qnode def f(): ... m = qml.measure() if m == 1: # do something ... ``` without an error, since a measurement value is always treated as truthy, even if that is not what the user was meaning to do. **Description of the Change:** Raises a `ValueError` if someone tries to treat a `MeasurementValue` as a boolean. **Benefits:** Reduces confusion and mistakes when trying to condition on a mid circuit measurement. **Possible Drawbacks:** **Related GitHub Issues:**
**Context:** Users might be able to do: ``` @qml.qnode def f(): ... m = qml.measure() if m == 1: # do something ... ``` without an error, since a measurement value is always treated as truthy, even if that is not what the user was meaning to do. **Description of the Change:** Raises a `ValueError` if someone tries to treat a `MeasurementValue` as a boolean. **Benefits:** Reduces confusion and mistakes when trying to condition on a mid circuit measurement. **Possible Drawbacks:** **Related GitHub Issues:**
Context:
Users might be able to do:
without an error, since a measurement value is always treated as truthy, even if that is not what the user was meaning to do.
Description of the Change:
Raises a
ValueError
if someone tries to treat aMeasurementValue
as a boolean.Benefits:
Reduces confusion and mistakes when trying to condition on a mid circuit measurement.
Possible Drawbacks:
Related GitHub Issues: