class_docstr: Tests for the SPSA gradient transform
class_docstr_tok: ["Tests","for","the","SPSA","gradient","transform"]
docstr: Test that the transform output shape matches that of the QNode.
docstr_tok: ["Test","that","the","transform","output","shape","matches","that","of","the","QNode","."]
code: def test_output_shape_matches_qnode(self):
      """Test that the transform output shape matches that of the QNode."""
      dev = qml.device(
          "default.qubit", wires=4, shots=many_shots_shot_vector
      )
  
      def cost1(x):
          qml.Rot(*x, wires=0)
          return qml.expval(qml.PauliZ(0))
  
      def cost2(x):
          qml.Rot(*x, wires=0)
          return [qml.expval(qml.PauliZ(0))]
  
      def cost3(x):
          qml.Rot(*x, wires=0)
          return [qml.expval(qml.PauliZ(0)), qml.expval(qml.PauliZ(1))]
  
      def cost4(x):
          qml.Rot(*x, wires=0)
          return qml.probs([0, 1])
  
      def cost5(x):
          qml.Rot(*x, wires=0)
          return [qml.probs([0, 1])]
  
      def cost6(x):
          qml.Rot(*x, wires=0)
          return qml.probs([0, 1]), qml.probs([2, 3])
  
      x = np.random.rand(3)
      circuits = [
          qml.QNode(cost, dev)
          for cost in (cost1, cost2, cost3, cost4, cost5, cost6)
      ]
  
      transform = [
          qml.math.shape(spsa_grad(c, h=h_val)(x)) for c in circuits
      ]
  
      expected = [
          (3, 3),
          (1, 3, 3),
          (3, 2, 3),
          (3, 3, 4),
          (1, 3, 3, 4),
          (3, 2, 3, 4),
      ]
  
      assert all(t == q for t, q in zip(transform, expected))
  
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 14 for calling the TestSpsaGradient obj's underlying member method code with example usage: obj.test_output_shape_matches_qnode() and returns: qml, list, list, qml, list, qml,  qml