Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix method ambiguities and limit operate to Number subtypes #2224

Merged
merged 8 commits into from
Aug 2, 2023

Conversation

odow
Copy link
Member

@odow odow commented Jun 24, 2023

@blegat
Copy link
Member

blegat commented Jun 24, 2023

Maybe we could add tests actually

@odow
Copy link
Member Author

odow commented Jun 24, 2023

What we really need to do is fix:

julia> Test.detect_ambiguities(MOI; recursive = true)
41-element Vector{Tuple{Method, Method}}:
[...]

@odow
Copy link
Member Author

odow commented Jun 24, 2023

There are lots of these that are pedantic. Like

a = dot(α::T, func::Union{MathOptInterface.ScalarAffineFunction{T}, MathOptInterface.ScalarQuadraticFunction{T}, MathOptInterface.VectorAffineFunction{T}, MathOptInterface.VectorQuadraticFunction{T}}) where T in MathOptInterface.Utilities at /Users/oscar/.julia/dev/MathOptInterface/src/Utilities/functions.jl:1760
b = dot(::ChainRulesCore.NoTangent, ::Any) in ChainRulesCore at /Users/oscar/.julia/packages/ChainRulesCore/a4mIA/src/tangent_arithmetic.jl:67

would only happen for MathOptInterface.ScalarAffineFunction{ChainRulesCore.NoTangent}.

They mostly stem from cases where T is not <:Number. We should really rethink the weak assumption there.

julia> for (a, b) in Test.detect_ambiguities(MOI; recursive = true)
           @show a
           @show b
           println()
       end
a = *(f::T, g::Union{MathOptInterface.ScalarAffineFunction{T}, MathOptInterface.ScalarQuadraticFunction{T}, MathOptInterface.VectorAffineFunction{T}, MathOptInterface.VectorQuadraticFunction{T}}) where T in MathOptInterface.Utilities at /Users/oscar/.julia/dev/MathOptInterface/src/Utilities/functions.jl:1678
b = *(z::MutableArithmetics.Zero, ::Any) in MutableArithmetics at /Users/oscar/.julia/packages/MutableArithmetics/geMUn/src/rewrite.jl:53

a = operate(::typeof(+), ::Type{T}, f::MathOptInterface.ScalarAffineFunction{T}, g::Union{MathOptInterface.VariableIndex, MathOptInterface.ScalarAffineFunction{T}, T}) where T in MathOptInterface.Utilities at /Users/oscar/.julia/dev/MathOptInterface/src/Utilities/operate.jl:127
b = operate(::typeof(+), ::Type{T}, f::Union{MathOptInterface.VariableIndex, MathOptInterface.ScalarAffineFunction{T}, MathOptInterface.ScalarNonlinearFunction, MathOptInterface.ScalarQuadraticFunction{T}, T}, g::MathOptInterface.ScalarNonlinearFunction) where T in MathOptInterface.Utilities at /Users/oscar/.julia/dev/MathOptInterface/src/Utilities/operate.jl:174

a = *(f::Union{MathOptInterface.VariableIndex, MathOptInterface.ScalarAffineFunction{T}, MathOptInterface.ScalarQuadraticFunction{T}} where T, g::Union{MathOptInterface.VariableIndex, MathOptInterface.ScalarAffineFunction{T}, MathOptInterface.ScalarQuadraticFunction{T}} where T, args::Union{MathOptInterface.VariableIndex, MathOptInterface.ScalarAffineFunction{T}, MathOptInterface.ScalarQuadraticFunction{T}} where T...) in MathOptInterface.Utilities at /Users/oscar/.julia/dev/MathOptInterface/src/Utilities/functions.jl:1572
b = *(f::Union{MathOptInterface.ScalarAffineFunction{T}, MathOptInterface.ScalarQuadraticFunction{T}, MathOptInterface.VectorAffineFunction{T}, MathOptInterface.VectorQuadraticFunction{T}}, g::T) where T in MathOptInterface.Utilities at /Users/oscar/.julia/dev/MathOptInterface/src/Utilities/functions.jl:1666

a = *(f::T, g::Union{MathOptInterface.ScalarAffineFunction{T}, MathOptInterface.ScalarQuadraticFunction{T}, MathOptInterface.VectorAffineFunction{T}, MathOptInterface.VectorQuadraticFunction{T}}) where T in MathOptInterface.Utilities at /Users/oscar/.julia/dev/MathOptInterface/src/Utilities/functions.jl:1678
b = *(::ChainRulesCore.ZeroTangent, ::Any) in ChainRulesCore at /Users/oscar/.julia/packages/ChainRulesCore/a4mIA/src/tangent_arithmetic.jl:104

a = *(f::Union{MathOptInterface.ScalarAffineFunction{T}, MathOptInterface.ScalarQuadraticFunction{T}, MathOptInterface.VectorAffineFunction{T}, MathOptInterface.VectorQuadraticFunction{T}}, g::T) where T in MathOptInterface.Utilities at /Users/oscar/.julia/dev/MathOptInterface/src/Utilities/functions.jl:1666
b = *(::Any, ::ChainRulesCore.NoTangent) in ChainRulesCore at /Users/oscar/.julia/packages/ChainRulesCore/a4mIA/src/tangent_arithmetic.jl:65

a = get(model::MathOptInterface.ModelLike, attr::MathOptInterface.AbstractConstraintAttribute, bridge::MathOptInterface.Bridges.Constraint.AbstractFunctionConversionBridge) in MathOptInterface.Bridges.Constraint at /Users/oscar/.julia/dev/MathOptInterface/src/Bridges/Constraint/bridges/functionize.jl:17
b = get(model::MathOptInterface.ModelLike, ::MathOptInterface.CanonicalConstraintFunction, bridge::MathOptInterface.Bridges.AbstractBridge) in MathOptInterface.Bridges at /Users/oscar/.julia/dev/MathOptInterface/src/Bridges/bridge.jl:151

a = operate(::typeof(*), ::Type{T}, f::T, g::MathOptInterface.ScalarNonlinearFunction) where T in MathOptInterface.Utilities at /Users/oscar/.julia/dev/MathOptInterface/src/Utilities/operate.jl:566
b = operate(::typeof(*), ::Type{T}, f::MathOptInterface.ScalarNonlinearFunction, g::T) where T in MathOptInterface.Utilities at /Users/oscar/.julia/dev/MathOptInterface/src/Utilities/operate.jl:593

a = operate(::typeof(*), ::Type{T}, f::T, g::MathOptInterface.VectorOfVariables) where T in MathOptInterface.Utilities at /Users/oscar/.julia/dev/MathOptInterface/src/Utilities/operate.jl:541
b = operate(::typeof(*), ::Type{T}, f::Union{MathOptInterface.VariableIndex, MathOptInterface.ScalarAffineFunction{T}, MathOptInterface.ScalarQuadraticFunction{T}, MathOptInterface.VectorAffineFunction{T}, MathOptInterface.VectorOfVariables, MathOptInterface.VectorQuadraticFunction{T}}, g::T) where T in MathOptInterface.Utilities at /Users/oscar/.julia/dev/MathOptInterface/src/Utilities/operate.jl:577

a = /(f::Union{MathOptInterface.ScalarAffineFunction{T}, MathOptInterface.ScalarQuadraticFunction{T}, MathOptInterface.VectorAffineFunction{T}, MathOptInterface.VectorQuadraticFunction{T}}, g::T) where T in MathOptInterface.Utilities at /Users/oscar/.julia/dev/MathOptInterface/src/Utilities/functions.jl:1717
b = /(::Any, x::ChainRulesCore.NotImplemented) in ChainRulesCore at /Users/oscar/.julia/packages/ChainRulesCore/a4mIA/src/tangent_types/notimplemented.jl:43

a = promote_operation(::typeof(*), ::Type{T}, ::Type{T}, ::Type{MathOptInterface.VectorOfVariables}) where T in MathOptInterface.Utilities at /Users/oscar/.julia/dev/MathOptInterface/src/Utilities/promote_operation.jl:214
b = promote_operation(::typeof(*), ::Type{T}, ::Type{MathOptInterface.VectorOfVariables}, ::Type{T}) where T in MathOptInterface.Utilities at /Users/oscar/.julia/dev/MathOptInterface/src/Utilities/promote_operation.jl:254

