# Callback function in IPOP for catching inner iterations

**URL:** <https://discourse.julialang.org/t/callback-function-in-ipop-for-catching-inner-iterations/98246>\
**Category:** Optimization (Mathematical)\
**Tags:** jump, optimization, ipopt\
**Created:** [May 3, 2023, 12:18pm UTC](https://discourse.julialang.org/t/callback-function-in-ipop-for-catching-inner-iterations/98246 "2023-05-03T12:18:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Annaquest](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/annaquest/32/47482_2.png) [@Annaquest](https://discourse.julialang.org/u/Annaquest)\
**Post date:** [May 3, 2023, 12:18pm UTC](https://discourse.julialang.org/t/callback-function-in-ipop-for-catching-inner-iterations/98246/1 "2023-05-03T12:18:56Z")

</div>

Hi, I am currently using a callback function to get the number of inner iterations.  
Firstly, I have this: set\_optimizer\_attributes(model, “mu\_target” =\> μ, “mu\_init” =\> μ);  
Where μ is updated outside of IPOPT ( I have my reasons for doing so) However, I am calling the callback function like this,

```julia
iters = []
function my_callback(
            alg_mod::Cint,
            iter_count::Cint,
            obj_value::Float64,
            inf_pr::Float64,
            inf_du::Float64,
            mu::Float64,
            d_norm::Float64,
            regularization_size::Float64,
            alpha_du::Float64,
            alpha_pr::Float64,
            ls_trials::Cint)

            append!(iters, iter_count)
            [...]

```

After IPOPT has successfully found the solution for my specific barrier parameter, I want to know the number of iterations IPOPT used. As I set the barrier parameter myself there will be no “outer” iterations. I believe that I should get the number of iterations by taking: ` j += last(iters)`. However, when I debug my way into the iters vector I see this,  
 ![iterations](https://global.discourse-cdn.com/julialang/original/3X/0/1/0125682d8765f14e6fee1f11400e39269f44273b.png)  
where the purple color represent the element in the vector. I expected that length(iters) -1 = last(iters) (-1 because the iteration starts at 0 which is the initial value and therefore not counted as an iteration) Why is this not the case?

---

<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 4, 2023, 9:02pm UTC](https://discourse.julialang.org/t/callback-function-in-ipop-for-catching-inner-iterations/98246/2 "2023-05-04T21:02:03Z")

</div>

I’ve moved this question to the “Optimization (Mathematical)” section.

It’s hard to say anything without a reproducible example. We’re not doing anything special in Ipopt.jl, so the behavior you’re seeing is what is coming from the Ipopt algorithm.

x-ref [Increasing the barrier parameter manuelly, IPOPT - #2 by odow](https://discourse.julialang.org/t/increasing-the-barrier-parameter-manuelly-ipopt/98313/2)
