Optimization.jl Iterations

Hello, how do I extract the number of iterations from Optimization.jl (specifically the NLopt package)?

Here is a sample code

using Optimization, OptimizationNLopt, ModelingToolkit

function calc_sse(x0,p)
    return sum(x0) + a
end

x0 = zeros(2)
lower_bounds = zeros(2).-1
upper_bounds = zeros(2).+1
a = 2

p = [a]
f = OptimizationFunction(calc_sse, Optimization.AutoModelingToollkit(false,false))
prob = Optimization.OptimizationProblem(f, x0,p, lb = lower_bounds, ub = upper_bounds)
sol = solve(prob, NLopt.LD_LBFGS())

The function solve returns an OptimizationSolution, a data structure described here: Optimization Solutions · Optimization.jl (sciml.ai).

It sounds like you should be able to find that information in the sol.stats field.

Thank you!

My bad on not fully reading the documentation. Should probably do so before asking a question on here.

1 Like

No problem! Glad I was able to help.

1 Like