Skip to content

Commit e22ae6a

Browse files
committed
Rename copy keyword arguments
1 parent 03432e5 commit e22ae6a

File tree

8 files changed

+48
-48
lines changed

8 files changed

+48
-48
lines changed

src/Bridges/bridgeoptimizer.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ function MOI.supports(b::AbstractBridgeOptimizer,
8787
return MOI.supports(b.model, attr)
8888
end
8989
function MOI.copy_to(b::AbstractBridgeOptimizer, src::MOI.ModelLike;
90-
copynames = true)
91-
return MOIU.default_copy_to(b, src, copynames)
90+
copy_names = true)
91+
return MOIU.default_copy_to(b, src, copy_names)
9292
end
9393

9494
# References

src/MathOptInterface.jl

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

7575
"""
76-
copy_to(dest::ModelLike, src::ModelLike; copynames=true, warnattributes=true)
76+
copy_to(dest::ModelLike, src::ModelLike; copy_names=true, warn_attributes=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
8080
a dictionary-like object that translates variable and constraint indices from
8181
the `src` model to the corresponding indices in the `dest` model.
8282
83-
If `copynames` is `false`, the `Name`, `VariableName` and `ConstraintName`
83+
If `copy_names` is `false`, the `Name`, `VariableName` and `ConstraintName`
8484
attributes are not copied even if they are set in `src`. If a constraint that
8585
is copied from `src` is not supported by `dest` then an
8686
[`UnsupportedConstraint`](@ref) error is thrown. Similarly, if a model, variable
8787
or constraint attribute that is copied from `src` is not supported by `dest`
8888
then an [`UnsupportedAttribute`](@ref) error is thrown. Unsupported *optimizer*
8989
attributes are treated differently:
9090
91-
* If `warnattributes` is `true`, a warning is displayed, otherwise,
91+
* If `warn_attributes` is `true`, a warning is displayed, otherwise,
9292
* the attribute is silently ignored.
9393
9494
### Example

src/Test/modellike.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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_to(dest, src, copynames=false)
195+
dict = MOI.copy_to(dest, src, copy_names=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
@@ -122,7 +122,7 @@ errors can be thrown.
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_to(model.optimizer, model.model_cache, copynames=false)
125+
indexmap = MOI.copy_to(model.optimizer, model.model_cache, copy_names=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_to(m::CachingOptimizer, src::MOI.ModelLike; copynames=true)
138-
return default_copy_to(m, src, copynames)
137+
function MOI.copy_to(m::CachingOptimizer, src::MOI.ModelLike; copy_names=true)
138+
return default_copy_to(m, src, copy_names)
139139
end
140140

141141
function MOI.empty!(m::CachingOptimizer)
@@ -400,7 +400,7 @@ function MOI.set(m::CachingOptimizer, attr::Union{MOI.AbstractVariableAttribute,
400400
MOI.set(m.model_cache, attr, index, value)
401401
end
402402

403-
# Names are not copied, i.e. we use the option `copynames=false` in
403+
# Names are not copied, i.e. we use the option `copy_names=false` in
404404
# `attachoptimizer`, so the caching optimizer can support names even if the
405405
# optimizer does not.
406406
function MOI.supports(m::CachingOptimizer,

src/Utilities/copy.jl

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -20,52 +20,52 @@ Base.delete!(idxmap::IndexMap, ci::MOI.ConstraintIndex) = delete!(idxmap.conmap,
2020
Base.keys(idxmap::IndexMap) = Iterators.flatten((keys(idxmap.varmap), keys(idxmap.conmap)))
2121

2222
"""
23-
passattributes!(dest::MOI.ModelLike, src::MOI.ModelLike, copynames::Bool, idxmap::IndexMap, passattr!::Function=MOI.set)
23+
passattributes!(dest::MOI.ModelLike, src::MOI.ModelLike, copy_names::Bool, idxmap::IndexMap, passattr!::Function=MOI.set)
2424
25-
Pass the model attributes from the model `src` to the model `dest` using `canpassattr` to check if the attribute can be passed and `passattr!` to pass the attribute. Does not copy `Name` if `copynames` is `false`.
25+
Pass the model attributes from the model `src` to the model `dest` using `canpassattr` to check if the attribute can be passed and `passattr!` to pass the attribute. Does not copy `Name` if `copy_names` is `false`.
2626
27-
passattributes!(dest::MOI.ModelLike, src::MOI.ModelLike, copynames::Bool, idxmap::IndexMap, vis_src::Vector{MOI.VariableIndex}, passattr!::Function=MOI.set)
27+
passattributes!(dest::MOI.ModelLike, src::MOI.ModelLike, copy_names::Bool, idxmap::IndexMap, vis_src::Vector{MOI.VariableIndex}, passattr!::Function=MOI.set)
2828
29-
Pass the variable attributes from the model `src` to the model `dest` using `canpassattr` to check if the attribute can be passed and `passattr!` to pass the attribute. Does not copy `VariableName` if `copynames` is `false`.
29+
Pass the variable attributes from the model `src` to the model `dest` using `canpassattr` to check if the attribute can be passed and `passattr!` to pass the attribute. Does not copy `VariableName` if `copy_names` is `false`.
3030
31-
passattributes!(dest::MOI.ModelLike, src::MOI.ModelLike, copynames::Bool, idxmap::IndexMap, cis_src::Vector{MOI.ConstraintIndex{F, S}}, passattr!::Function=MOI.set) where {F, S}
31+
passattributes!(dest::MOI.ModelLike, src::MOI.ModelLike, copy_names::Bool, idxmap::IndexMap, cis_src::Vector{MOI.ConstraintIndex{F, S}}, passattr!::Function=MOI.set) where {F, S}
3232
33-
Pass the constraint attributes of `F`-in-`S` constraints from the model `src` to the model `dest` using `canpassattr` to check if the attribute can be passed and `passattr!` to pass the attribute. Does not copy `ConstraintName` if `copynames` is `false`.
33+
Pass the constraint attributes of `F`-in-`S` constraints from the model `src` to the model `dest` using `canpassattr` to check if the attribute can be passed and `passattr!` to pass the attribute. Does not copy `ConstraintName` if `copy_names` is `false`.
3434
"""
3535
function passattributes! end
3636

37-
function passattributes!(dest::MOI.ModelLike, src::MOI.ModelLike, copynames::Bool, idxmap::IndexMap, passattr!::Function=MOI.set)
37+
function passattributes!(dest::MOI.ModelLike, src::MOI.ModelLike, copy_names::Bool, idxmap::IndexMap, passattr!::Function=MOI.set)
3838
# Copy model attributes
3939
attrs = MOI.get(src, MOI.ListOfModelAttributesSet())
40-
_passattributes!(dest, src, copynames, idxmap, attrs, tuple(), tuple(), tuple(), passattr!)
40+
_passattributes!(dest, src, copy_names, idxmap, attrs, tuple(), tuple(), tuple(), passattr!)
4141
end
42-
function passattributes!(dest::MOI.ModelLike, src::MOI.ModelLike, copynames::Bool, idxmap::IndexMap, vis_src::Vector{VI}, passattr!::Function=MOI.set)
42+
function passattributes!(dest::MOI.ModelLike, src::MOI.ModelLike, copy_names::Bool, idxmap::IndexMap, vis_src::Vector{VI}, passattr!::Function=MOI.set)
4343
# Copy variable attributes
4444
attrs = MOI.get(src, MOI.ListOfVariableAttributesSet())
4545
vis_dest = map(vi -> idxmap[vi], vis_src)
46-
_passattributes!(dest, src, copynames, idxmap, attrs, (VI,), (vis_src,), (vis_dest,), passattr!)
46+
_passattributes!(dest, src, copy_names, idxmap, attrs, (VI,), (vis_src,), (vis_dest,), passattr!)
4747
end
48-
function passattributes!(dest::MOI.ModelLike, src::MOI.ModelLike, copynames::Bool, idxmap::IndexMap, cis_src::Vector{CI{F, S}}, passattr!::Function=MOI.set) where {F, S}
48+
function passattributes!(dest::MOI.ModelLike, src::MOI.ModelLike, copy_names::Bool, idxmap::IndexMap, cis_src::Vector{CI{F, S}}, passattr!::Function=MOI.set) where {F, S}
4949
# Copy constraint attributes
5050
attrs = MOI.get(src, MOI.ListOfConstraintAttributesSet{F, S}())
5151
cis_dest = map(ci -> idxmap[ci], cis_src)
52-
_passattributes!(dest, src, copynames, idxmap, attrs, (CI{F, S},), (cis_src,), (cis_dest,), passattr!)
52+
_passattributes!(dest, src, copy_names, idxmap, attrs, (CI{F, S},), (cis_src,), (cis_dest,), passattr!)
5353
end
5454

55-
function _passattributes!(dest::MOI.ModelLike, src::MOI.ModelLike, copynames::Bool, idxmap::IndexMap, attrs, canargs, getargs, setargs, passattr!::Function=MOI.set)
55+
function _passattributes!(dest::MOI.ModelLike, src::MOI.ModelLike, copy_names::Bool, idxmap::IndexMap, attrs, canargs, getargs, setargs, passattr!::Function=MOI.set)
5656
for attr in attrs
57-
if (copynames || !(attr isa MOI.Name || attr isa MOI.VariableName || attr isa MOI.ConstraintName))
57+
if (copy_names || !(attr isa MOI.Name || attr isa MOI.VariableName || attr isa MOI.ConstraintName))
5858
passattr!(dest, attr, setargs..., attribute_value_map(idxmap, MOI.get(src, attr, getargs...)))
5959
end
6060
end
6161
end
6262

6363
"""
64-
copyconstraints!(dest::MOI.ModelLike, src::MOI.ModelLike, copynames::Bool, idxmap::IndexMap, ::Type{F}, ::Type{S}) where {F<:MOI.AbstractFunction, S<:MOI.AbstractSet}
64+
copyconstraints!(dest::MOI.ModelLike, src::MOI.ModelLike, copy_names::Bool, idxmap::IndexMap, ::Type{F}, ::Type{S}) where {F<:MOI.AbstractFunction, S<:MOI.AbstractSet}
6565
66-
Copy the constraints of type `F`-in-`S` from the model `src` the model `dest` and fill `idxmap` accordingly. Does not copy `ConstraintName` if `copynames` is `false`.
66+
Copy the constraints of type `F`-in-`S` from the model `src` the model `dest` and fill `idxmap` accordingly. Does not copy `ConstraintName` if `copy_names` is `false`.
6767
"""
68-
function copyconstraints!(dest::MOI.ModelLike, src::MOI.ModelLike, copynames::Bool, idxmap::IndexMap, ::Type{F}, ::Type{S}) where {F<:MOI.AbstractFunction, S<:MOI.AbstractSet}
68+
function copyconstraints!(dest::MOI.ModelLike, src::MOI.ModelLike, copy_names::Bool, idxmap::IndexMap, ::Type{F}, ::Type{S}) where {F<:MOI.AbstractFunction, S<:MOI.AbstractSet}
6969
# Copy constraints
7070
cis_src = MOI.get(src, MOI.ListOfConstraintIndices{F, S}())
7171
for ci_src in cis_src
@@ -76,7 +76,7 @@ function copyconstraints!(dest::MOI.ModelLike, src::MOI.ModelLike, copynames::Bo
7676
idxmap.conmap[ci_src] = ci_dest
7777
end
7878

79-
passattributes!(dest, src, copynames, idxmap, cis_src)
79+
passattributes!(dest, src, copy_names, idxmap, cis_src)
8080
end
8181

8282
attribute_value_map(idxmap, f::MOI.AbstractFunction) = mapvariables(idxmap, f)
@@ -85,7 +85,7 @@ function default_copy_to(dest::MOI.ModelLike, src::MOI.ModelLike)
8585
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)
8686
default_copy_to(dest, src, true)
8787
end
88-
function default_copy_to(dest::MOI.ModelLike, src::MOI.ModelLike, copynames::Bool)
88+
function default_copy_to(dest::MOI.ModelLike, src::MOI.ModelLike, copy_names::Bool)
8989
MOI.empty!(dest)
9090

9191
idxmap = IndexMap()
@@ -97,15 +97,15 @@ function default_copy_to(dest::MOI.ModelLike, src::MOI.ModelLike, copynames::Boo
9797
end
9898

9999
# Copy variable attributes
100-
passattributes!(dest, src, copynames, idxmap, vis_src)
100+
passattributes!(dest, src, copy_names, idxmap, vis_src)
101101

102102
# Copy model attributes
103-
passattributes!(dest, src, copynames, idxmap)
103+
passattributes!(dest, src, copy_names, idxmap)
104104

105105
# Copy constraints
106106
for (F, S) in MOI.get(src, MOI.ListOfConstraints())
107107
# do the rest in copyconstraints! which is type stable
108-
copyconstraints!(dest, src, copynames, idxmap, F, S)
108+
copyconstraints!(dest, src, copy_names, idxmap, F, S)
109109
end
110110

111111
return idxmap
@@ -193,7 +193,7 @@ Sets the constraint function and set for the constraint of index `ci`.
193193
"""
194194
function loadconstraint! end
195195

