Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/braket/pennylane_plugin/translation.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,8 @@ def translate_result_type( # noqa: C901
observable = measurement.obs

if isinstance(measurement, qml.measurements.ProbabilityMP):
if observable and observable.diagonalizing_gates():
raise qml.DeviceError("Probability result type not supported for observables")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks to be causing some issues for the tests. Is this the expected outcome now?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So at the moment the pl-device-tests are xfailing the hadamard gradient tests due to the incorrect results. We may instead need to xfail at a different location as now we get an error on execution, instead of on result comparison:

https://github.com/PennyLaneAI/pennylane/blob/883c3ed0a66d06841e074c90f59317972af36cee/pennylane/devices/tests/test_gradients_autograd.py#L141

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the device tests are still failing; is there a workaround I can use?

return Probability(targets)

if isinstance(measurement, qml.measurements.StateMP):
Expand Down
11 changes: 11 additions & 0 deletions test/unit_tests/test_translation.py
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,17 @@ def test_translate_result_type_unsupported_obs():
translate_result_type(tape.measurements[0], [0], frozenset())


def test_translate_result_type_probs_observable():
"""Tests if a DeviceError is raised by translate_result_type for a Probability return type
with an observable attached"""
mp = qml.probs(op=qml.X(wires=0))

with pytest.raises(
qml.DeviceError, match="Probability result type not supported for observables"
):
translate_result_type(mp, [0], frozenset())


def test_translate_result():
result_dict = _result_meta()
result_dict["resultTypes"] = [
Expand Down
Loading