JuMP & Ipopt: failed to converge solution for standard Rosenbrock

Hi everyone, I am new to Julia (and programming in general). I encountered an error while using JuMP and Ipopt to solve unconstrained maximization for a standard Rosenbrock function. It reports that “EXIT: Optimal Solution Found” but “Optimization failed or stopped early: LOCALLY_SOLVED”. (or if directly using value(x) after optimization, then reported objects of type FLOT64 are not callable

I literally copied the codes, so I am really curious about what else can go wrong.

Any help is much appreciated!

using JuMP
using Ipopt

model = Model(Ipopt.Optimizer)

@variable(model, x, start = 0.0)
@variable(model, y, start = 0.0)

# Define the objective function
@objective(model, Min, (1 - x)^2 + 100 * (y - x^2)^2)

JuMP.optimize!(model)

if termination_status(model) == MOI.OPTIMAL
    println("Optimal value of x: ", value(x))
    println("Optimal value of y: ", value(y))
else
    println("Optimization failed or stopped early: ", termination_status(model))
end

Hi @GY3090, welcome to the forum :smile:

I literally copied the codes, so I am really curious about what else can go wrong.

Ooo! Copied from where? We should fix the documentation.

Here’s the link to the official JuMP documentation: Simple examples · JuMP

There are a few things to fix with your code:

Ipopt is a local solver, so it cannot prove the solution is OPTIMAL. Do instead

if termination_status(model) == LOCALLY_SOLVED
    println("Optimal value of x: ", value(x))
    println("Optimal value of y: ", value(y))
else
    println("Optimization failed or stopped early: ", termination_status(model))
end

There are quite a few complexities with the various statuses, so if you are new to Julia and programming, just use:

if is_solved_and_feasible(model)
    println("Optimal value of x: ", value(x))
    println("Optimal value of y: ", value(y))
else
    println("Optimization failed or stopped early: ", termination_status(model))
end

Here’s what I get when I run that code:

julia> using JuMP

julia> using Ipopt

julia> begin
           model = Model(Ipopt.Optimizer)
           @variable(model, x, start = 0.0)
           @variable(model, y, start = 0.0)
           @objective(model, Min, (1 - x)^2 + 100 * (y - x^2)^2)
           optimize!(model)
           if is_solved_and_feasible(model)
               println("Optimal value of x: ", value(x))
               println("Optimal value of y: ", value(y))
           else
               println("Optimization failed or stopped early: ", termination_status(model))
           end
       end
This is Ipopt version 3.14.17, running with linear solver MUMPS 5.7.3.

Number of nonzeros in equality constraint Jacobian...:        0
Number of nonzeros in inequality constraint Jacobian.:        0
Number of nonzeros in Lagrangian Hessian.............:        3

Total number of variables............................:        2
                     variables with only lower bounds:        0
                variables with lower and upper bounds:        0
                     variables with only upper bounds:        0
Total number of equality constraints.................:        0
Total number of inequality constraints...............:        0
        inequality constraints with only lower bounds:        0
   inequality constraints with lower and upper bounds:        0
        inequality constraints with only upper bounds:        0

iter    objective    inf_pr   inf_du lg(mu)  ||d||  lg(rg) alpha_du alpha_pr  ls
   0  1.0000000e+00 0.00e+00 2.00e+00  -1.0 0.00e+00    -  0.00e+00 0.00e+00   0
   1  9.5312500e-01 0.00e+00 1.25e+01  -1.0 1.00e+00    -  1.00e+00 2.50e-01f  3
   2  4.8320569e-01 0.00e+00 1.01e+00  -1.0 9.03e-02    -  1.00e+00 1.00e+00f  1
   3  4.5708829e-01 0.00e+00 9.53e+00  -1.0 4.29e-01    -  1.00e+00 5.00e-01f  2
   4  1.8894205e-01 0.00e+00 4.15e-01  -1.0 9.51e-02    -  1.00e+00 1.00e+00f  1
   5  1.3918726e-01 0.00e+00 6.51e+00  -1.7 3.49e-01    -  1.00e+00 5.00e-01f  2
   6  5.4940990e-02 0.00e+00 4.51e-01  -1.7 9.29e-02    -  1.00e+00 1.00e+00f  1
   7  2.9144630e-02 0.00e+00 2.27e+00  -1.7 2.49e-01    -  1.00e+00 5.00e-01f  2
   8  9.8586451e-03 0.00e+00 1.15e+00  -1.7 1.10e-01    -  1.00e+00 1.00e+00f  1
   9  2.3237475e-03 0.00e+00 1.00e+00  -1.7 1.00e-01    -  1.00e+00 1.00e+00f  1
iter    objective    inf_pr   inf_du lg(mu)  ||d||  lg(rg) alpha_du alpha_pr  ls
  10  2.3797236e-04 0.00e+00 2.19e-01  -1.7 5.09e-02    -  1.00e+00 1.00e+00f  1
  11  4.9267371e-06 0.00e+00 5.95e-02  -1.7 2.53e-02    -  1.00e+00 1.00e+00f  1
  12  2.8189506e-09 0.00e+00 8.31e-04  -2.5 3.20e-03    -  1.00e+00 1.00e+00f  1
  13  9.6379889e-16 0.00e+00 8.68e-07  -5.7 9.78e-05    -  1.00e+00 1.00e+00f  1
  14  3.0814879e-29 0.00e+00 2.02e-13  -8.6 4.65e-08    -  1.00e+00 1.00e+00f  1

Number of Iterations....: 14

                                   (scaled)                 (unscaled)
Objective...............:   3.0814879110195774e-29    3.0814879110195774e-29
Dual infeasibility......:   2.0183854587685121e-13    2.0183854587685121e-13
Constraint violation....:   0.0000000000000000e+00    0.0000000000000000e+00
Variable bound violation:   0.0000000000000000e+00    0.0000000000000000e+00
Complementarity.........:   0.0000000000000000e+00    0.0000000000000000e+00
Overall NLP error.......:   2.0183854587685121e-13    2.0183854587685121e-13


Number of objective function evaluations             = 36
Number of objective gradient evaluations             = 15
Number of equality constraint evaluations            = 0
Number of inequality constraint evaluations          = 0
Number of equality constraint Jacobian evaluations   = 0
Number of inequality constraint Jacobian evaluations = 0
Number of Lagrangian Hessian evaluations             = 14
Total seconds in IPOPT                               = 0.005

EXIT: Optimal Solution Found.
Optimal value of x: 0.9999999999999899
Optimal value of y: 0.9999999999999792

Your objects of type Float64 are not callable error is not related to the code you have posted. This happens if you have

julia> value = 1.0
1.0

julia> value(1)
ERROR: MethodError: objects of type Float64 are not callable
Maybe you forgot to use an operator such as *, ^, %, / etc. ?
Stacktrace:
[1] top-level scope
@ REPL[2]:1

I see the problem! Thank you, and it works :slight_smile: I copied the part from an unofficial source, so maybe there are some misunderstandings.

No problem. Let me know if you have any other questions.

If you’re new to Julia and programming, you may want to check out our “getting started” tutorials: Getting started with Julia · JuMP