class_docstr: Test that stoch_pulse_grad integrates correctly with QNodes and ML interfaces.
class_docstr_tok: ["Test","that","stoch_pulse_grad","integrates","correctly","with","QNodes","and","ML","interfaces","."]
docstr: Test that an advanced qnode can be differentiated with stoch_pulse_grad.
docstr_tok: ["Test","that","an","advanced","qnode","can","be","differentiated","with","stoch_pulse_grad","."]
code: def test_advanced_qnode(self, dev_name):
      """Test that an advanced qnode can be differentiated with stoch_pulse_grad."""
      import jax
      import jax.numpy as jnp
  
      jax.config.update("jax_enable_x64", True)
  
      params = [
          jnp.array(0.21),
          jnp.array(-0.171),
          jnp.array([0.05, 0.03, -0.1]),
      ]
      dev = qml.device(dev_name, wires=2)
      ham = (
          qml.pulse.constant * qml.PauliX(0)
          + (lambda p, t: jnp.sin(p * t)) * qml.PauliZ(0)
          + jnp.polyval * (qml.PauliY(0) @ qml.PauliY(1))
      )
  
      def ansatz(params):
          qml.evolve(ham)(params, 0.1)
          return qml.expval(qml.PauliY(0) @ qml.PauliX(1))
  
      num_split_times = 10
      qnode_pulse_grad = qml.QNode(
          ansatz,
          dev,
          interface="jax",
          diff_method=stoch_pulse_grad,
          num_split_times=num_split_times,
          sampler_seed=7123,
      )
      qnode_backprop = qml.QNode(ansatz, dev, interface="jax")
  
      with qml.Tracker(dev) as tracker:
          grad_pulse_grad = jax.grad(qnode_pulse_grad)(params)
      assert (
          tracker.totals["executions"] == (1 + 2 * 3 * num_split_times)
          if dev_name == "default.qubit.jax"
          else 1
      )
      grad_backprop = jax.grad(qnode_backprop)(params)
  
      assert all(
          qml.math.allclose(r, e, rtol=0.4)
          for r, e in zip(grad_pulse_grad, grad_backprop)
      )
      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 6 for calling the TestStochPulseGradIntegration obj's underlying member method code with example usage: obj.test_advanced_qnode(dev_name) and returns: qml