class_docstr: Unit tests for the hadamard_grad function
class_docstr_tok: ["Unit","tests","for","the","hadamard_grad","function"]
docstr: Tests that the automatic gradient of an arbitrary controlled Euler-angle-parameterized
  gate is correct.
code: def test_CRot_gradient_with_expansion(self, theta, tol):
      """Tests that the automatic gradient of an arbitrary controlled Euler-angle-parameterized
      gate is correct."""
      dev = qml.device("default.qubit", wires=3)
      a, b, c = np.array([theta, theta**3, np.sqrt(2) * theta])
  
      with qml.queuing.AnnotatedQueue() as q:
          qml.StatePrep(
              np.array([1.0, -1.0], requires_grad=False) / np.sqrt(2),
              wires=0,
          )
          qml.CRot(a, b, c, wires=[0, 1])
          qml.expval(qml.PauliX(0))
  
      tape = qml.tape.QuantumScript.from_queue(q)
      tape.trainable_params = {1, 2, 3}
  
      res_hadamard = dev.execute(tape)
      expected = -np.cos(b / 2) * np.cos(0.5 * (a + c))
      assert np.allclose(res_hadamard, expected, atol=tol, rtol=0)
  
      grad, _ = grad_fn(tape, dev)
  
      expected = np.array(
          [
              0.5 * np.cos(b / 2) * np.sin(0.5 * (a + c)),
              0.5 * np.sin(b / 2) * np.cos(0.5 * (a + c)),
              0.5 * np.cos(b / 2) * np.sin(0.5 * (a + c)),
          ]
      )
  
      assert isinstance(grad, tuple)
      assert len(grad) == 5
      assert np.allclose(-grad[1] / 2, expected[0], atol=tol, rtol=0)
      assert np.allclose(-grad[2] / 2, expected[1], atol=tol, rtol=0)
      assert np.allclose(-grad[1] / 2, expected[2], atol=tol, rtol=0)
  
imports: import pytest
  import pennylane
  from pennylane import numpy
label_desc: Use image node_id 9 for calling the TestHadamardGrad obj's underlying member method code with example usage: obj.test_CRot_gradient_with_expansion(theta, tol) without return types