class_docstr: Test working cases of stoch_pulse_grad.
class_docstr_tok: ["Test","working","cases","of","stoch_pulse_grad","."]
docstr: Test that the derivative of a pulse generated by two constant commuting Hamiltonians
  is computed correctly.
docstr_tok: ["Test","that","the","derivative","of","a","pulse","generated","by","two","constant","commuting","Hamiltonians","is","computed","correctly","."]
code: def test_constant_commuting(self, dev_name, t):
      """Test that the derivative of a pulse generated by two constant commuting Hamiltonians
      is computed correctly."""
      import jax
      import jax.numpy as jnp
  
      jax.config.update("jax_enable_x64", True)
      params = [jnp.array(0.24), jnp.array(-0.672)]
      T = t if isinstance(t, tuple) else (0, t)
      op = qml.evolve(
          qml.pulse.constant * qml.PauliX(0)
          + qml.pulse.constant * qml.PauliY(1)
      )(params, t)
      tape = qml.tape.QuantumScript(
          [op], [qml.expval(qml.PauliZ(0) @ qml.PauliZ(1))]
      )
  
      dev = qml.device(dev_name, wires=2)
      r = qml.execute([tape], dev, None)
      # Effective rotation parameters
      p = [_p * (T[1] - T[0]) for _p in params]
      assert qml.math.isclose(r, jnp.cos(2 * p[0]) * jnp.cos(2 * p[1]))
      tapes, fn = stoch_pulse_grad(tape)
      assert len(tapes) == 4
  
      res = fn(qml.execute(tapes, dev, None))
      exp_grad = [
          -2 * jnp.sin(2 * p[0]) * jnp.cos(2 * p[1]) * (T[1] - T[0]),
          -2 * jnp.sin(2 * p[1]) * jnp.cos(2 * p[0]) * (T[1] - T[0]),
      ]
      assert qml.math.allclose(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 10 for calling the TestStochPulseGrad obj's underlying member method code with example usage: obj.test_constant_commuting(dev_name, t) without return types