Skip to content
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

qml.grouping.is_pauli_word returns false for non-observables #3039

Merged
merged 3 commits into from
Sep 8, 2022
Merged
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
3 changes: 3 additions & 0 deletions doc/releases/changelog-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,9 @@
and the diagonalising gates using the factors/summands instead of using the full matrix.
[(#3022)](https://github.com/PennyLaneAI/pennylane/pull/3022)

* `qml.grouping.is_pauli_word` now returns `False` for operators that don't inherit from `qml.Observable`, instead of raising an error.
[(#3039)](https://github.com/PennyLaneAI/pennylane/pull/3039)

<h3>Breaking changes</h3>

* Measuring an operator that might not be hermitian as an observable now raises a warning instead of an
Expand Down
2 changes: 1 addition & 1 deletion pennylane/grouping/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def is_pauli_word(observable):
"""

if not isinstance(observable, Observable):
raise TypeError(f"Expected {Observable} instance, instead got {type(observable)} instance.")
return False

pauli_word_names = ["Identity", "PauliX", "PauliY", "PauliZ"]
if isinstance(observable, Tensor):
Expand Down
8 changes: 8 additions & 0 deletions tests/grouping/test_grouping_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,14 @@ def test_is_pauli_word(self):
assert not is_pauli_word(observable_3)
assert not is_pauli_word(observable_4)

def test_is_pauli_word_non_observable(self):
"""Test that non-observables are not Pauli Words."""

class DummyOp(qml.operation.Operator):
num_wires = 1

assert not is_pauli_word(DummyOp(1))

def test_are_identical_pauli_words(self):
"""Tests for determining if two Pauli words have the same ``wires`` and ``name`` attributes."""

Expand Down