Skip to content

Commit 481683c

Browse files
albi3roJaybsoni
andauthored
qml.grouping.is_pauli_word returns false for non-observables (#3039)
* qml.grouping.is_pauli_word returns false for non-observables * Update doc/releases/changelog-dev.md * Update doc/releases/changelog-dev.md Co-authored-by: Jay Soni <[email protected]> Co-authored-by: Jay Soni <[email protected]>
1 parent 74ba19e commit 481683c

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

doc/releases/changelog-dev.md

+3
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,9 @@
296296
and the diagonalising gates using the factors/summands instead of using the full matrix.
297297
[(#3022)](https://github.com/PennyLaneAI/pennylane/pull/3022)
298298

299+
* `qml.grouping.is_pauli_word` now returns `False` for operators that don't inherit from `qml.Observable`, instead of raising an error.
300+
[(#3039)](https://github.com/PennyLaneAI/pennylane/pull/3039)
301+
299302
<h3>Breaking changes</h3>
300303

301304
* Measuring an operator that might not be hermitian as an observable now raises a warning instead of an

pennylane/grouping/utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def is_pauli_word(observable):
7474
"""
7575

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

7979
pauli_word_names = ["Identity", "PauliX", "PauliY", "PauliZ"]
8080
if isinstance(observable, Tensor):

tests/grouping/test_grouping_utils.py

+8
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,14 @@ def test_is_pauli_word(self):
256256
assert not is_pauli_word(observable_3)
257257
assert not is_pauli_word(observable_4)
258258

259+
def test_is_pauli_word_non_observable(self):
260+
"""Test that non-observables are not Pauli Words."""
261+
262+
class DummyOp(qml.operation.Operator):
263+
num_wires = 1
264+
265+
assert not is_pauli_word(DummyOp(1))
266+
259267
def test_are_identical_pauli_words(self):
260268
"""Tests for determining if two Pauli words have the same ``wires`` and ``name`` attributes."""
261269

0 commit comments

Comments
 (0)