-
Notifications
You must be signed in to change notification settings - Fork 37
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 qml.sample()
without specifying the observable
#266
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #266 +/- ##
===========================================
- Coverage 100.00% 99.18% -0.82%
===========================================
Files 7 7
Lines 1211 1223 +12
Branches 295 302 +7
===========================================
+ Hits 1211 1213 +2
- Misses 0 8 +8
- Partials 0 2 +2 ☔ 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.
This change is an interesting improvement, but I don't think it addresses the issue #179.
The idea is to support a vector for the shots
argument, like: https://docs.pennylane.ai/en/stable/code/api/pennylane.devices.default_qubit.DefaultQubit.html?highlight=shot_vector#pennylane.devices.default_qubit.DefaultQubit.shot_vector
The vector would be able to indicate a different number of shots
to execute each circuit, rather than having every circuit executed the same number of shots.,
if return_type is ObservableReturnTypes.Sample and observable is None: | ||
if isinstance(measurement, qml.measurements.SampleMeasurement): | ||
return tuple( | ||
Sample(BraketObservable.Z(), target) for target in targets or measurement.wires | ||
) | ||
raise NotImplementedError(f"Unsupported measurement type: {type(measurement)}") |
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.
instead of embedding this logic here, would it be possible to have _translate_observable
return both an observable and targets, and have it fall back to these defaults if observable
is none and/or targets
is none? Might be slightly cleaner (and then maybe wouldn't require the C901
suppression above either, since the logic would be outside this function).
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.
I am not sure about that. The target cannot be specified if an observable is specified, so the branching will be based on whether the observable is None. Therefore, I believe that the overall logic will remain the same, and it will only be divided into more functions.
if measurement.return_type is ObservableReturnTypes.Sample and observable is None: | ||
if isinstance(measurement, qml.measurements.SampleMeasurement): | ||
if targets: | ||
return [m[targets] for m in braket_result.measurements] | ||
return braket_result.measurements | ||
raise NotImplementedError(f"Unsupported measurement type: {type(measurement)}") |
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.
same question here, would it be possible to embed this logic inside translate_result_type
somehow?
execute
and batch_execute
qml.sample()
without specifying the observable
Sorry for the misunderstanding. I do not think I will be able to provide a solution to issue #179 before the end of the unitary hack, so I will change the goal of the pull request to support |
Issue #, if available:
Related to #98
Description of changes:
qml.sample()
can now be used without specifying the observable.Example:
output:
Testing done:
Merge Checklist
Put an
x
in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your pull request.General
Tests
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.