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

**URL:** <https://discourse.julialang.org/t/how-to-stop-a-long-running-optimization-process-in-jump/114656>\
**Category:** Optimization (Mathematical)\
**Tags:** question, jump, optimization, gurobi\
**Created:** [May 24, 2024, 3:41am UTC](https://discourse.julialang.org/t/how-to-stop-a-long-running-optimization-process-in-jump/114656 "2024-05-24T03:41:04Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shuhua](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/shuhua/32/27618_2.png) [@Shuhua](https://discourse.julialang.org/u/Shuhua)\
**Post date:** [May 24, 2024, 3:41am UTC](https://discourse.julialang.org/t/how-to-stop-a-long-running-optimization-process-in-jump/114656/1 "2024-05-24T03:41:04Z")

</div>

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)?

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [May 24, 2024, 4:02am UTC](https://discourse.julialang.org/t/how-to-stop-a-long-running-optimization-process-in-jump/114656/2 "2024-05-24T04:02:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Shuhua](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/shuhua/32/27618_2.png) [@Shuhua](https://discourse.julialang.org/u/Shuhua)\
**Post date:** [May 24, 2024, 7:01am UTC](https://discourse.julialang.org/t/how-to-stop-a-long-running-optimization-process-in-jump/114656/3 "2024-05-24T07:01:44Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [May 24, 2024, 7:11am UTC](https://discourse.julialang.org/t/how-to-stop-a-long-running-optimization-process-in-jump/114656/4 "2024-05-24T07:11:04Z")

</div>

Which solver?

---

<div class="post-metadata">

**Author:** ![Shuhua](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/shuhua/32/27618_2.png) [@Shuhua](https://discourse.julialang.org/u/Shuhua)\
**Post date:** [May 24, 2024, 7:14am UTC](https://discourse.julialang.org/t/how-to-stop-a-long-running-optimization-process-in-jump/114656/5 "2024-05-24T07:14:21Z")

</div>

Gurobi.

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [May 24, 2024, 7:15am UTC](https://discourse.julialang.org/t/how-to-stop-a-long-running-optimization-process-in-jump/114656/6 "2024-05-24T07:15:56Z")

</div>

The jupyter printing issue is discussed in

> [@Gurobi does not display log](https://discourse.julialang.org/t/gurobi-does-not-display-log/114442):
>
> I am using Convex.jl in conjuction with Gurobi in a Jupyter notebook to solve a convex programming problem. Everything works but Gurobi is not displaying its log to the console in “realtime”, but it displays everything at once only at the end of the optimization. I tried to “force” the logging (even though it should be enabled by the default options), inizializing the optimizer with opt = MOI.OptimizerWithAttributes(() -\> Gurobi.Optimizer(GUROBI\_ENV), "DisplayInterval" =\> 1, "OutputFlag" =\> 1, …

---

<div class="post-metadata">

**Author:** ![CaG21](https://avatars.discourse-cdn.com/v4/letter/c/c2a13f/32.png) [@CaG21](https://discourse.julialang.org/u/CaG21)\
**Post date:** [May 24, 2024, 2:31pm UTC](https://discourse.julialang.org/t/how-to-stop-a-long-running-optimization-process-in-jump/114656/7 "2024-05-24T14:31:46Z")

</div>

I am jumping in (no pun intended 😃) 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.
