-
Notifications
You must be signed in to change notification settings - Fork 94
[breaking] remove automatic_copy_to #1512
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,7 @@ | ||
# This file contains default implementations for the `MOI.copy_to` function that | ||
# can be used by a model. | ||
|
||
""" | ||
automatic_copy_to( | ||
dest::MOI.ModelLike, | ||
src::MOI.ModelLike; | ||
copy_names::Bool=true, | ||
filter_constraints::Union{Nothing,Function} = nothing, | ||
) | ||
|
||
A default fallback for [`MOI.copy_to`](@ref). | ||
|
||
To use this method, define | ||
[`MathOptInterface.supports_incremental_interface`](@ref). | ||
|
||
If the `filter_constraints` arguments is given, only the constraints for which | ||
this function returns `true` will be copied. This function is given a | ||
constraint index as argument. | ||
""" | ||
function automatic_copy_to( | ||
dest::MOI.ModelLike, | ||
src::MOI.ModelLike; | ||
copy_names::Bool = true, | ||
filter_constraints::Union{Nothing,Function} = nothing, | ||
) | ||
if !MOI.supports_incremental_interface(dest, copy_names) | ||
error( | ||
"Model $(typeof(dest)) does not support copy", | ||
copy_names ? " with names" : "", | ||
".", | ||
) | ||
end | ||
return default_copy_to(dest, src, copy_names, filter_constraints) | ||
end | ||
|
||
@deprecate automatic_copy_to default_copy_to | ||
@deprecate supports_default_copy_to MOI.supports_incremental_interface | ||
|
||
include("copy/index_map.jl") | ||
|
@@ -486,14 +454,6 @@ function copy_free_variables( | |
return | ||
end | ||
|
||
function default_copy_to(dest::MOI.ModelLike, src::MOI.ModelLike) | ||
Base.depwarn( | ||
"default_copy_to(dest, src) is deprecated, use default_copy_to(dest, src, true) instead or default_copy_to(dest, src, false) if you do not want to copy names.", | ||
:default_copy_to, | ||
) | ||
return default_copy_to(dest, src, true) | ||
end | ||
|
||
function sorted_variable_sets_by_cost(dest::MOI.ModelLike, src::MOI.ModelLike) | ||
constraint_types = MOI.get(src, MOI.ListOfConstraintTypesPresent()) | ||
single_or_vector_variables_types = [ | ||
|
@@ -575,29 +535,54 @@ only once all the model information is gathered. | |
""" | ||
function final_touch(::MOI.ModelLike, idxmap) end | ||
|
||
function default_copy_to( | ||
dest::MOI.ModelLike, | ||
src::MOI.ModelLike, | ||
copy_names::Bool, | ||
filter_constraints::Union{Nothing,Function} = nothing, | ||
) | ||
@warn( | ||
"The `copy_names` and `filter_constraints` arguments to " * | ||
"`default_copy_to` are now keyword arguments.", | ||
maxlog = 1, | ||
) | ||
return default_copy_to( | ||
dest, | ||
src; | ||
copy_names = copy_names, | ||
filter_constraints = filter_constraints, | ||
) | ||
end | ||
|
||
""" | ||
default_copy_to( | ||
dest::MOI.ModelLike, | ||
src::MOI.ModelLike, | ||
copy_names::Bool, | ||
src::MOI.ModelLike; | ||
copy_names::Bool = true, | ||
filter_constraints::Union{Nothing,Function} = nothing, | ||
) | ||
|
||
Implements `MOI.copy_to(dest, src)` by adding the variables and then the | ||
constraints and attributes incrementally. The function | ||
[`MathOptInterface.supports_incremental_interface`](@ref) can be used to check | ||
whether `dest` supports the copying a model incrementally. | ||
A default implementation of `MOI.copy_to(dest, src)` for models that implement | ||
the incremental interface, i.e., [`MOI.supports_incremental_interface`](@ref) | ||
returns `true`. | ||
|
||
If the `filter_constraints` arguments is given, only the constraints for which | ||
this function returns `true` will be copied. This function is given a | ||
constraint index as argument. | ||
If `filter_constraints` is a `Function`, only constraints for which | ||
`filter_constraints(ci)` returns `true` will be copied, where `ci` is the | ||
[`MOI.ConstraintIndex`](@ref) of the constraint. | ||
""" | ||
function default_copy_to( | ||
dest::MOI.ModelLike, | ||
src::MOI.ModelLike, | ||
copy_names::Bool, | ||
src::MOI.ModelLike; | ||
copy_names::Bool = true, | ||
filter_constraints::Union{Nothing,Function} = nothing, | ||
) | ||
if !MOI.supports_incremental_interface(dest, copy_names) | ||
error( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm wondering whether it makes sense to remove this error. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This check is trivial and will be in-lined. It also prevents a later error like "add variable not allowed" in some cases. I'd suggest we leave it in, at least until all the solvers are updated. We could remove it for 1.0 if it's not needed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes, I was not worried about peformance
Sounds good |
||
"Model $(typeof(dest)) does not support copy", | ||
copy_names ? " with names" : "", | ||
".", | ||
) | ||
end | ||
MOI.empty!(dest) | ||
|
||
vis_src = MOI.get(src, MOI.ListOfVariableIndices()) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems crazy, but this has been sitting here since MOI 0.2.0! 1ae8661