• Stars
    star
    149
  • Rank 246,959 (Top 5 %)
  • Language
    Julia
  • License
    Other
  • Created almost 11 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Julia interface to the Ipopt nonlinear solver

Ipopt.jl

Build Status codecov

Ipopt.jl is a wrapper for the Ipopt solver.

Affiliation

This wrapper is maintained by the JuMP community and is not a COIN-OR project.

License

Ipopt.jl is licensed under the MIT License.

The underlying solver, coin-or/Ipopt, is licensed under the Eclipse public license.

Installation

Install Ipopt.jl using the Julia package manager:

import Pkg
Pkg.add("Ipopt")

In addition to installing the Ipopt.jl package, this will also download and install the Ipopt binaries. You do not need to install Ipopt separately.

To use a custom binary, read the Custom solver binaries section of the JuMP documentation.

For details on using a different linear solver, see the Linear Solvers section below. You do not need a custom binary to change the linear solver.

Use with JuMP

You can use Ipopt with JuMP as follows:

using JuMP, Ipopt
model = Model(Ipopt.Optimizer)
set_attribute(model, "max_cpu_time", 60.0)
set_attribute(model, "print_level", 0)

MathOptInterface API

The Ipopt optimizer supports the following constraints and attributes.

List of supported objective functions:

List of supported variable types:

List of supported constraint types:

List of supported model attributes:

Options

Supported options are listed in the Ipopt documentation.

Solver-specific callbacks

Ipopt provides a callback that can be used to log the status of the optimization during a solve. It can also be used to terminate the optimization by returning false. Here is an example:

using JuMP, Ipopt, Test
model = Model(Ipopt.Optimizer)
set_silent(model)
@variable(model, x >= 1)
@objective(model, Min, x + 0.5)
x_vals = Float64[]
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,
)
   push!(x_vals, callback_value(model, x))
   @test isapprox(obj_value, 1.0 * x_vals[end] + 0.5, atol = 1e-1)
   # return `true` to keep going, or `false` to terminate the optimization.
   return iter_count < 1
end
MOI.set(model, Ipopt.CallbackFunction(), my_callback)
optimize!(model)
@test MOI.get(model, MOI.TerminationStatus()) == MOI.INTERRUPTED
@test length(x_vals) == 2

See the Ipopt documentation for an explanation of the arguments to the callback. They are identical to the output contained in the logging table printed to the screen.

To access the current solution and primal, dual, and complementarity violations of each iteration, use Ipopt.GetIpoptCurrentViolations and Ipopt.GetIpoptCurrentIterate. The two functions are identical to the ones in the Ipopt C interface.

C API

Ipopt.jl wraps the Ipopt C interface with minimal modifications.

A complete example is available in the test/C_wrapper.jl file.

For simplicity, the five callbacks required by Ipopt are slightly different to the C interface. They are as follows:

"""
   eval_f(x::Vector{Float64})::Float64

Returns the objective value `f(x)`.
"""
function eval_f end

"""
   eval_grad_f(x::Vector{Float64}, grad_f::Vector{Float64})::Nothing

Fills `grad_f` in-place with the gradient of the objective function evaluated at
`x`.
"""
function eval_grad_f end

"""
   eval_g(x::Vector{Float64}, g::Vector{Float64})::Nothing

Fills `g` in-place with the value of the constraints evaluated at `x`.
"""
function eval_g end

"""
   eval_jac_g(
      x::Vector{Float64},
      rows::Vector{Cint},
      cols::Vector{Cint},
      values::Union{Nothing,Vector{Float64}},
   )::Nothing

Compute the Jacobian matrix.

* If `values === nothing`
   - Fill `rows` and `cols` with the 1-indexed sparsity structure
* Otherwise:
   - Fill `values` with the elements of the Jacobian matrix according to the
     sparsity structure.

!!! warning
    If `values === nothing`, `x` is an undefined object. Accessing any elements
    in it will cause Julia to segfault.
"""
function eval_jac_g end

"""
   eval_h(
      x::Vector{Float64},
      rows::Vector{Cint},
      cols::Vector{Cint},
      obj_factor::Float64,
      lambda::Float64,
      values::Union{Nothing,Vector{Float64}},
   )::Nothing

Compute the Hessian-of-the-Lagrangian matrix.

* If `values === nothing`
   - Fill `rows` and `cols` with the 1-indexed sparsity structure
* Otherwise:
   - Fill `values` with the Hessian matrix according to the sparsity structure.

!!! warning
    If `values === nothing`, `x` is an undefined object. Accessing any elements
    in it will cause Julia to segfault.
"""
function eval_h end

INVALID_MODEL error

If you get a termination status MOI.INVALID_MODEL, it is probably because you have some undefined value in your model, for example, a division by zero. Fix this by removing the division, or by imposing variable bounds so that you cut off the undefined region.

Instead of

model = Model(Ipopt.Optimizer)
@variable(model, x)
@NLobjective(model, 1 / x)

do

model = Model(Ipopt.Optimizer)
@variable(model, x >= 0.0001)
@NLobjective(model, 1 / x)

Linear Solvers

To improve performance, Ipopt supports a number of linear solvers.

HSL

Obtain a license and download HSL_jll.jl from https://licences.stfc.ac.uk/product/julia-hsl.

There are two versions available: LBT and OpenBLAS. LBT is the recommended option for Julia ≥ v1.9.

Install this download into your current environment using:

import Pkg
Pkg.develop(path = "/full/path/to/HSL_jll.jl")

Then, use a linear solver in HSL by setting the hsllib and linear_solver attributes:

using JuMP, Ipopt
import HSL_jll
model = Model(Ipopt.Optimizer)
set_attribute(model, "hsllib", HSL_jll.libhsl_path)
set_attribute(model, "linear_solver", "ma86")

macOS users

Due to the security policy of macOS, Mac users may need to delete the quarantine attribute of the ZIP archive before extracting. For example:

xattr -d com.apple.quarantine lbt_HSL_jll.jl-2023.5.26.zip
xattr -d com.apple.quarantine openblas_HSL_jll.jl-2023.5.26.zip

Pardiso

Download Pardiso from https://www.pardiso-project.org. Save the shared library somewhere, and record the filename.

Then, use Pardiso by setting the pardisolib and linear_solver attributes:

using JuMP, Ipopt
model = Model(Ipopt.Optimizer)
set_attribute(model, "pardisolib", "/full/path/to/libpardiso")
set_attribute(model, "linear_solver", "pardiso")

SPRAL

If you use Ipopt.jl with Julia ≥ v1.9, the linear solver SPRAL is available. You can use it by setting the linear_solver attribute:

using JuMP, Ipopt
model = Model(Ipopt.Optimizer)
set_attribute(model, "linear_solver", "spral")

Note that the following environment variables must be set before starting Julia:

export OMP_CANCELLATION=TRUE
export OMP_NESTED=TRUE
export OMP_PROC_BIND=TRUE

More Repositories

1

JuMP.jl

Modeling language for Mathematical Optimization (linear, mixed-integer, conic, semidefinite, nonlinear)
Julia
2,203
star
2

Convex.jl

A Julia package for disciplined convex programming
Julia
554
star
3

MathOptInterface.jl

An abstraction layer for mathematical optimization solvers
Julia
374
star
4

Gurobi.jl

A Julia interface to the Gurobi Optimizer
Julia
219
star
5

JuMPTutorials.jl

Tutorials on using JuMP for mathematical optimization in Julia
Jupyter Notebook
141
star
6

Hypatia.jl

interior point solver for general convex conic optimization problems
Julia
139
star
7

CPLEX.jl

A Julia interface to the CPLEX solver
Julia
131
star
8

Pajarito.jl

A solver for mixed-integer convex optimization
Julia
130
star
9

DiffOpt.jl

Differentiating convex optimization programs w.r.t. program parameters
Julia
122
star
10

SumOfSquares.jl

Sum of Squares Programming for Julia
Julia
114
star
11

HiGHS.jl

A Julia interface to the HiGHS solver
Julia
103
star
12

GLPK.jl

A Julia interface to the GNU Linear Programming Kit
Julia
101
star
13

Dualization.jl

Automatic dualization feature for MathOptInterface.jl
Julia
95
star
14

SCS.jl

A Julia interface for the SCS conic programming solver
Julia
82
star
15

Cbc.jl

A Julia interface to the Coin-OR Branch and Cut solver (CBC)
Julia
81
star
16

KNITRO.jl

A Julia interface to the Artelys Knitro solver
Julia
77
star
17

Xpress.jl

A Julia interface to the FICO Xpress Optimization suite
Julia
65
star
18

AmplNLWriter.jl

A Julia interface to AMPL-enabled solvers
Julia
65
star
19

MultiObjectiveAlgorithms.jl

A Julia package for solving multi-objective optimization problems
Julia
60
star
20

Pavito.jl

A gradient-based outer approximation solver for convex mixed-integer nonlinear programming (MINLP)
Julia
59
star
21

Clp.jl

A Julia interface to the Coin-OR Linear Programming solver (CLP)
Julia
52
star
22

MutableArithmetics.jl

Interface for arithmetics on mutable types in Julia
TeX
49
star
23

PolyJuMP.jl

A JuMP extension for Polynomial Optimization
Julia
41
star
24

ECOS.jl

A Julia interface to the ECOS conic optimization solver
Julia
40
star
25

ParametricOptInterface.jl

Extension for dealing with parameters
Julia
36
star
26

MosekTools.jl

A MathOptInterface.jl interface to the MOSEK solver
Julia
29
star
27

CSDP.jl

A Julia interface to the Coin-OR solver CSDP
Julia
21
star
28

benchmarks

A repository for long-term benchmarking of JuMP performance
Julia
19
star
29

MathOptFormat

Specification and description of the MathOptFormat file format
Python
18
star
30

BARON.jl

A Julia interface to the BARON mixed-integer nonlinear programming solver
Julia
18
star
31

MiniZinc.jl

A Julia interface to the MiniZinc constraint modeling language
Julia
15
star
32

MINLPTests.jl

Unit and Integration Tests for JuMP NLP and MINLP solvers
Julia
12
star
33

jump-dev.github.io

Source for jump.dev
Jupyter Notebook
11
star
34

SDPA.jl

A Julia interface to the SDPA semidefinite programming solver
Julia
11
star
35

MatrixOptInterface.jl

An interface to pass matrix form problems
Julia
11
star
36

SDPNAL.jl

A Julia interface to the SDPNAL+ solver
Julia
10
star
37

ComplexOptInterface.jl

Extension of MathOptInterface to complex sets
Julia
8
star
38

SDPLR.jl

Julia wrapper for SDPLR
Julia
7
star
39

Penopt.jl

A Julia interface to the Penopt SDP solver
Julia
7
star
40

SolverTests

Test that all solvers pass the tests before a new MOI release
7
star
41

SeDuMi.jl

A Julia interface to the SeDuMi SDP solver
Julia
6
star
42

SDPT3.jl

A Julia interface to the SDPT3 solver
Julia
5
star
43

DSDP.jl

A Julia interface to the DSDP semidefinite programming solver
Julia
4
star
44

GSOC2021

GSOC2021 information for JuMP
3
star
45

JuMPPaperBenchmarks

Benchmarks for a paper on JuMP 1.0
Julia
2
star
46

Gurobi_jll.jl

A Julia package for installing the Gurobi Optimizer
Julia
2
star
47

MOIPaperBenchmarks

Benchmarks for a paper on MathOptInterface
Julia
1
star
48

GSOC2022

GSOC2022 information for JuMP
1
star
49

HiGHSBuilder

Julia
1
star
50

GSOC2020

GSOC2020 information for JuMP
1
star
51

GSOC

1
star
52

open-energy-modeling-benchmarks

1
star