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 a constant Hamiltonian,
  which is a Pauli sentence, is computed correctly.
docstr_tok: ["Test","that","the","derivative","of","a","pulse","generated","by","a","constant","Hamiltonian",",","which","is","a","Pauli","sentence",",","is","computed","correctly","."]
code: def test_constant_ry_rescaled(self, dev_name, num_split_times, t):
      """Test that the derivative of a pulse generated by a constant Hamiltonian,
      which is a Pauli sentence, is computed correctly."""
      import jax
      import jax.numpy as jnp
  
      jax.config.update("jax_enable_x64", True)
      params = [jnp.array(0.24)]
      T = t if isinstance(t, tuple) else (0, t)
      ham_single_q_const = qml.pulse.constant * qml.dot(
          [0.2, 0.9], [qml.PauliY(0), qml.PauliX(0)]
      )
      op = qml.evolve(ham_single_q_const)(params, t)
      tape = qml.tape.QuantumScript([op], [qml.expval(qml.PauliZ(0))])
  
      dev = qml.device(dev_name, wires=1)
      # Prefactor due to the generator being a Pauli sentence
      prefactor = np.sqrt(0.85)
      # Effective rotation parameter
      p = params[0] * (delta_t := (T[-1] - T[0])) * prefactor
      r = qml.execute([tape], dev, None)
      assert qml.math.isclose(r, jnp.cos(2 * p), atol=1e-4)
      tapes, fn = stoch_pulse_grad(
          tape, num_split_times=num_split_times
      )
      assert len(tapes) == num_split_times * 2
  
      res = fn(qml.execute(tapes, dev, None))
      assert qml.math.isclose(
          res, -2 * jnp.sin(2 * p) * delta_t * prefactor
      )
      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 5 for calling the TestStochPulseGrad obj's underlying member method code with example usage: obj.test_constant_ry_rescaled(dev_name, num_split_times, t) without return types