class_docstr: Test the AdaGrad (adaptive gradient) optimizer
docstr: Test that the gradient can be applied correctly to a set of parameters
  and that accumulation works correctly.
docstr_tok: ["Test","that","the","gradient","can","be","applied","correctly","to","a","set","of","parameters","and","that","accumulation","works","correctly","."]
code: def test_apply_grad(self, grad, args, tol):
      """
      Test that the gradient can be applied correctly to a set of parameters
      and that accumulation works correctly.
      """
      stepsize, eps = 0.1, 1e-8
      sgd_opt = AdagradOptimizer(stepsize, eps=eps)
  
      grad = (np.array(grad),)
      args = (np.array(args, requires_grad=True),)
  
      a1 = grad[0] ** 2
      expected = args[0] - stepsize / np.sqrt(a1 + eps) * grad[0]
      res = sgd_opt.apply_grad(grad, args)
      assert np.allclose(res, expected, atol=tol)
  
      # Simulate a new step
      grad = (grad[0] + args[0],)
      args = (expected,)
  
      res = sgd_opt.apply_grad(grad, args)
  
      a2 = a1 + grad[0] ** 2
      expected = args - stepsize / np.sqrt(a2 + eps) * grad[0]
  
      assert np.allclose(res, expected, atol=tol)
  
imports: import pytest
  from pennylane import numpy
  from pennylane.optimize import AdagradOptimizer
label_desc: Use image node_id 1 for calling the TestAdagradOptimizer obj's underlying member method code with example usage: obj.test_apply_grad(grad, args, tol) without return types