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

Nonlinear expressions illegally modify their children #3825

Closed
odow opened this issue Sep 13, 2024 · 1 comment · Fixed by #3826
Closed

Nonlinear expressions illegally modify their children #3825

odow opened this issue Sep 13, 2024 · 1 comment · Fixed by #3826
Labels

Comments

@odow
Copy link
Member

odow commented Sep 13, 2024

Found by lanl-ansi/PowerModelsDistribution.jl#459 (comment)

I don't know how we have't come across this before:

julia> using JuMP

julia> model = Model();

julia> @variable(model, x[1:2]);

julia> y = [NonlinearExpr(:+, Any[xi]) for xi in x]
2-element Vector{NonlinearExpr}:
 +(x[1])
 +(x[2])

julia> a = @expression(model, sum(y[i] for i in 1:2))
x[1] + x[2]

julia> y
2-element Vector{NonlinearExpr}:
 x[1] + x[2]
 +(x[2])

Note that y[1] has been modified.

@odow
Copy link
Member Author

odow commented Sep 13, 2024

This is the issue:

julia> using JuMP

julia> import JuMP._MA as MA

julia> model = Model();

julia> @variable(model, x);

julia> y = NonlinearExpr(:+, Any[x])
+(x)

julia> a = MA.operate!!(MA.add_mul, MA.Zero(), y)
+(x)

julia> a === y
true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging a pull request may close this issue.

1 participant