-
-
Notifications
You must be signed in to change notification settings - Fork 393
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
Custom attributes not queried correctly with caching optimizer #2587
Comments
One option would be to make |
But there are also variable and constraint attributes.
I don't think this is a workable solution. We have a counter-example with Gurobi, and there are bound to be other examples. |
We could have a function similar to |
|
Conclusion from the call is that Gurobi should wrap the attribute in |
Actually, we probably want |
Sounds good |
I think this could be better handled via JuMP: function JuMP.get_optimizer_attribute(
model::Model,
attr::MOI.AbstractModelAttribute,
)
return MOI.get(backend(model), MOI.Utilities.AttributeFromOptimizer(attr))
end
model = Model(Gurobi.Optimizer)
MOI.Utilities.attach_optimizer(model)
get_optimizer_attribute(model, Gurobi.ModelAttribute("IsMIP")) At the MOI level, it's sufficient to wrap attributes in |
This works. Needs docs and tests function JuMP.get_optimizer_attribute(
model::Model,
attr::MOI.AbstractModelAttribute,
)
b = backend(model)
if mode(model) == DIRECT
return MOI.get(b, attr)
end
return MOI.get(b, MOI.Utilities.AttributeFromOptimizer(attr))
end
function JuMP.get_optimizer_attribute(
model::Model,
attr::MOI.AbstractConstraintAttribute,
c::ConstraintRef,
)
b = backend(model)
if mode(model) == DIRECT
return MOI.get(b, attr, index(c))
else
return MOI.get(b, MOI.Utilities.AttributeFromOptimizer(attr), index(c))
end
end
function JuMP.get_optimizer_attribute(
model::Model,
attr::MOI.AbstractVariableAttribute,
x::VariableRef,
)
b = backend(model)
if mode(model) == DIRECT
return MOI.get(b, attr, index(x))
else
return MOI.get(b, MOI.Utilities.AttributeFromOptimizer(attr), index(x))
end
end
model = Model(Gurobi.Optimizer)
@variable(model, x >= 1.5)
@constraint(model, c, 2x + 1 == 0)
MOI.Utilities.attach_optimizer(model)
get_optimizer_attribute(model, Gurobi.ModelAttribute("IsMIP")) == 0
get_optimizer_attribute(model, Gurobi.VariableAttribute("LB"), x) == 1.5
get_optimizer_attribute(model, Gurobi.ConstraintAttribute("RHS"), c) == -1.0 |
How much of that extends to other solvers? Also, what about cases where you want to query attributes from a pair of variables (in a quadratic) and a pair variable-constraint (coefficients for instance). I had a use case in DiffOpt.jl where we want to query derivatives from all problem data. Maybe we can have a more generic method with some "args..." and pass them through a convert_to_index_if_needed function? |
Closing in favor of jump-dev/Gurobi.jl#425 |
See https://stackoverflow.com/questions/61922425/how-can-i-determine-whether-a-jump-model-solved-by-gurobi-is-a-mip
Issue is in functions like this:
https://github.com/JuliaOpt/MathOptInterface.jl/blob/3f872f9edb50b1a97cb65011430a0160fd56111e/src/Utilities/cachingoptimizer.jl#L539-L557
where we need a branch to see if it is possible to query directly from the optimizer.
The text was updated successfully, but these errors were encountered: