class_docstr: Test the Rotoselect (gradient-free) optimizer
class_docstr_tok: ["Test","the","Rotoselect","(","gradient-free",")","optimizer"]
docstr: Test that the correct cost is returned via the step_and_cost method for the
  Rotoselect momentum optimizer
docstr_tok: ["Test","that","the","correct","cost","is","returned","via","the","step_and_cost","method","for","the","Rotoselect","momentum","optimizer"]
code: def test_step_and_cost_autograd_rotoselect(self, params):
      """Test that the correct cost is returned via the step_and_cost method for the
      Rotoselect momentum optimizer"""
      rotoselect_opt = RotoselectOptimizer()
      generators = [qml.RY, qml.RX]
      possible_generators = [qml.RX, qml.RY, qml.RZ]
      rotoselect_opt.possible_generators = possible_generators
  
      dev = qml.device("default.qubit", shots=None, wires=2)
  
      def ansatz(params, generators):
          generators[0](params[0], wires=0)
          generators[1](params[1], wires=1)
          qml.CNOT(wires=[0, 1])
  
      @qml.qnode(dev)
      def circuit_1(
          params, generators=None
      ):  # generators will be passed as a keyword arg
          ansatz(params, generators)
          return qml.expval(qml.PauliZ(0)), qml.expval(qml.PauliY(1))
  
      @qml.qnode(dev)
      def circuit_2(
          params, generators=None
      ):  # generators will be passed as a keyword arg
          ansatz(params, generators)
          return qml.expval(qml.PauliX(0))
  
      def cost_fn(params, generators):
          Z_1, Y_2 = circuit_1(params, generators=generators)
          X_1 = circuit_2(params, generators=generators)
          return 0.5 * Y_2 + 0.8 * Z_1 - 0.2 * X_1
  
      _, _, res = rotoselect_opt.step_and_cost(
          cost_fn, params, generators
      )
      expected = cost_fn(params, generators)
  
      assert np.all(res == expected)
  
file_path: pennylane/tests/optimize/test_rotoselect.py
imports: import itertools
  import numpy
  import pytest
  import pennylane
  from pennylane import numpy
  from pennylane.optimize import RotoselectOptimizer
label_desc: Use image node_id 1 for calling the TestRotoselectOptimizer obj's underlying member method code with example usage: obj.test_step_and_cost_autograd_rotoselect(params) and returns: qml,  qml, qml, unknown