-
-
Notifications
You must be signed in to change notification settings - Fork 399
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
Allocations in MA (or possibly JuMP) #3936
Comments
I did a binary search and this is not MA fault. The issue is something from JuMP 1.23.5 release |
Probably this: #3883 |
We should investigate ways to opt-in to this only if needed: Lines 259 to 261 in 41db3c3
|
For my future reference, see these examples: julia> using JuMP
julia> model = Model();
julia> @variable(model, x);
julia> @expression(model, expr, 2 * x);
julia> @macroexpand @constraint(model, 0 <= expr <= 1)
quote
#= REPL[28]:1 =#
JuMP._valid_model(model, :model)
begin
#= /Users/oscar/.julia/packages/JuMP/CU7H5/src/macros.jl:399 =#
let model = model
#= /Users/oscar/.julia/packages/JuMP/CU7H5/src/macros.jl:400 =#
begin
#= /Users/oscar/.julia/packages/JuMP/CU7H5/src/macros/@constraint.jl:171 =#
begin
#= /Users/oscar/.julia/packages/JuMP/CU7H5/src/macros/@constraint.jl:482 =#
var"#135###261" = (MutableArithmetics).copy_if_mutable(expr)
#= /Users/oscar/.julia/packages/JuMP/CU7H5/src/macros/@constraint.jl:483 =#
var"#136###262" = (MutableArithmetics).copy_if_mutable(0)
#= /Users/oscar/.julia/packages/JuMP/CU7H5/src/macros/@constraint.jl:484 =#
var"#137###263" = (MutableArithmetics).copy_if_mutable(1)
end
#= /Users/oscar/.julia/packages/JuMP/CU7H5/src/macros/@constraint.jl:172 =#
var"#138#build" = JuMP.model_convert(model, JuMP.build_constraint(JuMP.Containers.var"#error_fn#98"{String}("At REPL[28]:1: `@constraint(model, 0 <= expr <= 1)`: "), var"#135###261", var"#136###262", var"#137###263"))
#= /Users/oscar/.julia/packages/JuMP/CU7H5/src/macros/@constraint.jl:173 =#
JuMP.add_constraint(model, var"#138#build", "")
end
end
end
end There's also this example that we could be cleverer about: julia> using JuMP
julia> model = Model();
julia> @variable(model, x);
julia> @expression(model, expr, 2 * x);
julia> @macroexpand @constraint(model, expr <= 0)
quote
#= REPL[33]:1 =#
JuMP._valid_model(model, :model)
begin
#= /Users/oscar/.julia/packages/JuMP/CU7H5/src/macros.jl:399 =#
let model = model
#= /Users/oscar/.julia/packages/JuMP/CU7H5/src/macros.jl:400 =#
begin
#= /Users/oscar/.julia/packages/JuMP/CU7H5/src/macros/@constraint.jl:171 =#
begin
#= /Users/oscar/.julia/packages/JuMP/CU7H5/src/macros.jl:264 =#
var"#155###267" = begin
#= /Users/oscar/.julia/packages/MutableArithmetics/bmgkg/src/rewrite.jl:374 =#
let
#= /Users/oscar/.julia/packages/MutableArithmetics/bmgkg/src/rewrite.jl:375 =#
begin
#= /Users/oscar/.julia/packages/MutableArithmetics/bmgkg/src/rewrite.jl:371 =#
var"#156###268" = (MutableArithmetics.copy_if_mutable)(expr)
var"#157###269" = (MutableArithmetics.operate!!)(MutableArithmetics.sub_mul, var"#156###268", 0)
end
#= /Users/oscar/.julia/packages/MutableArithmetics/bmgkg/src/rewrite.jl:376 =#
var"#157###269"
end
end
#= /Users/oscar/.julia/packages/JuMP/CU7H5/src/macros.jl:265 =#
var"#158###270" = (JuMP.flatten!)(var"#155###267")
end
#= /Users/oscar/.julia/packages/JuMP/CU7H5/src/macros/@constraint.jl:172 =#
var"#159#build" = JuMP.model_convert(model, JuMP.build_constraint(JuMP.Containers.var"#error_fn#98"{String}("At REPL[33]:1: `@constraint(model, expr <= 0)`: "), JuMP._functionize(var"#158###270"), LessThanZero()))
#= /Users/oscar/.julia/packages/JuMP/CU7H5/src/macros/@constraint.jl:173 =#
JuMP.add_constraint(model, var"#159#build", "")
end
end
end
end |
I don't know that there's much we can do here:
|
This actually has some interesting consequences: julia> model = Model();
julia> @variable(model, x);
julia> @expression(model, a[1:1], x+1)
1-element Vector{AffExpr}:
x + 1
julia> @expression(model, b[i in 1:1], a[i])
1-element Vector{AffExpr}:
x + 1
julia> add_to_expression!(a[1], 1)
x + 2
julia> a
1-element Vector{AffExpr}:
x + 2
julia> b
1-element Vector{AffExpr}:
x + 1 I think this is arguably the correct behavior, but JuMP 1.23.4 had: julia> using JuMP
julia> model = Model();
julia> @variable(model, x);
julia> @expression(model, a[1:1], x+1)
1-element Vector{AffExpr}:
x + 1
julia> @expression(model, b[i in 1:1], a[i])
1-element Vector{AffExpr}:
x + 1
julia> add_to_expression!(a[1], 1)
x + 2
julia> a
1-element Vector{AffExpr}:
x + 2
julia> b
1-element Vector{AffExpr}:
x + 2 |
Closing because I don't think there is much to do here. The regression is a bug fix. |
All using GenX 0.4.2 and their case data: https://github.com/GenXProject/GenX.jl/tree/main/example_systems/8_three_zones_w_colocated_VRE_storage_electrolyzers
we started with:
After: jump-dev/MutableArithmetics.jl#303
(versions 1.5.1 and 1.5.2 lead to the same result above)
But more recently we got some extra allocations back
script:
The text was updated successfully, but these errors were encountered: