Optim.jl
Optim.jl copied to clipboard
Add MOI wrapper
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
Codecov Report
Merging #929 (57f6a22) into master (1f79069) will decrease coverage by
0.36%. The diff coverage is78.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%> (ø) |
Thanks, this seems like a lot of work you've done. I'll review it
@pkofod I just updated it to MOI v1. Could you get a look ?
Bump :)
:)
Sorry, I had not noticed any of these bumps.
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
Optimization.jl wraps both Optim.jl and the JuMP methods (through MOI), so it effectively achieves the same goal.
I dont see how it is the same goal. The user wanted to call Optim from JuMP.
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 Thanks, I just rebased on master to get the fix from https://github.com/JuliaNLSolvers/Optim.jl/pull/1043 and it's all green :)
You are way too patient. Thanks @blegat !