class_docstr: Test that differentiating tapes with ``pulse_odegen`` works.
class_docstr_tok: ["Test","that","differentiating","tapes","with","``","pulse_odegen","``","works","."]
docstr: Test that a single pulse with a single Hamiltonian term is
  differentiated correctly.
docstr_tok: ["Test","that","a","single","pulse","with","a","single","Hamiltonian","term","is","differentiated","correctly","."]
code: def test_single_pulse_single_term(self, dev_name, shots, tol):
      """Test that a single pulse with a single Hamiltonian term is
      differentiated correctly."""
      import jax
      import jax.numpy as jnp
  
      prng_key = jax.random.PRNGKey(8251)
      key = "prng_key" if dev_name == "default.qubit.jax" else "seed"
      dev = qml.device(
          dev_name, wires=1, shots=shots, **{key: prng_key}
      )
  
      H = jnp.polyval * X(0)
      x = jnp.array([0.4, 0.2, 0.1])
      t = [0.2, 0.3]
      op = qml.evolve(H)([x], t=t)
      tape = qml.tape.QuantumScript(
          [op], [qml.expval(Z(0))], shots=shots
      )
  
      val = qml.execute([tape], dev)
      theta = integral_of_polyval(x, t)
      assert qml.math.allclose(val, jnp.cos(2 * theta), atol=tol)
  
      _tapes, fn = pulse_odegen(tape)
      assert len(_tapes) == 2
  
      grad = fn(qml.execute(_tapes, dev))
      par_jac = jax.jacobian(integral_of_polyval)(x, t)
      exp_grad = -2 * par_jac * jnp.sin(2 * theta)
      if isinstance(shots, list):
          assert isinstance(grad, tuple) and len(grad) == len(shots)
          assert all(
              isinstance(g, jnp.ndarray) and g.shape == x.shape
              for g in grad
          )
          assert qml.math.allclose(grad, exp_grad, atol=tol)
      else:
          assert isinstance(grad, jnp.ndarray) and grad.shape == x.shape
          assert qml.math.allclose(grad, exp_grad, atol=tol)
  
imports: import copy
  import pytest
  import numpy
  import pennylane
  from pennylane import numpy
  from pennylane.ops.qubit.special_unitary import pauli_basis_matrices, pauli_basis_strings
  from pennylane.math import expand_matrix
  from pennylane.gradients.pulse_gradient_odegen import _generate_tapes_and_coeffs, pulse_odegen, _insert_op, _nonzero_coeffs_and_words, _one_parameter_generators, _one_parameter_paulirot_coeffs, _parshift_and_contract
label_desc: Use image node_id 1 for calling the TestPulseOdegenTape obj's underlying member method code with example usage: obj.test_single_pulse_single_term(dev_name, shots, tol) without return types