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

defer_measurements raises errors for unsupported measurements #4701

Merged
merged 158 commits into from
Oct 23, 2023
Merged

Conversation

mudit2812
Copy link
Contributor

@mudit2812 mudit2812 commented Oct 20, 2023

Context:
Measurements that cover all wires can give users unexpected outputs when using mid-circuit measurements. So, defer_measurements now explicitly removes support for such measurements by raising errors.

Description of the Change:

  • Raise an error if qml.state() is used.
  • Raise an error if qml.probs(), qml.sample(), or qml.counts() is used if wires or an observable isn't specified.
  • Add warning to docs

Benefits:

Possible Drawbacks:

Related GitHub Issues:
#4363

@mudit2812 mudit2812 requested a review from a team October 20, 2023 17:46
@mudit2812 mudit2812 added this to the v0.33 milestone Oct 20, 2023
@mudit2812 mudit2812 linked an issue Oct 20, 2023 that may be closed by this pull request
1 task
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.

I know there's a lot of debate over this, but I'm fine with this decision and its better than people being confused about what their answers actually mean.

@mudit2812
Copy link
Contributor Author

I know there's a lot of debate over this, but I'm fine with this decision and its better than people being confused about what their answers actually mean.

For reference, @trbromley and I had a discussion offline and the decision was to go in this direction in the end.

@Alex-Preciado
Copy link
Contributor

@mudit2812 Thank you for validating with @trbromley and for posting the update here.

Co-authored-by: Tom Bromley <49409390+trbromley@users.noreply.github.com>
Base automatically changed from mcm-post to master October 23, 2023 18:30
@mudit2812 mudit2812 added the merge-ready ✔️ All tests pass and the PR is ready to be merged. label Oct 23, 2023
@codecov
Copy link

codecov bot commented Oct 23, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (a7114a9) 99.64% compared to head (a4cf441) 99.64%.
Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4701      +/-   ##
==========================================
- Coverage   99.64%   99.64%   -0.01%     
==========================================
  Files         379      380       +1     
  Lines       34126    33983     -143     
==========================================
- Hits        34005    33861     -144     
- Misses        121      122       +1     
Files Coverage Δ
pennylane/_device.py 99.41% <100.00%> (+<0.01%) ⬆️
pennylane/devices/default_qubit.py 100.00% <100.00%> (ø)
pennylane/devices/qubit/sampling.py 100.00% <100.00%> (ø)
pennylane/devices/qubit/simulate.py 100.00% <100.00%> (ø)
pennylane/drawer/draw.py 100.00% <100.00%> (ø)
pennylane/math/single_dispatch.py 99.48% <100.00%> (+<0.01%) ⬆️
pennylane/measurements/mid_measure.py 100.00% <100.00%> (ø)
pennylane/operation.py 97.27% <100.00%> (-0.02%) ⬇️
pennylane/ops/op_math/composite.py 100.00% <100.00%> (ø)
pennylane/ops/op_math/controlled.py 99.63% <ø> (-0.01%) ⬇️
... and 7 more

... and 39 files with indirect coverage changes

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

@mudit2812 mudit2812 merged commit cc3d7cc into master Oct 23, 2023
33 checks passed
@mudit2812 mudit2812 deleted the mcm-state branch October 23, 2023 19:18
@trbromley
Copy link
Contributor

Looking back at this PR, we probably should have given a recommendation, i.e., if you're seeing an error because of qml.state(), try using qml.density_matrix() instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merge-ready ✔️ All tests pass and the PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Using qml.state() with mid-circuit measurements