a = dot(f::Union{MathOptInterface.VariableIndex, MathOptInterface.ScalarAffineFunction{T}, MathOptInterface.ScalarQuadraticFunction{T}} where T, g::Union{MathOptInterface.VariableIndex, MathOptInterface.ScalarAffineFunction{T}, MathOptInterface.ScalarQuadraticFunction{T}} where T) in MathOptInterface.Utilities at /Users/oscar/.julia/dev/MathOptInterface/src/Utilities/functions.jl:1759
b = dot::T, func::Union{MathOptInterface.ScalarAffineFunction{T}, MathOptInterface.ScalarQuadraticFunction{T}, MathOptInterface.VectorAffineFunction{T}, MathOptInterface.VectorQuadraticFunction{T}}) where T in MathOptInterface.Utilities at /Users/oscar/.julia/dev/MathOptInterface/src/Utilities/functions.jl:1760

a = dot(func::Union{MathOptInterface.ScalarAffineFunction{T}, MathOptInterface.ScalarQuadraticFunction{T}, MathOptInterface.VectorAffineFunction{T}, MathOptInterface.VectorQuadraticFunction{T}}, α::T) where T in MathOptInterface.Utilities at /Users/oscar/.julia/dev/MathOptInterface/src/Utilities/functions.jl:1761
b = dot(::Any, ::ChainRulesCore.NoTangent) in ChainRulesCore at /Users/oscar/.julia/packages/ChainRulesCore/a4mIA/src/tangent_arithmetic.jl:68

a = get(bridge::MathOptInterface.Bridges.Constraint._AbstractSlackBridge{T, VF, ZS, F, S} where S, ::MathOptInterface.ListOfConstraintIndices{F, ZS}) where {T, VF, ZS, F} in MathOptInterface.Bridges.Constraint at /Users/oscar/.julia/dev/MathOptInterface/src/Bridges/Constraint/bridges/slack.jl:35
b = get(bridge::MathOptInterface.Bridges.Constraint._AbstractSlackBridge{T, VF, ZS, F, S}, ::MathOptInterface.ListOfConstraintIndices{VF, S}) where {T, VF, ZS, F, S} in MathOptInterface.Bridges.Constraint at /Users/oscar/.julia/dev/MathOptInterface/src/Bridges/Constraint/bridges/slack.jl:42

a = promote_operation(::typeof(*), ::Type{T}, ::Type{T}, ::Type{MathOptInterface.VariableIndex}) where T in MathOptInterface.Utilities at /Users/oscar/.julia/dev/MathOptInterface/src/Utilities/promote_operation.jl:205
b = promote_operation(::typeof(*), ::Type{T}, ::Type{MathOptInterface.VariableIndex}, ::Type{T}) where T in MathOptInterface.Utilities at /Users/oscar/.julia/dev/MathOptInterface/src/Utilities/promote_operation.jl:245

a = operate(::typeof(+), ::Type{T}, f::MathOptInterface.VariableIndex, g::T) where T in MathOptInterface.Utilities at /Users/oscar/.julia/dev/MathOptInterface/src/Utilities/operate.jl:102
b = operate(::typeof(+), ::Type{T}, f::Union{MathOptInterface.VariableIndex, MathOptInterface.ScalarAffineFunction{T}, MathOptInterface.ScalarNonlinearFunction, MathOptInterface.ScalarQuadraticFunction{T}, T}, g::MathOptInterface.ScalarNonlinearFunction) where T in MathOptInterface.Utilities at /Users/oscar/.julia/dev/MathOptInterface/src/Utilities/operate.jl:174

a = dot(f::Union{MathOptInterface.VariableIndex, MathOptInterface.ScalarAffineFunction{T}, MathOptInterface.ScalarQuadraticFunction{T}} where T, g::Union{MathOptInterface.VariableIndex, MathOptInterface.ScalarAffineFunction{T}, MathOptInterface.ScalarQuadraticFunction{T}} where T) in MathOptInterface.Utilities at /Users/oscar/.julia/dev/MathOptInterface/src/Utilities/functions.jl:1759
b = dot(func::Union{MathOptInterface.ScalarAffineFunction{T}, MathOptInterface.ScalarQuadraticFunction{T}, MathOptInterface.VectorAffineFunction{T}, MathOptInterface.VectorQuadraticFunction{T}}, α::T) where T in MathOptInterface.Utilities at /Users/oscar/.julia/dev/MathOptInterface/src/Utilities/functions.jl:1761

a = _add_sub_affine_terms(op::Union{typeof(+), typeof(-)}, terms::Array{MathOptInterface.ScalarAffineTerm{T}, 1}, α::T, f::MathOptInterface.VariableIndex, β::T) where T in MathOptInterface.Utilities at /Users/oscar/.julia/dev/MathOptInterface/src/Utilities/mutable_arithmetics.jl:267
b = _add_sub_affine_terms(op::Union{typeof(+), typeof(-)}, terms::Array{MathOptInterface.ScalarAffineTerm{T}, 1}, α::T, β::T, args::Vararg{Union{MathOptInterface.VariableIndex, MathOptInterface.ScalarAffineFunction{T}, MathOptInterface.ScalarQuadraticFunction{T}, T} where T, N}) where {T, N} in MathOptInterface.Utilities at /Users/oscar/.julia/dev/MathOptInterface/src/Utilities/mutable_arithmetics.jl:361

a = dot(func::Union{MathOptInterface.ScalarAffineFunction{T}, MathOptInterface.ScalarQuadraticFunction{T}, MathOptInterface.VectorAffineFunction{T}, MathOptInterface.VectorQuadraticFunction{T}}, α::T) where T in MathOptInterface.Utilities at /Users/oscar/.julia/dev/MathOptInterface/src/Utilities/functions.jl:1761
b = dot(::Any, x::ChainRulesCore.NotImplemented) in ChainRulesCore at /Users/oscar/.julia/packages/ChainRulesCore/a4mIA/src/tangent_arithmetic.jl:40

a = dot::T, func::Union{MathOptInterface.ScalarAffineFunction{T}, MathOptInterface.ScalarQuadraticFunction{T}, MathOptInterface.VectorAffineFunction{T}, MathOptInterface.VectorQuadraticFunction{T}}) where T in MathOptInterface.Utilities at /Users/oscar/.julia/dev/MathOptInterface/src/Utilities/functions.jl:1760
b = dot(::ChainRulesCore.ZeroTangent, ::Any) in ChainRulesCore at /Users/oscar/.julia/packages/ChainRulesCore/a4mIA/src/tangent_arithmetic.jl:107

a = _add_sub_affine_terms(op::Union{typeof(+), typeof(-)}, terms::Array{MathOptInterface.ScalarAffineTerm{T}, 1}, f::MathOptInterface.VariableIndex, β::T) where T in MathOptInterface.Utilities at /Users/oscar/.julia/dev/MathOptInterface/src/Utilities/mutable_arithmetics.jl:278
b = _add_sub_affine_terms(op::Union{typeof(+), typeof(-)}, terms::Array{MathOptInterface.ScalarAffineTerm{T}, 1}, α::T, f::MathOptInterface.VariableIndex) where T in MathOptInterface.Utilities at /Users/oscar/.julia/dev/MathOptInterface/src/Utilities/mutable_arithmetics.jl:288

a = dot::T, func::Union{MathOptInterface.ScalarAffineFunction{T}, MathOptInterface.ScalarQuadraticFunction{T}, MathOptInterface.VectorAffineFunction{T}, MathOptInterface.VectorQuadraticFunction{T}}) where T in MathOptInterface.Utilities at /Users/oscar/.julia/dev/MathOptInterface/src/Utilities/functions.jl:1760
b = dot(::ChainRulesCore.NoTangent, ::Any) in ChainRulesCore at /Users/oscar/.julia/packages/ChainRulesCore/a4mIA/src/tangent_arithmetic.jl:67

a = operate(::typeof(-), ::Type{T}, f::MathOptInterface.ScalarAffineFunction{T}, g::Union{MathOptInterface.VariableIndex, MathOptInterface.ScalarAffineFunction{T}, T}) where T in MathOptInterface.Utilities at /Users/oscar/.julia/dev/MathOptInterface/src/Utilities/operate.jl:372
b = operate(::typeof(-), ::Type{T}, f::Union{MathOptInterface.VariableIndex, MathOptInterface.ScalarAffineFunction{T}, MathOptInterface.ScalarNonlinearFunction, MathOptInterface.ScalarQuadraticFunction{T}, T}, g::MathOptInterface.ScalarNonlinearFunction) where T in MathOptInterface.Utilities at /Users/oscar/.julia/dev/MathOptInterface/src/Utilities/operate.jl:423

