Skip to content

Commit

Permalink
Fix failing test in legacy opmath (#6272)
Browse files Browse the repository at this point in the history
A follow up of #6252, does
the same but with a different test.
  • Loading branch information
astralcai authored and mudit2812 committed Sep 18, 2024
1 parent 0c7b2d7 commit cde7b81
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions tests/transforms/test_diagonalize_measurements.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
null_postprocessing,
)

# pylint: disable=protected-access


class TestDiagonalizeObservable:
"""Tests for the _diagonalize_observable method"""
Expand Down Expand Up @@ -315,13 +317,9 @@ def test_diagonalize_all_measurements(self, to_eigvals):
assert isinstance(new_tape.measurements[1], VarianceMP)
assert new_tape.measurements[0].wires == qml.wires.Wires([0])
assert new_tape.measurements[1].wires == qml.wires.Wires([1, 2])
assert qml.math.allclose(sorted(new_tape.measurements[0]._eigvals), [-1.0, 1.0])
assert qml.math.allclose(
sorted(new_tape.measurements[0]._eigvals), # pylint: disable=protected-access
[-1.0, 1.0],
)
assert qml.math.allclose(
sorted(new_tape.measurements[1]._eigvals), # pylint: disable=protected-access
[-2.0, 0.0, 0.0, 2.0],
sorted(new_tape.measurements[1]._eigvals), [-2.0, 0.0, 0.0, 2.0]
)
else:
assert new_tape.measurements == [qml.expval(Z(0)), qml.var(Z(1) + Z(2))]
Expand Down Expand Up @@ -448,11 +446,16 @@ def test_with_duplicate_measurements(self, to_eigvals, supported_base_obs):
new_tape = tapes[0]

if to_eigvals:
assert new_tape.measurements == [
ExpectationMP(eigvals=[1.0, -1], wires=[0]),
VarianceMP(eigvals=[2.0, 0.0, 0.0, -2.0], wires=[1, 2]),
SampleMP(eigvals=[1.0, -1.0, -1.0, 1.0], wires=[0, 2]),
]
assert len(new_tape.measurements) == 3
assert isinstance(new_tape.measurements[0], ExpectationMP)
assert isinstance(new_tape.measurements[1], VarianceMP)
assert isinstance(new_tape.measurements[2], SampleMP)
assert new_tape.measurements[0].wires == qml.wires.Wires([0])
assert new_tape.measurements[1].wires == qml.wires.Wires([1, 2])
assert new_tape.measurements[2].wires == qml.wires.Wires([0, 2])
assert np.allclose(sorted(new_tape.measurements[0]._eigvals), [-1.0, 1])
assert np.allclose(sorted(new_tape.measurements[1]._eigvals), [-2.0, 0, 0, 2.0])
assert np.allclose(sorted(new_tape.measurements[2]._eigvals), [-1.0, -1.0, 1.0, 1.0])
else:
assert new_tape.measurements == [
qml.expval(Z(0)),
Expand Down

0 comments on commit cde7b81

Please sign in to comment.