scipy/minimize-unused-argument
| Rule | minimize-unused-argument |
|---|---|
| Pack | SciPy |
| Severity | warning |
| Fix | none, edit by hand |
| Library versions | every version |
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.
Message
Section titled “Message”xpd prints this message with the issue. A name that starts with $ stands for code from your file.
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.Browse the other rules of the SciPy pack.