-
Notifications
You must be signed in to change notification settings - Fork 643
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
Support joint measurement statistics for mid-circuit measurements #4888
Conversation
Hello. You may have forgotten to update the changelog!
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #4888 +/- ##
==========================================
- Coverage 99.66% 99.65% -0.02%
==========================================
Files 388 388
Lines 35379 35158 -221
==========================================
- Hits 35262 35038 -224
- Misses 117 120 +3 ☔ View full report in Codecov by Sentry. |
[sc-48303] |
Co-authored-by: Tom Bromley <49409390+trbromley@users.noreply.github.com>
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.
looks great, super comprehensive testing! got a few questions first but very nice 😎
Smol breaking change: |
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.
🎉
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.
Impressive amount of work and an exciting new feature!
) **Context:** Adding support for advanced statistics for mid-circuit measurements. Users can now collect statistics on multiple measurement values. This can be done in two ways: 1. Using arithmetic operators to collect measurement values into a composite value. Eg: `m0 * m1 - 2 * m3` or `m1 > m0` or `~m0 & m1`, etc. Available for `qml.expval`, `qml.var`, `qml.sample`, `qml.counts`. 2. Putting values in a list. This will give wire-like results. Eg: `[m0, m1, m2]`. Available for `qml.sample`, `qml.probs`, `qml.counts`. **Composite vs single `MeasurementValue`s**: Composite `MeasurementValue`s refers to `MeasurementValue`s created by applying arithmetic/boolean operators to `MeasurementValue`s as shown in the first point above. A single `MeasurementValue` is the output of `qml.measure`. Applying arithmetic/boolean operators to `MeasurementValue`s also returns `MeasurementValue`s. **Description of the Change:** * Add `__repr__` to `MeasurementValue` and update `MeasurementProcess.__repr__` appropriately. * Update `MeasurementProcess.eigvals` to return outcomes of composed `MeasurementValue`s when in use. If a list of `MeasurementValue`s is given, the eigenvalues are just `range(2**num_wires)`. * Update `QubitDevice` to use the correct eigenvalues for composite `MeasurementValue`s, and treat a list of `MeasurementValue`s as wires. * Update `qml.expval` and `qml.var` to disallow using lists of `MeasurementValue`s, and allow composite MeasurementValue`s. * Update `qml.sample` and `qml.counts` to allow both lists of `MeasurementValue`s as well as composite `MeasurementValue`s. * Update `qml.defer_measurements` to disallow using `qml.probs` with composite `MeasurementValue`s. This is done because the wire order of the composite value is not deterministic as the sorting is determined by the ID of the mid-circuit measurements, which are generated randomly. There isn't really a way to go around this at the moment, so I just blocked users from being able to do it. Besides, the results should be the same as when they use a list of `MeasurementValue`s. **TODO**: Add docs. **Benefits:** * Advanced mid-circuit statistics are now supported! And in multiple ways 😄 **Possible Drawbacks:** **Related GitHub Issues:** --------- Co-authored-by: Tom Bromley <49409390+trbromley@users.noreply.github.com>
) **Context:** Adding support for advanced statistics for mid-circuit measurements. Users can now collect statistics on multiple measurement values. This can be done in two ways: 1. Using arithmetic operators to collect measurement values into a composite value. Eg: `m0 * m1 - 2 * m3` or `m1 > m0` or `~m0 & m1`, etc. Available for `qml.expval`, `qml.var`, `qml.sample`, `qml.counts`. 2. Putting values in a list. This will give wire-like results. Eg: `[m0, m1, m2]`. Available for `qml.sample`, `qml.probs`, `qml.counts`. **Composite vs single `MeasurementValue`s**: Composite `MeasurementValue`s refers to `MeasurementValue`s created by applying arithmetic/boolean operators to `MeasurementValue`s as shown in the first point above. A single `MeasurementValue` is the output of `qml.measure`. Applying arithmetic/boolean operators to `MeasurementValue`s also returns `MeasurementValue`s. **Description of the Change:** * Add `__repr__` to `MeasurementValue` and update `MeasurementProcess.__repr__` appropriately. * Update `MeasurementProcess.eigvals` to return outcomes of composed `MeasurementValue`s when in use. If a list of `MeasurementValue`s is given, the eigenvalues are just `range(2**num_wires)`. * Update `QubitDevice` to use the correct eigenvalues for composite `MeasurementValue`s, and treat a list of `MeasurementValue`s as wires. * Update `qml.expval` and `qml.var` to disallow using lists of `MeasurementValue`s, and allow composite MeasurementValue`s. * Update `qml.sample` and `qml.counts` to allow both lists of `MeasurementValue`s as well as composite `MeasurementValue`s. * Update `qml.defer_measurements` to disallow using `qml.probs` with composite `MeasurementValue`s. This is done because the wire order of the composite value is not deterministic as the sorting is determined by the ID of the mid-circuit measurements, which are generated randomly. There isn't really a way to go around this at the moment, so I just blocked users from being able to do it. Besides, the results should be the same as when they use a list of `MeasurementValue`s. **TODO**: Add docs. **Benefits:** * Advanced mid-circuit statistics are now supported! And in multiple ways 😄 **Possible Drawbacks:** **Related GitHub Issues:** --------- Co-authored-by: Tom Bromley <49409390+trbromley@users.noreply.github.com>
Context:
Adding support for advanced statistics for mid-circuit measurements. Users can now collect statistics on multiple measurement values. This can be done in two ways:
m0 * m1 - 2 * m3
orm1 > m0
or~m0 & m1
, etc. Available forqml.expval
,qml.var
,qml.sample
,qml.counts
.[m0, m1, m2]
. Available forqml.sample
,qml.probs
,qml.counts
.Composite vs single
MeasurementValue
s:Composite
MeasurementValue
s refers toMeasurementValue
s created by applying arithmetic/boolean operators toMeasurementValue
s as shown in the first point above. A singleMeasurementValue
is the output ofqml.measure
. Applying arithmetic/boolean operators toMeasurementValue
s also returnsMeasurementValue
s.Description of the Change:
__repr__
toMeasurementValue
and updateMeasurementProcess.__repr__
appropriately.MeasurementProcess.eigvals
to return outcomes of composedMeasurementValue
s when in use. If a list ofMeasurementValue
s is given, the eigenvalues are justrange(2**num_wires)
.QubitDevice
to use the correct eigenvalues for compositeMeasurementValue
s, and treat a list ofMeasurementValue
s as wires.qml.expval
andqml.var
to disallow using lists ofMeasurementValue
s, and allow composite MeasurementValue`s.qml.sample
andqml.counts
to allow both lists ofMeasurementValue
s as well as compositeMeasurementValue
s.qml.defer_measurements
to disallow usingqml.probs
with compositeMeasurementValue
s. This is done because the wire order of the composite value is not deterministic as the sorting is determined by the ID of the mid-circuit measurements, which are generated randomly. There isn't really a way to go around this at the moment, so I just blocked users from being able to do it. Besides, the results should be the same as when they use a list ofMeasurementValue
s.TODO: Add docs.
Benefits:
Possible Drawbacks:
Related GitHub Issues: