# Set Ipot (with JuMP) to terminate only if max time is reached

**URL:** <https://discourse.julialang.org/t/set-ipot-with-jump-to-terminate-only-if-max-time-is-reached/72160>\
**Category:** Optimization (Mathematical)\
**Created:** [November 27, 2021, 12:11pm UTC](https://discourse.julialang.org/t/set-ipot-with-jump-to-terminate-only-if-max-time-is-reached/72160 "2021-11-27T12:11:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![cricci](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cricci/32/25160_2.png) [@cricci](https://discourse.julialang.org/u/cricci)\
**Post date:** [November 27, 2021, 12:11pm UTC](https://discourse.julialang.org/t/set-ipot-with-jump-to-terminate-only-if-max-time-is-reached/72160/1 "2021-11-27T12:11:14Z")

</div>

I would like to do the following: setting the Ipopt optimizer (used via JuMP) to terminate ONLY when `max_cpu_time` is reached. Is it possible?

motivation for doing such a stupid thing:  
I need to run multiple optimization in parallel on the same machine. They are completely independent. However, by setting the option `max_cpu_time` via `set_optimizer_attribute(model, "max_cpu_time", 100.0)` the max time is divided by the number of processes running in parallel. There is an option `max_wall_time` on the ipopt documentation, but is only for future version of ipopt, not already compatible with Julia. Hence what I usually do is simply set a default value for `max_cpu_time` and then multiply that value by the number of processes that I want to run in parallel. However this partially works, because if for example one optimization ends quickly, then all the others will run for too much time (to account for the time that the first one didn’t use). Hence I would like to set the termination condition only based to time, so that I avoid this issue.

Thanks!

(EDIT: add small example to work with)

```julia
function ff(x) 
    return x^2
end

function jumpTimeOnlyTermination()
    model = Model(Ipopt.Optimizer);
    set_optimizer_attribute(model, "linear_solver", "ma57")
    set_optimizer_attribute(model, "max_iter", 1000)
    set_optimizer_attribute(model, "max_cpu_time", 100.0)

    @variable(model,xx) 

    register(model, :ff, 1, ff; autodiff = true)
    @NLobjective(model,Min,ff(xx))

    JuMP.set_start_value(xx,15)

    JuMP.optimize!(model)
    return model 
end

```

---

<div class="post-metadata">

**Author:** ![blob](https://avatars.discourse-cdn.com/v4/letter/b/ebca7d/32.png) [@blob](https://discourse.julialang.org/u/blob)\
**Post date:** [November 27, 2021, 12:55pm UTC](https://discourse.julialang.org/t/set-ipot-with-jump-to-terminate-only-if-max-time-is-reached/72160/2 "2021-11-27T12:55:20Z")

</div>

Maybe a callback would be of use: [Ipopt: Ipopt::TNLP Class Reference](https://coin-or.github.io/Ipopt/classIpopt_1_1TNLP.html#a2f962a4c43464adb7928771af84503d6)? Looking at the [MOI wrapper](https://github.com/jump-dev/Ipopt.jl/blob/master/src/MOI_wrapper.jl) to ipopt callbacks should be available from JuMP (I have neve used it, though).

---

<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:** [November 27, 2021, 9:56pm UTC](https://discourse.julialang.org/t/set-ipot-with-jump-to-terminate-only-if-max-time-is-reached/72160/3 "2021-11-27T21:56:59Z")

</div>

You’d likely have to play with the different options, e.g., tightening the optimality criteria. But I don’t know if you can make Ipopt sit there after it has found the provably optimal solution (it seems a niche request, so unlikely to be supported).

---

<div class="post-metadata">

**Author:** ![jd-foster](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jd-foster/32/35824_2.png) [@jd-foster](https://discourse.julialang.org/u/jd-foster)\
**Post date:** [November 29, 2021, 12:28am UTC](https://discourse.julialang.org/t/set-ipot-with-jump-to-terminate-only-if-max-time-is-reached/72160/4 "2021-11-29T00:28:31Z")

</div>

I guess this ultimately could be addressed via [https://github.com/jump-dev/Ipopt.jl/issues/246](https://github.com/jump-dev/Ipopt.jl/issues/246)?
