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

Initialize JuMP model when optimizer is nothing #2172

Closed
odow opened this issue Feb 19, 2020 · 2 comments
Closed

Initialize JuMP model when optimizer is nothing #2172

odow opened this issue Feb 19, 2020 · 2 comments

Comments

@odow
Copy link
Member

odow commented Feb 19, 2020

The NREL folks suggest adding a method:

Model(::Nothing; kwargs...) = Model(; kwargs...)

so that they can create models if the user doesn't pass an optimizer (e.g., it remains the default nothing).

The alternative is them writing

model = optimizer === nothing ? Model(; kwargs...) : Model(optimizer; kwargs...)

cc @kdheepak, @jd-lara

@mlubin
Copy link
Member

mlubin commented Feb 19, 2020

The alternative is

m = Model()
if !isnothing(optimizer)
    set_optimizer(m, optimizer)
end

I'm not seeing a big issue with that version. This is a slippery slope if we start adding Nothing versions of all JuMP methods that take objects.

@odow
Copy link
Member Author

odow commented Feb 20, 2020

This is a slippery slope if we start adding Nothing versions of all JuMP methods that take objects.

Agreed.

They will continue to implement a work-around down-stream.

For future readers, SDDP.jl implements a similar solution:
https://github.com/odow/SDDP.jl/blob/ff628f52afb01f52e7b64aa9a915cbead48f39f7/src/user_interface.jl#L458-L476

@odow odow closed this as completed Feb 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants