class_docstr: Test the AdaGrad (adaptive gradient) optimizer
docstr: Tests that adagrad optimizer takes one and two steps correctly
  for univariate functions.
docstr_tok: ["Tests","that","adagrad","optimizer","takes","one","and","two","steps","correctly","for","univariate","functions","."]
code: def test_adagrad_optimizer_univar(self, x_start, tol):
      """Tests that adagrad optimizer takes one and two steps correctly
      for univariate functions."""
      stepsize = 0.1
      adag_opt = AdagradOptimizer(stepsize)
  
      univariate_funcs = [
          np.sin,
          lambda x: np.exp(x / 10.0),
          lambda x: x**2,
      ]
      grad_uni_fns = [
          np.cos,
          lambda x: np.exp(x / 10.0) / 10.0,
          lambda x: 2 * x,
      ]
  
      for gradf, f in zip(grad_uni_fns, univariate_funcs):
          adag_opt.reset()
  
          x_onestep = adag_opt.step(f, x_start)
          past_grads = gradf(x_start) * gradf(x_start)
          adapt_stepsize = stepsize / np.sqrt(past_grads + 1e-8)
          x_onestep_target = x_start - gradf(x_start) * adapt_stepsize
          assert np.allclose(x_onestep, x_onestep_target, atol=tol)
  
          x_twosteps = adag_opt.step(f, x_onestep)
          past_grads = gradf(x_start) * gradf(x_start) + gradf(
              x_onestep
          ) * gradf(x_onestep)
          adapt_stepsize = stepsize / np.sqrt(past_grads + 1e-8)
          x_twosteps_target = (
              x_onestep - gradf(x_onestep) * adapt_stepsize
          )
          assert np.allclose(x_twosteps, x_twosteps_target, atol=tol)
  
imports: import pytest
  from pennylane import numpy
  from pennylane.optimize import AdagradOptimizer
label_desc: Use image node_id 2 for calling the TestAdagradOptimizer obj's underlying member method code with example usage: obj.test_adagrad_optimizer_univar(x_start, tol) without return types