Conversation
joehuchette
left a comment
There was a problem hiding this comment.
Is this a general problem that a number of optimizers run into? Or is it mostly just a problem with the CachingOptimizer, because of it's extra layer or redirection?
|
This is mainly But more widely, standardizing the return types of |
|
Alternatively, we could avoid having a non-concrete type for the optimizer as suggested in jump-dev/JuMP.jl#2520. |
If these types are properly defined in MOI, then we can add unit tests that solvers return the correct types. This prevents surprises when using the solver from JuMP. In terms of bikeshedding, I'd suggest |
|
Independently of the alternative, this could indeed be useful, attribute_value_type(::ModelLike, attr::AnyAttribute) = attribute_value_type(attr)
attribute_value_type(::ModelLike, attr::Union{MOI.VariablePrimal, MOI.VariablePrimalStart, ...}) = MOI.get(model, CoefficientType())If there is only one method of |
|
I'm a +1 to standardizing the "attribute value types" of MOI attributes, and having MOIT unit tests for this expected behavior. |
d639eea to
dc25770
Compare
src/Test/UnitTests/attributes.jl
Outdated
| function $(f)(model::MOI.ModelLike, config::TestConfig) | ||
| MOI.empty!(model) | ||
| MOI.optimize!(model) | ||
| attribute = MOI.$(attr)() |
There was a problem hiding this comment.
Maybe skip the test is supports is false
There was a problem hiding this comment.
For now I've made these tests opt-in individually (They aren't in the unittest testset). We probably want to wait a few releases for solvers to adapt before enforcing it and breaking every solver.
There was a problem hiding this comment.
What are the changes needed in the solver ? I assume they already have objects of the correct type returned, don't they ?
There was a problem hiding this comment.
They will return the correct object, but they may not infer correctly.
There was a problem hiding this comment.
Now that we're breaking things, I added the tests by default. It would be good for solvers to fix them.
|
@blegat how is this. I changed to |
|
@blegat bump. |
src/Test/UnitTests/attributes.jl
Outdated
| MOI.get(model, attribute) | ||
| catch err | ||
| if err isa ArgumentError | ||
| return # Solver does not support accessing the attribute. |
Originally proposed all the way back in #31.
Problem
Lots of
MOI.getfail to infer. For example, getting the termination statusof a caching optimizer is
Anyinstead ofTerminationStatusCode.Whereas with this PR we have
Unfortunately, attributes like
MOI.VariablePrimalfail to infer, because we don't know if they areFloat64or not.Alternatives
If we won't want to add
MOI.return_type, I can move it into CachingOptimizer.