196-
function allocateconstraints!(dest::MOI.ModelLike, src::MOI.ModelLike, copynames::Bool, idxmap::IndexMap, ::Type{F}, ::Type{S}) where {F<:MOI.AbstractFunction, S<:MOI.AbstractSet}
196+
function allocateconstraints!(dest::MOI.ModelLike, src::MOI.ModelLike, copy_names::Bool, idxmap::IndexMap, ::Type{F}, ::Type{S}) where {F<:MOI.AbstractFunction, S<:MOI.AbstractSet}
197197
# Allocate constraints
198198
cis_src = MOI.get(src, MOI.ListOfConstraintIndices{F, S}())
199199

@@ -205,10 +205,10 @@ function allocateconstraints!(dest::MOI.ModelLike, src::MOI.ModelLike, copynames
205205
idxmap.conmap[ci_src] = ci_dest
206206
end
207207

208-
return passattributes!(dest, src, copynames, idxmap, cis_src, allocate!)
208+
return passattributes!(dest, src, copy_names, idxmap, cis_src, allocate!)
209209
end
210210

211-
function loadconstraints!(dest::MOI.ModelLike, src::MOI.ModelLike, copynames::Bool, idxmap::IndexMap, ::Type{F}, ::Type{S}) where {F<:MOI.AbstractFunction, S<:MOI.AbstractSet}
211+
function loadconstraints!(dest::MOI.ModelLike, src::MOI.ModelLike, copy_names::Bool, idxmap::IndexMap, ::Type{F}, ::Type{S}) where {F<:MOI.AbstractFunction, S<:MOI.AbstractSet}
212212
# Load constraints
213213
cis_src = MOI.get(src, MOI.ListOfConstraintIndices{F, S}())
214214
for ci_src in cis_src
@@ -219,15 +219,15 @@ function loadconstraints!(dest::MOI.ModelLike, src::MOI.ModelLike, copynames::Bo
219219
loadconstraint!(dest, ci_dest, f_dest, s)
220220
end
221221

222-
return passattributes!(dest, src, copynames, idxmap, cis_src, load!)
222+
return passattributes!(dest, src, copy_names, idxmap, cis_src, load!)
223223
end
224224

225225
"""
226226
allocate_load(dest::MOI.ModelLike, src::MOI.ModelLike)
227227
228228
Implements `MOI.copy_to(dest, src)` using the allocate-load interface.
229229
"""
230-
function allocate_load(dest::MOI.ModelLike, src::MOI.ModelLike, copynames::Bool)
230+
function allocate_load(dest::MOI.ModelLike, src::MOI.ModelLike, copy_names::Bool)
231231
MOI.empty!(dest)
232232

233233
idxmap = IndexMap()
@@ -241,30 +241,30 @@ function allocate_load(dest::MOI.ModelLike, src::MOI.ModelLike, copynames::Bool)
241241
end
242242

243243
# Allocate variable attributes
244-
passattributes!(dest, src, copynames, idxmap, vis_src, allocate!)
244+
passattributes!(dest, src, copy_names, idxmap, vis_src, allocate!)
245245

246246
# Allocate model attributes
247-
passattributes!(dest, src, copynames, idxmap, allocate!)
247+
passattributes!(dest, src, copy_names, idxmap, allocate!)
248248

249249
# Allocate constraints
250250
for (F, S) in MOI.get(src, MOI.ListOfConstraints())
251251
# do the rest in copyconstraints! which is type stable
252-
allocateconstraints!(dest, src, copynames, idxmap, F, S)
252+
allocateconstraints!(dest, src, copy_names, idxmap, F, S)
253253
end
254254

255255
# Load variables
256256
loadvariables!(dest, nvars)
257257

258258
# Load variable attributes
259-
passattributes!(dest, src, copynames, idxmap, vis_src, load!)
259+
passattributes!(dest, src, copy_names, idxmap, vis_src, load!)
260260

261261
# Load model attributes
262-
passattributes!(dest, src, copynames, idxmap, load!)
262+
passattributes!(dest, src, copy_names, idxmap, load!)
263263

264264
# Copy constraints
265265
for (F, S) in MOI.get(src, MOI.ListOfConstraints())
266266
# do the rest in copyconstraints! which is type stable
267-
loadconstraints!(dest, src, copynames, idxmap, F, S)
267+
loadconstraints!(dest, src, copy_names, idxmap, F, S)
268268
end
269269

270270
return idxmap

src/Utilities/mockoptimizer.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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_to(mock::MockOptimizer, src::MOI.ModelLike; copynames=true)
272+
function MOI.copy_to(mock::MockOptimizer, src::MOI.ModelLike; copy_names=true)
273273
if needs_allocate_load(mock)
274-
allocate_load(mock, src, copynames)
274+
allocate_load(mock, src, copy_names)
275275
else
276-
default_copy_to(mock, src, copynames)
276+
default_copy_to(mock, src, copy_names)
277277
end
278278
end
279279

src/Utilities/model.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ function MOI.isempty(model::AbstractModel)
329329
iszero(model.nextvariableid) && iszero(model.nextconstraintid)
330330
end
331331

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

334334
# Allocate-Load Interface
335335
# Even if the model does not need it and use default_copy_to, it could be used by a layer that needs it

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_to(uf::UniversalFallback, src::MOI.ModelLike; copynames=true) = MOIU.default_copy_to(uf, src, copynames)
49+
MOI.copy_to(uf::UniversalFallback, src::MOI.ModelLike; copy_names=true) = MOIU.default_copy_to(uf, src, copy_names)
5050

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

0 commit comments

Comments
 (0)