class_docstr: Test basic optimization integration
class_docstr_tok: ["Test","basic","optimization","integration"]
docstr: Test that the correct cost and step is returned via the
  step_and_cost method for the QNG optimizer
docstr_tok: ["Test","that","the","correct","cost","and","step","is","returned","via","the","step_and_cost","method","for","the","QNG","optimizer"]
code: def test_step_and_cost_autograd(self):
      """Test that the correct cost and step is returned via the
      step_and_cost method for the QNG optimizer"""
      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))
  
      var = np.array([0.011, 0.012])
      opt = qml.QNGOptimizer(stepsize=0.01)
  
      step1, res = opt.step_and_cost(circuit, var)
      step2 = opt.step(circuit, var)
  
      expected = circuit(var)
      expected_step = var - opt.stepsize * 4 * qml.grad(circuit)(var)
      assert np.all(res == expected)
      assert np.allclose(step1, expected_step)
      assert np.allclose(step2, expected_step)
  
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 1 for calling the TestOptimize obj's underlying member method code with example usage: obj.test_step_and_cost_autograd() and returns: qml