JuMP tutorial

This tutorial shows how to solve a model written in JuMP with Penelopt.jl, using NLPModelsJuMP.jl.

Inequality Constraints

Penelopt.jl solves problems of the form minimize f(x) s.t. c(x) = 0. If your JuMP model has inequality constraints, the solver will fail.

1. Build the JuMP model

In this example, we use the Hock–Schittkowski problem HS6.

using JuMP
model = Model()

@variable(model, x1, start = -1.2)
@variable(model, x2, start = 1.0)

@objective(model, Min, (1 - x1)^2)

@constraint(model, 10 * (x2 - x1^2) == 0)

2. Wrap it as an NLPModel

using NLPModelsJuMP

nlp = MathOptNLPModel(model)

3. Solve with Penelopt

using Penelopt

stats = L2Penalty(nlp; print_level = 1)
┌ Info: 
│ This is Penelopt.jl v1.0.0.
│ Running with linear solver MUMPS v5.9.1.
│ 
│ NLPModelsJuMP.MathOptNLPModel
│   Problem name: Generic
│    All variables: ████████████████████ 2      All constraints: ████████████████████ 1
│             free: ████████████████████ 2                 free: ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ 0
│            lower: ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ 0                lower: ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ 0
│            upper: ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ 0                upper: ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ 0
│          low/upp: ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ 0              low/upp: ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ 0
│            fixed: ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ 0                fixed: ████████████████████ 1
│           infeas: ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ 0               infeas: ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ 0
│             nnzh: ( 33.33% sparsity)   2               linear: ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ 0
│                                                     nonlinear: ████████████████████ 1
│                                                          nnzj: (  0.00% sparsity)   2
│                                                      lin_nnzj: (------% sparsity)
│                                                      nln_nnzj: (  0.00% sparsity)   2
│ 
│   Counters:
│              obj: ████████████████████ 1                 grad: ████████████████████ 1                 cons: ████████████████████ 1
│         cons_lin: ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ 0             cons_nln: ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ 0                 jcon: ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ 0
│            jgrad: ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ 0                  jac: ████████████████████ 1              jac_lin: ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ 0
│          jac_nln: ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ 0                jprod: ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ 0            jprod_lin: ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ 0
│        jprod_nln: ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ 0               jtprod: ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ 0           jtprod_lin: ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ 0
│       jtprod_nln: ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ 0                 hess: ████████████████████ 1                hprod: ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ 0
│            jhess: ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ 0               jhprod: ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ 0
└ 
[ Info: ------------------------------------------------------------------------------------------------------
[ Info: Iter   sIter  Objective       pfeas       dfeas       τ           ptol        dtol        ‖x‖
[ Info: ------------------------------------------------------------------------------------------------------
[ Info: 0      0      +4.8400000e+00  4.40e+00    1.56e+00    1.00e+00    1.00e+00    1.56e-02    1.56e+00
[ Info: 1      8      +1.4515287e-04  4.25e-02    9.71e-03    1.00e+00    4.25e-04    9.71e-05    1.39e+00
[ Info: 2      2      +9.9022568e-11  3.91e-06    7.88e-06    1.00e+00    8.05e-08    7.88e-08    1.41e+00
[ Info: 3      1      +2.3314684e-15  9.81e-10    3.85e-08    1.00e+00    8.05e-08    3.82e-08    1.41e+00
[ Info: 4      1      +0.0000000e+00  2.31e-14    6.09e-11    1.00e+00    8.05e-08    3.82e-08    1.41e+00
┌ Info: 
│ Number of Iterations: 4
│ 
│ 
│ Objective...........: +0.000000000000000e+00
│ Primal Feasibility..:  2.309263891220326e-14
│ Dual Feasibility....:  6.090412441422988e-11
│ 
│ 
└ EXIT: first_order.
println("status    : ", stats.status)
println("objective : ", stats.objective)
println("solution  : ", stats.solution)
status    : first_order
objective : 0.0
solution  : [0.9999999999238836, 0.9999999998477648]

See the options reference for the full list of keyword arguments accepted by the solver.