class_docstr: Test working cases of stoch_pulse_grad.
class_docstr_tok: ["Test","working","cases","of","stoch_pulse_grad","."]
docstr: Test that the derivatives of two pulses in a circuit are computed correctly.
docstr_tok: ["Test","that","the","derivatives","of","two","pulses","in","a","circuit","are","computed","correctly","."]
code: def test_two_pulses(self, dev_name):
      """Test that the derivatives of two pulses in a circuit are computed correctly."""
      import jax
      import jax.numpy as jnp
  
      jax.config.update("jax_enable_x64", True)
  
      ham_0 = qml.pulse.constant * qml.PauliX(0) + (
          lambda p, t: jnp.sin(p * t)
      ) * qml.PauliY(0)
      ham_1 = qml.dot(
          [0.3, jnp.polyval],
          [qml.PauliZ(0), qml.PauliY(0) @ qml.PauliY(1)],
      )
      params_0 = [jnp.array(1.51), jnp.array(-0.371)]
      params_1 = [jnp.array([0.2, 0.2, -0.4])]
      dev = qml.device(dev_name, wires=2)
  
      @qml.qnode(dev, interface="jax")
      def qnode(params_0, params_1):
          qml.evolve(ham_0)(params_0, 0.1)
          qml.evolve(ham_1)(params_1, 0.15)
          return qml.expval(qml.PauliY(0) @ qml.PauliZ(1))
  
      qnode.construct((params_0, params_1), {})
  
      num_split_times = 3
      qnode.tape.trainable_params = [0, 1, 2]
      tapes, fn = stoch_pulse_grad(
          qnode.tape, num_split_times=num_split_times, sampler_seed=7123
      )
      assert len(tapes) == 3 * 2 * num_split_times
  
      res = fn(qml.execute(tapes, dev, None))
      exp_grad = jax.grad(qnode, argnums=(0, 1))(params_0, params_1)
      exp_grad = exp_grad[0] + exp_grad[1]
      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 13 for calling the TestStochPulseGrad obj's underlying member method code with example usage: obj.test_two_pulses(dev_name) and returns: qml