a = promote_rule(F::Type{MathOptInterface.ScalarQuadraticFunction{T}}, ::Type{T}) where T in MathOptInterface.Utilities at /Users/oscar/.julia/dev/MathOptInterface/src/Utilities/functions.jl:2274
b = promote_rule(F::Type{var"#s288"} where var"#s288"<:Union{MathOptInterface.ScalarAffineFunction, MathOptInterface.ScalarQuadraticFunction}, ::Type{MathOptInterface.VariableIndex}) in MathOptInterface.Utilities at /Users/oscar/.julia/dev/MathOptInterface/src/Utilities/functions.jl:2281

a = *(f::Union{MathOptInterface.ScalarAffineFunction{T}, MathOptInterface.ScalarQuadraticFunction{T}, MathOptInterface.VectorAffineFunction{T}, MathOptInterface.VectorQuadraticFunction{T}}, g::T) where T in MathOptInterface.Utilities at /Users/oscar/.julia/dev/MathOptInterface/src/Utilities/functions.jl:1666
b = *(::Any, ::ChainRulesCore.ZeroTangent) in ChainRulesCore at /Users/oscar/.julia/packages/ChainRulesCore/a4mIA/src/tangent_arithmetic.jl:105

a = *(f::T, g::Union{MathOptInterface.ScalarAffineFunction{T}, MathOptInterface.ScalarQuadraticFunction{T}, MathOptInterface.VectorAffineFunction{T}, MathOptInterface.VectorQuadraticFunction{T}}) where T in MathOptInterface.Utilities at /Users/oscar/.julia/dev/MathOptInterface/src/Utilities/functions.jl:1678
b = *(::ChainRulesCore.NoTangent, ::Any) in ChainRulesCore at /Users/oscar/.julia/packages/ChainRulesCore/a4mIA/src/tangent_arithmetic.jl:64

a = promote_rule(F::Type{MathOptInterface.ScalarAffineFunction{T}}, ::Type{T}) where T in MathOptInterface.Utilities at /Users/oscar/.julia/dev/MathOptInterface/src/Utilities/functions.jl:2267
b = promote_rule(F::Type{var"#s288"} where var"#s288"<:Union{MathOptInterface.ScalarAffineFunction, MathOptInterface.ScalarQuadraticFunction}, ::Type{MathOptInterface.VariableIndex}) in MathOptInterface.Utilities at /Users/oscar/.julia/dev/MathOptInterface/src/Utilities/functions.jl:2281

a = *(f::Union{MathOptInterface.ScalarAffineFunction{T}, MathOptInterface.ScalarQuadraticFunction{T}, MathOptInterface.VectorAffineFunction{T}, MathOptInterface.VectorQuadraticFunction{T}}, g::T) where T in MathOptInterface.Utilities at /Users/oscar/.julia/dev/MathOptInterface/src/Utilities/functions.jl:1666
b = *(::Any, x::ChainRulesCore.NotImplemented) in ChainRulesCore at /Users/oscar/.julia/packages/ChainRulesCore/a4mIA/src/tangent_arithmetic.jl:38

a = *(f::T, g::Union{MathOptInterface.ScalarAffineFunction{T}, MathOptInterface.ScalarQuadraticFunction{T}, MathOptInterface.VectorAffineFunction{T}, MathOptInterface.VectorQuadraticFunction{T}}) where T in MathOptInterface.Utilities at /Users/oscar/.julia/dev/MathOptInterface/src/Utilities/functions.jl:1678
b = *(x::ChainRulesCore.NotImplemented, ::Any) in ChainRulesCore at /Users/oscar/.julia/packages/ChainRulesCore/a4mIA/src/tangent_arithmetic.jl:37

