How to stop a long-running optimization process in JuMP?

Some optimization problem can be quite time-consuming. I used JuMP in Jupyter notebook (VS Code) and Julia REPL. After optimize! is called, the optimization starts, and sometimes I want to interrupt it. However

  • The stop button in Jupyter notebook does not work and gets no response.
  • The Ctrl+C in REPL does not work either.

How can I stop a running optimization process in JuMP (without shutting down VS code or the REPL completely)?

1 Like

Which solver? Ctrl C should generally work. If it doesn’t please open a bug report and we can try to fix it

Sorry. Just found that Ctrl C worked in the REPL. It was only in the Jupyter notebook that we cannot stop. Besides, the log was dumped all at once after a long running time in Jupyter notebook, but the log was printed line by line in REPL.

Which solver?


The jupyter printing issue is discussed in

I am jumping in (no pun intended :smiley:) since as pointed out (I am the OP of the linked thread) I have the same issue both on the display and on the stop.
At the moment, I did not find any solution for either.
Just to be clear, what I found out is that when working with Jupyter:

  1. There is no way to stop the optimization process, for any of the solvers I tested (Gurobi, MOSEK, CPlex). My current workaround is to restart the kernel, that is ok if you are only doing the optimization, but it can be a pain if you perform other long-running operations before.
  2. While CPlex and MOSEK are able to log to Jupyter in real-time, Gurobi is not and shows the log all-in-once just at the end.

PS: Another stuff that I found out but for the REPL is that, if you kill multiple times with Ctrl+C Gurobi in the REPL, it gives you a segfault that kills Julia. If you are interested I can reproduce the behaviour and send the exact error message.