class_docstr: Tests for CV integration
class_docstr_tok: ["Tests","for","CV","integration"]
docstr: Test variance of a second order CV expectation value
docstr_tok: ["Test","variance","of","a","second","order","CV","expectation","value"]
code: def test_second_order_observable(
      self, diff_method, kwargs, interface, tol
  ):
      """Test variance of a second order CV expectation value"""
      dev = qml.device("default.gaussian", wires=1)
      if diff_method == "spsa":
          kwargs["sampler_rng"] = np.random.default_rng(SEED_FOR_SPSA)
          tol = TOL_FOR_SPSA
  
      n = 0.12
      a = 0.765
  
      @qnode(
          dev, interface=interface, diff_method=diff_method, **kwargs
      )
      def circuit(n, a):
          qml.ThermalState(n, wires=0)
          qml.Displacement(a, 0, wires=0)
          return qml.var(qml.NumberOperator(0))
  
      res = circuit(n, a)
      expected = n**2 + n + np.abs(a) ** 2 * (1 + 2 * n)
      assert np.allclose(res, expected, atol=tol, rtol=0)
  
      # circuit jacobians
      res = jax.grad(circuit, argnums=[0, 1])(n, a)
      expected = np.array([2 * a**2 + 2 * n + 1, 2 * a * (2 * n + 1)])
      assert np.allclose(res, expected, atol=tol, rtol=0)
  
imports: import pytest
  import pennylane
  from pennylane import numpy
  from pennylane import qnode
  from pennylane.tape import QuantumScript
label_desc: Use image node_id 2 for calling the TestCV obj's underlying member method code with example usage: obj.test_second_order_observable(diff_method, kwargs, interface, tol) and returns: qml