Optim.jl icon indicating copy to clipboard operation
Optim.jl copied to clipboard

Add MOI wrapper

Open blegat opened this issue 4 years ago • 5 comments

With this MOI wrapper, one should be able to use Optim with JuMP doing:

model = Model(Optim.Optimizer)

If there are nonlinear constraints created with @NLconstraint, it would select IPNewton. Otherwise, this would select the method using fallback_method which is wrapped in Fminbox if there are variable bounds. The objective need to be created with @NLobjective.

julia> model = Model(Optim.Optimizer)
A JuMP Model
Feasibility problem with:
Variables: 0
Model mode: AUTOMATIC
CachingOptimizer state: EMPTY_OPTIMIZER
Solver name: Optim

julia> @variable(model, x[1:2])
2-element Vector{VariableRef}:
 x[1]
 x[2]

julia> @NLobjective(model, Min, (1.0 - x[1])^2 + 100.0 * (x[2] - x[1]^2)^2)

julia> @NLconstraint(model, x[1]^2 + x[2]^2 <= 0.5^2)
(x[1] ^ 2.0 + x[2] ^ 2.0) - 0.5 ^ 2.0 ≤ 0

julia> optimize!(model)

julia> objective_value(model)
0.22226228958462926

julia> value.(x)
2-element Vector{Float64}:
 0.5287447092556342
 0.2782265698193508

Note: Quadratic and affine objective created with @objective and constraints created with @constraint are not supported directly by the wrapper but it might be usable with Optim without the need to change anything in this wrapper with the idea suggested in https://github.com/jump-dev/MathOptInterface.jl/issues/1397

This addresses the third item of https://github.com/JuliaNLSolvers/Optim.jl/issues/609

blegat avatar Jun 20 '21 01:06 blegat

Codecov Report

Merging #929 (57f6a22) into master (1f79069) will decrease coverage by 0.36%. The diff coverage is 78.32%.

:exclamation: Current head 57f6a22 differs from pull request most recent head 0168e55. Consider uploading reports for the commit 0168e55 to get more accurate results

@@            Coverage Diff             @@
##           master     #929      +/-   ##
==========================================
- Coverage   85.29%   84.93%   -0.36%     
==========================================
  Files          43       44       +1     
  Lines        3202     3405     +203     
==========================================
+ Hits         2731     2892     +161     
- Misses        471      513      +42     
Impacted Files Coverage Δ
src/Optim.jl 100.00% <ø> (ø)
src/MOI_wrapper.jl 78.32% <78.32%> (ø)

... and 2 files with indirect coverage changes

codecov[bot] avatar Jun 20 '21 13:06 codecov[bot]

Thanks, this seems like a lot of work you've done. I'll review it

pkofod avatar Jul 26 '21 08:07 pkofod

@pkofod I just updated it to MOI v1. Could you get a look ?

blegat avatar Apr 15 '22 12:04 blegat

Bump :)

blegat avatar Jul 25 '22 21:07 blegat

:)

Sorry, I had not noticed any of these bumps.

pkofod avatar Sep 02 '22 07:09 pkofod

One of the questions of this talk: https://meetings.siam.org/sess/dsp_talk.cfm?p=129039 was whether Optim could be used from JuMP

blegat avatar Jun 02 '23 18:06 blegat

Optimization.jl wraps both Optim.jl and the JuMP methods (through MOI), so it effectively achieves the same goal.

ChrisRackauckas avatar Jun 02 '23 20:06 ChrisRackauckas

I dont see how it is the same goal. The user wanted to call Optim from JuMP.

joaquimg avatar Jun 04 '23 08:06 joaquimg

One of the questions of this talk: https://meetings.siam.org/sess/dsp_talk.cfm?p=129039 was whether Optim could be used from JuMP

want to get it finished if I promise to review and get it in this time? :)

pkofod avatar Jun 12 '23 19:06 pkofod

@pkofod Thanks, I just rebased on master to get the fix from https://github.com/JuliaNLSolvers/Optim.jl/pull/1043 and it's all green :)

blegat avatar Jun 13 '23 09:06 blegat

You are way too patient. Thanks @blegat !

pkofod avatar Oct 08 '23 18:10 pkofod