Skip to content

Commit 4c98be5

Browse files
committed
Don't copy ScalarNonlinearFunction in VectorOfConstraints
1 parent 1694a00 commit 4c98be5

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/Utilities/vector_of_constraints.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,14 @@ function MOI.get(
103103
) where {F,S}
104104
MOI.throw_if_not_valid(v, ci)
105105
f, _ = v.constraints[ci]::Tuple{F,S}
106-
return copy(f)
106+
# Since `MA.mutability(MOI.ScalarNonlinearFunction)` is `MA.IsNotMutable`,
107+
# this does not copy `MOI.ScalarNonlinearFunction`. This is important if the
108+
# function share aliases of the same subexpression at different parts of
109+
# it's expression graph or the expression graph of other functions of the
110+
# model. If we `copy`, they won't be aliases of the same subexpression
111+
# anymore hence `MOI.Nonlinear.ReverseAD` won't detect them as common
112+
# subexpressions.
113+
return MA.copy_if_mutable(f)
107114
end
108115

109116
function MOI.get(

0 commit comments

Comments
 (0)