class_docstr: Test the SPSA optimizer.
docstr: Test that a gradient step can be applied correctly to a multivariate
  function.
docstr_tok: ["Test","that","a","gradient","step","can","be","applied","correctly","to","a","multivariate","function","."]
code: def test_apply_grad_multivar(self, f):
      """Test that a gradient step can be applied correctly to a multivariate
      function."""
      alpha = 0.602
      gamma = 0.101
      c = 0.2
      A = 10.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])).T.reshape(-1, 2)
  
      spsa_opt = qml.SPSAOptimizer(A=A)
  
      x_vals = np.linspace(-10, 10, 16, endpoint=False)
  
      for jdx in range(len(x_vals[:-1])):
          args = x_vals[jdx : jdx + 2]
          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 = f(thetaplus)
              yminus = f(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
          args_res = spsa_opt.apply_grad(grad, args)
          expected = args - ak * grad
          assert np.allclose(args_res, expected, atol=tol)
  
imports: import pytest
  import pennylane
  from pennylane import numpy
label_desc: Use image node_id 2 for calling the TestSPSAOptimizer obj's underlying member method code with example usage: obj.test_apply_grad_multivar(f) without return types