MathOptInterface.jl icon indicating copy to clipboard operation
MathOptInterface.jl copied to clipboard

Don't copy ScalarNonlinearFunction in VectorOfConstraints

Open blegat opened this issue 5 months ago • 1 comments

Extracted from https://github.com/jump-dev/MathOptInterface.jl/pull/2788

I'm not too convinced by the current approach.

For canonical, I think we need to implement canonical with a cache that checks that it creates aliases when it sees a second time an alias to the same sub-expression.

For the copy in ConstraintFunction, I think we add it mostly to be extra-sure the user does not alter the function but we don't really need it in the context of MOI.copy_to since add_constraint specifies that the model should have its own copy. Maybe we should also have UnsafeConstraintFunction that is used inside MOI.copy_to, it should also safe wasteful copies for ScalarAffineFunction and ScalarQuadraticFunction. So if we have tests that checks that solvers have their own copies in add_constraint then it should be safe.

blegat avatar Aug 06 '25 07:08 blegat

I think the first step before we go making any changes to this is to come up with a large suite of benchmarks and tests. There are a number of subtle behaviors here.

odow avatar Aug 07 '25 03:08 odow