class_docstr: Test tensor sample values.
class_docstr_tok: ["Test","tensor","sample","values","."]
docstr: Test that a tensor product involving qml.Hermitian works correctly
code: def test_hermitian(self, device, tol, skip_if):
      """Test that a tensor product involving qml.Hermitian works correctly"""
      n_wires = 3
      dev = device(n_wires)
  
      if dev.shots is None:
          pytest.skip(
              "Device is in analytic mode, cannot test sampling."
          )
  
      if "Hermitian" not in dev.observables:
          pytest.skip(
              "Skipped because device does not support the Hermitian observable."
          )
  
      skip_if(dev, {"supports_tensor_observables": False})
  
      theta = 0.432
      phi = 0.123
      varphi = -0.543
  
      A_ = 0.1 * np.array(
          [
              [-6, 2 + 1j, -3, -5 + 2j],
              [2 - 1j, 0, 2 - 1j, -5 + 4j],
              [-3, 2 + 1j, 0, -4 + 3j],
              [-5 - 2j, -5 - 4j, -4 - 3j, -6],
          ]
      )
  
      @qml.qnode(dev)
      def circuit():
          qml.RX(theta, wires=[0])
          qml.RX(phi, wires=[1])
          qml.RX(varphi, wires=[2])
          qml.CNOT(wires=[0, 1])
          qml.CNOT(wires=[1, 2])
          return qml.sample(
              qml.PauliZ(wires=[0]) @ qml.Hermitian(A_, wires=[1, 2])
          )
  
      res = circuit()
  
      # res should only contain the eigenvalues of
      # the hermitian matrix tensor product Z
      Z = np.diag([1, -1])
      eigvals = np.linalg.eigvalsh(np.kron(Z, A_))
      assert np.allclose(
          sorted(np.unique(res)), sorted(eigvals), atol=tol(False)
      )
  
      mean = np.mean(res)
      expected = (
          0.1
          * 0.5
          * (
              -6 * np.cos(theta) * (np.cos(varphi) + 1)
              - 2
              * np.sin(varphi)
              * (np.cos(theta) + np.sin(phi) - 2 * np.cos(phi))
              + 3 * np.cos(varphi) * np.sin(phi)
              + np.sin(phi)
          )
      )
      assert np.allclose(mean, expected, atol=tol(False))
  
      var = np.var(res)
      expected = (
          0.01
          * (
              1057
              - np.cos(2 * phi)
              + 12 * (27 + np.cos(2 * phi)) * np.cos(varphi)
              - 2
              * np.cos(2 * varphi)
              * np.sin(phi)
              * (16 * np.cos(phi) + 21 * np.sin(phi))
              + 16 * np.sin(2 * phi)
              - 8
              * (-17 + np.cos(2 * phi) + 2 * np.sin(2 * phi))
              * np.sin(varphi)
              - 8
              * np.cos(2 * theta)
              * (3 + 3 * np.cos(varphi) + np.sin(varphi)) ** 2
              - 24
              * np.cos(phi)
              * (np.cos(phi) + 2 * np.sin(phi))
              * np.sin(2 * varphi)
              - 8
              * np.cos(theta)
              * (
                  4
                  * np.cos(phi)
                  * (
                      4
                      + 8 * np.cos(varphi)
                      + np.cos(2 * varphi)
                      - (1 + 6 * np.cos(varphi)) * np.sin(varphi)
                  )
                  + np.sin(phi)
                  * (
                      15
                      + 8 * np.cos(varphi)
                      - 11 * np.cos(2 * varphi)
                      + 42 * np.sin(varphi)
                      + 3 * np.sin(2 * varphi)
                  )
              )
          )
          / 16
      )
      assert np.allclose(var, expected, atol=tol(False))
  
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 3 for calling the TestTensorSample obj's underlying member method code with example usage: obj.test_hermitian(device, tol, skip_if) and returns: qml