Skip to content

Don't copy ScalarNonlinearFunction in VectorOfConstraints #2803

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

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

blegat
Copy link
Member

@blegat blegat commented Aug 6, 2025

Extracted from #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.

@odow
Copy link
Member

odow commented Aug 7, 2025

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.

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.

2 participants