From df4aab7d6e221d054e26f80baa07b9bc758289de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathieu=20Besan=C3=A7on?= Date: Fri, 19 Apr 2019 12:11:44 +0200 Subject: [PATCH 1/6] added Project.toml for 1.0 compat --- Project.toml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 Project.toml diff --git a/Project.toml b/Project.toml new file mode 100644 index 0000000000..caa577d141 --- /dev/null +++ b/Project.toml @@ -0,0 +1,15 @@ +name = "MathOptInterface" +uuid = "b8f27783-ece8-5eb3-8dc8-9495eed66fee" +authors = ["JuliaOpt"] +version = "0.9.0" + +[deps] +BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf" +LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" +SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" + +[extras] +Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" + +[targets] +test = ["Test"] From 91b757e5f3a4c85636537dc43a68251773ea8a96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathieu=20Besan=C3=A7on?= Date: Fri, 19 Apr 2019 12:11:52 +0200 Subject: [PATCH 2/6] remove 06 deps --- .gitignore | 1 + .travis.yml | 5 ++--- REQUIRE | 3 +-- appveyor.yml | 1 - src/Bridges/Bridges.jl | 2 -- src/Bridges/intervalbridge.jl | 6 +++--- src/Bridges/lazybridgeoptimizer.jl | 2 +- src/Bridges/quadtosocbridge.jl | 4 ++-- src/Bridges/squarepsdbridge.jl | 2 +- src/Test/Test.jl | 3 +-- src/Test/contconic.jl | 2 +- src/Utilities/Utilities.jl | 3 +-- src/Utilities/copy.jl | 2 +- src/Utilities/functions.jl | 5 ++--- src/Utilities/parser.jl | 6 +++--- test/Utilities/functions.jl | 3 +-- test/bridge.jl | 3 +-- test/functions.jl | 3 +-- test/hygiene.jl | 2 +- test/runtests.jl | 3 +-- 20 files changed, 25 insertions(+), 36 deletions(-) diff --git a/.gitignore b/.gitignore index 6b2ea0ab40..20f12aaf02 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ *.jl.mem docs/build/ docs/site/ +Manifest.toml diff --git a/.travis.yml b/.travis.yml index 3e7816b365..c820eb2bdd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,6 @@ os: - linux # - osx julia: - - 0.6 - 0.7 - 1.0 - 1.1 @@ -23,7 +22,7 @@ notifications: on_start: never # options: [always|never|change] default: always after_success: - - julia -e 'if VERSION < v"0.7-"; cd(Pkg.dir("MathOptInterface")); else; import Pkg; end; Pkg.add("Coverage"); using Coverage; Codecov.submit(process_folder())' + - julia -e 'import Pkg; Pkg.add("Coverage"); using Coverage; Codecov.submit(process_folder())' jobs: include: @@ -31,7 +30,7 @@ jobs: julia: 1.0 os: linux script: - - julia --project=docs/ -e 'using Pkg; Pkg.instantiate(); + - julia --project=docs/ -e 'import Pkg; Pkg.instantiate(); Pkg.develop(PackageSpec(path=pwd()))' - julia --project=docs/ docs/make.jl after_success: skip diff --git a/REQUIRE b/REQUIRE index 23ed20ab7b..859ad4616a 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1,2 +1 @@ -julia 0.6 -Compat 0.68 +julia 0.7 diff --git a/appveyor.yml b/appveyor.yml index 8a629ea8ba..f8af16207d 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,6 +1,5 @@ environment: matrix: -# - julia_version: 0.6 # Disabled to speed up CI, Julia v0.6 and v0.7 are still # - julia_version: 0.7 # tested on Linux with Travis - julia_version: 1.0 diff --git a/src/Bridges/Bridges.jl b/src/Bridges/Bridges.jl index e95284f73a..a52a8b57f1 100644 --- a/src/Bridges/Bridges.jl +++ b/src/Bridges/Bridges.jl @@ -1,7 +1,5 @@ module Bridges -using Compat - using MathOptInterface const MOI = MathOptInterface const MOIU = MOI.Utilities diff --git a/src/Bridges/intervalbridge.jl b/src/Bridges/intervalbridge.jl index 33f2bdbb26..6e96c37330 100644 --- a/src/Bridges/intervalbridge.jl +++ b/src/Bridges/intervalbridge.jl @@ -52,11 +52,11 @@ function MOI.get(model::MOI.ModelLike, ::MOI.ConstraintBasisStatus, c::SplitInte lower_stat = MOI.get(model, MOI.ConstraintBasisStatus(), c.lower) upper_stat = MOI.get(model, MOI.ConstraintBasisStatus(), c.upper) if lower_stat == MOI.NONBASIC_AT_LOWER - Compat.@warn("GreaterThan constraints should not have basis status:" * + @warn("GreaterThan constraints should not have basis status:" * " NONBASIC_AT_LOWER, instead use NONBASIC.") end if upper_stat == MOI.NONBASIC_AT_UPPER - Compat.@warn("LessThan constraints should not have basis status:" * + @warn("LessThan constraints should not have basis status:" * " NONBASIC_AT_UPPER, instead use NONBASIC.") end if lower_stat == MOI.NONBASIC @@ -66,7 +66,7 @@ function MOI.get(model::MOI.ModelLike, ::MOI.ConstraintBasisStatus, c::SplitInte return MOI.NONBASIC_AT_UPPER end if lower_stat != upper_stat - Compat.@warn("Basis status of lower (`$lower_stat`) and upper (`$upper_stat`) constraint are inconsistent," * + @warn("Basis status of lower (`$lower_stat`) and upper (`$upper_stat`) constraint are inconsistent," * " both should be basic or super basic.") end return lower_stat diff --git a/src/Bridges/lazybridgeoptimizer.jl b/src/Bridges/lazybridgeoptimizer.jl index 595e7fbeab..bd4c6b2834 100644 --- a/src/Bridges/lazybridgeoptimizer.jl +++ b/src/Bridges/lazybridgeoptimizer.jl @@ -45,7 +45,7 @@ function update_dist!(b::LazyBridgeOptimizer, constraints) for (F, S) in constraints if MOI.supports_constraint(BT, F, S) && all(C -> supports_constraint_no_update(b, C[1], C[2]), added_constraint_types(BT, F, S)) # Number of bridges needed using BT - dist = 1 + Compat.mapreduce( + dist = 1 + mapreduce( C -> _dist(b, C[1], C[2]), +, added_constraint_types(BT, F, S), init = 0) # Is it better that what can currently be done ? diff --git a/src/Bridges/quadtosocbridge.jl b/src/Bridges/quadtosocbridge.jl index 2e0390ce41..ca884d3d8b 100644 --- a/src/Bridges/quadtosocbridge.jl +++ b/src/Bridges/quadtosocbridge.jl @@ -1,4 +1,4 @@ -using Compat.LinearAlgebra, Compat.SparseArrays +using LinearAlgebra, SparseArrays """ QuadtoSOCBridge{T} @@ -70,7 +70,7 @@ function QuadtoSOCBridge{T}(model, func::MOI.ScalarQuadraticFunction{T}, end Q, index_to_variable_map = matrix_from_quadratic_terms(func.quadratic_terms) if !less_than - Compat.rmul!(Q, -1) + rmul!(Q, -1) end # We have L × L' ≈ Q[p, p] L, p = try diff --git a/src/Bridges/squarepsdbridge.jl b/src/Bridges/squarepsdbridge.jl index 9cf9e845e4..d8145ba9dc 100644 --- a/src/Bridges/squarepsdbridge.jl +++ b/src/Bridges/squarepsdbridge.jl @@ -95,7 +95,7 @@ function SquarePSDBridge{T, F, G}(model::MOI.ModelLike, f::F, # functions at entries (i, j) and (j, i) are almost identical if !MOIU.isapprox_zero(diff, 1e-10) if MOIU.isapprox_zero(diff, 1e-8) - Compat.@warn "The entries ($i, $j) and ($j, $i) of the" * + @warn "The entries ($i, $j) and ($j, $i) of the" * " positive semidefinite constraint are almost" * " identical but a constraint is added to ensure their" * " equality because the largest difference between the" * diff --git a/src/Test/Test.jl b/src/Test/Test.jl index 4ab759683f..b88ad44263 100644 --- a/src/Test/Test.jl +++ b/src/Test/Test.jl @@ -4,8 +4,7 @@ using MathOptInterface const MOI = MathOptInterface const MOIU = MOI.Utilities -using Compat -using Compat.Test +using Test include("config.jl") diff --git a/src/Test/contconic.jl b/src/Test/contconic.jl index 3bbaf3f989..7a8d7e2033 100644 --- a/src/Test/contconic.jl +++ b/src/Test/contconic.jl @@ -1,5 +1,5 @@ # Continuous conic problems -using Compat.LinearAlgebra # for dot +using LinearAlgebra # for dot function _lin1test(model::MOI.ModelLike, config::TestConfig, vecofvars::Bool) atol = config.atol diff --git a/src/Utilities/Utilities.jl b/src/Utilities/Utilities.jl index 4bc5699953..b7de6876f9 100644 --- a/src/Utilities/Utilities.jl +++ b/src/Utilities/Utilities.jl @@ -1,7 +1,6 @@ module Utilities -using Compat # For firstindex, lastindex, Nothing and `@warn` -using Compat.LinearAlgebra # For dot +using LinearAlgebra # For dot using MathOptInterface const MOI = MathOptInterface diff --git a/src/Utilities/copy.jl b/src/Utilities/copy.jl index d83dcd682a..506f506174 100644 --- a/src/Utilities/copy.jl +++ b/src/Utilities/copy.jl @@ -130,7 +130,7 @@ function _pass_attributes(dest::MOI.ModelLike, src::MOI.ModelLike, # As starting values are simply *hints* for the optimization, not # supporting them gives a warning, not an error if !MOI.supports(dest, attr, supports_args...) - Compat.@warn("$attr is not supported by $(typeof(dest)). This ", + @warn("$attr is not supported by $(typeof(dest)). This ", "information will be discarded.") continue end diff --git a/src/Utilities/functions.jl b/src/Utilities/functions.jl index 2a7c1c2761..33eb37427f 100644 --- a/src/Utilities/functions.jl +++ b/src/Utilities/functions.jl @@ -1,5 +1,4 @@ -using Compat -using Compat.Test +using Test """ evalvariables(varval::Function, f::AbstractFunction) @@ -132,7 +131,7 @@ end Base.eltype(it::ScalarFunctionIterator{VVF}) = SVF Base.eltype(it::ScalarFunctionIterator{VAF{T}}) where T = SAF{T} Base.eltype(it::ScalarFunctionIterator{VQF{T}}) where T = SQF{T} -Compat.lastindex(it::ScalarFunctionIterator) = length(it) +Base.lastindex(it::ScalarFunctionIterator) = length(it) # Define getindex for Vector functions diff --git a/src/Utilities/parser.jl b/src/Utilities/parser.jl index 147e3860c8..6aa962c0ea 100644 --- a/src/Utilities/parser.jl +++ b/src/Utilities/parser.jl @@ -204,14 +204,14 @@ parsedtoMOI(model, s::Union{Float64, Int64}) = s for typename in [:ParsedScalarAffineTerm,:ParsedScalarAffineFunction,:ParsedVectorAffineTerm,:ParsedVectorAffineFunction, :ParsedScalarQuadraticTerm,:ParsedScalarQuadraticFunction,:ParsedVectorQuadraticTerm,:ParsedVectorQuadraticFunction, :ParsedSingleVariable,:ParsedVectorOfVariables] - moiname = Compat.Meta.parse(replace(string(typename), "Parsed" => "MOI.")) + moiname = Meta.parse(replace(string(typename), "Parsed" => "MOI.")) fields = fieldnames(eval(typename)) constructor = Expr(:call, moiname, [Expr(:call,:parsedtoMOI,:model,Expr(:.,:f,Base.Meta.quot(field))) for field in fields]...) @eval parsedtoMOI(model, f::$typename) = $constructor end function loadfromstring!(model, s) - parsedlines = filter(ex -> ex != nothing, Compat.Meta.parse.(split(s,"\n"))) + parsedlines = filter(ex -> ex != nothing, Meta.parse.(split(s,"\n"))) for line in parsedlines label, ex = separatelabel(line) @@ -240,7 +240,7 @@ function loadfromstring!(model, s) f = parsedtoMOI(model, parsefunction(ex.args[2])) if ex.args[1] == :in # Could be safer here - set = Compat.Core.eval(MOI, ex.args[3]) + set = Core.eval(MOI, ex.args[3]) elseif ex.args[1] == :<= set = MOI.LessThan(ex.args[3]) elseif ex.args[1] == :>= diff --git a/test/Utilities/functions.jl b/test/Utilities/functions.jl index d80ee230e0..0e91cca91a 100644 --- a/test/Utilities/functions.jl +++ b/test/Utilities/functions.jl @@ -1,5 +1,4 @@ -using Compat -using Compat.Test +using Test using MathOptInterface const MOI = MathOptInterface const MOIU = MOI.Utilities diff --git a/test/bridge.jl b/test/bridge.jl index 4b300c8d08..d447607d45 100644 --- a/test/bridge.jl +++ b/test/bridge.jl @@ -1,5 +1,4 @@ -using Compat -using Compat.Test +using Test using MathOptInterface const MOI = MathOptInterface diff --git a/test/functions.jl b/test/functions.jl index 0c62a0c1d5..03c404b555 100644 --- a/test/functions.jl +++ b/test/functions.jl @@ -1,5 +1,4 @@ -using Compat -using Compat.Test +using Test using MathOptInterface const MOI = MathOptInterface diff --git a/test/hygiene.jl b/test/hygiene.jl index 52b1d067fb..2f89b7a356 100644 --- a/test/hygiene.jl +++ b/test/hygiene.jl @@ -1,6 +1,6 @@ module Hygiene -using Compat, Compat.Test +using Test import MathOptInterface const MOI = MathOptInterface diff --git a/test/runtests.jl b/test/runtests.jl index f186b1d130..fc6d780c86 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -4,8 +4,7 @@ const MOIT = MathOptInterface.Test const MOIU = MathOptInterface.Utilities const MOIB = MathOptInterface.Bridges -using Compat -using Compat.Test +using Test # Tests for solvers are located in MOI.Test. From cf0421d24054112e1ea103e11303c41cfe9f397d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathieu=20Besan=C3=A7on?= Date: Fri, 19 Apr 2019 12:17:38 +0200 Subject: [PATCH 3/6] using Unicode --- .travis.yml | 3 +-- Project.toml | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index c820eb2bdd..572a384a70 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,7 +30,6 @@ jobs: julia: 1.0 os: linux script: - - julia --project=docs/ -e 'import Pkg; Pkg.instantiate(); - Pkg.develop(PackageSpec(path=pwd()))' + - julia --project=docs/ -e 'import Pkg; Pkg.instantiate(); Pkg.develop(PackageSpec(path=pwd()))' - julia --project=docs/ docs/make.jl after_success: skip diff --git a/Project.toml b/Project.toml index caa577d141..6a460e779e 100644 --- a/Project.toml +++ b/Project.toml @@ -7,6 +7,7 @@ version = "0.9.0" BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" +Unicode = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5" [extras] Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" From ff6876d09eb19ab9024ab93f95ad43f35b4db733 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathieu=20Besan=C3=A7on?= Date: Fri, 19 Apr 2019 12:32:34 +0200 Subject: [PATCH 4/6] remove version checks --- src/Bridges/quadtosocbridge.jl | 9 ++--- src/MathOptInterface.jl | 11 +++--- src/Test/modellike.jl | 32 +++++------------ src/Utilities/functions.jl | 33 ++++++------------ src/Utilities/model.jl | 5 ++- src/Utilities/parser.jl | 56 +++++++++--------------------- src/attributes.jl | 8 ++--- src/functions.jl | 22 ++---------- test/Utilities/cachingoptimizer.jl | 53 ++++++++++++---------------- test/Utilities/mockoptimizer.jl | 12 ++----- test/attributes.jl | 9 ++--- test/bridge.jl | 32 ++++------------- 12 files changed, 84 insertions(+), 198 deletions(-) diff --git a/src/Bridges/quadtosocbridge.jl b/src/Bridges/quadtosocbridge.jl index ca884d3d8b..85ac65b1c1 100644 --- a/src/Bridges/quadtosocbridge.jl +++ b/src/Bridges/quadtosocbridge.jl @@ -74,13 +74,8 @@ function QuadtoSOCBridge{T}(model, func::MOI.ScalarQuadraticFunction{T}, end # We have L × L' ≈ Q[p, p] L, p = try - @static if VERSION >= v"0.7-" - F = cholesky(Symmetric(Q)) - sparse(F.L), F.p - else - F = cholfact(Symmetric(Q)) - sparse(F[:L]), F[:p] - end + F = cholesky(Symmetric(Q)) + sparse(F.L), F.p catch err if err isa PosDefException error("The optimizer supports second-order cone constraints and", diff --git a/src/MathOptInterface.jl b/src/MathOptInterface.jl index 04c9b357f5..e4838c17d5 100644 --- a/src/MathOptInterface.jl +++ b/src/MathOptInterface.jl @@ -1,4 +1,3 @@ -VERSION < v"0.7.0-beta2.199" && __precompile__() module MathOptInterface """ @@ -8,11 +7,11 @@ Abstract supertype for objects that implement the "Model" interface for defining an optimization problem. """ abstract type ModelLike end -@static if VERSION >= v"0.7-" - # This allows to use `ModelLike`s in broadcast calls without the need to - # embed it in a `Ref` - Base.broadcastable(model::ModelLike) = Ref(model) -end + +# This allows to use `ModelLike`s in broadcast calls without the need to +# embed it in a `Ref` +Base.broadcastable(model::ModelLike) = Ref(model) + """ AbstractOptimizer diff --git a/src/Test/modellike.jl b/src/Test/modellike.jl index 209dbb5c5a..6709a60d94 100644 --- a/src/Test/modellike.jl +++ b/src/Test/modellike.jl @@ -391,33 +391,17 @@ function scalar_function_constant_not_zero(model::MOI.ModelLike) @testset "Constraint with nonzero function constant" begin err = MOI.ScalarFunctionConstantNotZero{Float64, MOI.ScalarAffineFunction{Float64}, MOI.EqualTo{Float64}}(1.0) - if VERSION < v"0.7-" - @test_throws typeof(err) begin - MOI.add_constraint(model, - MOI.ScalarAffineFunction(MOI.ScalarAffineTerm{Float64}[], 1.0), - MOI.EqualTo(2.0)) - end - else - @test_throws err begin - MOI.add_constraint(model, - MOI.ScalarAffineFunction(MOI.ScalarAffineTerm{Float64}[], 1.0), - MOI.EqualTo(2.0)) - end + @test_throws err begin + MOI.add_constraint(model, + MOI.ScalarAffineFunction(MOI.ScalarAffineTerm{Float64}[], 1.0), + MOI.EqualTo(2.0)) end err = MOI.ScalarFunctionConstantNotZero{Float64, MOI.ScalarAffineFunction{Float64}, MOI.GreaterThan{Float64}}(2.0) - if VERSION < v"0.7-" - @test_throws typeof(err) begin - MOI.add_constraint(model, - MOI.ScalarAffineFunction(MOI.ScalarAffineTerm{Float64}[], 2.0), - MOI.GreaterThan(1.0)) - end - else - @test_throws err begin - MOI.add_constraint(model, - MOI.ScalarAffineFunction(MOI.ScalarAffineTerm{Float64}[], 2.0), - MOI.GreaterThan(1.0)) - end + @test_throws err begin + MOI.add_constraint(model, + MOI.ScalarAffineFunction(MOI.ScalarAffineTerm{Float64}[], 2.0), + MOI.GreaterThan(1.0)) end end end diff --git a/src/Utilities/functions.jl b/src/Utilities/functions.jl index 33eb37427f..de6bfed72f 100644 --- a/src/Utilities/functions.jl +++ b/src/Utilities/functions.jl @@ -9,11 +9,7 @@ function evalvariables end evalvariables(varval::Function, f::SVF) = varval(f.variable) evalvariables(varval::Function, f::VVF) = varval.(f.variables) function evalvariables(varval::Function, f::SAF) - @static if VERSION >= v"0.7-" - return mapreduce(t->evalterm(varval, t), +, f.terms, init=f.constant) - else - return mapreduce(t->evalterm(varval, t), +, f.constant, f.terms) - end + return mapreduce(t->evalterm(varval, t), +, f.terms, init=f.constant) end function evalvariables(varval::Function, f::VAF) out = copy(f.constants) @@ -24,13 +20,8 @@ function evalvariables(varval::Function, f::VAF) end function evalvariables(varval::Function, f::SQF) init = zero(f.constant) - @static if VERSION >= v"0.7-" - lin = mapreduce(t->evalterm(varval, t), +, f.affine_terms, init=init) - quad = mapreduce(t->evalterm(varval, t), +, f.quadratic_terms, init=init) - else - lin = mapreduce(t->evalterm(varval, t), +, init, f.affine_terms) - quad = mapreduce(t->evalterm(varval, t), +, init, f.quadratic_terms) - end + lin = mapreduce(t->evalterm(varval, t), +, f.affine_terms, init=init) + quad = mapreduce(t->evalterm(varval, t), +, f.quadratic_terms, init=init) return lin + quad + f.constant end function evalvariables(varval::Function, f::VQF) @@ -112,19 +103,15 @@ struct ScalarFunctionIterator{F<:MOI.AbstractVectorFunction} f::F end eachscalar(f::MOI.AbstractVectorFunction) = ScalarFunctionIterator(f) -@static if VERSION >= v"0.7-" - function Base.iterate(it::ScalarFunctionIterator, state = 1) - if state > length(it) - return nothing - else - return (it[state], state + 1) - end + +function Base.iterate(it::ScalarFunctionIterator, state = 1) + if state > length(it) + return nothing + else + return (it[state], state + 1) end -else - Base.start(it::ScalarFunctionIterator) = 1 - Base.done(it::ScalarFunctionIterator, state) = state > length(it) - Base.next(it::ScalarFunctionIterator, state) = (it[state], state+1) end + function Base.length(it::ScalarFunctionIterator{<:MOI.AbstractVectorFunction}) return MOI.output_dimension(it.f) end diff --git a/src/Utilities/model.jl b/src/Utilities/model.jl index fee94e930d..567236e5de 100644 --- a/src/Utilities/model.jl +++ b/src/Utilities/model.jl @@ -491,9 +491,8 @@ function _typedfun(s::SymbolFun) end # Base.lowercase is moved to Unicode.lowercase in Julia v0.7 -if VERSION >= v"0.7.0-DEV.2813" - using Unicode -end +using Unicode + _field(s::SymbolFS) = Symbol(replace(lowercase(string(s.s)), "." => "_")) _getC(s::SymbolSet) = :(ConstraintEntry{F, $(_typedset(s))}) diff --git a/src/Utilities/parser.jl b/src/Utilities/parser.jl index 6aa962c0ea..e06c9c95f6 100644 --- a/src/Utilities/parser.jl +++ b/src/Utilities/parser.jl @@ -148,45 +148,23 @@ function parsefunction(ex) end # see tests for examples -if VERSION > v"0.7-" - function separatelabel(ex) - if isexpr(ex, :call) && ex.args[1] == :(:) - return ex.args[2], ex.args[3] - elseif isexpr(ex, :tuple) - ex = copy(ex) - @assert isexpr(ex.args[1], :call) && ex.args[1].args[1] == :(:) - label = ex.args[1].args[2] - ex.args[1] = ex.args[1].args[3] - return label, ex - elseif isexpr(ex, :call) - ex = copy(ex) - @assert isexpr(ex.args[2], :call) && ex.args[2].args[1] == :(:) - label = ex.args[2].args[2] - ex.args[2] = ex.args[2].args[3] - return label, ex - else - error("Unrecognized expression $ex") - end - end -else - function separatelabel(ex) - if isexpr(ex, :(:)) - return ex.args[1], ex.args[2] - elseif isexpr(ex, :tuple) - ex = copy(ex) - @assert isexpr(ex.args[1], :(:)) - label = ex.args[1].args[1] - ex.args[1] = ex.args[1].args[2] - return label, ex - elseif isexpr(ex, :call) - ex = copy(ex) - @assert isexpr(ex.args[2], :(:)) - label = ex.args[2].args[1] - ex.args[2] = ex.args[2].args[2] - return label, ex - else - error("Unrecognized expression $ex") - end +function separatelabel(ex) + if isexpr(ex, :call) && ex.args[1] == :(:) + return ex.args[2], ex.args[3] + elseif isexpr(ex, :tuple) + ex = copy(ex) + @assert isexpr(ex.args[1], :call) && ex.args[1].args[1] == :(:) + label = ex.args[1].args[2] + ex.args[1] = ex.args[1].args[3] + return label, ex + elseif isexpr(ex, :call) + ex = copy(ex) + @assert isexpr(ex.args[2], :call) && ex.args[2].args[1] == :(:) + label = ex.args[2].args[2] + ex.args[2] = ex.args[2].args[3] + return label, ex + else + error("Unrecognized expression $ex") end end diff --git a/src/attributes.jl b/src/attributes.jl index 84a220e760..0fdd7aa9c6 100644 --- a/src/attributes.jl +++ b/src/attributes.jl @@ -36,11 +36,9 @@ abstract type AbstractConstraintAttribute end const AnyAttribute = Union{AbstractOptimizerAttribute, AbstractModelAttribute, AbstractVariableAttribute, AbstractConstraintAttribute} -@static if VERSION >= v"0.7-" - # This allows to use attributes in broadcast calls without the need to - # embed it in a `Ref` - Base.broadcastable(attribute::AnyAttribute) = Ref(attribute) -end +# This allows to use attributes in broadcast calls without the need to +# embed it in a `Ref` +Base.broadcastable(attribute::AnyAttribute) = Ref(attribute) """ struct UnsupportedAttribute{AttrType} <: UnsupportedError diff --git a/src/functions.jl b/src/functions.jl index 8c39de9998..a827ed329d 100644 --- a/src/functions.jl +++ b/src/functions.jl @@ -23,11 +23,7 @@ Abstract supertype for scalar-valued function objects. abstract type AbstractScalarFunction <: AbstractFunction end output_dimension(::AbstractScalarFunction) = 1 -@static if VERSION >= v"0.7-" - # This allows to use `AbstractScalarFunction`s in broadcast calls without - # the need to embed it in a `Ref` - Base.broadcastable(f::AbstractScalarFunction) = Ref(f) -end +Base.broadcastable(f::AbstractScalarFunction) = Ref(f) """ AbstractVectorFunction @@ -396,19 +392,11 @@ function VectorAffineFunction{T}(f::VectorOfVariables) where T return VectorAffineFunction(map(i -> VectorAffineTerm(i, ScalarAffineTerm(one(T), f.variables[i])), 1:n), zeros(T, n)) end -if VERSION < v"0.7-" - isone(x) = x == one(x) -end - # Conversion between scalar functions # Conversion to SingleVariable function Base.convert(::Type{SingleVariable}, f::ScalarAffineFunction) if !iszero(f.constant) || !isone(length(f.terms)) || !isone(f.terms[1].coefficient) - if VERSION >= v"0.7-" - throw(InexactError(:convert, SingleVariable, f)) - else - throw(InexactError()) - end + throw(InexactError(:convert, SingleVariable, f)) end return SingleVariable(f.terms[1].variable_index) end @@ -425,11 +413,7 @@ end function Base.convert(::Type{ScalarAffineFunction{T}}, f::ScalarQuadraticFunction{T}) where T if !Base.isempty(f.quadratic_terms) - if VERSION >= v"0.7-" - throw(InexactError(:convert, ScalarAffineFunction{T}, f)) - else - throw(InexactError()) - end + throw(InexactError(:convert, ScalarAffineFunction{T}, f)) end return ScalarAffineFunction{T}(f.affine_terms, f.constant) end diff --git a/test/Utilities/cachingoptimizer.jl b/test/Utilities/cachingoptimizer.jl index de2edc9231..44dcf6f2f9 100644 --- a/test/Utilities/cachingoptimizer.jl +++ b/test/Utilities/cachingoptimizer.jl @@ -13,36 +13,29 @@ @test MOI.get(model, MOI.PrimalStatus()) == MOI.NO_SOLUTION @test MOI.get(model, MOI.DualStatus()) == MOI.NO_SOLUTION x = MOI.add_variables(model, 2) - if VERSION < v"0.7" - @test_throws Exception MOI.get(model, MOI.VariablePrimal(), x[1]) - @test_throws Exception MOI.get(model, MOI.VariablePrimal(), x) - @test_throws Exception MOI.get(model, MOI.SolverName()) - @test_throws Exception MOI.get(model, MOI.ResultCount()) - else - attr = MOI.VariablePrimal() - exception = ErrorException( - "Cannot query $(attr) from caching optimizer because no optimizer" * - " is attached.") - @test_throws exception MOI.get(model, MOI.VariablePrimal(), x[1]) - @test_throws exception MOI.get(model, MOI.VariablePrimal(), x) - - attr = MOI.SolverName() - exception = ErrorException( - "Cannot query $(attr) from caching optimizer because no optimizer" * - " is attached.") - @test_throws exception MOI.get(model, attr) - attr = MOI.Silent() - exception = ErrorException( - "Cannot query $(attr) from caching optimizer because no optimizer" * - " is attached.") - @test_throws exception MOI.get(model, attr) - - attr = MOI.ResultCount() - exception = ErrorException( - "Cannot query $(attr) from caching optimizer because no optimizer" * - " is attached.") - @test_throws exception MOI.get(model, attr) - end + attr = MOI.VariablePrimal() + exception = ErrorException( + "Cannot query $(attr) from caching optimizer because no optimizer" * + " is attached.") + @test_throws exception MOI.get(model, MOI.VariablePrimal(), x[1]) + @test_throws exception MOI.get(model, MOI.VariablePrimal(), x) + + attr = MOI.SolverName() + exception = ErrorException( + "Cannot query $(attr) from caching optimizer because no optimizer" * + " is attached.") + @test_throws exception MOI.get(model, attr) + attr = MOI.Silent() + exception = ErrorException( + "Cannot query $(attr) from caching optimizer because no optimizer" * + " is attached.") + @test_throws exception MOI.get(model, attr) + + attr = MOI.ResultCount() + exception = ErrorException( + "Cannot query $(attr) from caching optimizer because no optimizer" * + " is attached.") + @test_throws exception MOI.get(model, attr) end @testset "Copyable solver attributes" begin diff --git a/test/Utilities/mockoptimizer.jl b/test/Utilities/mockoptimizer.jl index a21ac60f77..08896d752e 100644 --- a/test/Utilities/mockoptimizer.jl +++ b/test/Utilities/mockoptimizer.jl @@ -58,17 +58,9 @@ end soc = MOI.add_constraint(optimizer, MOI.VectorOfVariables(v), MOI.SecondOrderCone(2)) err = ErrorException("No mock primal is set for variable `$(v[1])`.") - if VERSION < v"0.7-" - @test_throws ErrorException MOI.get(optimizer, MOI.VariablePrimal(), v[1]) - else - @test_throws err MOI.get(optimizer, MOI.VariablePrimal(), v[1]) - end + @test_throws err MOI.get(optimizer, MOI.VariablePrimal(), v[1]) err = ErrorException("No mock dual is set for constraint `$c1`.") - if VERSION < v"0.7-" - @test_throws ErrorException MOI.get(optimizer, MOI.ConstraintDual(), c1) - else - @test_throws err MOI.get(optimizer, MOI.ConstraintDual(), c1) - end + @test_throws err MOI.get(optimizer, MOI.ConstraintDual(), c1) # Load fake solution # TODO: Provide a more compact API for this. diff --git a/test/attributes.jl b/test/attributes.jl index e0308d015b..e503cf5999 100644 --- a/test/attributes.jl +++ b/test/attributes.jl @@ -25,12 +25,7 @@ "number of values (2) set to `$attr`.") model = DummyModel() x = MOI.VariableIndex(1) - if VERSION < v"0.7-" - @test_throws DimensionMismatch MOI.set( - model, MOI.VariablePrimalStart(), [x], ones(2)) - else - @test_throws err MOI.set(model, MOI.VariablePrimalStart(), [x], - ones(2)) - end + @test_throws err MOI.set(model, MOI.VariablePrimalStart(), [x], + ones(2)) end end diff --git a/test/bridge.jl b/test/bridge.jl index d447607d45..3f1598fb90 100644 --- a/test/bridge.jl +++ b/test/bridge.jl @@ -68,11 +68,7 @@ end x = MOI.add_variable(bridged_mock) ci = MOI.add_constraint(bridged_mock, MOI.SingleVariable(x), MOI.Interval(0.0, 1.0)) - if VERSION < v"0.7-" - @test_throws typeof(err) MOI.get(bridged_mock, attr, ci) - else - @test_throws err MOI.get(bridged_mock, attr, ci) - end + @test_throws err MOI.get(bridged_mock, attr, ci) end @testset "Issue #453" begin @@ -243,16 +239,9 @@ end x = MOI.add_variables(bridged_mock, 4) err = MOI.UnsupportedConstraint{MOI.VectorOfVariables, MOI.RotatedSecondOrderCone}() - if VERSION < v"0.7-" - @test_throws typeof(err) begin - MOI.add_constraint(bridged_mock, MOI.VectorOfVariables(x), - MOI.RotatedSecondOrderCone(4)) - end - else - @test_throws err begin - MOI.add_constraint(bridged_mock, MOI.VectorOfVariables(x), - MOI.RotatedSecondOrderCone(4)) - end + @test_throws err begin + MOI.add_constraint(bridged_mock, MOI.VectorOfVariables(x), + MOI.RotatedSecondOrderCone(4)) end end @@ -282,16 +271,9 @@ end x = MOI.add_variables(bridged_mock, 3) err = MOI.UnsupportedConstraint{MOI.VectorAffineFunction{Float64}, MOI.LogDetConeTriangle}() - if VERSION < v"0.7-" - @test_throws typeof(err) begin - MOIB.bridge_type(bridged_mock, MOI.VectorAffineFunction{Float64}, - MOI.LogDetConeTriangle) - end - else - @test_throws err begin - MOIB.bridge_type(bridged_mock, MOI.VectorAffineFunction{Float64}, - MOI.LogDetConeTriangle) - end + @test_throws err begin + MOIB.bridge_type(bridged_mock, MOI.VectorAffineFunction{Float64}, + MOI.LogDetConeTriangle) end c = MOI.add_constraint(bridged_mock, MOI.VectorOfVariables(x), MOI.RotatedSecondOrderCone(3)) From 426891ccbc7ef7a06d21022886b87d4380102224 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathieu=20Besan=C3=A7on?= Date: Fri, 19 Apr 2019 12:52:00 +0200 Subject: [PATCH 5/6] project update for documenter --- docs/Project.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/Project.toml b/docs/Project.toml index ce87d15720..0a586d964f 100644 --- a/docs/Project.toml +++ b/docs/Project.toml @@ -1,5 +1,6 @@ [deps] Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" +MathOptInterface = "b8f27783-ece8-5eb3-8dc8-9495eed66fee" [compat] Documenter = "~0.21" From 46c15f11a7d062a73f01c9ffbd0b0191a9ab80b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathieu=20Besan=C3=A7on?= Date: Fri, 19 Apr 2019 13:23:21 +0200 Subject: [PATCH 6/6] explicit import --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 572a384a70..c90f542df1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,6 +30,6 @@ jobs: julia: 1.0 os: linux script: - - julia --project=docs/ -e 'import Pkg; Pkg.instantiate(); Pkg.develop(PackageSpec(path=pwd()))' + - julia --project=docs/ -e 'import Pkg; Pkg.instantiate(); Pkg.develop(Pkg.PackageSpec(path=pwd()))' - julia --project=docs/ docs/make.jl after_success: skip