-
Notifications
You must be signed in to change notification settings - Fork 22
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
feat: add flexibility for solvers besides Gurobi #99
Conversation
fb8a713
to
2211ec8
Compare
println("Connection closed successfully!") | ||
if isa(optimizer_factory, Gurobi.Env) | ||
Gurobi.finalize(optimizer_factory) | ||
println("Connection closed successfully!") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need to do similar thing for other solvers or this is something to explore?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know that other solvers have a similar 'environment' feature that needs to be managed.
function new_model(factory_like)::Union{JuMP.Model, JuMP.MOI.AbstractOptimizer} | ||
if isa(factory_like, Gurobi.Env) | ||
return JuMP.direct_model(Gurobi.Optimizer(factory_like)) | ||
else | ||
return JuMP.Model(factory_like) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, this implies JuMP treats Gurobi differently but all the other solvers in the same way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to use the direct_model
feature to be able to pass the Gurobi environment to the Gurobi.Optimizer
.
@BainanXia we can have JuMP treat Gurobi the same as all of the other optimizers if we call import REISE
import Gurobi
REISE.run_scenario(; interval=1, n_interval=3, start_index=1, inputfolder="path_to_your_local_input_files", optimizer_factory=Gurobi.Optimizer) |
Good to know. I think it is better to make Gurobi one of the options instead of one special option? |
The reason that we have the 'special' code for Gurobi is because we want to have the ability to reuse a single Gurobi environment for all of the solves, for performance reasons. I don't think there's any convenient way to pass this to For example, we could refactor |
For other solvers, if possible, we also want to reuse the environment setup for all of the solves to improve the performance, right? |
It depends. Some solvers have that capability, some do not. Some solvers don't even let you reassign values for constraints, etc. Using |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given @danielolsen has tested with optimizations, I think for now this is good enough to have such capability only. We may explore in the future on how to support other solvers better, but given we are focusing on Gurobi, it is reasonable to say our framework is optimized based on Gurobi, which is obviously the suggested solver.
start_index, inputfolder, outputfolder) | ||
|
||
Given: | ||
- a Gurobi environment `env` | ||
- optimizer instantiation object `factory_like`: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering about the term factory_like
...I'm not sure exactly what it communicates. Maybe something like factory_spec
or factory_env
or optimization_factory_env
, etc?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's either an optimization factory or a Gurobi environment.
Purpose
Add flexibility for solvers besides Gurobi. Closes #97
What is the code doing
In loop.jl:
symbolize
(unrelated refactor to clean up the manual conversion from a Dict of strings to a NamedTuple withininterval_loop
).new_model
, which returns a new JuMP model. This function can take either a Gurobi environment, or an optimizer factory.interval_loop
:new_model
function.symbolize
function for succinctness (unrelated)In REISE.jl, we add a new optional input
optimizer_factory
if
block.interval_loop
Testing
This has been tested with both
Clp.jl
andGLPK.jl
, as well as in the default mode with Gurobi.with GLPK.jl installed:
with Clp.jl installed:
Time to review
30 minutes.