class_docstr: Test basic optimization integration
class_docstr_tok: ["Test","basic","optimization","integration"]
docstr: Test qubit rotation has the correct QNG value
  every step, the correct parameter updates,
  and correct cost after 200 steps
docstr_tok: ["Test","qubit","rotation","has","the","correct","QNG","value","every","step",",","the","correct","parameter","updates",",","and","correct","cost","after","200","steps"]
code: def test_qubit_rotation(self, tol):
      """Test qubit rotation has the correct QNG value
      every step, the correct parameter updates,
      and correct cost after 200 steps"""
      dev = qml.device("default.qubit", wires=1)
  
      @qml.qnode(dev)
      def circuit(params):
          qml.RX(params[0], wires=0)
          qml.RY(params[1], wires=0)
          return qml.expval(qml.PauliZ(0))
  
      def gradient(params):
          """Returns the gradient of the above circuit"""
          da = -np.sin(params[0]) * np.cos(params[1])
          db = -np.cos(params[0]) * np.sin(params[1])
          return np.array([da, db])
  
      eta = 0.01
      init_params = np.array([0.011, 0.012])
      num_steps = 200
  
      opt = qml.QNGOptimizer(eta)
      theta = init_params
  
      # optimization for 200 steps total
      for _ in range(num_steps):
          theta_new = opt.step(circuit, theta)
  
          # check metric tensor
          res = opt.metric_tensor
          exp = np.diag([0.25, (np.cos(theta[0]) ** 2) / 4])
          assert np.allclose(res, exp, atol=tol, rtol=0)
  
          # check parameter update
          dtheta = eta * sp.linalg.pinvh(exp) @ gradient(theta)
          assert np.allclose(
              dtheta, theta - theta_new, atol=tol, rtol=0
          )
  
          theta = theta_new
  
      # check final cost
      assert np.allclose(circuit(theta), -0.9963791, atol=tol, rtol=0)
  
file_path: pennylane/tests/optimize/test_qng.py
imports: import pytest
  import scipy
  import pennylane
  from pennylane import numpy
label_desc: Use image node_id 5 for calling the TestOptimize obj's underlying member method code with example usage: obj.test_qubit_rotation(tol) and returns: qml, np