class_docstr: Test that the transform is differentiable
class_docstr_tok: ["Test","that","the","transform","is","differentiable"]
docstr: Tests that the output of the SPSA gradient transform
  of a ragged tape can be differentiated using TF, yielding second derivatives.
docstr_tok: ["Tests","that","the","output","of","the","SPSA","gradient","transform","of","a","ragged","tape","can","be","differentiated","using","TF",",","yielding","second","derivatives","."]
code: def test_tf_ragged(self, dev_name, approx_order, strategy):
      """Tests that the output of the SPSA gradient transform
      of a ragged tape can be differentiated using TF, yielding second derivatives.
      """
      import tensorflow as tf
  
      dev = qml.device(dev_name, wires=2, shots=many_shots_shot_vector)
      execute_fn = (
          dev.execute
          if dev_name == "default.qubit"
          else dev.batch_execute
      )
      params = tf.Variable([0.543, -0.654], dtype=tf.float64)
      rng = np.random.default_rng(42)
  
      with tf.GradientTape(persistent=True) as t:
          with qml.queuing.AnnotatedQueue() as q:
              qml.RX(params[0], wires=[0])
              qml.RY(params[1], wires=[1])
              qml.CNOT(wires=[0, 1])
              qml.expval(qml.PauliZ(0))
              qml.probs(wires=[1])
  
          tape = qml.tape.QuantumScript.from_queue(
              q, shots=many_shots_shot_vector
          )
          tape.trainable_params = {0, 1}
          tapes, fn = spsa_grad(
              tape,
              n=1,
              approx_order=approx_order,
              strategy=strategy,
              h=h_val,
              sampler_rng=rng,
          )
  
          jac_01 = fn(execute_fn(tapes))[1][0]
  
      x, y = 1.0 * params
  
      res_01 = t.jacobian(jac_01, params)
  
      expected = np.array(
          [-np.cos(x) * np.cos(y) / 2, np.sin(x) * np.sin(y) / 2]
      )
  
      assert np.allclose(
          res_01[0], expected, atol=spsa_shot_vec_tol, rtol=0
      )
  
imports: import numpy
  import pytest
  from pennylane import numpy
  import pennylane
  from pennylane.gradients import spsa_grad
  from pennylane.devices import DefaultQubitLegacy
  from pennylane.measurements import Shots
  from pennylane.operation import Observable, AnyWires
label_desc: Use image node_id 4 for calling the TestSpsaGradientDifferentiation obj's underlying member method code with example usage: obj.test_tf_ragged(dev_name, approx_order, strategy) without return types