class_docstr: Test the RMSProp (root mean square propagation) optimizer
docstr: Tests that rmsprop optimizer takes one and two steps correctly
  for multivariate functions.
docstr_tok: ["Tests","that","rmsprop","optimizer","takes","one","and","two","steps","correctly","for","multivariate","functions","."]
code: def test_rmsprop_optimizer_multivar(self, tol):
      """Tests that rmsprop optimizer takes one and two steps correctly
      for multivariate functions."""
      stepsize, gamma = 0.1, 0.5
      rms_opt = RMSPropOptimizer(stepsize, decay=gamma)
  
      multivariate_funcs = [
          lambda x: np.sin(x[0]) + np.cos(x[1]),
          lambda x: np.exp(x[0] / 3) * np.tanh(x[1]),
          lambda x: np.sum([x_**2 for x_ in x]),
      ]
      grad_multi_funcs = [
          lambda x: (np.array([np.cos(x[0]), -np.sin(x[1])]),),
          lambda x: (
              np.array(
                  [
                      np.exp(x[0] / 3) / 3 * np.tanh(x[1]),
                      np.exp(x[0] / 3) * (1 - np.tanh(x[1]) ** 2),
                  ]
              ),
          ),
          lambda x: (np.array([2 * x_ for x_ in x]),),
      ]
  
      x_vals = np.linspace(-10, 10, 16, endpoint=False)
  
      for gradf, f in zip(grad_multi_funcs, multivariate_funcs):
          for jdx in range(len(x_vals[:-1])):
              rms_opt.reset()
  
              x_vec = x_vals[jdx : jdx + 2]
              x_onestep = rms_opt.step(f, x_vec)
              past_grads = (
                  (1 - gamma) * gradf(x_vec)[0] * gradf(x_vec)[0]
              )
              adapt_stepsize = stepsize / np.sqrt(past_grads + 1e-8)
              x_onestep_target = (
                  x_vec - gradf(x_vec)[0] * adapt_stepsize
              )
              assert np.allclose(x_onestep, x_onestep_target, atol=tol)
  
              x_twosteps = rms_opt.step(f, x_onestep)
              past_grads = (1 - gamma) * gamma * gradf(x_vec)[
                  0
              ] * gradf(x_vec)[0] + (1 - gamma) * gradf(x_onestep)[
                  0
              ] * gradf(
                  x_onestep
              )[
                  0
              ]
              adapt_stepsize = stepsize / np.sqrt(past_grads + 1e-8)
              x_twosteps_target = (
                  x_onestep - gradf(x_onestep)[0] * adapt_stepsize
              )
              assert np.allclose(
                  x_twosteps, x_twosteps_target, atol=tol
              )
  
imports: import pytest
  from pennylane import numpy
  from pennylane.optimize import RMSPropOptimizer
label_desc: Use image node_id 3 for calling the TestRMSPropOptimizer obj's underlying member method code with example usage: obj.test_rmsprop_optimizer_multivar(tol) without return types