class_docstr: Test basic optimization integration
class_docstr_tok: ["Test","basic","optimization","integration"]
docstr: Test that the correct cost and update is returned via the step_and_cost
  method for the QNG optimizer when providing an explicit grad_fn.
  Using a circuit with multiple inputs containing the parameters.
docstr_tok: ["Test","that","the","correct","cost","and","update","is","returned","via","the","step_and_cost","method","for","the","QNG","optimizer","when","providing","an","explicit","grad_fn",".","Using","a","circuit","with","multiple","inputs","containing","the","parameters","."]
code: def test_step_and_cost_with_grad_fn_split_input(self):
      """Test that the correct cost and update is returned via the step_and_cost
      method for the QNG optimizer when providing an explicit grad_fn.
      Using a circuit with multiple inputs containing the parameters."""
      dev = qml.device("default.qubit", wires=1)
  
      @qml.qnode(dev)
      def circuit(params_0, params_1):
          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)
  
      # With autograd gradient function
      grad_fn = qml.grad(circuit)
      step1, cost1 = opt.step_and_cost(circuit, *var, grad_fn=grad_fn)
      step2 = opt.step(circuit, *var, grad_fn=grad_fn)
  
      # With more custom gradient function, forward has to be computed explicitly.
      grad_fn = lambda params_0, params_1: np.array(
          qml.grad(circuit)(params_0, params_1)
      )
      step3, cost2 = opt.step_and_cost(circuit, *var, grad_fn=grad_fn)
      opt.step(circuit, *var, grad_fn=grad_fn)
      expected_step = var - opt.stepsize * 4 * grad_fn(*var)
      expected_cost = circuit(*var)
  
      for step in [step1, step2, step3, step3]:
          assert np.allclose(step, expected_step)
      assert np.isclose(cost1, expected_cost)
      assert np.isclose(cost2, expected_cost)
  
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 4 for calling the TestOptimize obj's underlying member method code with example usage: obj.test_step_and_cost_with_grad_fn_split_input() and returns: qml