Skip to content

Automatic fallback in CachingOptimizer #1310

@blegat

Description

@blegat

We have fallbacks for a few attributes such as ConstraintPrimal but currently, they are only used by MockOptimizer.
When you have a CachingOptimizer{Solver.Optimizer}, a common use case is to do

try
    MOI.get(model, MOI.ConstraintPrimal(), ...)
catch
    MOI.get_fallback(model, MOI.ConstraintPrimal(), ...)
end

However, as mentioned in #1249, relying on try-catch for such normal behavior is not ideal. Moreover, we might catch other errors that shouldn't be ignored.
We decided against having a supports for getters and Solver.Optimizer cannot call get_fallback because it does not implement MOI.ConstraintFunction. Maybe we could have a function use_fallback and in the caching optimizer, we call use_fallback first and if it returns true then we call get_fallback instead of get.

Then if a solver does not natively support giving the ConstraintPrimal nor the ConstraintFunction, it can implement use_fallback(::Solver.Optimizer, ::MOI.ConstraintPrimal) = true. It would then be able to pass the MOI tests needed ConstraintPrimal.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions