diff --git a/src/Benchmarks/Benchmarks.jl b/src/Benchmarks/Benchmarks.jl index 0fa2ff2a92..2acf35f86b 100644 --- a/src/Benchmarks/Benchmarks.jl +++ b/src/Benchmarks/Benchmarks.jl @@ -6,8 +6,7 @@ module Benchmarks -using BenchmarkTools - +import BenchmarkTools import MathOptInterface as MOI const BENCHMARKS = Dict{String,Function}() @@ -35,10 +34,10 @@ end ``` """ function suite(new_model::Function; exclude::Vector{Regex} = Regex[]) - group = BenchmarkGroup() + group = BenchmarkTools.BenchmarkGroup() for (name, func) in BENCHMARKS any(occursin.(exclude, Ref(name))) && continue - group[name] = @benchmarkable $func($new_model) + group[name] = BenchmarkTools.@benchmarkable $func($new_model) end return group end @@ -63,12 +62,12 @@ function create_baseline( directory::String = "", kwargs..., ) - tune!(suite) + BenchmarkTools.tune!(suite) BenchmarkTools.save( joinpath(directory, name * "_params.json"), - params(suite), + BenchmarkTools.params(suite), ) - results = run(suite; kwargs...) + results = BenchmarkTools.run(suite; kwargs...) BenchmarkTools.save(joinpath(directory, name * "_baseline.json"), results) return end @@ -108,19 +107,19 @@ function compare_against_baseline( if !isfile(params_filename) || !isfile(baseline_filename) error("You create a baseline with `create_baseline` first.") end - loadparams!( + BenchmarkTools.loadparams!( suite, BenchmarkTools.load(params_filename)[1], :evals, :samples, ) - new_results = run(suite; kwargs...) + new_results = BenchmarkTools.run(suite; kwargs...) old_results = BenchmarkTools.load(baseline_filename)[1] open(joinpath(directory, report_filename), "w") do io println(stdout, "\n========== Results ==========") println(io, "\n========== Results ==========") for key in keys(new_results) - judgement = judge( + judgement = BenchmarkTools.judge( BenchmarkTools.median(new_results[key]), BenchmarkTools.median(old_results[key]), ) diff --git a/src/FileFormats/MOF/MOF.jl b/src/FileFormats/MOF/MOF.jl index b176ca6675..17a443122b 100644 --- a/src/FileFormats/MOF/MOF.jl +++ b/src/FileFormats/MOF/MOF.jl @@ -7,7 +7,7 @@ module MOF import ..FileFormats -import OrderedCollections +import OrderedCollections: OrderedDict import JSON import MathOptInterface as MOI @@ -16,7 +16,7 @@ const VERSION = v"1.5" const SUPPORTED_VERSIONS = (v"1.5", v"1.4", v"1.3", v"1.2", v"1.1", v"1.0", v"0.6", v"0.5", v"0.4") -const OrderedObject = OrderedCollections.OrderedDict{String,Any} +const OrderedObject = OrderedDict{String,Any} const UnorderedObject = Dict{String,Any} const Object = Union{OrderedObject,UnorderedObject} diff --git a/src/Nonlinear/Nonlinear.jl b/src/Nonlinear/Nonlinear.jl index 6b3231aa3f..9e8f0fc334 100644 --- a/src/Nonlinear/Nonlinear.jl +++ b/src/Nonlinear/Nonlinear.jl @@ -14,7 +14,6 @@ """ module Nonlinear -import Base.Meta: isexpr import ForwardDiff import ..MathOptInterface as MOI import OrderedCollections: OrderedDict diff --git a/src/Nonlinear/parse.jl b/src/Nonlinear/parse.jl index c68350156c..77ecdedb06 100644 --- a/src/Nonlinear/parse.jl +++ b/src/Nonlinear/parse.jl @@ -108,8 +108,8 @@ function parse_expression( end function _parse_expression(stack, data, expr, x, parent_index) - if isexpr(x, :call) - if length(x.args) == 2 && !isexpr(x.args[2], :...) + if Meta.isexpr(x, :call) + if length(x.args) == 2 && !Meta.isexpr(x.args[2], :...) _parse_univariate_expression(stack, data, expr, x, parent_index) else # The call is either n-ary, or it is a splat, in which case we @@ -117,11 +117,11 @@ function _parse_expression(stack, data, expr, x, parent_index) # Punt to multivariate and try to recover later. _parse_multivariate_expression(stack, data, expr, x, parent_index) end - elseif isexpr(x, :comparison) + elseif Meta.isexpr(x, :comparison) _parse_comparison_expression(stack, data, expr, x, parent_index) - elseif isexpr(x, :...) + elseif Meta.isexpr(x, :...) _parse_splat_expression(stack, data, expr, x, parent_index) - elseif isexpr(x, :&&) || isexpr(x, :||) + elseif Meta.isexpr(x, :&&) || Meta.isexpr(x, :||) _parse_logic_expression(stack, data, expr, x, parent_index) else error("Unsupported expression: $x") @@ -129,7 +129,7 @@ function _parse_expression(stack, data, expr, x, parent_index) end function _parse_splat_expression(stack, data, expr, x, parent_index) - @assert isexpr(x, :...) && length(x.args) == 1 + @assert Meta.isexpr(x, :...) && length(x.args) == 1 if parent_index == -1 error( "Unsupported use of the splatting operator. This is only " * @@ -155,7 +155,7 @@ function _parse_univariate_expression( x::Expr, parent_index::Int, ) - @assert isexpr(x, :call, 2) + @assert Meta.isexpr(x, :call, 2) id = get(data.operators.univariate_operator_to_id, x.args[1], nothing) if id === nothing # It may also be a multivariate operator like * with one argument. @@ -177,7 +177,7 @@ function _parse_multivariate_expression( x::Expr, parent_index::Int, ) - @assert isexpr(x, :call) + @assert Meta.isexpr(x, :call) id = get(data.operators.multivariate_operator_to_id, x.args[1], nothing) if id === nothing if haskey(data.operators.univariate_operator_to_id, x.args[1]) @@ -364,7 +364,7 @@ end _replace_comparison(expr) = expr function _replace_comparison(expr::Expr) - if isexpr(expr, :call, 4) && expr.args[1] in (:<=, :>=, :(==), :<, :>) + if Meta.isexpr(expr, :call, 4) && expr.args[1] in (:<=, :>=, :(==), :<, :>) return Expr( :comparison, expr.args[2], diff --git a/src/Test/Test.jl b/src/Test/Test.jl index fd1f12c59b..db45ed653a 100644 --- a/src/Test/Test.jl +++ b/src/Test/Test.jl @@ -32,10 +32,10 @@ The work-around is to wrap `Test` in a module so that `MOI.Test.Test` is `MOI.Test`. =# module _BaseTest -using Test +import Test: @testset, @test, @test_throws, @inferred end -using ._BaseTest: @testset, @test, @test_throws, @inferred +import ._BaseTest: @testset, @test, @test_throws, @inferred # Be wary of adding new fields to this Config struct. Always think: can it be # achieved a different way? diff --git a/src/Utilities/CleverDicts.jl b/src/Utilities/CleverDicts.jl index 737b1a9dc4..5b75f0c860 100644 --- a/src/Utilities/CleverDicts.jl +++ b/src/Utilities/CleverDicts.jl @@ -11,7 +11,7 @@ module CleverDicts # solvers using `CleverDicts` to implement it themselves. import MathOptInterface as MOI -import OrderedCollections +import OrderedCollections: OrderedDict """ index_to_key(::Type{K}, index::Int) @@ -83,7 +83,7 @@ mutable struct CleverDict{K,V,F<:Function,I<:Function} <: AbstractDict{K,V} inverse_hash::I is_dense::Bool vector::Vector{V} - dict::OrderedCollections.OrderedDict{K,V} + dict::OrderedDict{K,V} function CleverDict{K,V}( hash::F = key_to_index, inverse_hash::I = index_to_key, @@ -94,7 +94,7 @@ mutable struct CleverDict{K,V,F<:Function,I<:Function} <: AbstractDict{K,V} inverse_hash, true, V[], - OrderedCollections.OrderedDict{K,V}(), + OrderedDict{K,V}(), ) end end diff --git a/src/Utilities/Utilities.jl b/src/Utilities/Utilities.jl index c553545f4f..7bd9145302 100644 --- a/src/Utilities/Utilities.jl +++ b/src/Utilities/Utilities.jl @@ -6,13 +6,11 @@ module Utilities -using LinearAlgebra # For dot -using OrderedCollections # for OrderedDict in UniversalFallback - +import LinearAlgebra import MathOptInterface as MOI -import MutableArithmetics as MA - import MathOptInterface.Utilities as MOIU # used in macro +import MutableArithmetics as MA +import OrderedCollections: OrderedDict const SVF = MOI.VariableIndex const VVF = MOI.VectorOfVariables diff --git a/src/Utilities/operate.jl b/src/Utilities/operate.jl index 8b9e30984c..de4afa1f6a 100644 --- a/src/Utilities/operate.jl +++ b/src/Utilities/operate.jl @@ -805,7 +805,7 @@ end function operate( ::typeof(*), ::Type{T}, - D::Diagonal{T}, + D::LinearAlgebra.Diagonal{T}, func::MOI.VectorQuadraticFunction{T}, ) where {T<:Number} return MOI.VectorQuadraticFunction{T}( @@ -818,7 +818,7 @@ end function operate( ::typeof(*), ::Type{T}, - D::Diagonal{T}, + D::LinearAlgebra.Diagonal{T}, func::MOI.VectorAffineFunction{T}, ) where {T<:Number} return MOI.VectorAffineFunction{T}( @@ -830,7 +830,7 @@ end function operate( ::typeof(*), ::Type{T}, - D::Diagonal{T}, + D::LinearAlgebra.Diagonal{T}, func::MOI.VectorOfVariables, ) where {T<:Number} return MOI.VectorAffineFunction{T}( @@ -847,7 +847,7 @@ end function operate( ::typeof(*), ::Type{T}, - D::Diagonal{T}, + D::LinearAlgebra.Diagonal{T}, v::AbstractVector{T}, ) where {T<:Number} return T[D.diag[i] * v[i] for i in eachindex(v)] @@ -1556,7 +1556,7 @@ end ### 3a: operate_term(::typeof(*), ::Diagonal, ::Vector{<:VectorTerm}) -function operate_terms(::typeof(*), D::Diagonal, terms) +function operate_terms(::typeof(*), D::LinearAlgebra.Diagonal, terms) return map(term -> operate_term(*, D, term), terms) end diff --git a/src/Utilities/parser.jl b/src/Utilities/parser.jl index 610d145906..01e942cd8d 100644 --- a/src/Utilities/parser.jl +++ b/src/Utilities/parser.jl @@ -4,8 +4,6 @@ # Use of this source code is governed by an MIT-style license that can be found # in the LICENSE.md file or at https://opensource.org/licenses/MIT. -using Base.Meta: isexpr - struct _ParsedScalarAffineTerm{T} coefficient::T variable::Symbol @@ -61,7 +59,7 @@ end function _parse_function(ex, ::Type{T} = Float64) where {T} if isa(ex, Symbol) return _ParsedVariableIndex(ex) - elseif isexpr(ex, :vect) + elseif Meta.isexpr(ex, :vect) if all(s -> isa(s, Symbol), ex.args) return _ParsedVectorOfVariables(copy(ex.args)) else @@ -113,20 +111,21 @@ function _parse_function(ex, ::Type{T} = Float64) where {T} end end else - if isexpr(ex, :call, 2) && ex.args[1] == :ScalarNonlinearFunction + if Meta.isexpr(ex, :call, 2) && ex.args[1] == :ScalarNonlinearFunction return ex - elseif isexpr(ex, :call, 2) && ex.args[1] == :VectorNonlinearFunction + elseif Meta.isexpr(ex, :call, 2) && + ex.args[1] == :VectorNonlinearFunction return ex end # For simplicity, only accept Expr(:call, :+, ...); no recursive # expressions - if isexpr(ex, :call) && ex.args[1] == :* + if Meta.isexpr(ex, :call) && ex.args[1] == :* ex = Expr(:call, :+, ex) # Handle 2x as (+)(2x) end if ex isa Number ex = Expr(:call, :+, ex) end - @assert isexpr(ex, :call) + @assert Meta.isexpr(ex, :call) if ex.args[1] != :+ error( "Unsupported operator in `loadfromstring!`: `$(ex.args[1])`. " * @@ -139,7 +138,7 @@ function _parse_function(ex, ::Type{T} = Float64) where {T} quadratic_terms = _ParsedScalarQuadraticTerm{T}[] constant = zero(T) for subex in ex.args[2:end] - if isexpr(subex, :call) && subex.args[1] == :* + if Meta.isexpr(subex, :call) && subex.args[1] == :* if length(subex.args) == 3 # constant * variable coef = if isa(subex.args[2], Number) @@ -199,19 +198,19 @@ end # see tests for examples function _separate_label(ex) - if isexpr(ex, :call) && ex.args[1] == :(:) + if Meta.isexpr(ex, :call) && ex.args[1] == :(:) # A line like `variables: x`. return ex.args[2], ex.args[3] - elseif isexpr(ex, :tuple) + elseif Meta.isexpr(ex, :tuple) # A line like `variables: x, y`. _Parsed as `((variables:x), y)` ex = copy(ex) - @assert isexpr(ex.args[1], :call) && ex.args[1].args[1] == :(:) + @assert Meta.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) + elseif Meta.isexpr(ex, :call) ex = copy(ex) - if isexpr(ex.args[2], :call) && ex.args[2].args[1] == :(:) + if Meta.isexpr(ex.args[2], :call) && ex.args[2].args[1] == :(:) # A line like `c: x <= 1` label = ex.args[2].args[2] ex.args[2] = ex.args[2].args[3] @@ -241,9 +240,9 @@ _parsed_to_moi(model, s::Vector) = _parsed_to_moi.(model, s) _parsed_to_moi(model, s::Number) = s function _parsed_to_moi(model, s::Expr) - if isexpr(s, :call, 2) && s.args[1] == :ScalarNonlinearFunction + if Meta.isexpr(s, :call, 2) && s.args[1] == :ScalarNonlinearFunction return _parsed_scalar_to_moi(model, s.args[2]) - elseif isexpr(s, :call, 2) && s.args[1] == :VectorNonlinearFunction + elseif Meta.isexpr(s, :call, 2) && s.args[1] == :VectorNonlinearFunction return _parsed_vector_to_moi(model, s.args[2]) end args = Any[_parsed_to_moi(model, arg) for arg in s.args[2:end]] @@ -378,7 +377,7 @@ function loadfromstring!(model, s) label, ex = _separate_label(line) T, label = _split_type(label) if label == :variables - if isexpr(ex, :tuple) + if Meta.isexpr(ex, :tuple) for v in ex.args vindex = MOI.add_variable(model) MOI.set(model, MOI.VariableName(), vindex, String(v)) @@ -416,7 +415,7 @@ function loadfromstring!(model, s) MOI.set(model, MOI.ObjectiveFunction{typeof(f)}(), f) else # constraint - @assert isexpr(ex, :call) + @assert Meta.isexpr(ex, :call) f = _parsed_to_moi(model, _parse_function(ex.args[2], T)) if ex.args[1] == :in # Could be safer here @@ -446,10 +445,10 @@ end _split_type(ex) = Float64, ex function _split_type(ex::Expr) - if isexpr(ex, Symbol("::"), 1) + if Meta.isexpr(ex, Symbol("::"), 1) return Core.eval(Base, ex.args[1]), Symbol("") else - @assert isexpr(ex, Symbol("::"), 2) + @assert Meta.isexpr(ex, Symbol("::"), 2) return Core.eval(Base, ex.args[2]), ex.args[1] end end diff --git a/src/Utilities/print.jl b/src/Utilities/print.jl index f7e92ab04a..41d3e747bc 100644 --- a/src/Utilities/print.jl +++ b/src/Utilities/print.jl @@ -4,8 +4,6 @@ # Use of this source code is governed by an MIT-style license that can be found # in the LICENSE.md file or at https://opensource.org/licenses/MIT. -using Printf - _drop_moi(s) = replace(string(s), "MathOptInterface." => "") _escape_braces(s) = replace(replace(s, "{" => "\\{"), "}" => "\\}") diff --git a/src/Utilities/promote_operation.jl b/src/Utilities/promote_operation.jl index 2d7fbe2107..9e465b72e8 100644 --- a/src/Utilities/promote_operation.jl +++ b/src/Utilities/promote_operation.jl @@ -305,7 +305,7 @@ end function promote_operation( ::typeof(*), ::Type{T}, - ::Type{<:Diagonal{T}}, + ::Type{<:LinearAlgebra.Diagonal{T}}, ::Type{F}, ) where {T,F} U = promote_operation(*, T, T, scalar_type(F))