Repository: Qiskit/qiskit

Issue:
L_BFGS_B maxiter and maxfun defaults should be swapped
### Environment

Generic implementation bug, not about environment

### What is happening?

Note that in qiskit.algorithms.optimizers.l_bfgs_b, we have the following defaults:
 
```
def __init__(
    self,
    maxfun: int = 1000,
    maxiter: int = 15000,
    ...
```

This is problematic since if maxfun is less than maxiter, the optimization will always get terminated by maxfun, since maxfun is always larger than maxiter (as calling from scipy library). Typically, one would get something like, depend on your option setting,

```
{'_x': (ignored here),
 '_fun': 942148.4943465312,
 '_jac': None,
 '_nfev': 12768,
 '_njev': 224,
 '_nit': 211}
```

Here, nit = 211 << nfev = 12768. Therefore I would think it is proper to have those two defaults swapped. It has been a while for me that I have to swap them manually each time.



### How can we reproduce the issue?

The issue is about default values.

### What should happen?

I suggest we set qiskit.algorithms.optimizers.l_bfgs_b to
 
```
def __init__(
    self,
    maxfun: int = 15000,
    maxiter: int = 1000,
    ...
```

### Any suggestions?

_No response_


Discussion:
We could also switch to the defaults that SciPy has, which is 15'000 for both `maxfun` and `maxiter`: https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.fmin_l_bfgs_b.html#scipy.optimize.fmin_l_bfgs_b
> We could also switch to the defaults that SciPy has, which is 15'000 for both `maxfun` and `maxiter`: https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.fmin_l_bfgs_b.html#scipy.optimize.fmin_l_bfgs_b

That would be wonderful. 15,000 seems to be a good number.

Resolving patch:
diff --git a/qiskit/algorithms/optimizers/l_bfgs_b.py b/qiskit/algorithms/optimizers/l_bfgs_b.py
--- a/qiskit/algorithms/optimizers/l_bfgs_b.py
+++ b/qiskit/algorithms/optimizers/l_bfgs_b.py
@@ -16,7 +16,6 @@
 
 import numpy as np
 
-
 from .scipy_optimizer import SciPyOptimizer
 
 
@@ -39,7 +38,7 @@ class L_BFGS_B(SciPyOptimizer):  # pylint: disable=invalid-name
     and also to form an estimate of the Hessian matrix (second derivative) of :math:`f`.
     L-BFGS-B extends L-BFGS to handle simple, per-variable bound constraints.
 
-    Uses scipy.optimize.fmin_l_bfgs_b.
+    Uses ``scipy.optimize.fmin_l_bfgs_b``.
     For further detail, please refer to
     https://docs.scipy.org/doc/scipy/reference/optimize.minimize-lbfgsb.html
     """
@@ -49,10 +48,9 @@ class L_BFGS_B(SciPyOptimizer):  # pylint: disable=invalid-name
     # pylint: disable=unused-argument
     def __init__(
         self,
-        maxfun: int = 1000,
+        maxfun: int = 15000,
         maxiter: int = 15000,
         ftol: float = 10 * np.finfo(float).eps,
-        factr: Optional[float] = None,
         iprint: int = -1,
         eps: float = 1e-08,
         options: Optional[dict] = None,
@@ -63,17 +61,18 @@ def __init__(
         Args:
             maxfun: Maximum number of function evaluations.
             maxiter: Maximum number of iterations.
-            ftol: The iteration stops when (f\^k - f\^{k+1})/max{\|f\^k\|,\|f\^{k+1}\|,1} <= ftol.
-            iprint: Controls the frequency of output. iprint < 0 means no output;
-                iprint = 0 print only one line at the last iteration; 0 < iprint < 99
-                print also f and \|proj g\| every iprint iterations; iprint = 99 print
-                details of every iteration except n-vectors; iprint = 100 print also the
-                changes of active set and final x; iprint > 100 print details of
-                every iteration including x and g.
+            ftol: The iteration stops when
+                :math:`(f^k - f^{k+1}) / \max\{|f^k|, |f^{k+1}|,1\} \leq \text{ftol}`.
+            iprint: Controls the frequency of output. ``iprint < 0`` means no output;
+                ``iprint = 0`` print only one line at the last iteration; ``0 < iprint < 99``
+                print also :math:`f` and :math:`|\text{proj} g|` every iprint iterations;
+                ``iprint = 99`` print details of every iteration except n-vectors; ``iprint = 100``
+                print also the changes of active set and final :math:`x`; ``iprint > 100`` print
+                details of every iteration including :math:`x` and :math:`g`.
             eps: If jac is approximated, use this value for the step size.
             options: A dictionary of solver options.
             max_evals_grouped: Max number of default gradient evaluations performed simultaneously.
-            kwargs: additional kwargs for scipy.optimize.minimize.
+            kwargs: additional kwargs for ``scipy.optimize.minimize``.
         """
         if options is None:
             options = {}


Test patch: