Executing differentiable circuits with adjoint and Sum
expectation values raises an error
#285
Labels
bug
Something isn't working
Sum
expectation values raises an error
#285
Describe the bug
I found this issue when attempting to run the Computing gradients in parallel with Amazon Braket PennyLane demo locally. When attempting to optimize a circuit measuring a
LinearCombination
, the execution raises a warning saying that adjoint differentation isn't supported for circuits with multi-term observables. This was a pennylane-side issue that is being addressed currently. However, after applying the PL-side fix, there is another error being raised. See details below. Note that I've only observed this failure for cases where theLinearCombination
can be simplified. I've provided details in the "Additional context" section.To reproduce
The following is a minimum working example where I observe the failure:
Expected behavior
I expected the execution to give correct results.
Screenshots or logs
Running the above code block gives the following output:
System information
A description of your system. Please provide:
Additional context
Based on my debugging, this is happening when the pennylane observable is being translated into a braket observable. In
BraketQubitDevice._apply_gradient_result_type
, we get thetargets
using the wires of the terms of the observable. However, in the subsequent call toget_adjoint_gradient_result_type
(intranslation.py
), we simplify the pennylane observable (when calling_flatten_observable
), but the targets are still the same as the unsimplified observable. This causes a mismatch when initializingAdjointGradient
and raises the error seen above.Note that if you tried running the example provided above with latest pennylane, the error will not occur (because of the warning mentioned in the bug description; a side effect of that warning is to change the diff method from adjoint to parameter-shift), so the
mudit/0.40-fixes
branch must be used. That branch will be merged into the v0.40 release candidate by end of week.The text was updated successfully, but these errors were encountered: