MathOptInterface.jl
MathOptInterface.jl copied to clipboard
promote not working
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
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}.
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, 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.
This is true, maybe model_convert fixes this now, I'll try it out in https://github.com/jump-dev/SumOfSquares.jl/pull/249
What is the status of this?
Haven't had time to check yet
@blegat should we just close this? I don't think we want to add it to MOI directly?
Let me take a look this week :)