Define copy_to_and_optimize! #1520
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I've just refactored ECOS with MatrixOfConstraints (jump-dev/ECOS.jl#121).
There is something tricky that will also be problematic for other similar solvers.
When you implement
copy_to!(dest::Optimizer, src::OptimizerCache)
,src
contains exactly the data you need to call the solver directly. However, you cannot call it yet, you need to wait foroptimize!
to be called.So you need to store a cache
src
indest
. You need to store a copy sincesrc
could be modified or its data could be free'd beforeoptimize!
is called.This create a lot of edge cases that kind of defeat the purpose of #1381 to remove the need for the optimizer to have a cache as this is handled by the
CachingOptimizer
.This PR defines a one-shot optimization function that both gives
src
and optimizes.For one-shot solver such as most conic solvers, this will considerably simplify the MOI wrapper. It would prevent using these wrapper with
copy_to
andoptimize!
separately without any other MOI layer but it does not matter much.99% of the use cases would be using it with JuMP or with
MOI.instantiate
with bridges which would add a CachingOptimizer layer anyone.So there shouldn't be much difference for the user. It would just simplify a lot the writing of these solvers. No need to complicate it to cover the case where
src
is modified between copy and optimizer while we know this will almost only be used by the CachingOptimizer'soptimize!
method which just calls optimize directly after the copy.The docstring might be clarified to insist that this is a very particular use case. We could even move the function in
MOI.Utilities
if that would clarify it.