class_docstr: Tests for the variance return type
class_docstr_tok: ["Tests","for","the","variance","return","type"]
docstr: Tests if the samples of a Hermitian observable returned by sample have
  the correct values
code: def test_var_hermitian(self, device, tol):
      """Tests if the samples of a Hermitian observable returned by sample have
      the correct values
      """
      n_wires = 2
      dev = device(n_wires)
  
      if "Hermitian" not in dev.observables:
          pytest.skip(
              "Skipped because device does not support the Hermitian observable."
          )
  
      phi = 0.543
      theta = 0.6543
      # test correct variance for <H> of a rotated state
      H = 0.1 * np.array([[4, -1 + 6j], [-1 - 6j, 2]])
  
      @qml.qnode(dev)
      def circuit():
          qml.RX(phi, wires=[0])
          qml.RY(theta, wires=[0])
          return qml.var(qml.Hermitian(H, wires=0))
  
      res = circuit()
  
      expected = (
          0.01
          * 0.5
          * (
              2 * np.sin(2 * theta) * np.cos(phi) ** 2
              + 24
              * np.sin(phi)
              * np.cos(phi)
              * (np.sin(theta) - np.cos(theta))
              + 35 * np.cos(2 * phi)
              + 39
          )
      )
  
      assert np.allclose(res, expected, atol=tol(dev.shots))
  
imports: import pytest
  from flaky import flaky
  from scipy.sparse import csr_matrix
  import pennylane
  from pennylane import numpy
  from pennylane.measurements import ClassicalShadowMP, MeasurementTransform, SampleMeasurement, SampleMP, StateMeasurement, StateMP
label_desc: Use image node_id 2 for calling the TestVar obj's underlying member method code with example usage: obj.test_var_hermitian(device, tol) and returns: qml