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 single MeasurementValue support to measurement processes #4544

Merged
merged 94 commits into from Sep 21, 2023

Conversation

mudit2812
Copy link
Contributor

@mudit2812 mudit2812 commented Aug 29, 2023

Context:
PR 1 for adding support for collecting statistics for mid-circuit measurements. This PR adds support for single measurement values. Supported devices are default.qubit, default.mixed, and DefaultQubit2. Supported measurement processes are qml.expval, qml.var, qml.probs, qml.sample, qml.counts.

Description of the Change:

  • Update QubitDevice expval, var, sample and statistics to handle measurement processes that have a MeasurementValue as their observable.
  • Update qml.expval, qml.probs, qml.sample, qml.var, qml.counts to handle MeasurmentValues.
  • Update ExpectationMP, VarianceMP, SampleMP, CountsMP to handle MeasurementValues as observables for state and sample processing.

measurements.rst will be updated in a follow-up PR.

Benefits:
Mid-circuit measurement statistics work.

Possible Drawbacks:

Related GitHub Issues:

@github-actions
Copy link
Contributor

Hello. You may have forgotten to update the changelog!
Please edit doc/releases/changelog-dev.md with:

  • A one-to-two sentence description of the change. You may include a small working example for new features.
  • A link back to this PR.
  • Your name (or GitHub username) in the contributors section.

@codecov
Copy link

codecov bot commented Aug 29, 2023

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (f2d784d) 99.62% compared to head (86fc10e) 99.63%.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #4544   +/-   ##
=======================================
  Coverage   99.62%   99.63%           
=======================================
  Files         375      375           
  Lines       33486    33536   +50     
=======================================
+ Hits        33362    33412   +50     
  Misses        124      124           
Files Changed Coverage Δ
pennylane/measurements/__init__.py 100.00% <ø> (ø)
pennylane/_qubit_device.py 99.44% <100.00%> (+<0.01%) ⬆️
pennylane/devices/qubit/measure.py 100.00% <100.00%> (ø)
pennylane/measurements/counts.py 100.00% <100.00%> (ø)
pennylane/measurements/expval.py 100.00% <100.00%> (ø)
pennylane/measurements/measurements.py 100.00% <100.00%> (ø)
pennylane/measurements/mid_measure.py 100.00% <100.00%> (ø)
pennylane/measurements/probs.py 100.00% <100.00%> (ø)
pennylane/measurements/sample.py 100.00% <100.00%> (ø)
pennylane/measurements/var.py 100.00% <100.00%> (ø)
... and 1 more

☔ 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 August 30, 2023 16:48
@mudit2812 mudit2812 requested a review from a team August 30, 2023 16:48
@mudit2812 mudit2812 removed the request for review from lillian542 September 18, 2023 18:28
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.

looking super good! I think there are just some remnant of the old implementation, but otherwise it's shaping up 👍

doc/introduction/measurements.rst Outdated Show resolved Hide resolved
pennylane/measurements/measurements.py Show resolved Hide resolved
pennylane/measurements/sample.py Outdated Show resolved Hide resolved
pennylane/measurements/var.py Outdated Show resolved Hide resolved
pennylane/tape/qscript.py Outdated Show resolved Hide resolved
pennylane/tape/qscript.py Outdated Show resolved Hide resolved
pennylane/tape/qscript.py Outdated Show resolved Hide resolved
pennylane/transforms/convert_to_numpy_parameters.py Outdated Show resolved Hide resolved
pennylane/transforms/defer_measurements.py Outdated Show resolved Hide resolved
tests/transforms/test_defer_measurements.py Outdated Show resolved Hide resolved
Co-authored-by: Matthew Silverman <matthews@xanadu.ai>
mudit2812 and others added 4 commits September 20, 2023 14:42
Co-authored-by: Matthew Silverman <matthews@xanadu.ai>
Co-authored-by: Matthew Silverman <matthews@xanadu.ai>
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.

one last concern, but otherwise this looks ready to roll!

pennylane/transforms/defer_measurements.py Show resolved Hide resolved
pennylane/transforms/defer_measurements.py Outdated Show resolved Hide resolved
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.

🎉 thanks for addressing all my questions! I am now realizing that the repr for a MeasurementProcess with a MeasurementValue (and the repr for those too) could use some work, but we can do it in another PR to get this one merged rn

@mudit2812 mudit2812 enabled auto-merge (squash) September 21, 2023 19:22
@mudit2812 mudit2812 merged commit 408c4f7 into master Sep 21, 2023
39 checks passed
@mudit2812 mudit2812 deleted the mcm-stats-1 branch September 21, 2023 20:32
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