class_docstr: Test the Rotoselect (gradient-free) optimizer
class_docstr_tok: ["Test","the","Rotoselect","(","gradient-free",")","optimizer"]
docstr: test rotoselect accepts keywords
docstr_tok: ["test","rotoselect","accepts","keywords"]
code: def test_keywords_rotoselect(self, x_start, tol):
      """test rotoselect accepts keywords"""
      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, shift=0.0):
          Z_1, Y_2 = circuit_1(params, generators=generators)
          X_1 = circuit_2(params, generators=generators)
          return (
              0.5 * (Y_2 - shift) ** 2
              + 0.8 * (Z_1 - shift) ** 2
              - 0.2 * (X_1 - shift) ** 2
          )
  
      params_new, *_ = rotoselect_opt.step_and_cost(
          cost_fn, x_start, generators, shift=0.0
      )
      params_new2, _, res_new2 = rotoselect_opt.step_and_cost(
          cost_fn, x_start, generators, shift=1.0
      )
  
      assert not np.allclose(params_new, params_new2, atol=tol)
      assert np.allclose(
          res_new2, cost_fn(x_start, generators, shift=1.0), atol=tol
      )
  
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 4 for calling the TestRotoselectOptimizer obj's underlying member method code with example usage: obj.test_keywords_rotoselect(x_start, tol) and returns: qml,  qml, qml, unknown