jump-dev / MathOptInterface.jl

A data structure for mathematical optimization problems
http://jump.dev/MathOptInterface.jl/
Other
380 stars 86 forks source link

Fix Bridges.runtests when model has no variable #2499

Closed blegat closed 2 months ago

blegat commented 2 months ago

Needed for https://github.com/jump-dev/SumOfSquares.jl/pull/296

Without the fix of this PR, the added tests throws

test_runtests: Error During Test at /home/blegat/.julia/dev/MathOptInterface/src/Bridges/Bridges.jl:286
  Test threw exception
  Expression: MOI.get(model, attr, x) ≈ primal_start
  MethodError: no method matching zero(::Type{Any})

  Closest candidates are:
    zero(::Type{Union{Missing, T}}) where T
     @ Base missing.jl:105
    zero(::Type{Union{}}, Any...)
     @ Base number.jl:310
    zero(::Type{Missing})
     @ Base missing.jl:104
    ...

  Stacktrace:
   [1] zero(::Type{Any})
     @ Base ./missing.jl:106
   [2] norm(itr::Vector{Any}, p::Int64)
     @ LinearAlgebra ~/.julia/juliaup/julia-1.10.3+0.x64.linux.gnu/share/julia/stdlib/v1.10/LinearAlgebra/src/generic.jl:596
   [3] isapprox(x::Vector{Any}, y::Vector{Float64}; atol::Int64, rtol::Float64, nans::Bool, norm::typeof(LinearAlgebra.norm))
     @ LinearAlgebra ~/.julia/juliaup/julia-1.10.3+0.x64.linux.gnu/share/julia/stdlib/v1.10/LinearAlgebra/src/generic.jl:1789
   [4] isapprox(x::Vector{Any}, y::Vector{Float64})
     @ LinearAlgebra ~/.julia/juliaup/julia-1.10.3+0.x64.linux.gnu/share/julia/stdlib/v1.10/LinearAlgebra/src/generic.jl:1785
   [5] eval_test(evaluated::Expr, quoted::Expr, source::LineNumberNode, negate::Bool)
     @ Test ~/.julia/juliaup/julia-1.10.3+0.x64.linux.gnu/share/julia/stdlib/v1.10/Test/src/Test.jl:355
   [6] macro expansion
     @ ~/.julia/juliaup/julia-1.10.3+0.x64.linux.gnu/share/julia/stdlib/v1.10/Test/src/Test.jl:669 [inlined]
   [7] runtests(Bridge::Type{MathOptInterface.Bridges.Constraint.GreaterToLessBridge}, input_fn::Main.TestConstraintFlipSign.var"#59#61", output_fn::Main.TestConstraintFlipSign.var"#60#62"; variable_start::Float64, constraint_start::Float64, eltype::Type, print_inner_model::Bool)
     @ MathOptInterface.Bridges ~/.julia/dev/MathOptInterface/src/Bridges/Bridges.jl:286
blegat commented 2 months ago

I rebased to check, https://github.com/jump-dev/MathOptInterface.jl/pull/2501does not fix the error

odow commented 2 months ago

Correct. That PR was to fix the Union{}[] return type, but it doesn't fix norm(::Vector{Any}). I'll take a look at this.