-
-
Notifications
You must be signed in to change notification settings - Fork 409
Description
The unsafe_backend is very useful to get info about the backend, especially with the new show methods in MOI. But it's much less useful when the backend does not support any getter.
For instance, this is not so helpful:
julia> model = Model(SDPLR.Optimizer);
julia> unsafe_backend(model)
SDPLR.Optimizer
├ ObjectiveSense: unknown
├ ObjectiveFunctionType: unknown
├ NumberOfVariables: unknown
└ NumberOfConstraints: unknownHowever, if there is a cache, then it would give all the information about the model.
We could have unsafe_backend(model, with_cache = true) that returns the CachingOptimizer that is inside the bridges so that the user has both the optimizer and the corresponding cache.
If there is no cache, this would provide the helpful time to the user that he should use Model(..., with_cache_type = Float64)!
julia> model = Model(SDPLR.Optimizer);
julia> unsafe_backend(model, with_cache = true)
ERROR: The optimizer does not have a cache, either use `with_cache = false` or use `with_cache_type = Float64` in `Model` or `set_optimizer`Then the user would do
julia> model = Model(SDPLR.Optimizer, with_cache_type = Float64)
julia> @variable(model, x)
x
julia> @variable(model, X[1:2, 1:2] in PSDCone())
2×2 Symmetric{VariableRef, Matrix{VariableRef}}:
X[1,1] X[1,2]
X[1,2] X[2,2]
julia> @constraint(model, x == sum(X))
x - X[1,1] - 2 X[1,2] - X[2,2] = 0
julia> optimize!(model)
*** SDPLR 1.03-beta ***
===================================================
major minor val infeas time
---------------------------------------------------
1 0 8.68291638e-05 2.6e-02 0
2 1 8.68839195e-04 1.2e-02 0
3 3 -4.28299100e-05 1.3e-03 0
4 4 1.09718980e-05 5.9e-04 0
5 5 4.40824487e-31 4.5e-17 0
===================================================
DIMACS error measures: 4.47e-17 0.00e+00 0.00e+00 1.27e-14 0.00e+00 5.75e-31
julia> backend(model).optimizer.model # That will be unsafe_backend(model, with_cache = true)
MOIU.CachingOptimizer
├ state: ATTACHED_OPTIMIZER
├ mode: AUTOMATIC
├ model_cache: MOIU.UniversalFallback{MOIU.Model{Float64}}
│ ├ ObjectiveSense: FEASIBILITY_SENSE
│ ├ ObjectiveFunctionType: MOI.ScalarAffineFunction{Float64}
│ ├ NumberOfVariables: 5
│ └ NumberOfConstraints: 3
│ ├ MOI.ScalarAffineFunction{Float64} in MOI.EqualTo{Float64}: 1
│ ├ MOI.VectorOfVariables in MOI.Nonnegatives: 1
│ └ MOI.VectorOfVariables in MOI.PositiveSemidefiniteConeTriangle: 1
└ optimizer: SDPLR.Optimizer
├ ObjectiveSense: unknown
├ ObjectiveFunctionType: unknown
├ NumberOfVariables: unknown
└ NumberOfConstraints: unknownThis model information, along with print_active_bridges would be essential in conic programming for the user to understand what the bridges did