a = get(::MathOptInterface.Bridges.Constraint._AbstractSlackBridge{T, VF, ZS, F, S} where S, ::MathOptInterface.NumberOfConstraints{F, ZS}) where {T, VF, ZS, F} in MathOptInterface.Bridges.Constraint at /Users/oscar/.julia/dev/MathOptInterface/src/Bridges/Constraint/bridges/slack.jl:21
b = get(::MathOptInterface.Bridges.Constraint._AbstractSlackBridge{T, VF, ZS, F, S}, ::MathOptInterface.NumberOfConstraints{VF, S}) where {T, VF, ZS, F, S} in MathOptInterface.Bridges.Constraint at /Users/oscar/.julia/dev/MathOptInterface/src/Bridges/Constraint/bridges/slack.jl:28

a = operate(::typeof(-), ::Type{T}, f::MathOptInterface.ScalarQuadraticFunction{T}, g::Union{MathOptInterface.VariableIndex, MathOptInterface.ScalarAffineFunction{T}, MathOptInterface.ScalarQuadraticFunction{T}, T}) where T in MathOptInterface.Utilities at /Users/oscar/.julia/dev/MathOptInterface/src/Utilities/operate.jl:394
b = operate(::typeof(-), ::Type{T}, f::Union{MathOptInterface.VariableIndex, MathOptInterface.ScalarAffineFunction{T}, MathOptInterface.ScalarNonlinearFunction, MathOptInterface.ScalarQuadraticFunction{T}, T}, g::MathOptInterface.ScalarNonlinearFunction) where T in MathOptInterface.Utilities at /Users/oscar/.julia/dev/MathOptInterface/src/Utilities/operate.jl:423

a = *(f::Union{MathOptInterface.VariableIndex, MathOptInterface.ScalarAffineFunction{T}, MathOptInterface.ScalarQuadraticFunction{T}} where T, g::Union{MathOptInterface.VariableIndex, MathOptInterface.ScalarAffineFunction{T}, MathOptInterface.ScalarQuadraticFunction{T}} where T, args::Union{MathOptInterface.VariableIndex, MathOptInterface.ScalarAffineFunction{T}, MathOptInterface.ScalarQuadraticFunction{T}} where T...) in MathOptInterface.Utilities at /Users/oscar/.julia/dev/MathOptInterface/src/Utilities/functions.jl:1572
b = *(f::T, g::Union{MathOptInterface.ScalarAffineFunction{T}, MathOptInterface.ScalarQuadraticFunction{T}, MathOptInterface.VectorAffineFunction{T}, MathOptInterface.VectorQuadraticFunction{T}}) where T in MathOptInterface.Utilities at /Users/oscar/.julia/dev/MathOptInterface/src/Utilities/functions.jl:1678

a = operate(::typeof(+), ::Type{T}, f::MathOptInterface.ScalarQuadraticFunction{T}, g::Union{MathOptInterface.VariableIndex, MathOptInterface.ScalarAffineFunction{T}, MathOptInterface.ScalarQuadraticFunction{T}, T}) where T in MathOptInterface.Utilities at /Users/oscar/.julia/dev/MathOptInterface/src/Utilities/operate.jl:145
b = operate(::typeof(+), ::Type{T}, f::Union{MathOptInterface.VariableIndex, MathOptInterface.ScalarAffineFunction{T}, MathOptInterface.ScalarNonlinearFunction, MathOptInterface.ScalarQuadraticFunction{T}, T}, g::MathOptInterface.ScalarNonlinearFunction) where T in MathOptInterface.Utilities at /Users/oscar/.julia/dev/MathOptInterface/src/Utilities/operate.jl:174

a = dot(func::Union{MathOptInterface.ScalarAffineFunction{T}, MathOptInterface.ScalarQuadraticFunction{T}, MathOptInterface.VectorAffineFunction{T}, MathOptInterface.VectorQuadraticFunction{T}}, α::T) where T in MathOptInterface.Utilities at /Users/oscar/.julia/dev/MathOptInterface/src/Utilities/functions.jl:1761
b = dot(::Any, ::ChainRulesCore.ZeroTangent) in ChainRulesCore at /Users/oscar/.julia/packages/ChainRulesCore/a4mIA/src/tangent_arithmetic.jl:108

a = dot::T, func::Union{MathOptInterface.ScalarAffineFunction{T}, MathOptInterface.ScalarQuadraticFunction{T}, MathOptInterface.VectorAffineFunction{T}, MathOptInterface.VectorQuadraticFunction{T}}) where T in MathOptInterface.Utilities at /Users/oscar/.julia/dev/MathOptInterface/src/Utilities/functions.jl:1760
b = dot(x::ChainRulesCore.NotImplemented, ::Any) in ChainRulesCore at /Users/oscar/.julia/packages/ChainRulesCore/a4mIA/src/tangent_arithmetic.jl:39

