Skip to content

Turn warnings into errors in CI and fix last remaining warnings #393

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

Merged
merged 4 commits into from
Jun 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ notifications:

## uncomment the following lines to override the default test script
script:
- julia -e 'Pkg.clone(pwd()); Pkg.build("MathOptInterface"); Pkg.test("MathOptInterface"; coverage=true)'
- julia -e 'Pkg.clone(pwd()); Pkg.build("MathOptInterface"); Pkg.add("Compat")' # warnings here about needed to do using Pkg but it also installs Compat
- julia --depwarn=error -e 'using Compat; using Compat.Pkg; Pkg.test("MathOptInterface"; coverage=true)'
after_success:
# push coverage results to Coveralls
#- julia -e 'cd(Pkg.dir("MathOptInterface")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'
Expand Down
2 changes: 1 addition & 1 deletion src/Bridges/Bridges.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Bridges

using Compat # For lastindex
using Compat

using MathOptInterface
const MOI = MathOptInterface
Expand Down
6 changes: 3 additions & 3 deletions src/Bridges/bridgeoptimizer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ function MOI.get(b::AbstractBridgeOptimizer, loc::MOI.ListOfConstraintIndices{F,
end
for bridge in values(b.bridges)
for c in MOI.get(bridge, loc)
i = findfirst(locr, c)
if (VERSION >= v"0.7.0-DEV.3395" && i !== nothing) || (VERSION < v"0.7.0-DEV.3395" && !iszero(i))
i = something(findfirst(isequal(c), locr), 0)
if !iszero(i)
MOI.deleteat!(locr, i)
end
end
Expand Down Expand Up @@ -128,7 +128,7 @@ function MOI.get(b::AbstractBridgeOptimizer, attr::MOI.ListOfConstraints)
# of that type have been created by bridges and not by the user.
# The code in `NumberOfConstraints` takes care of removing these constraints
# from the counter so we can rely on it to remove these constraint types.
types_to_remove = find(iszero.(map(FS -> MOI.get(b, MOI.NumberOfConstraints{FS...}()), list_of_types)))
types_to_remove = findall(iszero.(map(FS -> MOI.get(b, MOI.NumberOfConstraints{FS...}()), list_of_types)))
deleteat!(list_of_types, types_to_remove)
list_of_types
end
Expand Down
2 changes: 1 addition & 1 deletion src/Bridges/detbridge.jl
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function LogDetBridge{T}(model, f::MOI.VectorAffineFunction{T}, s::MOI.LogDetCon
d = s.dimension
t, D, Δ, sdindex = extract_eigenvalues(model, f, d)
l = MOI.addvariables!(model, d)
lcindex = sublog.(model, l, D, T)
lcindex = sublog.(Ref(model), l, D, T)
tlindex = subsum(model, t, l, T)

LogDetBridge(Δ, l, sdindex, lcindex, tlindex)
Expand Down
4 changes: 2 additions & 2 deletions src/Bridges/geomeanbridge.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function GeoMeanBridge{T}(model, f::MOI.VectorAffineFunction{T}, s::MOI.Geometri
# With sqrt(2)^l*t - xl1, we should scale both the ConstraintPrimal and ConstraintDual
tubc = MOI.addconstraint!(model, MOI.ScalarAffineFunction([t.terms; MOI.ScalarAffineTerm(-sN, xl1)], t.constant), MOI.LessThan(zero(T)))

socrc = Vector{CI{MOI.VectorAffineFunction{T}, MOI.RotatedSecondOrderCone}}(N-1)
socrc = Vector{CI{MOI.VectorAffineFunction{T}, MOI.RotatedSecondOrderCone}}(undef, N-1)
offset = offsetnext = 0
for i in 1:l
offsetnext = offset + i
Expand Down Expand Up @@ -114,7 +114,7 @@ function MOI.canget(model::MOI.ModelLike, a::MOI.ConstraintPrimal, ::Type{GeoMea
MOI.canget(model, a, CI{MOI.VectorAffineFunction{T}, MOI.RotatedSecondOrderCone})
end
function _getconstrattr(model, a, c::GeoMeanBridge{T}) where T
output = Vector{T}(c.d)
output = Vector{T}(undef, c.d)
output[1] = MOI.get(model, a, c.tubc)
N = length(c.xij)+1
offset = div(N, 2) - 1 # 1 + 2 + ... + n/4
Expand Down
6 changes: 3 additions & 3 deletions src/Bridges/soctopsdbridge.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ function _SOCtoPSDCaff(f::MOI.VectorAffineFunction{T}, g::MOI.ScalarAffineFuncti
N0 = length(f.terms)
Ni = length(g.terms)
N = N0 + (dim-1) * Ni
terms = Vector{MOI.VectorAffineTerm{T}}(N)
terms = Vector{MOI.VectorAffineTerm{T}}(undef, N)
terms[1:N0] = MOI.VectorAffineTerm.(map(t -> trimap.(t.output_index, 1), f.terms),
MOI.ScalarAffineTerm.(map(t -> t.scalar_term.coefficient, f.terms),
map(t -> t.scalar_term.variable_index, f.terms)))
constant = [f.constants; zeros(T, n - dim)]
cur = N0
for i in 2:dim
k = trimap(i, i)
terms[cur+(1:Ni)] = MOI.VectorAffineTerm.(k, MOI.ScalarAffineTerm.(map(t -> t.coefficient, g.terms),
map(t -> t.variable_index, g.terms)))
terms[cur.+(1:Ni)] = MOI.VectorAffineTerm.(k, MOI.ScalarAffineTerm.(map(t -> t.coefficient, g.terms),
map(t -> t.variable_index, g.terms)))
constant[k] = g.constant
cur += Ni
end
Expand Down
2 changes: 1 addition & 1 deletion src/Test/UnitTests/basic_constraint_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ function basic_constraint_test_helper(model::MOI.ModelLike, config::TestConfig,
c_indices = MOI.get(model, MOI.ListOfConstraintIndices{F,S}())
# for sanity, check that we've added 3 constraints as expected.
@test length(c_indices) == 3
@test all(MOI.isvalid.(model, c_indices))
@test all(MOI.isvalid.(Ref(model), c_indices))
end

if delete
Expand Down
2 changes: 1 addition & 1 deletion src/Test/UnitTests/constraints.jl
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ function solve_affine_deletion_edge_cases(model::MOI.ModelLike, config::TestConf
MOI.empty!(model)
x = MOI.addvariable!(model)
# helpers. The function 1.0x + 0.0
saf = MOI.ScalarAffineFunction(MOI.ScalarAffineTerm.([1.0], x), 0.0)
saf = MOI.ScalarAffineFunction([MOI.ScalarAffineTerm(1.0, x)], 0.0)
vaf = MOI.VectorAffineFunction([MOI.VectorAffineTerm(1, MOI.ScalarAffineTerm(1.0, x))], [0.0])
vaf2 = MOI.VectorAffineFunction([MOI.VectorAffineTerm(1, MOI.ScalarAffineTerm(1.0, x))], [-2.0])
# max x
Expand Down
1 change: 1 addition & 0 deletions src/Test/contconic.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Continuous conic problems
using Compat.LinearAlgebra # for dot

function _lin1test(model::MOI.ModelLike, config::TestConfig, vecofvars::Bool)
atol = config.atol
Expand Down
2 changes: 1 addition & 1 deletion src/Test/modellike.jl
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ function copytest(dest::MOI.ModelLike, src::MOI.ModelLike)
@test MOI.get(dest, MOI.ConstraintSet(), dict[csv]) == MOI.EqualTo(2.)
@test !MOI.canget(dest, MOI.ConstraintName(), typeof(cvv)) || MOI.get(dest, MOI.ConstraintName(), cvv) == ""
@test MOI.canget(dest, MOI.ConstraintFunction(), typeof(dict[cvv]))
@test MOI.get(dest, MOI.ConstraintFunction(), dict[cvv]) == MOI.VectorOfVariables(getindex.(dict, v))
@test MOI.get(dest, MOI.ConstraintFunction(), dict[cvv]) == MOI.VectorOfVariables(getindex.(Ref(dict), v))
@test MOI.canget(dest, MOI.ConstraintSet(), typeof(dict[cvv]))
@test MOI.get(dest, MOI.ConstraintSet(), dict[cvv]) == MOI.Nonnegatives(3)
@test !MOI.canget(dest, MOI.ConstraintName(), typeof(csa)) || MOI.get(dest, MOI.ConstraintName(), csa) == ""
Expand Down
8 changes: 5 additions & 3 deletions src/Utilities/cachingoptimizer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ function MOI.get(m::CachingOptimizer, attr::Union{MOI.AbstractVariableAttribute,
if MOI.canget(m.model_cache, attr, eltype(indices))
return MOI.get(m.model_cache, attr, indices)
elseif m.state == AttachedOptimizer && MOI.canget(m.optimizer, attr, eltype(indices))
return attribute_value_map.(m.optimizer_to_model_map,MOI.get(m.optimizer, attr, getindex.(m.model_to_optimizer_map,indices)))
return attribute_value_map.(Ref(m.optimizer_to_model_map),MOI.get(m.optimizer, attr, getindex.(Ref(m.model_to_optimizer_map),indices)))
end
error("Attribute $attr not accessible")
end
Expand Down Expand Up @@ -478,10 +478,12 @@ function MOI.set!(m::CachingOptimizer, attr::AttributeFromOptimizer{T}, v) where
return MOI.set!(m.optimizer, attr.attr, attribute_value_map(m.model_to_optimizer_map,v))
end

# Map vector of indices into vector of indices or one index into one index
map_indices_to_optimizer(m::CachingOptimizer, idx::MOI.Index) = m.model_to_optimizer_map[idx]
map_indices_to_optimizer(m::CachingOptimizer, indices::Vector{<:MOI.Index}) = getindex.(Ref(m.model_to_optimizer_map), indices)
function MOI.set!(m::CachingOptimizer, attr::AttributeFromOptimizer{T}, idx, v) where {T <: Union{MOI.AbstractVariableAttribute,MOI.AbstractConstraintAttribute}}
@assert m.state == AttachedOptimizer
# TODO: getindex. causes this to return a vector of results for scalar idx
return MOI.set!(m.optimizer, attr.attr, getindex.(m.model_to_optimizer_map,idx), attribute_value_map(m.model_to_optimizer_map,v))
return MOI.set!(m.optimizer, attr.attr, map_indices_to_optimizer(m, idx), attribute_value_map(m.model_to_optimizer_map,v))
end

function MOI.canset(m::CachingOptimizer, attr::AttributeFromModelCache{T}) where {T <: MOI.AbstractModelAttribute}
Expand Down
1 change: 0 additions & 1 deletion src/Utilities/mockoptimizer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ end
MOI.get(mock::MockOptimizer, attr::MOI.AbstractConstraintAttribute, idx::MOI.ConstraintIndex) = MOI.get(mock.inner_model, attr, xor_index(idx))
MOI.get(mock::MockOptimizer, ::MOI.ConstraintDual, idx::MOI.ConstraintIndex) = mock.condual[xor_index(idx)]
MOI.get(mock::MockOptimizer, ::MockConstraintAttribute, idx::MOI.ConstraintIndex) = mock.conattribute[xor_index(idx)]
MOI.get(mock::MockOptimizer, attr::MOI.AnyAttribute, idx::Vector{<:MOI.Index}) = MOI.get.(mock, attr, idx)

function MOI.empty!(mock::MockOptimizer)
MOI.empty!(mock.inner_model)
Expand Down
2 changes: 1 addition & 1 deletion src/Utilities/parser.jl
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ end

# Used for Vector{Symbol}, Vector{ParsedScalarAffineTerm}, Vector{ParsedVectorAffineTerm},
# Vector{ParsedScalarQuadraticTerm} and Vector{ParsedVectorQuadraticTerm}
parsedtoMOI(model, s::Vector) = parsedtoMOI.(model, s)
parsedtoMOI(model, s::Vector) = parsedtoMOI.(Ref(model), s)

parsedtoMOI(model, s::Union{Float64, Int64}) = s

Expand Down
4 changes: 2 additions & 2 deletions src/attributes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ function get end
# We want to avoid being too specific in the type arguments to avoid method ambiguity.
# For model, get(::ModelLike, ::AbstractVariableAttribute, ::Vector{VariableIndex}) would not allow
# to define get(::SomeModel, ::AnyAttribute, ::Vector)
get(model::ModelLike, attr::AnyAttribute, idxs::Vector) = get.(model, attr, idxs)
get(model::ModelLike, attr::AnyAttribute, idxs::Vector) = get.(Ref(model), Ref(attr), idxs)

function get(model::ModelLike, attr::AnyAttribute, args...)
throw(ArgumentError("ModelLike of type $(typeof(model)) does not support accessing the attribute $attr"))
Expand Down Expand Up @@ -228,7 +228,7 @@ Assign a value respectively to the attribute `attr` of each constraint in the co
"""
function set! end
# See note with get
set!(model::ModelLike, attr::Union{AbstractVariableAttribute, AbstractConstraintAttribute}, idxs::Vector, vector_of_values::Vector) = set!.(model, attr, idxs, vector_of_values)
set!(model::ModelLike, attr::Union{AbstractVariableAttribute, AbstractConstraintAttribute}, idxs::Vector, vector_of_values::Vector) = set!.(Ref(model), Ref(attr), idxs, vector_of_values)

function set!(model::ModelLike, attr::AnyAttribute, args...)
throw(ArgumentError("ModelLike of type $(typeof(model)) does not support setting the attribute $attr"))
Expand Down
2 changes: 1 addition & 1 deletion src/constraints.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ This call is equivalent to `addconstraint!.(model, funcs, sets)` but may be more
function addconstraints! end

# default fallback
addconstraints!(model::ModelLike, funcs, sets) = addconstraint!.(model, funcs, sets)
addconstraints!(model::ModelLike, funcs, sets) = addconstraint!.(Ref(model), funcs, sets)

"""
## Modify Function
Expand Down
2 changes: 1 addition & 1 deletion src/functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ _pair(t::ScalarAffineTerm) = t.variable_index => t.coefficient
_canonicalize(v1::VariableIndex, v2::VariableIndex) = VariableIndex.(extrema((v1.value, v2.value)))
_pair(t::ScalarQuadraticTerm) = _canonicalize(t.variable_index_1, t.variable_index_2) => t.coefficient

_dicts(f::Union{ScalarAffineFunction, VectorAffineFunction}) = sum_dict(_pair.(f.terms))
_dicts(f::Union{ScalarAffineFunction, VectorAffineFunction}) = (sum_dict(_pair.(f.terms)),)

_dicts(f::Union{ScalarQuadraticFunction, VectorQuadraticFunction}) = (sum_dict(_pair.(f.affine_terms)),
sum_dict(_pair.(f.quadratic_terms)))
Expand Down
2 changes: 1 addition & 1 deletion src/indextypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Base.delete!(model::ModelLike, index::Index) = throw(MethodError(Base.delete!, (

Return a `Bool` indicating whether all the objects referred to by `indices` can be removed from the model `model`.
"""
candelete(model::ModelLike, indices::Vector{<:Index}) = all(candelete.(model, indices))
candelete(model::ModelLike, indices::Vector{<:Index}) = all(candelete.(Ref(model), indices))

"""
delete!{R}(model::ModelLike, indices::Vector{R<:Index})
Expand Down
10 changes: 5 additions & 5 deletions test/bridge.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ function test_delete_bridge(m::MOIB.AbstractBridgeOptimizer, ci::MOI.ConstraintI
end

@testset "BridgeOptimizer" begin
const mock = MOIU.MockOptimizer(SimpleModel{Float64}())
const bridgedmock = MOIB.SplitInterval{Float64}(mock)
mock = MOIU.MockOptimizer(SimpleModel{Float64}())
bridgedmock = MOIB.SplitInterval{Float64}(mock)

@testset "Name test" begin
MOIT.nametest(bridgedmock)
Expand All @@ -47,7 +47,7 @@ end
end

@testset "Custom test" begin
const model = MOIB.SplitInterval{Int}(SimpleModel{Int}())
model = MOIB.SplitInterval{Int}(SimpleModel{Int}())
@test !MOIB.supportsbridgingconstraint(model, MOI.VectorAffineFunction{Float64}, MOI.Interval{Float64})

x, y = MOI.addvariables!(model, 2)
Expand Down Expand Up @@ -95,8 +95,8 @@ end
MOIU.@model NoRSOCModel () (EqualTo, GreaterThan, LessThan, Interval) (Zeros, Nonnegatives, Nonpositives, SecondOrderCone, ExponentialCone, PositiveSemidefiniteConeTriangle) () (SingleVariable,) (ScalarAffineFunction,) (VectorOfVariables,) (VectorAffineFunction,)

@testset "LazyBridgeOptimizer" begin
const mock = MOIU.MockOptimizer(NoRSOCModel{Float64}())
const bridgedmock = MOIB.LazyBridgeOptimizer(mock, Model{Float64}())
mock = MOIU.MockOptimizer(NoRSOCModel{Float64}())
bridgedmock = MOIB.LazyBridgeOptimizer(mock, Model{Float64}())
MOIB.addbridge!(bridgedmock, MOIB.SplitIntervalBridge{Float64})
MOIB.addbridge!(bridgedmock, MOIB.RSOCtoPSDCBridge{Float64})
MOIB.addbridge!(bridgedmock, MOIB.SOCtoPSDCBridge{Float64})
Expand Down