Skip to content

Commit 615a40b

Browse files
authored
Merge pull request #491 from JuliaOpt/bl/renamecopy
Rename copy! -> copy_to
2 parents 16b4dda + d99c4b6 commit 615a40b

File tree

12 files changed

+37
-37
lines changed

12 files changed

+37
-37
lines changed

docs/src/apimanual.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,7 @@ will additionally support `ScalarAffineFunction`-in-`Interval`.
762762
[The interface is designed for multiple dispatch, e.g., attributes, combinations of sets and functions.]
763763

764764
Avoid storing extra copies of the problem when possible. This means that solver wrappers should not use
765-
`CachingOptimizer` as part of the wrapper. Instead, just implement `copy!` if the solver's API
765+
`CachingOptimizer` as part of the wrapper. Instead, just implement `copy_to` if the solver's API
766766
does not support an `add_variable`-like API. Let users or JuMP decide to use `CachingOptimizer` instead.
767767

768768
### JuMP mapping

docs/src/apireference.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ read_from_file
3939
Copying
4040

4141
```@docs
42-
copy!
42+
copy_to
4343
```
4444

4545
List of model attributes

src/Bridges/bridgeoptimizer.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ function MOI.supports(b::AbstractBridgeOptimizer,
8686
MOI.AbstractOptimizerAttribute})
8787
return MOI.supports(b.model, attr)
8888
end
89-
function MOI.copy!(b::AbstractBridgeOptimizer, src::MOI.ModelLike;
89+
function MOI.copy_to(b::AbstractBridgeOptimizer, src::MOI.ModelLike;
9090
copynames=false)
91-
return MOIU.defaultcopy!(b, src, copynames)
91+
return MOIU.default_copy_to(b, src, copynames)
9292
end
9393

9494
# References

src/MathOptInterface.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ Empty the model, that is, remove all variables, constraints and model attributes
7373
function empty! end
7474

7575
"""
76-
copy!(dest::ModelLike, src::ModelLike; copynames=true, warnattributes=true)
76+
copy_to(dest::ModelLike, src::ModelLike; copynames=true, warnattributes=true)
7777
7878
Copy the model from `src` into `dest`. The target `dest` is emptied, and all
7979
previous indices to variables or constraints in `dest` are invalidated. Returns
@@ -101,12 +101,12 @@ x = add_variable(src)
101101
is_valid(src, x) # true
102102
is_valid(dest, x) # false (`dest` has no variables)
103103
104-
index_map = copy!(dest, src)
104+
index_map = copy_to(dest, src)
105105
is_valid(dest, x) # false (unless index_map[x] == x)
106106
is_valid(dest, index_map[x]) # true
107107
```
108108
"""
109-
function copy! end
109+
function copy_to end
110110

111111
include("error.jl")
112112
include("indextypes.jl")

src/Test/modellike.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,19 +156,19 @@ MOI.get(::BadConstraintAttributeModel, ::MOI.ListOfConstraintAttributesSet) = MO
156156

157157
function failcopytestc(dest::MOI.ModelLike)
158158
@test !MOI.supports_constraint(dest, MOI.SingleVariable, UnknownSet)
159-
@test_throws MOI.UnsupportedConstraint MOI.copy!(dest, BadConstraintModel())
159+
@test_throws MOI.UnsupportedConstraint MOI.copy_to(dest, BadConstraintModel())
160160
end
161161
function failcopytestia(dest::MOI.ModelLike)
162162
@test !MOI.supports(dest, UnknownModelAttribute())
163-
@test_throws MOI.UnsupportedAttribute MOI.copy!(dest, BadModelAttributeModel())
163+
@test_throws MOI.UnsupportedAttribute MOI.copy_to(dest, BadModelAttributeModel())
164164
end
165165
function failcopytestva(dest::MOI.ModelLike)
166166
@test !MOI.supports(dest, UnknownVariableAttribute(), MOI.VariableIndex)
167-
@test_throws MOI.UnsupportedAttribute MOI.copy!(dest, BadVariableAttributeModel())
167+
@test_throws MOI.UnsupportedAttribute MOI.copy_to(dest, BadVariableAttributeModel())
168168
end
169169
function failcopytestca(dest::MOI.ModelLike)
170170
@test !MOI.supports(dest, UnknownConstraintAttribute(), MOI.ConstraintIndex{MOI.SingleVariable, MOI.EqualTo{Float64}})
171-
@test_throws MOI.UnsupportedAttribute MOI.copy!(dest, BadConstraintAttributeModel())
171+
@test_throws MOI.UnsupportedAttribute MOI.copy_to(dest, BadConstraintAttributeModel())
172172
end
173173

174174
function copytest(dest::MOI.ModelLike, src::MOI.ModelLike)
@@ -192,7 +192,7 @@ function copytest(dest::MOI.ModelLike, src::MOI.ModelLike)
192192
@test MOI.supports_constraint(dest, MOI.ScalarAffineFunction{Float64}, MOI.LessThan{Float64})
193193
@test MOI.supports_constraint(dest, MOI.VectorAffineFunction{Float64}, MOI.Zeros)
194194

195-
dict = MOI.copy!(dest, src, copynames=false)
195+
dict = MOI.copy_to(dest, src, copynames=false)
196196

197197
@test !MOI.supports(dest, MOI.Name()) || MOI.get(dest, MOI.Name()) == ""
198198
@test MOI.get(dest, MOI.NumberOfVariables()) == 3

src/Utilities/cachingoptimizer.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,13 @@ end
116116
Attaches the optimizer to `model`, copying all model data into it. Can be called
117117
only from the `EmptyOptimizer` state. If the copy succeeds, the
118118
`CachingOptimizer` will be in state `AttachedOptimizer` after the call,
119-
otherwise an error is thrown; see [`copy!`](@ref) for more details on which
119+
otherwise an error is thrown; see [`copy_to`](@ref) for more details on which
120120
errors can be thrown.
121121
"""
122122
function attachoptimizer!(model::CachingOptimizer)
123123
@assert model.state == EmptyOptimizer
124124
# We do not need to copy names because name-related operations are handled by `m.model_cache`
125-
indexmap = MOI.copy!(model.optimizer, model.model_cache, copynames=false)
125+
indexmap = MOI.copy_to(model.optimizer, model.model_cache, copynames=false)
126126
model.state = AttachedOptimizer
127127
# MOI does not define the type of index_map, so we have to copy it into a
128128
# concrete container. Also load the reverse map.
@@ -134,8 +134,8 @@ function attachoptimizer!(model::CachingOptimizer)
134134
end
135135
end
136136

137-
function MOI.copy!(m::CachingOptimizer, src::MOI.ModelLike; copynames=true)
138-
return defaultcopy!(m, src, copynames)
137+
function MOI.copy_to(m::CachingOptimizer, src::MOI.ModelLike; copynames=true)
138+
return default_copy_to(m, src, copynames)
139139
end
140140

141141
function MOI.empty!(m::CachingOptimizer)

src/Utilities/copy.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,11 @@ end
8181

8282
attribute_value_map(idxmap, f::MOI.AbstractFunction) = mapvariables(idxmap, f)
8383
attribute_value_map(idxmap, attribute_value) = attribute_value
84-
function defaultcopy!(dest::MOI.ModelLike, src::MOI.ModelLike)
85-
Base.depwarn("defaultcopy!(dest, src) is deprecated, use defaultcopy!(dest, src, true) instead or defaultcopy!(dest, src, false) if you do not want to copy names.", :defaultcopy!)
86-
defaultcopy!(dest, src, true)
84+
function default_copy_to(dest::MOI.ModelLike, src::MOI.ModelLike)
85+
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)
86+
default_copy_to(dest, src, true)
8787
end
88-
function defaultcopy!(dest::MOI.ModelLike, src::MOI.ModelLike, copynames::Bool)
88+
function default_copy_to(dest::MOI.ModelLike, src::MOI.ModelLike, copynames::Bool)
8989
MOI.empty!(dest)
9090

9191
idxmap = IndexMap()
@@ -118,14 +118,14 @@ end
118118
# During the first pass (called allocate) : the model collects the relevant information about the problem so that
119119
# on the second pass (called load), the constraints can be loaded directly to the solver (in case of SDOI) or written directly into the matrix of constraints (in case of SCS and ECOS).
120120

121-
# To support `MOI.copy!` using this 2-pass mechanism, implement the allocate-load interface defined below and do:
122-
# MOI.copy!(dest::ModelType, src::MOI.ModelLike) = MOIU.allocateload!(dest, src)
121+
# To support `MOI.copy_to` using this 2-pass mechanism, implement the allocate-load interface defined below and do:
122+
# MOI.copy_to(dest::ModelType, src::MOI.ModelLike) = MOIU.allocateload!(dest, src)
123123
# In the implementation of the allocate-load interface, it can be assumed that the different functions will the called in the following order:
124124
# 1) `allocatevariables!`
125125
# 2) `allocate!` and `allocateconstraint!`
126126
# 3) `loadvariables!` and `allocateconstraint!`
127127
# 4) `load!` and `loadconstraint!`
128-
# The interface is not meant to be used to create new constraints with `allocateconstraint!` followed by `loadconstraint!` after a solve, it is only meant for being used in this order to implement `MOI.copy!`.
128+
# The interface is not meant to be used to create new constraints with `allocateconstraint!` followed by `loadconstraint!` after a solve, it is only meant for being used in this order to implement `MOI.copy_to`.
129129

130130
"""
131131
needsallocateload(model::MOI.ModelLike)::Bool
@@ -226,7 +226,7 @@ end
226226
"""
227227
allocateload!(dest::MOI.ModelLike, src::MOI.ModelLike)
228228
229-
Implements `MOI.copy!(dest, src)` using the allocate-load interface.
229+
Implements `MOI.copy_to(dest, src)` using the allocate-load interface.
230230
"""
231231
function allocateload!(dest::MOI.ModelLike, src::MOI.ModelLike, copynames::Bool)
232232
MOI.empty!(dest)

src/Utilities/mockoptimizer.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ mutable struct MockOptimizer{MT<:MOI.ModelLike} <: MOI.AbstractOptimizer
1616
attribute::Int # MockModelAttribute
1717
varattribute::Dict{MOI.VariableIndex,Int} # MockVariableAttribute
1818
conattribute::Dict{MOI.ConstraintIndex,Int} # MockConstraintAttribute
19-
needsallocateload::Bool # Allows to tests the Allocate-Load interface, see copy!
19+
needsallocateload::Bool # Allows to tests the Allocate-Load interface, see copy_to
2020
add_var_allowed::Bool
2121
add_con_allowed::Bool # If false, the optimizer throws AddConstraintNotAllowed
2222
modify_allowed::Bool # If false, the optimizer throws Modify...NotAllowed
@@ -269,11 +269,11 @@ end
269269
# TODO: transform
270270

271271
MOI.supports_constraint(mock::MockOptimizer, F::Type{<:MOI.AbstractFunction}, S::Type{<:MOI.AbstractSet}) = MOI.supports_constraint(mock.inner_model, F, S)
272-
function MOI.copy!(mock::MockOptimizer, src::MOI.ModelLike; copynames=true)
272+
function MOI.copy_to(mock::MockOptimizer, src::MOI.ModelLike; copynames=true)
273273
if needsallocateload(mock)
274274
allocateload!(mock, src, copynames)
275275
else
276-
defaultcopy!(mock, src, copynames)
276+
default_copy_to(mock, src, copynames)
277277
end
278278
end
279279

src/Utilities/model.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,10 +329,10 @@ function MOI.isempty(model::AbstractModel)
329329
iszero(model.nextvariableid) && iszero(model.nextconstraintid)
330330
end
331331

332-
MOI.copy!(dest::AbstractModel, src::MOI.ModelLike; copynames=true) = defaultcopy!(dest, src, copynames)
332+
MOI.copy_to(dest::AbstractModel, src::MOI.ModelLike; copynames=true) = default_copy_to(dest, src, copynames)
333333

334334
# Allocate-Load Interface
335-
# Even if the model does not need it and use defaultcopy!, it could be used by a layer that needs it
335+
# Even if the model does not need it and use default_copy_to, it could be used by a layer that needs it
336336
needsallocateload(model::AbstractModel) = false
337337

338338
allocatevariables!(model::AbstractModel, nvars) = MOI.add_variables(model, nvars)

src/Utilities/universalfallback.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function MOI.empty!(uf::UniversalFallback)
4646
empty!(uf.varattr)
4747
empty!(uf.conattr)
4848
end
49-
MOI.copy!(uf::UniversalFallback, src::MOI.ModelLike; copynames=true) = MOIU.defaultcopy!(uf, src, copynames)
49+
MOI.copy_to(uf::UniversalFallback, src::MOI.ModelLike; copynames=true) = MOIU.default_copy_to(uf, src, copynames)
5050

5151
# References
5252
MOI.is_valid(uf::UniversalFallback, idx::VI) = MOI.is_valid(uf.model, idx)

src/attributes.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Abstract supertype for attribute objects that can be used to set or get attribut
77
88
### Note
99
10-
The difference between `AbstractOptimizerAttribute` and `AbstractModelAttribute` lies in the behavior of `isempty`, `empty!` and `copy!`.
10+
The difference between `AbstractOptimizerAttribute` and `AbstractModelAttribute` lies in the behavior of `isempty`, `empty!` and `copy_to`.
1111
Typically optimizer attributes only affect how the model is solved.
1212
"""
1313
abstract type AbstractOptimizerAttribute end
@@ -73,28 +73,28 @@ message(err::SetAttributeNotAllowed) = err.message
7373
supports(model::ModelLike, attr::AbstractOptimizerAttribute)::Bool
7474
7575
Return a `Bool` indicating whether `model` supports the optimizer attribute
76-
`attr`. That is, it returns `false` if `copy!(model, src)` shows a warning in
76+
`attr`. That is, it returns `false` if `copy_to(model, src)` shows a warning in
7777
case `attr` is in the [`ListOfOptimizerAttributesSet`](@ref) of `src`; see
78-
[`copy!`](@ref) for more details on how unsupported optimizer attributes are
78+
[`copy_to`](@ref) for more details on how unsupported optimizer attributes are
7979
handled in copy.
8080
8181
supports(model::ModelLike, attr::AbstractModelAttribute)::Bool
8282
8383
Return a `Bool` indicating whether `model` supports the model attribute `attr`.
84-
That is, it returns `false` if `copy!(model, src)` cannot be performed in case
84+
That is, it returns `false` if `copy_to(model, src)` cannot be performed in case
8585
`attr` is in the [`ListOfModelAttributesSet`](@ref) of `src`.
8686
8787
supports(model::ModelLike, attr::AbstractVariableAttribute, ::Type{VariableIndex})::Bool
8888
8989
Return a `Bool` indicating whether `model` supports the variable attribute
90-
`attr`. That is, it returns `false` if `copy!(model, src)` cannot be performed
90+
`attr`. That is, it returns `false` if `copy_to(model, src)` cannot be performed
9191
in case `attr` is in the [`ListOfVariableAttributesSet`](@ref) of `src`.
9292
9393
supports(model::ModelLike, attr::AbstractConstraintAttribute, ::Type{ConstraintIndex{F,S}})::Bool where {F,S}
9494
9595
Return a `Bool` indicating whether `model` supports the constraint attribute
9696
`attr` applied to an `F`-in-`S` constraint. That is, it returns `false` if
97-
`copy!(model, src)` cannot be performed in case `attr` is in the
97+
`copy_to(model, src)` cannot be performed in case `attr` is in the
9898
[`ListOfConstraintAttributesSet`](@ref) of `src`.
9999
100100
For all four methods, if the attribute is only not supported in specific

src/constraints.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
supports_constraint(model::ModelLike, ::Type{F}, ::Type{S})::Bool where {F<:AbstractFunction,S<:AbstractSet}
55
66
Return a `Bool` indicating whether `model` supports `F`-in-`S` constraints, that is,
7-
`copy!(model, src)` does not return `CopyUnsupportedConstraint` when `src` contains `F`-in-`S` constraints.
7+
`copy_to(model, src)` does not return `CopyUnsupportedConstraint` when `src` contains `F`-in-`S` constraints.
88
If `F`-in-`S` constraints are only not supported in specific circumstances, e.g. `F`-in-`S` constraints cannot be combined with another type of constraint, it should still return `true`.
99
"""
1010
supports_constraint(model::ModelLike, ::Type{<:AbstractFunction}, ::Type{<:AbstractSet}) = false

0 commit comments

Comments
 (0)