I've made an app that performs multivariate constrained optimization using Scipy's minimize()
function (using the SLSQP solver).
Some scenarios can take quite a while to optimize, and sometimes a user could inadvertently trigger a 'long' optimization process and might want a way to terminate the process, fix some inputs, and then try again.
The optimization itself is done in a 'background processs' script, which accesses a 'tasks' database table where the optimization requests are queued. I'm also using minimize()
's callback()
function to update the database with progress of the optimization process.
The documentation says that for ‘trust-constr’, if the callback()
returns True
, then the process will terminate.
This feature would be ideal for me, however I'm using SLSQP solver (not trust-constr), and unfortunately it doesn't terminate the solver when my callback()
returns True
.
Are there any other ways I could write the code so that the user could terminate the optimization?
I'm fairly sure it would need to utilize the callback()
function, so that each iteration it can check whether the user has clicked 'terminate'.
I've also tried raise SystemExit(0)
, but that kills the whole background process. Perhaps there is a way to stop and restart my background process?