class_docstr: Test the SPSA optimizer.
docstr: Test SPSAOptimizer implementation with lightning.qubit device.
docstr_tok: ["Test","SPSAOptimizer","implementation","with","lightning.qubit","device","."]
code: def test_lighting_device(self):
      """Test SPSAOptimizer implementation with lightning.qubit device."""
      coeffs = [0.2, -0.543, 0.4514]
      obs = [
          qml.PauliX(0) @ qml.PauliZ(1),
          qml.PauliZ(0) @ qml.Hadamard(2),
          qml.PauliX(3) @ qml.PauliZ(1),
      ]
      H = qml.Hamiltonian(coeffs, obs)
      num_qubits = 4
      dev = qml.device("lightning.qubit", wires=num_qubits)
  
      @qml.qnode(dev)
      def cost_fun(params, num_qubits=1):
          qml.BasisState(
              np.array([1, 1, 0, 0]), wires=range(num_qubits)
          )
          for i in range(num_qubits):
              qml.Rot(*params[i], wires=0)
              qml.CNOT(wires=[2, 3])
              qml.CNOT(wires=[2, 0])
              qml.CNOT(wires=[3, 1])
          return qml.expval(H)
  
      init_params = np.random.normal(
          0, np.pi, (num_qubits, 3), requires_grad=True
      )
      params = init_params
  
      init_energy = cost_fun(init_params, num_qubits)
  
      max_iterations = 100
      opt = qml.SPSAOptimizer(maxiter=max_iterations)
      for _ in range(max_iterations):
          params, energy = opt.step_and_cost(
              cost_fun, params, num_qubits=num_qubits
          )
  
      assert np.all(params != init_params)
      assert energy < init_energy
  
imports: import pytest
  import pennylane
  from pennylane import numpy
label_desc: Use image node_id 17 for calling the TestSPSAOptimizer obj's underlying member method code with example usage: obj.test_lighting_device() and returns: qml