class_docstr: Test the SPSA optimizer.
docstr: Test that a gradient step can be applied correctly with a univariate
  function.
docstr_tok: ["Test","that","a","gradient","step","can","be","applied","correctly","with","a","univariate","function","."]
code: def test_apply_grad(self, args, f):
      """Test that a gradient step can be applied correctly with a univariate
      function."""
      gamma = 0.3
      c = 0.1
      spsa_opt = qml.SPSAOptimizer(maxiter=10, c=c, gamma=gamma)
      args = np.array([args], requires_grad=True)
  
      alpha = 0.602
      A = 1.0
      a = 0.05 * (A + 1) ** alpha
      k = 1
      ck = c / k**gamma
      ak = a / (A + k) ** alpha
      # assume delta is 1.
      di = 1
      multiplier = ck * di
      yplus = f(args + multiplier)
      yminus = f(args - multiplier)
      grad = (yplus - yminus) / (2 * multiplier)
  
      res = spsa_opt.apply_grad(grad, args)
      expected = args - ak * grad
      assert np.allclose(res, expected)
  
imports: import pytest
  import pennylane
  from pennylane import numpy
label_desc: Use image node_id 1 for calling the TestSPSAOptimizer obj's underlying member method code with example usage: obj.test_apply_grad(args, f) without return types