# How do I get scipy.minimize to terminate below a certain loss threshold?

I was looking at the scipy.minimize documentation to see if I could find a way to terminate optimization when the loss gets below some cut-off, and I couldn't see an obvious way to do it.

The callback option only lets me pass it the xk, but I need to pass additional parameters to evaluate my loss.

Any thoughts on a straightforward way to do this?

• I think they have tolerances for the vector and the function. – nicoguaro May 18 '20 at 3:09
• I tried them, I think those tolerances are for the difference in loss between steps for some number of steps, rather than the actual value of the loss. – user49404 May 18 '20 at 3:10
• Yes, you're right. The callback options seems to see the way to go, maybe some of the solvers let you to pass a function value. – nicoguaro May 18 '20 at 3:20
• I went ahead and just modified the scipy optimize.py source to do what I wanted. <_<. The callback doesn't work for me here because I need to pass additional parameters that scipy isn't allowing. – user49404 May 18 '20 at 3:28

def _minimize_powell

        if fval < 0.1: