class_docstr: Test the SPSA optimizer.
docstr: Test that the correct param is returned via the step method.
docstr_tok: ["Test","that","the","correct","param","is","returned","via","the","step","method","."]
code: def test_step_spsa(self):
      """Test that the correct param is returned via the step method."""
      spsa_opt = qml.SPSAOptimizer(maxiter=10)
  
      @qml.qnode(qml.device("default.qubit", wires=1))
      def quant_fun(params):
          qml.RX(params[0], wires=[0])
          qml.RY(params[1], wires=[0])
          qml.RY(params[2], wires=[0])
          return qml.expval(qml.PauliZ(0))
  
      args = np.array([0.4, 0.2, 0.8], requires_grad=True)
  
      alpha = 0.602
      gamma = 0.101
      c = 0.2
      A = 1.0
      a = 0.05 * (A + 1) ** alpha
      k = 1
      ck = c / k**gamma
      ak = a / (A + k) ** alpha
      deltas = np.array(
          np.meshgrid([1, -1], [1, -1], [1, -1])
      ).T.reshape(-1, 3)
  
      y_pm = []
      for delta in deltas:
          thetaplus = list(args)
          thetaminus = list(args)
          for index, arg in enumerate(args):
              multiplier = ck * delta[index]
              thetaplus[index] = arg + multiplier
              thetaminus[index] = arg - multiplier
          yplus = quant_fun(thetaplus)
          yminus = quant_fun(thetaminus)
          y_pm.append(yplus - yminus)
      # choose one delta
      d = 0
      grad = np.array([y_pm[d] / (2 * ck * di) for di in deltas[d]])
      tol = ak * max(np.abs(y_pm)) / ck
  
      expected = args - ak * grad
  
      res = spsa_opt.step(quant_fun, args)
  
      assert np.allclose(res, expected, atol=tol)
  
imports: import pytest
  import pennylane
  from pennylane import numpy
label_desc: Use image node_id 6 for calling the TestSPSAOptimizer obj's underlying member method code with example usage: obj.test_step_spsa() and returns: qml