@@ -76,16 +76,17 @@ include("parametric_cubic_function.jl")
7676 evaluate_duals::Bool = true,
7777 save_original_objective_and_constraints::Bool = true,
7878 with_bridge_type = nothing,
79- with_cache_type = nothing ,
79+ with_cache_type = missing ,
8080 )
8181
8282Create an `Optimizer`, which allows the handling of parameters in an
8383optimization model.
8484
85+ If `ismissing(with_cache_type)`, the optimizer is instantiated with
86+ `MOI.instantiate(optimizer; with_bridge_type)`.
8587If `optimizer` is not a `MOI.ModelLike,` the inner optimizer is constructed
86- using `MOI.instantiate(optimizer; with_cache_type)`.
88+ using `MOI.instantiate(optimizer; with_bridge_type, with_cache_type)`.
8789
88- If `with_bridge_type !== nothing`, a `MOI.Bridges.full_bridge_optimizer` is
8990applied as an outer layer.
9091
9192The `{T}` type parameter is optional; it defaults to `Float64`.
@@ -296,25 +297,26 @@ Optimizer(arg; kwargs...) = Optimizer{Float64}(arg; kwargs...)
296297
297298function Optimizer {T} (
298299 optimizer_fn;
299- with_bridge_type = nothing ,
300- with_cache_type = nothing ,
300+ with_bridge_type:: Union{Nothing,Type} = nothing ,
301+ with_cache_type:: Union{Nothing,Type} = nothing ,
301302 kwargs... ,
302303) where {T}
303- inner = MOI. instantiate (optimizer_fn; with_cache_type)
304- if ! MOI. supports_incremental_interface (inner)
305- # Don't use `default_cache` for the cache because, for example, SCS's
306- # default cache doesn't support modifying coefficients of the constraint
307- # matrix. JuMP uses the default cache with SCS because it has an outer
308- # layer of caching; we don't have that here, so we can't use the
309- # default.
310- #
311- # We could revert to using the default cache if we fix this in MOI.
312- cache = MOI. Utilities. UniversalFallback (MOI. Utilities. Model {T} ())
313- inner = MOI. Utilities. CachingOptimizer (cache, inner)
314- end
315- if with_bridge_type != = nothing
316- inner = MOI. Bridges. full_bridge_optimizer (inner, with_bridge_type)
304+ # Dualization needs an incremental interface.
305+ # In `MOI.instantiate`, there a mechanism in place to enforce a cache
306+ # to be used if `with_bridge_type` is `true` because bridges also need the
307+ # incremental interface.
308+ # So we just hook into this mechanism by setting the following to `true`
309+ # if the user didn't explictly ask for a cache.
310+ cache_only_if_incremental_interface_not_supported = isnothing (with_cache_type)
311+ if isnothing (with_cache_type)
312+ with_cache_type = T
317313 end
314+ inner = MOI. instantiate (
315+ optimizer_fn;
316+ with_bridge_type,
317+ with_cache_type,
318+ cache_only_if_incremental_interface_not_supported,
319+ )
318320 return Optimizer {T} (inner; kwargs... )
319321end
320322
0 commit comments