class_docstr: Test for measurement expansion
class_docstr_tok: ["Test","for","measurement","expansion"]
docstr: Test the expansion of an hermitian observable
docstr_tok: ["Test","the","expansion","of","an","hermitian","observable"]
code: def test_expand_hermitian(self, tol):
      """Test the expansion of an hermitian observable"""
      H = np.array([[1, 2], [2, 4]])
      obs = qml.Hermitian(H, wires=["a"])
  
      m = qml.expval(op=obs)
      tape = m.expand()
  
      assert len(tape.operations) == 1
  
      assert tape.operations[0].name == "QubitUnitary"
      assert tape.operations[0].wires.tolist() == ["a"]
      assert np.allclose(
          tape.operations[0].parameters[0],
          np.array([[-2, 1], [1, 2]]) / np.sqrt(5),
          atol=tol,
          rtol=0,
      )
  
      assert len(tape.measurements) == 1
      assert tape.measurements[0].return_type is Expectation
      assert tape.measurements[0].wires.tolist() == ["a"]
      assert np.all(tape.measurements[0].eigvals() == np.array([0, 5]))
  
imports: import numpy
  import pytest
  import pennylane
  from pennylane.measurements import ClassicalShadowMP, Counts, CountsMP, Expectation, ExpectationMP, MeasurementProcess, MeasurementTransform, MeasurementValue, MidMeasure, MidMeasureMP, MutualInfoMP, PurityMP, Probability, ProbabilityMP, Sample, SampleMeasurement, SampleMP, ShadowExpvalMP, Shots, State, StateMeasurement, StateMP, Variance, VarianceMP, VnEntropyMP, expval, sample, var
  from pennylane.operation import DecompositionUndefinedError
  from pennylane.queuing import AnnotatedQueue
  from pennylane.wires import Wires
label_desc: Use image node_id 2 for calling the TestExpansion obj's underlying member method code with example usage: obj.test_expand_hermitian(tol) without return types