Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MOI wrapper #929

Merged
merged 7 commits into from
Oct 8, 2023
Merged

Add MOI wrapper #929

merged 7 commits into from
Oct 8, 2023

Conversation

blegat
Copy link
Contributor

@blegat blegat commented Jun 20, 2021

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 jump-dev/MathOptInterface.jl#1397

This addresses the third item of #609

@codecov
Copy link

codecov bot commented Jun 20, 2021

Codecov Report

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

❗ 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

@pkofod
Copy link
Member

pkofod commented Jul 26, 2021

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

@blegat
Copy link
Contributor Author

blegat commented Apr 15, 2022

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

@blegat
Copy link
Contributor Author

blegat commented Jul 25, 2022

Bump :)

@pkofod
Copy link
Member

pkofod commented Sep 2, 2022

:)

Sorry, I had not noticed any of these bumps.

@blegat
Copy link
Contributor Author

blegat commented Jun 2, 2023

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

@ChrisRackauckas
Copy link
Contributor

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

@joaquimg
Copy link

joaquimg commented Jun 4, 2023

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

@pkofod
Copy link
Member

pkofod commented Jun 12, 2023

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? :)

@blegat
Copy link
Contributor Author

blegat commented Jun 13, 2023

@pkofod Thanks, I just rebased on master to get the fix from #1043 and it's all green :)

@pkofod
Copy link
Member

pkofod commented Oct 8, 2023

You are way too patient. Thanks @blegat !

@pkofod pkofod merged commit 760993c into JuliaNLSolvers:master Oct 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants