class_docstr: Test the SPSA optimizer.
docstr: Test that the correct cost is returned via the step_and_cost method
  for the SPSA optimizer.
docstr_tok: ["Test","that","the","correct","cost","is","returned","via","the","step_and_cost","method","for","the","SPSA","optimizer","."]
code: def test_step_and_cost_supplied_cost(self):
      """Test that the correct cost is returned via the step_and_cost method
      for the SPSA optimizer."""
      spsa_opt = qml.SPSAOptimizer(maxiter=10)
  
      @qml.qnode(qml.device("default.qubit", wires=1))
      def quant_fun(variables):
          qml.RX(variables[0], wires=[0])
          qml.RY(variables[1], wires=[0])
          qml.RY(variables[2], wires=[0])
          return qml.expval(qml.PauliZ(0))
  
      inputs = np.array([0.4, 0.2, 0.4], requires_grad=True)
  
      expected = quant_fun(inputs)
      _, res = spsa_opt.step_and_cost(quant_fun, inputs)
  
      assert np.all(res == expected)
  
imports: import pytest
  import pennylane
  from pennylane import numpy
label_desc: Use image node_id 4 for calling the TestSPSAOptimizer obj's underlying member method code with example usage: obj.test_step_and_cost_supplied_cost() and returns: qml