@@ -125,36 +125,68 @@ end
125125"""
126126 instantiate(
127127 optimizer_constructor,
128- with_bridge_type::Union{Nothing, Type} = nothing,
128+ with_cache_type::Union{Nothing,Type} = nothing,
129+ with_bridge_type::Union{Nothing,Type} = nothing,
129130 )
130131
131- Creates an instance of optimizer by either:
132+ Create an instance of an optimizer by either:
133+
132134 * calling `optimizer_constructor.optimizer_constructor()` and setting the
133135 parameters in `optimizer_constructor.params` if `optimizer_constructor` is a
134136 [`OptimizerWithAttributes`](@ref)
135137* calling `optimizer_constructor()` if `optimizer_constructor` is callable.
136138
137- If `with_bridge_type` is not `nothing`, it enables all the bridges defined in
138- the MathOptInterface.Bridges submodule with coefficient type `with_bridge_type`.
139+ ## with_cache_type
140+
141+ If `with_cache_type` is not `nothing`, then the optimizer is wrapped in a
142+ [`Utilities.CachingOptimizer`](@ref) to store a cache of the model. This is most
143+ useful if the optimizer you are constructing does not support the incremental
144+ interface (see [`supports_incremental_interface`](@ref)).
145+
146+ ## with_bridge_type
147+
148+ If `with_bridge_type` is not `nothing`, the optimizer is wrapped in a
149+ [`Bridges.full_bridge_optimizer`](@ref), enabling all the bridges defined in
150+ the MOI.Bridges submodule with coefficient type `with_bridge_type`.
151+
152+ In addition, if the optimizer created by `optimizer_constructor` does not
153+ support the incremental interface (see [`supports_incremental_interface`](@ref)),
154+ then, irrespective of `with_cache_type`, the optimizer is wrapped in a
155+ [`Utilities.CachingOptimizer`](@ref) to store a cache of the bridged model.
139156
140- If the optimizer created by `optimizer_constructor` does not support loading the
141- problem incrementally (see [`supports_incremental_interface`](@ref)), then a
142- [`Utilities.CachingOptimizer`](@ref) is added to store a cache of the bridged
143- model.
157+ If `with_cache_type` and `with_bridge_type` are both not `nothing`, then they
158+ must be the same type.
144159"""
145160function instantiate (
146161 (@nospecialize optimizer_constructor);
147162 with_bridge_type:: Union{Nothing,Type} = nothing ,
163+ with_cache_type:: Union{Nothing,Type} = nothing ,
148164)
165+ if with_bridge_type != = nothing && with_cache_type != = nothing
166+ if with_bridge_type != with_cache_type
167+ error (
168+ " If both provided, `with_bridge_type` and `with_cache_type` " *
169+ " must be the same type. Got " *
170+ " `with_bridge_type = $with_bridge_type ` and " *
171+ " `with_cache_type = $with_cache_type `" ,
172+ )
173+ end
174+ end
149175 optimizer = _instantiate_and_check (optimizer_constructor)
150176 if with_bridge_type === nothing
151- return optimizer
152- end
153- if ! supports_incremental_interface (optimizer)
154- cache = default_cache (optimizer, with_bridge_type)
155- optimizer = Utilities. CachingOptimizer (cache, optimizer)
177+ if with_cache_type === nothing
178+ return optimizer
179+ end
180+ cache = default_cache (optimizer, with_cache_type)
181+ return Utilities. CachingOptimizer (cache, optimizer)
182+ else
183+ if with_cache_type != = nothing ||
184+ ! supports_incremental_interface (optimizer)
185+ cache = default_cache (optimizer, with_bridge_type)
186+ optimizer = Utilities. CachingOptimizer (cache, optimizer)
187+ end
188+ return Bridges. full_bridge_optimizer (optimizer, with_bridge_type)
156189 end
157- return Bridges. full_bridge_optimizer (optimizer, with_bridge_type)
158190end
159191
160192"""
0 commit comments