amazon-braket / amazon-braket-pennylane-plugin-python

A plugin for allowing Xanadu PennyLane to use Amazon Braket devices
https://amazon-braket-pennylane-plugin-python.readthedocs.io/
Apache License 2.0
43 stars 38 forks source link

Support `Prod` as observables #241

Closed astralcai closed 6 months ago

astralcai commented 7 months ago

Describe the feature you'd like

In the latest version of PennyLane (0.36.0-dev), new opmath is enabled by default. Observables made with @ will now be instances of Prod instead of Tensor. This will not work:

qml.expval(qml.PauliX(0) @ qml.PauliY(1))

because the pennylane-braket plugin currently do not know how to handle Prod.

Solution

In translation.py, add

@_translate_observable.register
def _(t: qml.ops.Prod):
    return reduce(lambda x, y: x @ y, [_translate_observable(factor) for factor in t.operands])

should make it work with new opmath.

ashlhans commented 7 months ago

Hi @astralcai - thank you for raising this issue! We will look into this.