a = operate(::typeof(-), ::Type{T}, f::MathOptInterface.VariableIndex, g::T) where T in MathOptInterface.Utilities at /Users/oscar/.julia/dev/MathOptInterface/src/Utilities/operate.jl:347
b = operate(::typeof(-), ::Type{T}, f::Union{MathOptInterface.VariableIndex, MathOptInterface.ScalarAffineFunction{T}, MathOptInterface.ScalarNonlinearFunction, MathOptInterface.ScalarQuadraticFunction{T}, T}, g::MathOptInterface.ScalarNonlinearFunction) where T in MathOptInterface.Utilities at /Users/oscar/.julia/dev/MathOptInterface/src/Utilities/operate.jl:423

@blegat
Copy link
Member

blegat commented Jun 24, 2023

I think it's find to assume T<:Number

@odow
Copy link
Member Author

odow commented Jun 25, 2023

},
) where {T}
return g * f
end
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is breaking, but only in the sense that it was never documented or expected to work. having functions with non-number coefficients is just asking for trouble.

It's also weird because this is the only case where we'd expect things to work. You can't do *(::NonNumber, ::VariableIndex)

@@ -1697,7 +1669,7 @@ function Base.:/(
MOI.VectorQuadraticFunction{T},
},
g::T,
) where {T}
) where {T<:Number}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto here. The method below assumes Number, so these are really inconsistent and a bug fix.

@@ -641,7 +641,7 @@ function check_type_and_multiple_names(
value::T,
::Nothing,
name,
) where {T}
) where {T<:MOI.Index}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is non-breaking and just a pure fix.

@odow odow changed the title [Utilities] fix ambiguity with MutableArithmetics Fix method ambiguities and limit operate to Number subtypes Jun 26, 2023
@odow
Copy link
Member Author

odow commented Jun 26, 2023

I think I'm okay marking this as a bug-fix. We certainly never intended for MOI to work with non-number coefficients, and only a very small subset of methods would currently work.

@odow
Copy link
Member Author

odow commented Jun 27, 2023

Updated solver-tests, now with JuMP extensions: https://github.com/jump-dev/MathOptInterface.jl/actions/runs/5395649560

@odow
Copy link
Member Author

odow commented Jun 28, 2023

@blegat I guess we should hold off on this until SumOfSquares and PolyJuMP are installable and passing tests?

@odow
Copy link
Member Author

odow commented Jul 2, 2023

@odow
Copy link
Member Author

odow commented Jul 2, 2023

@blegat solver-tests looks good on this PR, so I think we're okay to merge?

@odow odow mentioned this pull request Jul 2, 2023
3 tasks
@blegat
Copy link
Member

blegat commented Jul 4, 2023

Yes, we can merge

@chriscoey
Copy link
Contributor

@odow I'd like to be able to replace the following logic (where f is often an SNF):

function canonicalize_SNF(::Type{T}, f) where {T <: Real}
    try
        f = convert(MOI.ScalarQuadraticFunction{T}, f)
        try
            f = convert(MOI.ScalarAffineFunction{T}, f)
        catch end
    catch end
    return f
end

with a single "canonicalize" call, like e.g. f = canonicalize(T, f), or something like that. Is that doable?

@odow
Copy link
Member Author

odow commented Aug 1, 2023

Rebased and re-ran solver-tests: https://github.com/jump-dev/MathOptInterface.jl/actions/runs/5732403691

@odow
Copy link
Member Author

odow commented Aug 1, 2023

@chriscoey let's talk about this separately. You'd probably need to write something like that in your own package. I don't know if we want it in MOI.

@odow
Copy link
Member Author

odow commented Aug 2, 2023

All solver-tests passing, so I think we're good to go. I'll wait for @blegat to take another look, since it has been a while.

@odow odow merged commit b1f7515 into master Aug 2, 2023
47 of 50 checks passed
@odow odow deleted the od/fix-ambiguity branch August 2, 2023 20:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

MutableArithmetics/MathOptInterface ambiguity with v1.18.0
3 participants