class_docstr: Test working cases of stoch_pulse_grad.
class_docstr_tok: ["Test","working","cases","of","stoch_pulse_grad","."]
docstr: Test the derivative of a more complex pulse.
docstr_tok: ["Test","the","derivative","of","a","more","complex","pulse","."]
code: def test_advanced_pulse(self, dev_name):
      """Test the derivative of a more complex pulse."""
      import jax
      import jax.numpy as jnp
  
      jax.config.update("jax_enable_x64", True)
  
      ham = (
          qml.pulse.constant * qml.PauliX(0)
          + (lambda p, t: jnp.sin(p * t)) * qml.PauliZ(0)
          + jnp.polyval
          * qml.dot(
              [1.0, 0.4],
              [
                  qml.PauliY(0) @ qml.PauliY(1),
                  qml.PauliX(0) @ qml.PauliX(1),
              ],
          )
      )
      params = [
          jnp.array(1.51),
          jnp.array(-0.371),
          jnp.array([0.2, 0.2, -0.4]),
      ]
      dev = qml.device(dev_name, wires=2)
  
      @qml.qnode(dev, interface="jax")
      def qnode(params):
          qml.evolve(ham, atol=1e-6)(params, 0.1)
          return qml.expval(qml.PauliY(0) @ qml.PauliX(1))
  
      qnode.construct((params,), {})
  
      num_split_times = 5
      qnode.tape.trainable_params = [0, 1, 2]
  
      tapes, fn = stoch_pulse_grad(
          qnode.tape, num_split_times=num_split_times, sampler_seed=7123
      )
      # Two generating terms with two shifts (X_0 and Z_0), one with eight shifts
      # (Y_0Y_1+0.4 X_1 has eigenvalues [-1.4, -0.6, 0.6, 1.4] yielding frequencies
      # [0.8, 1.2, 2.0, 2.8] and hence 2 * 4 = 8 shifts)
      num_shifts = 2 * 2 + 8
      assert len(tapes) == num_shifts * num_split_times
  
      res = fn(qml.execute(tapes, dev, None))
      exp_grad = jax.grad(qnode)(params)
      assert all(
          qml.math.allclose(r, e, rtol=0.4)
          for r, e in zip(res, exp_grad)
      )
      jax.clear_caches()
  
imports: import warnings
  import copy
  import pytest
  import numpy
  import pennylane
  from pennylane.gradients.general_shift_rules import eigvals_to_frequencies, generate_shift_rule
  from pennylane.gradients.pulse_gradient import _parshift_and_integrate, _split_evol_ops, _split_evol_tape, stoch_pulse_grad
label_desc: Use image node_id 11 for calling the TestStochPulseGrad obj's underlying member method code with example usage: obj.test_advanced_pulse(dev_name) and returns: qml