Skip to content

Conversation

AayushSabharwal
Copy link
Contributor

Continuation of #334

@AayushSabharwal AayushSabharwal force-pushed the as+bl/simplify_promote_type_fallback branch from 68975a9 to f99b96a Compare August 18, 2025 14:42
@AayushSabharwal
Copy link
Contributor Author

The JuMP tests fail because

MA.promote_operation(MA.add_mul, QuadExpr, Int, GenericQuadExpr{ComplexF64, VariableRef})

returns

GenericQuadExpr{CoefType, VariableRef} where CoefType

instead of

GenericQuadExpr{ComplexF64, VariableRef}

as it did before

@odow
Copy link
Member

odow commented Aug 19, 2025

The answer should be GenericQuadExpr{ComplexF64, VariableRef}. I won't want to break the JuMP tests for this.

@blegat
Copy link
Member

blegat commented Aug 19, 2025

We can fix it with a PR to JuMP. At the moment, it's a performance issue with JuMP since the corresponding MA.operate!! is allocating when using MA.promote_operation. So we can make a PR to JuMP and add an @allocated test to check that it stops allocating

@odow
Copy link
Member

odow commented Aug 20, 2025

Do you mean this method?
https://github.com/jump-dev/JuMP.jl/blob/4b60a84a0f6766396fb0580b0726be300dfae04f/src/mutable_arithmetics.jl#L291-L303

julia> using JuMP

julia> import JuMP._MA as MA

julia> begin
           model = Model()
           @variable(model, x)
           ret = zero(QuadExpr)
           f = (1.0 + 2.0im) * x^2
           MA.add_mul(ret, 2, f)
       end
(2 + 4im) x²

What do you want to fix in JuMP?

@AayushSabharwal
Copy link
Contributor Author

In JuMP, MA.promote_operation will currently allocate in the fallback method

Copy link

codecov bot commented Aug 22, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.55%. Comparing base (e470c6b) to head (777be85).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #335      +/-   ##
==========================================
+ Coverage   90.50%   90.55%   +0.05%     
==========================================
  Files          22       22              
  Lines        2253     2265      +12     
==========================================
+ Hits         2039     2051      +12     
  Misses        214      214              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@blegat
Copy link
Member

blegat commented Aug 22, 2025

Should be fixed by jump-dev/JuMP.jl#4057

@AayushSabharwal AayushSabharwal force-pushed the as+bl/simplify_promote_type_fallback branch from f99b96a to 2e089c2 Compare September 12, 2025 08:47
@AayushSabharwal AayushSabharwal force-pushed the as+bl/simplify_promote_type_fallback branch 3 times, most recently from 61de1dd to 8d48c21 Compare September 15, 2025 11:22
if isconcretetype(S) && isconcretetype(T)
return typeof(op(_instantiate_zero(S), _instantiate_zero(T)))
else
return promote_type(S, T)
Copy link
Member

Choose a reason for hiding this comment

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

Not covered by tests

if isconcretetype(S) && isconcretetype(T)
return typeof(op(_instantiate_zero(S), _instantiate_oneunit(T)))
else
return promote_type(S, T)
Copy link
Member

Choose a reason for hiding this comment

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

Not covered by tests

::Union{typeof(real),typeof(imag)},
::Type{Complex{T}},
) where {T}
return T
Copy link
Member

Choose a reason for hiding this comment

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

Not covered by tests

src/interface.jl Outdated
::Type{S},
::Type{LinearAlgebra.UniformScaling{T}},
) where {S,T}
return promote_operation(op, S, T)
Copy link
Member

Choose a reason for hiding this comment

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

How is this related to this PR ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

promote_type(Number, LinearAlgebra.UniformScaling{Bool}) ends up as Any, which is incorrect.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, this is avoidable

@AayushSabharwal AayushSabharwal force-pushed the as+bl/simplify_promote_type_fallback branch 2 times, most recently from afc95c1 to aaa3e5c Compare September 16, 2025 13:03
end

function promote_operation_fallback(
::Union{typeof(real),typeof(imag)},
Copy link
Member

Choose a reason for hiding this comment

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

This should be promote_operation, it's not a fallback

@AayushSabharwal AayushSabharwal force-pushed the as+bl/simplify_promote_type_fallback branch from aaa3e5c to 777be85 Compare September 16, 2025 16:24
@blegat blegat merged commit 2bffb5f into jump-dev:master Sep 17, 2025
11 checks passed
@AayushSabharwal AayushSabharwal deleted the as+bl/simplify_promote_type_fallback branch September 18, 2025 13:48
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.

3 participants