# Plotting the evolution of the optimization using Optim.jl

**URL:** <https://discourse.julialang.org/t/plotting-the-evolution-of-the-optimization-using-optim-jl/41978>\
**Category:** General Usage\
**Tags:** plotting, optim, forwarddiff\
**Created:** [June 24, 2020, 1:15pm UTC](https://discourse.julialang.org/t/plotting-the-evolution-of-the-optimization-using-optim-jl/41978 "2020-06-24T13:15:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![cmey](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cmey/32/200_2.png) [@cmey](https://discourse.julialang.org/u/cmey)\
**Post date:** [June 24, 2020, 1:15pm UTC](https://discourse.julialang.org/t/plotting-the-evolution-of-the-optimization-using-optim-jl/41978/1 "2020-06-24T13:15:38Z")

</div>

Hi! What’s a good strategy to plot the evolution of the solution `x` during the optimization using Optim.jl?

Note: I’m looking for the value of the solution, not the value of the objective function nor the value of the gradient norm that the **trace callback** contains.

Note 2: I would like to use `autodiff=:forward` overall, but would like to avoid the plotting code to be **autodiff** ’ed (it doesn’t help solve the problem), therefore I don’t think I can just put the plotting code inside the function used to optimize (1st arg to `optimize()` ) ? I’ve tried and getting errors, which makes sense to me since we’re getting passed a forward diff’ed type of the current solution in that function, not the current solution.

I’m sure others have had this need, and just can’t find how to do it.  
Thanks!

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [June 25, 2020, 11:44am UTC](https://discourse.julialang.org/t/plotting-the-evolution-of-the-optimization-using-optim-jl/41978/2 "2020-06-25T11:44:25Z")

</div>

Unfortunately, the “white box” API is not (yet) exposed. See

[https://github.com/JuliaNLSolvers/Optim.jl/pull/745](https://github.com/JuliaNLSolvers/Optim.jl/pull/745)

which should allow you to get started calling the optimizer step by step.

---

<div class="post-metadata">

**Author:** ![johnmyleswhite](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/johnmyleswhite/32/31_2.png) [@johnmyleswhite](https://discourse.julialang.org/u/johnmyleswhite)\
**Post date:** [June 25, 2020, 11:47am UTC](https://discourse.julialang.org/t/plotting-the-evolution-of-the-optimization-using-optim-jl/41978/3 "2020-06-25T11:47:29Z")

</div>

Do you need the plots to update live in response to the state? If not, Optim can generate a dump of its internal state that you can plot after the factt.

---

<div class="post-metadata">

**Author:** ![cmey](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cmey/32/200_2.png) [@cmey](https://discourse.julialang.org/u/cmey)\
**Post date:** [June 25, 2020, 1:52pm UTC](https://discourse.julialang.org/t/plotting-the-evolution-of-the-optimization-using-optim-jl/41978/4 "2020-06-25T13:52:19Z")

</div>

@johnmyleswhite It doesn’t need to update live during the optimization, although that would be cool, plotting the evolution after the optimization is finished is enough. I’ll look into the dump of the internal state. Thanks!

@Tamas_Papp That’s a good backup plan – Thanks!
