I have a fairly large and complex Python application to which I recently added the ability to perform nonlinear optimization using Mystic (https://github.com/uqfoundation/mystic). The optimization runs in a separate thread from the main (GUI) thread. I am naively using the fmin_powell
and diffev
to run the optimization.
Since the evaluation of the objective function can be lengthy, the user has the ability to click on a “stop” button and stop the simulation.
That said, I haven’t found an intelligent way to actually stop the optimization thread, as there seems not be to stop the fmin_powell
or diffev
functions. I don’t need to be able to stop the current function evaluation in the middle of the simulation, I would also be happy to wait until the current function evaluation is finished before halting the optimization.
Does anyone know if this is actually possible?
Thank you in advance for your help.
Andrea.
I'm the mystic
author. There are two ways, generally.
If you are using the function interface (i.e. mystic.solvers.diffev2(...)
), then you can use the keyword handler=True
. If you do a signal-interrupt, it will pause a running solver that has the handler enabled. Two things to note: (1) you have to enable the handler when you call the solver, and (2) it may not take effect immediately for solvers running in parallel.
The class interface (i.e. solver = mystic.solvers.DifferentialEvolutionSolver(...)
) allows you to use the handler (i.e. solver.enable_signal_handler()
), and/or also you can roll your own solution with solver.Step()
-- proceed with an optimization asynchronously. If you use Step
, it will run only one iteration at a time, so you can then write your own controls for how you want to the solver to progress.