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 is exactly the same when reusing a seed and
  that it differs when using a different seed.
docstr_tok: ["Test","that","the","derivative","of","a","pulse","is","exactly","the","same","when","reusing","a","seed","and","that","it","differs","when","using","a","different","seed","."]
code: def test_randomness(self, dev_name):
      """Test that the derivative of a pulse is exactly the same when reusing a seed and
      that it differs when using a different seed."""
      import jax
      import jax.numpy as jnp
  
      jax.config.update("jax_enable_x64", True)
  
      params = [jnp.array(1.51)]
      op = qml.evolve((lambda p, t: p * t) * qml.PauliX(0))(params, 0.4)
      tape = qml.tape.QuantumScript([op], [qml.expval(qml.PauliY(0))])
  
      seed_a = 8752
      seed_b = 8753
      tapes_a_0, fn_a_0 = stoch_pulse_grad(
          tape, num_split_times=2, sampler_seed=seed_a
      )
      tapes_a_1, fn_a_1 = stoch_pulse_grad(
          tape, num_split_times=2, sampler_seed=seed_a
      )
      tapes_b, fn_b = stoch_pulse_grad(
          tape, num_split_times=2, sampler_seed=seed_b
      )
  
      for tape_a_0, tape_a_1, tape_b in zip(
          tapes_a_0, tapes_a_1, tapes_b
      ):
          for op_a_0, op_a_1, op_b in zip(tape_a_0, tape_a_1, tape_b):
              if isinstance(op_a_0, qml.pulse.ParametrizedEvolution):
                  # The a_0 and a_1 operators are equal
                  assert qml.equal(op_a_0, op_a_1)
                  # The a_0 and b operators differ in time but are equal otherwise
                  assert not qml.equal(op_a_0, op_b)
                  op_b.t = op_a_0.t
                  assert qml.equal(op_a_0, op_b)
              else:
                  assert qml.equal(op_a_0, op_a_1) and qml.equal(
                      op_a_0, op_b
                  )
  
      dev = qml.device(dev_name, wires=1)
      res_a_0 = fn_a_0(qml.execute(tapes_a_0, dev, None))
      res_a_1 = fn_a_1(qml.execute(tapes_a_1, dev, None))
      res_b = fn_b(qml.execute(tapes_b, dev, None))
  
      assert res_a_0 == res_a_1
      assert not res_a_0 == res_b
      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 12 for calling the TestStochPulseGrad obj's underlying member method code with example usage: obj.test_randomness(dev_name) without return types