MathOptInterface.jl icon indicating copy to clipboard operation
MathOptInterface.jl copied to clipboard

promote not working

Open blegat opened this issue 3 years ago • 2 comments

julia> f = 1 * MOI.VariableIndex(1)
MathOptInterface.ScalarAffineFunction{Int64}(MathOptInterface.ScalarAffineTerm{Int64}[MathOptInterface.ScalarAffineTerm{Int64}(1, MathOptInterface.VariableIndex(1))], 0)

julia> g = 1.0 * f
MathOptInterface.ScalarAffineFunction{Float64}(MathOptInterface.ScalarAffineTerm{Float64}[MathOptInterface.ScalarAffineTerm{Float64}(1.0, MathOptInterface.VariableIndex(1))], 0.0)

julia> promote(f, g)
ERROR: promotion of types MathOptInterface.ScalarAffineFunction{Int64} and MathOptInterface.ScalarAffineFunction{Float64} failed to change any arguments
Stacktrace:
 [1] error(::String, ::String, ::String)
   @ Base ./error.jl:42
 [2] sametype_error(input::Tuple{MathOptInterface.ScalarAffineFunction{Int64}, MathOptInterface.ScalarAffineFunction{Float64}})
   @ Base ./promotion.jl:374
 [3] not_sametype(x::Tuple{MathOptInterface.ScalarAffineFunction{Int64}, MathOptInterface.ScalarAffineFunction{Float64}}, y::Tuple{MathOptInterface.ScalarAffineFunction{Int64}, MathOptInterface.ScalarAffineFunction{Float64}})
   @ Base ./promotion.jl:368
 [4] promote(x::MathOptInterface.ScalarAffineFunction{Int64}, y::MathOptInterface.ScalarAffineFunction{Float64})
   @ Base ./promotion.jl:351
 [5] top-level scope
   @ REPL[10]:1

blegat avatar Mar 28 '22 02:03 blegat

Did this ever work? In what context is it called? What should the return be? I think we want to be careful automatically promoting {Int} to {Float64}.

odow avatar Mar 31 '22 02:03 odow

This came across when working on https://github.com/jump-dev/SumOfSquares.jl/pull/249 Actually, a better fix is having a convert_coefficient defined in MOI. Currently, the SumOfSquares bridge works for any AbstractVectorFunction and without a function in MOI, we will have to restrict it to function defining some API defined in SumOfSquares like SumOfSquares.Bridges.Constraint._convert_coef which isn't ideal.

blegat avatar Mar 31 '22 11:03 blegat

@blegat, what do we need here now that JuMP has model_convert etc? It seems like we shouldn't be doing these conversions at the MOI level.

odow avatar Sep 13 '23 22:09 odow

This is true, maybe model_convert fixes this now, I'll try it out in https://github.com/jump-dev/SumOfSquares.jl/pull/249

blegat avatar Sep 14 '23 07:09 blegat

What is the status of this?

odow avatar Sep 28 '23 23:09 odow

Haven't had time to check yet

blegat avatar Sep 29 '23 07:09 blegat

@blegat should we just close this? I don't think we want to add it to MOI directly?

odow avatar Oct 23 '23 00:10 odow

Let me take a look this week :)

blegat avatar Oct 23 '23 07:10 blegat