How to get values from every iteration in JuMP

I'm solving a particular optimization problem in julia using JuMP, Ipopt and I have a problem finding the history of values i.e. value of x from every iteration. I couldn't find anything useful in documentations.

Minimal example:

using JuMP
import Ipopt

model = Model(Ipopt.Optimizer)
@variable(model, -2.0 <= x <= 2.0, start = -2.0)
@NLobjective(model, Min, (x - 1.0) ^ 2)
optimize!(model)
value(x)

and I'd like to see value of x from every iteration, not only the last to create plot of x vs iteration.

Looking for any help :)

Upvotes: 1

Views: 854

Answers (2)

Oscar Dowson
Oscar Dowson

Reputation: 2574

This is currently not possible. But there's an open issue: https://github.com/jump-dev/Ipopt.jl/issues/281

Upvotes: 1

Przemyslaw Szufel
Przemyslaw Szufel

Reputation: 42244

Each solver has a parameter on how verbose it is in representing the results. In case of Ipopt you can do before calling optimize!(model):

set_optimizer_attribute(model, "print_level", 7)

In logs loog for curr_x (here is a part of logs):

**************************************************
*** Summary of Iteration: 6:
**************************************************

iter    objective    inf_pr   inf_du lg(mu)  ||d||  lg(rg) alpha_du alpha_pr  ls
   6  3.8455657e-13 0.00e+00 8.39e-17  -5.7 5.74e-05    -  1.00e+00 1.00e+00f  1

**************************************************
*** Beginning Iteration 6 from the following point:
**************************************************

Current barrier parameter mu = 1.8449144625279479e-06
Current fraction-to-the-boundary parameter tau = 9.9999815508553747e-01

||curr_x||_inf   = 9.9999937987374388e-01
||curr_s||_inf   = 0.0000000000000000e+00
||curr_y_c||_inf = 0.0000000000000000e+00
||curr_y_d||_inf = 0.0000000000000000e+00
||curr_z_L||_inf = 6.1403864613595829e-07

Upvotes: 1

Related Questions