# Optim.jl callback

**URL:** <https://discourse.julialang.org/t/optim-jl-callback/52625>\
**Category:** Optimization (Mathematical)\
**Created:** [December 30, 2020, 5:46pm UTC](https://discourse.julialang.org/t/optim-jl-callback/52625 "2020-12-30T17:46:01Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![piever](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/piever/32/1815_2.png) [@piever](https://discourse.julialang.org/u/piever)\
**Post date:** [January 26, 2021, 4:44pm UTC](https://discourse.julialang.org/t/optim-jl-callback/52625/2 "2021-01-26T16:44:16Z")

</div>

I also needed the history of parameters values. @pkofod answered on slack that you need to turn on the extended trace for that. Then you will have `"x"` in the dictionary passed to the callback.

Example:

```julia
using OptimTestProblems, Optim
problem = MultivariateProblems.UnconstrainedProblems.examples["Rosenbrock"]
f = MultivariateProblems.objective(problem)
g! = MultivariateProblems.gradient(problem)
initial_x = problem.initial_x
d2 = OnceDifferentiable(f, g!, initial_x)
method = LBFGS()
xs = []
cb = tr -> begin
            push!(xs, tr[end].metadata["x"])
            false
        end

options = Optim.Options(callback = cb, show_every=3, store_trace=true, extended_trace=true)
optimize(d2, initial_x, method, options)
xs

```

---

_[View the full topic](https://discourse.julialang.org/t/optim-jl-callback/52625)._
