# How to record the optimization process when using the JuMP optimization package for optimization

**URL:** <https://discourse.julialang.org/t/how-to-record-the-optimization-process-when-using-the-jump-optimization-package-for-optimization/63124>\
**Category:** Optimization (Mathematical)\
**Tags:** jump\
**Created:** [June 18, 2021, 1:29am UTC](https://discourse.julialang.org/t/how-to-record-the-optimization-process-when-using-the-jump-optimization-package-for-optimization/63124 "2021-06-18T01:29:11Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![til1](https://avatars.discourse-cdn.com/v4/letter/t/898d66/32.png) [@til1](https://discourse.julialang.org/u/til1)\
**Post date:** [June 18, 2021, 1:29am UTC](https://discourse.julialang.org/t/how-to-record-the-optimization-process-when-using-the-jump-optimization-package-for-optimization/63124/1 "2021-06-18T01:29:11Z")

</div>

I want to know the result of each iteration of the independent variable and the target value. How can I get this information?

---

<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 18, 2021, 1:43am UTC](https://discourse.julialang.org/t/how-to-record-the-optimization-process-when-using-the-jump-optimization-package-for-optimization/63124/2 "2021-06-18T01:43:24Z")

</div>

Hi there!

Since this is your first post, please read [Please read: make it easier to help you](https://discourse.julialang.org/t/please-read-make-it-easier-to-help-you/14757).

However in general, there is no way to get this information. JuMP provides only the final optimal solution (if one exists).

Some solvers may support writing their progress to a log file. You should consult each solvers documentation for appropriate solver-specific parameters.

---

<div class="post-metadata">

**Author:** ![cvanaret](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cvanaret/32/11594_2.png) [@cvanaret](https://discourse.julialang.org/u/cvanaret)\
**Post date:** [June 25, 2021, 9:03am UTC](https://discourse.julialang.org/t/how-to-record-the-optimization-process-when-using-the-jump-optimization-package-for-optimization/63124/3 "2021-06-25T09:03:20Z")

</div>

**Edit: see post below**  
An easy way would be to print/record the values of the variables within the objective function. Each time it will be evaluated, you’ll have access to the values of the variables:

```julia
function objective(x)
  objective_value = ...
  println("Variables: ", x)
  println("Objective value: ", objective_value)
  return objective_value;
end

```

Of course, if the solver performs inner iterations to find an acceptable point (e.g. a line search), you will print/record all these points that ultimately will be discarded.

---

<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 25, 2021, 10:10pm UTC](https://discourse.julialang.org/t/how-to-record-the-optimization-process-when-using-the-jump-optimization-package-for-optimization/63124/4 "2021-06-25T22:10:48Z")

</div>

To clarify for future readers: the above post works for something like [https://github.com/JuliaNLSolvers/Optim.jl](https://github.com/JuliaNLSolvers/Optim.jl), but not for JuMP.

JuMP works differently so you don’t define a Julia function `objective(x)`. (There is one exception: user-defined nonlinear objective functions. But this is not a general solution.)

In general, there is no way to record the optimization process from JuMP because JuMP just _formulates_ the problem, and hands off the solution of that problem to an external solver, which is often written in C/C++.

---

<div class="post-metadata">

**Author:** ![cvanaret](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cvanaret/32/11594_2.png) [@cvanaret](https://discourse.julialang.org/u/cvanaret)\
**Post date:** [June 25, 2021, 10:15pm UTC](https://discourse.julialang.org/t/how-to-record-the-optimization-process-when-using-the-jump-optimization-package-for-optimization/63124/5 "2021-06-25T22:15:16Z")

</div>

True thing! I read the original post too quickly, my bad.
