Closed timmysilv closed 9 months ago
Hello and thank you for opening this! Braket is looking at making the changes to prepare for this. I shall assign the issue to myself to ensure this is followed up with.
Merged in https://github.com/amazon-braket/amazon-braket-pennylane-plugin-python/pull/222 to unblock this issue.
I shall resolve this issue once the braket-stable-latest
tests start to pass. The rest of the builds are passing within the test matrix.
Currently, the Braket stable test is using 1.23.0
. The changes were introduced in 1.24.0
. The expectation is that once this version is being used for the test, we shall see it begin to pass.
All checks are passing.
Hello from PennyLane! I'm here to request a migration from using the
Observable
type to using theMeasurementProcess
type in this plugin, becauseObservable.return_type
is being deprecated in the upcoming release of PennyLane. As this CI run shows, the PL-Braket plugin will need some updating to be compatible with the latest PennyLane.Request for this plugin
There are various functions that use/accept observables, but some of them actually need measurement processes. For example, BraketQubitDevice.statistics expects a list of Observables, then checks the
return_type
of the observables. This is a good indicator that we actually want the measurement processes. The proposed fix would be to callstatistics
withcircuit.measurements
instead ofcircuit.observables
, probably updating variable names and type-hints along the way.On the other hand, sometimes we intend on looking at the Observable and not the MeasurementProcess. From what I see, we only want to use Observables when we're about to call _translate_observable. Assuming you rename the
observable
argument fortranslate_result_type
to something likemeasurement
, you could add something likeobservable = measurement.obs
(perhaps gracefully handling the case where it'sNone
) before translating any Observables, and that should do it!Background
In PennyLane, measurement processes would previously be described using the Observable class. However, we've been moving towards using the MeasurementProcess class instead, as this encapsulates more accurate/general information about circuit measurements. As an example, consider the
qml.probs()
measurement - there is no PennyLane Observable being measured per se, but there is a measurement to be processed. This issue has been masked for some time by being able to sneak the type of measurement process onto anObservable
(on thereturn_type
property), but it is now deprecated. ComparingQuantumTape.observables
toQuantumTape.measurements
best highlights this distinction, so I'll show an example here:tape.observables
will quietly return something that isn't anObservable
, which can lead to unexpected behaviour. On the other hand,tape.measurements
will always return MeasurementProcess instances. The standard way to check if a process is measuring an observable ismp.obs is not None
.tl;dr,
tape.observables
returns a mish-mash ofObservable
andMeasurementProcess
instances, whereastape.measurements
always returns a list ofMeasurementProcess
instances, with themp.obs
property either being anObservable
, or None. So, if you need information about a measurement process, you should usetape.measurements
.Word of warning
The
Tensor
class actually has a property calledobs
, so there exists a funny case in which you might accidentally refer to the wrong attribute. For example: