class_docstr: Tests for the quantum gradients of various gates
  with expectation value output
docstr: Test the gradient of the squeezed gate. We also
  ensure that the gradient is correct even when an operation
  with no Heisenberg representation is a descendent.
docstr_tok: ["Test","the","gradient","of","the","squeezed","gate",".","We","also","ensure","that","the","gradient","is","correct","even","when","an","operation","with","no","Heisenberg","representation","is","a","descendent","."]
code: def test_squeezed_gradient(self, mocker, tol):
      """Test the gradient of the squeezed gate. We also
      ensure that the gradient is correct even when an operation
      with no Heisenberg representation is a descendent."""
      dev = qml.device("default.gaussian", wires=2, hbar=hbar)
  
      # pylint: disable=too-few-public-methods
      class Rotation(qml.operation.CVOperation):
          """Dummy operation that does not support
          heisenberg representation"""
  
          num_wires = 1
          par_domain = "R"
          grad_method = "A"
  
      alpha = 0.5643
      r = 0.23354
  
      with qml.queuing.AnnotatedQueue() as q:
          qml.Displacement(alpha, 0.0, wires=[0])
          qml.Squeezing(r, 0.0, wires=[0])
  
          # The following two gates have no effect
          # on the circuit gradient and expectation value
          qml.Beamsplitter(0.0, 0.0, wires=[0, 1])
          Rotation(0.543, wires=[1])
  
          qml.expval(qml.QuadX(0))
  
      tape = qml.tape.QuantumScript.from_queue(q)
      tape.trainable_params = {2}
  
      spy2 = mocker.spy(
          qml.gradients.parameter_shift_cv, "second_order_param_shift"
      )
  
      tapes, fn = param_shift_cv(tape, dev)
      grad_A = fn(dev.batch_execute(tapes))
      spy2.assert_not_called()
  
      tapes, fn = param_shift_cv(tape, dev, force_order2=True)
      grad_A2 = fn(dev.batch_execute(tapes))
      spy2.assert_called()
  
      expected = -np.exp(-r) * hbar * alpha
      assert np.allclose(grad_A, expected, atol=tol, rtol=0)
      assert np.allclose(grad_A2, expected, atol=tol, rtol=0)
  
imports: import unittest.mock
  import pytest
  import pennylane
  from pennylane import numpy
  from pennylane.gradients import param_shift_cv
  from pennylane.gradients.gradient_transform import choose_trainable_params
  from pennylane.gradients.parameter_shift_cv import _grad_method_cv, _find_gradient_methods_cv, _transform_observable
label_desc: Use image node_id 4 for calling the TestExpectationQuantumGradients obj's underlying member method code with example usage: obj.test_squeezed_gradient(mocker, tol) without return types