# How do I extract a trace of the optimization steps in JuMP

**URL:** <https://discourse.julialang.org/t/how-do-i-extract-a-trace-of-the-optimization-steps-in-jump/82328>\
**Category:** Optimization (Mathematical)\
**Tags:** question, jump\
**Created:** [June 6, 2022, 6:05pm UTC](https://discourse.julialang.org/t/how-do-i-extract-a-trace-of-the-optimization-steps-in-jump/82328 "2022-06-06T18:05:28Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![oxinabox](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oxinabox/32/206603_2.png) [@oxinabox](https://discourse.julialang.org/u/oxinabox)\
**Post date:** [June 6, 2022, 6:05pm UTC](https://discourse.julialang.org/t/how-do-i-extract-a-trace-of-the-optimization-steps-in-jump/82328/1 "2022-06-06T18:05:28Z")

</div>

During optimization via some interior point method or similar  
the solver will compute the value of the objective and probably a bunch of other things.  
And one should see it going down

Is there a standard way to capture this into a vector or similar?

Or is the best i can do turn on printing as a solver option, and redirect stdio into a stream then parse it using regex?

---

<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:** [June 6, 2022, 6:38pm UTC](https://discourse.julialang.org/t/how-do-i-extract-a-trace-of-the-optimization-steps-in-jump/82328/2 "2022-06-06T18:38:07Z")

</div>

There is no standard way. What solver?

---

<div class="post-metadata">

**Author:** ![oxinabox](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oxinabox/32/206603_2.png) [@oxinabox](https://discourse.julialang.org/u/oxinabox)\
**Post date:** [June 6, 2022, 6:55pm UTC](https://discourse.julialang.org/t/how-do-i-extract-a-trace-of-the-optimization-steps-in-jump/82328/3 "2022-06-06T18:55:39Z")

</div>

unknown but probably HiGHS.  
Maybe ECOS or Gurobi  
But lets say HiGHS

---

<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:** [June 6, 2022, 7:08pm UTC](https://discourse.julialang.org/t/how-do-i-extract-a-trace-of-the-optimization-steps-in-jump/82328/4 "2022-06-06T19:08:17Z")

</div>

Not possible, and I don’t even know if the log would be very helpful.

Most solvers only care about the final solution, not about the path to get there.

---

<div class="post-metadata">

**Author:** ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Post date:** [June 6, 2022, 8:02pm UTC](https://discourse.julialang.org/t/how-do-i-extract-a-trace-of-the-optimization-steps-in-jump/82328/5 "2022-06-06T20:02:41Z")

</div>

Currently solvers like CPLEX/Gurobi have a “synamic search mode” that they are trying to make default which is their name for “we do not want to give our users anymore the guarantee that our core algorithm is branch-and-bound”. This new dynamic search is a black box they can do whatever they want.

---

<div class="post-metadata">

**Author:** ![mtanneau](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mtanneau/32/17787_2.png) [@mtanneau](https://discourse.julialang.org/u/mtanneau)\
**Post date:** [June 7, 2022, 8:35am UTC](https://discourse.julialang.org/t/how-do-i-extract-a-trace-of-the-optimization-steps-in-jump/82328/6 "2022-06-07T08:35:25Z")

</div>

Some solvers (mostly the commercial ones) allow you to query _some_ information through a callback. Depending on the solver, you may be able to extract, e.g., the current simplex objective value and primal/dual infeasibility (this is from [Gurobi callback docs](https://www.gurobi.com/documentation/9.5/refman/cb_codes.html)). You’d need a solver-specific callback for that.

On the academic solver side, SCIP would allow you to do anything you want at the C level (through so-called “event handlers” and plugins), but I don’t know how much of that is exposed in Julia (and I’ve never used any of them myself). As far as I know, HiGHS doesn’t (yet) have callbacks / they are not exposed in Julia.

Another option would be to set logging to the highest level, and hopefully the information you want will be printed there. It will likely have an impact on performance though (lots of I/O operations).

---

<div class="post-metadata">

**Author:** ![oxinabox](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oxinabox/32/206603_2.png) [@oxinabox](https://discourse.julialang.org/u/oxinabox)\
**Post date:** [June 7, 2022, 10:31am UTC](https://discourse.julialang.org/t/how-do-i-extract-a-trace-of-the-optimization-steps-in-jump/82328/7 "2022-06-07T10:31:05Z")

</div>

I guess the particular thing i really want to know is when I terminate with a TERMINATION\_STATUS like “ALMOST\_OPTIMAL” or “ITERATION\_LIMIT” what rough areas were the objective value and the derivatives etc around, so I can see about relaxing my tolerances so those count as success.

Also, especially in the case of ITERATION\_LIMIT I want to know if my objective value had more or less plateau’ed recently (albeit not to the level of flat that would count as ALMOST OPTIMAL), or if it was still in a steep area and just hadn’t made it.

---

<div class="post-metadata">

**Author:** ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Post date:** [June 7, 2022, 12:47pm UTC](https://discourse.julialang.org/t/how-do-i-extract-a-trace-of-the-optimization-steps-in-jump/82328/8 "2022-06-07T12:47:19Z")

</div>

About ITERATION\_LIMIT, every solver I worked with will print when they find a new incumbent (i.e., a better solution than ever found before) in the log with the time this happened. I think most of them that support callbacks will also have a callback for when an incumbent is found. So this information at least is available.

---

<div class="post-metadata">

**Author:** ![mtanneau](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mtanneau/32/17787_2.png) [@mtanneau](https://discourse.julialang.org/u/mtanneau)\
**Post date:** [June 10, 2022, 12:43am UTC](https://discourse.julialang.org/t/how-do-i-extract-a-trace-of-the-optimization-steps-in-jump/82328/9 "2022-06-10T00:43:50Z")

</div>

You mentioned interior-point algorithm and HiGHS/ECOS/Gurobi as solvers; are you considering purely continuous, convex, possibly nonlinear problems? (if not, you can ignore what follows)

If so, and if Mosek is an option for you, they also have [callbacks](https://docs.mosek.com/latest/capi/callback.html#) that may provide some of the information you’re looking for.

More generally though: if you’re indeed playing with continuous, nonlinear convex problems, the only 2 reasons I know that IPM solvers would terminate with ALMOST\_OPTIMAL / ITERATION\_LIMIT / SLOW\_PROGRESS would be because of numerical issues (badly scaled problem) and because of loss of constraint qualification. Infeasible/unbounded problems can also cause trouble to solvers that don’t use a homogeneous embedding algorithm (AFAIK it’s the default choice for Mosek/ECOS). In my experience, for the former 2, you’ll often see a plateau in the objective value, yes.
