class_docstr: Test exceptions are raised for incorrect usage
docstr: Test that an exception is raised if the learning rate is beyond the
  lipschitz bound
docstr_tok: ["Test","that","an","exception","is","raised","if","the","learning","rate","is","beyond","the","lipschitz","bound"]
code: def test_learning_error(self):
      """Test that an exception is raised if the learning rate is beyond the
      lipschitz bound"""
      coeffs = [0.3, 0.1]
      H = qml.Hamiltonian(coeffs, [qml.PauliX(0), qml.PauliZ(0)])
      dev = qml.device("default.qubit", wires=1, shots=100)
  
      def ansatz(x, **kwargs):
          qml.RX(x, wires=0)
  
      expval_cost = catch_warn_ExpvalCost(ansatz, H, dev)
  
      opt = qml.ShotAdaptiveOptimizer(min_shots=10, stepsize=100.0)
  
      # lipschitz constant is given by sum(|coeffs|)
      lipschitz = np.sum(np.abs(coeffs))
  
      assert opt.stepsize > 2 / lipschitz
  
      with pytest.raises(
          ValueError,
          match=f"The learning rate must be less than {2 / lipschitz}",
      ):
          opt.step(expval_cost, np.array(0.5, requires_grad=True))
  
      # for a single QNode, the lipschitz constant is simply 1
      opt = qml.ShotAdaptiveOptimizer(min_shots=10, stepsize=100.0)
      with pytest.raises(
          ValueError,
          match=f"The learning rate must be less than {2 / 1}",
      ):
          opt.step(
              expval_cost.qnodes[0], np.array(0.5, requires_grad=True)
          )
  
imports: import pytest
  from flaky import flaky
  import pennylane
  from pennylane import numpy
label_desc: Use image node_id 2 for calling the TestExceptions obj's underlying member method code with example usage: obj.test_learning_error() without return types