NLPModelsJuMP.jl
NLPModelsJuMP.jl copied to clipboard
Support for JuMP's new Nonlinear interface
It would be great if this supported the new NL interface in JuMP. Right now it seems to ignore all constraints provided in that way.
CC @odow
You're right, I though this was added in #171, except for quadratic constraints (#173), but apparently it is failing for any constraint. This also means that https://github.com/JuliaSmoothOptimizers/Percival.jl/pull/152 is wrong.
cc. @blegat @tmigot
What is failing ? It's working for me: With quadratic
julia> using JuMP, NLPModelsJuMP, Percival
julia> model = Model(NLPModelsJuMP.Optimizer)
A JuMP Model
Feasibility problem with:
Variables: 0
Model mode: AUTOMATIC
CachingOptimizer state: EMPTY_OPTIMIZER
Solver name: NLPModels
julia> set_attribute(model, "solver", Percival.PercivalSolver)
julia> @variable(model, x[i=1:2], start = [-1.2; 1.0][i])
2-element Vector{VariableRef}:
x[1]
x[2]
julia> @objective(model, Min, (x[1] - 1)^2 + 100 * (x[2] - x[1]^2)^2)
(x[1]² - 2 x[1] + 1) + (100.0 * ((-x[1]² + x[2]) ^ 2.0))
julia> @constraint(model, x[1]^2 + x[2]^2 == 1)
x[1]² + x[2]² = 1
julia> optimize!(model)
[ Info: iter fx normgp normcx μ normy sumc inner_status iter_type
[ Info: 0 2.4e+01 2.3e+02 1.4e+00 1.0e+01 0.0e+00 3
[ Info: 1 2.4e+01 2.3e+02 1.4e+00 1.0e+02 0.0e+00 7 first_order update_μ
[ Info: 2 3.2e+00 2.1e+00 7.9e-04 1.0e+02 7.9e-02 20 first_order update_y
[ Info: 3 3.2e+00 7.3e-07 9.4e-03 1.0e+02 1.0e+00 30 first_order update_y
[ Info: 4 3.2e+00 9.8e-07 5.8e-05 1.0e+02 1.0e+00 40 first_order update_y
[ Info: 5 3.2e+00 4.5e-14 3.6e-07 1.0e+02 1.0e+00 52 first_order update_y
[ Info: 6 3.2e+00 2.2e-11 2.2e-09 1.0e+02 1.0e+00 61 first_order update_y
julia> solution_summary(model)
* Solver : NLPModels
* Status
Result count : 1
Termination status : LOCALLY_SOLVED
Message from the solver:
"first-order stationary"
* Candidate solution (result #1)
Primal status : FEASIBLE_POINT
Dual status : NO_SOLUTION
Objective value : 3.18638e+00
* Work counters
Solve time (sec) : 5.94959e-01
julia> value.(x)
2-element Vector{Float64}:
-0.7839301868019912
0.6208489868346048
With NL
julia> model = Model(NLPModelsJuMP.Optimizer)
A JuMP Model
Feasibility problem with:
Variables: 0
Model mode: AUTOMATIC
CachingOptimizer state: EMPTY_OPTIMIZER
Solver name: NLPModels
julia> set_attribute(model, "solver", Percival.PercivalSolver)
julia> @variable(model, x[i=1:2], start = [-1.2; 1.0][i])
2-element Vector{VariableRef}:
x[1]
x[2]
julia> @objective(model, Min, sqrt((x[1] - 1)^2 + 100 * (x[2] - x[1]^2)^2))
sqrt((x[1]² - 2 x[1] + 1) + (100.0 * ((-x[1]² + x[2]) ^ 2.0)))
julia> @constraint(model, sqrt(x[1]^2 + x[2]^2) == 1)
sqrt(x[1]² + x[2]²) - 1.0 = 0
julia> optimize!(model)
[ Info: iter fx normgp normcx μ normy sumc inner_status iter_type
[ Info: 0 4.9e+00 2.4e+01 5.6e-01 1.0e+01 0.0e+00 3
[ Info: 1 4.9e+00 2.4e+01 5.6e-01 1.0e+02 0.0e+00 7 first_order update_μ
[ Info: 2 1.8e+00 1.5e-01 5.2e-03 1.0e+02 5.2e-01 25 first_order update_y
[ Info: 3 1.8e+00 7.2e-09 5.2e-04 1.0e+02 5.7e-01 35 first_order update_y
[ Info: 4 1.8e+00 6.3e-14 1.5e-06 1.0e+02 5.7e-01 47 first_order update_y
[ Info: 5 1.8e+00 4.1e-11 4.6e-09 1.0e+02 5.7e-01 54 first_order update_y
julia> solution_summary(model)
* Solver : NLPModels
* Status
Result count : 1
Termination status : LOCALLY_SOLVED
Message from the solver:
"first-order stationary"
* Candidate solution (result #1)
Primal status : FEASIBLE_POINT
Dual status : NO_SOLUTION
Objective value : 1.78504e+00
* Work counters
Solve time (sec) : 2.96116e-04
julia> value.(x)
2-element Vector{Float64}:
-0.78393018356842
0.6208489817564649
The versions are
(Percival) pkg> st
Project Percival v0.7.0
Status `~/.julia/dev/Percival/Project.toml`
[10dff2fc] JSOSolvers v0.11.0
[4076af6c] JuMP v1.18.1
[ba0b0d4f] Krylov v0.9.5
[5c8ed15e] LinearOperators v2.6.0
[a4795742] NLPModels v0.20.0
[792afdf1] NLPModelsJuMP v0.12.5
[e01155f1] NLPModelsModifiers v0.6.6
[ff4d7338] SolverCore v0.3.7
[b5612192] SolverTools v0.8.7
[37e2e46d] LinearAlgebra
[56ddb016] Logging
The conversion to an NLPModel doesn't work.
using JuMP, NLPModelsJuMP, Percival
model = Model()
@variable(model, x[1:2])
@objective(model, Min, (x[1] - 1)^2 + 4 * (x[2] - x[1]^2)^2)
@constraint(model, x[1]^2 + x[2]^2 == 1)
@constraint(model, x[1]^4 + x[2]^4 == 1)
@constraint(model, x[1] * exp(x[2]) == 1)
nlp = MathOptNLPModel(model) # Warns Function MathOptInterface.ScalarQuadraticFunction{Float64} is not supported.
# And shows no constraints
output = percival(nlp) # Warns Problem does not have general constraints; calling tron
output.solution # Shows close to [1;1]
This is https://github.com/JuliaSmoothOptimizers/NLPModelsJuMP.jl/issues/173 but aren't constraints other than quadratic working ?
Apparently not