class_docstr: Test the Nesterov Momentum optimizer
docstr: Tests that nesterov momentum optimizer takes one and two steps correctly
  for univariate functions.
docstr_tok: ["Tests","that","nesterov","momentum","optimizer","takes","one","and","two","steps","correctly","for","univariate","functions","."]
code: def test_nesterovmomentum_optimizer_univar(self, x_start, tol):
      """Tests that nesterov momentum optimizer takes one and two steps correctly
      for univariate functions."""
      stepsize, gamma = 0.1, 0.5
      nesmom_opt = NesterovMomentumOptimizer(stepsize, momentum=gamma)
  
      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):
          nesmom_opt.reset()
  
          x_onestep = nesmom_opt.step(f, x_start)
          x_onestep_target = x_start - gradf(x_start) * stepsize
          assert np.allclose(x_onestep, x_onestep_target, atol=tol)
  
          x_twosteps = nesmom_opt.step(f, x_onestep)
          momentum_term = gamma * gradf(x_start)
          shifted_grad_term = gradf(
              x_onestep - stepsize * momentum_term
          )
          x_twosteps_target = (
              x_onestep - (shifted_grad_term + momentum_term) * stepsize
          )
          assert np.allclose(x_twosteps, x_twosteps_target, atol=tol)
  
file_path: pennylane/tests/optimize/test_nesterov_momentum.py
imports: import pytest
  import pennylane
  from pennylane import numpy
  from pennylane.optimize import NesterovMomentumOptimizer
label_desc: Use image node_id 3 for calling the TestNesterovMomentumOptimizer obj's underlying member method code with example usage: obj.test_nesterovmomentum_optimizer_univar(x_start, tol) without return types