I am trying to use the SHGO algorithm from SciPy and I would like to change the maximum number of iterations of the local minimizer.
To do so I have added the argument minimizer_kwargs = {'options':{'maxiter':200}} to the shgo function.
This the display of the local minimizer :
lres = message: Iteration limit reached
success: False
status: 9
fun: 26.05582140171688
x: [ 1.217e+02 -1.441e-01 1.302e-01 3.260e-01]
nit: 100
jac: [-1.317e-02 2.812e+01 0.000e+00 1.173e+02]
nfev: 1461
njev: 100
The optimization stopped because of maximum iteration reached and nit is 100 which is the default value as if the maxiter option has not been taken into account.
To have a clearer idea of the issue I have run the cattle-feed example and tried to limit the iterations number of the local minimizer to 2.
import scipy
import numpy as np
print('SciPy version :', scipy.__version__)
def f(x): # (cattle-feed)
return 24.55*x[0] + 26.75*x[1] + 39*x[2] + 40.50*x[3]
def g1(x):
return 2.3*x[0] + 5.6*x[1] + 11.1*x[2] + 1.3*x[3] - 5 # >=0
def g2(x):
return (12*x[0] + 11.9*x[1] +41.8*x[2] + 52.1*x[3] - 21
- 1.645 * np.sqrt(0.28*x[0]**2 + 0.19*x[1]**2
+ 20.5*x[2]**2 + 0.62*x[3]**2)) # >=0
def h1(x):
return x[0] + x[1] + x[2] + x[3] - 1 # == 0
cons = ({'type': 'ineq', 'fun': g1},
{'type': 'ineq', 'fun': g2},
{'type': 'eq', 'fun': h1})
bounds = [(0, 1.0),]*4
res = scipy.optimize.shgo(f, bounds, n=150, constraints=cons,
minimizer_kwargs = {'options':{'maxiter':2}},
options={'disp':True})
which returns :
SciPy version : 1.10.1
Splitting first generation
Starting minimization at [1.000 1.000 0.000 0.000]...
bounds in kwarg:
[[0.5, 1.0], [0.5, 1.0], [0.0, 0.5], [0.0, 0.5]]
lres = message: Positive directional derivative for linesearch
success: False
status: 8
fun: 33.64749052456115
x: [ 5.000e-01 5.000e-01 8.055e-02 1.199e-01]
nit: 8
jac: [ 2.455e+01 2.675e+01 3.900e+01 4.050e+01]
nfev: 20
njev: 4
Starting minimization at [0.000 0.000 1.000 0.000]...
bounds in kwarg:
[[0.0, 0.5], [0.0, 0.5], [0.5, 1.0], [0.0, 0.5]]
lres = message: Optimization terminated successfully
success: True
status: 0
fun: 31.77500000000491
x: [ 5.000e-01 1.835e-13 5.000e-01 0.000e+00]
nit: 2
jac: [ 2.455e+01 2.675e+01 3.900e+01 4.050e+01]
nfev: 10
njev: 2
Successfully completed construction of complex.
As you can see the first local minimization reaches 8 iterations so the maxiter option has not been considered and it is the same result as if minimizer_kwargs = {'options':{'maxiter':2}} was omitted.
Am I doing or understanding something wrong when trying to change the options of the local minimizer or should this approach work ?
(I also tried 'disp':True in the options and it also did nothing).