scipy/minimize-unused-argument
| Pack | Severity | Fix | Versions |
|---|---|---|---|
| SciPy | warning | none, edit by hand | All versions |
minimize ignores an argument such as jac= when the chosen method does not use it, and warns. Delete the argument, or choose a method that uses it.
res = minimize(f, x0, method="BFGS", jac=grad, bounds=[(0, 1)] * n)res = minimize(f, x0, method="L-BFGS-B", jac=grad, bounds=[(0, 1)] * n)What the rule reports
Section titled “What the rule reports”The rule reports an argument of optimize.minimize that the chosen method ignores. On SciPy
1.18.1, minimize warns RuntimeWarning and goes on without the argument.
| Argument | Methods that ignore it |
|---|---|
jac= |
Nelder-Mead, Powell, COBYLA, COBYQA |
hess=, hessp= |
each method that uses no Hessian |
constraints= |
each method that can't handle constraints |
bounds= |
CG, BFGS, Newton-CG, and the trust-region methods other than trust-constr |
How to fix it
Section titled “How to fix it”xpd has no automatic fix, so make the change by hand.
Choose whether to drop the argument or use a solver that can use it.
Diagnostic message
Section titled “Diagnostic message”minimize with method=$METH does not use gradient information, so it ignores jac= and warns RuntimeWarning. Delete jac=, or choose a method that uses it.See all rules in the SciPy pack.