class_docstr: Test exceptions are raised for incorrect usage
class_docstr_tok: ["Test","exceptions","are","raised","for","incorrect","usage"]
docstr: Test that if the objective function is not a
  QNode, an error is raised.
docstr_tok: ["Test","that","if","the","objective","function","is","not","a","QNode",",","an","error","is","raised","."]
code: def test_obj_func_not_a_qnode(self):
      """Test that if the objective function is not a
      QNode, an error is raised."""
  
      dev = qml.device("default.qubit", wires=1)
  
      @qml.qnode(dev)
      def circuit(a):
          qml.RX(a, wires=0)
          return qml.expval(qml.PauliZ(0))
  
      def cost(a):
          return circuit(a)
  
      opt = qml.QNGOptimizer()
      params = 0.5
  
      with pytest.raises(
          ValueError,
          match="The objective function must either be encoded as a single QNode or an ExpvalCost object",
      ):
          opt.step(cost, params)
  
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 TestExceptions obj's underlying member method code with example usage: obj.test_obj_func_not_a_qnode() and returns: qml, circuit