Skip to content

LinearExpression should return tuples instead of lists#3751

Merged
mrmundt merged 2 commits intoPyomo:mainfrom
michaelbynum:lin_expr_tuples
Oct 17, 2025
Merged

LinearExpression should return tuples instead of lists#3751
mrmundt merged 2 commits intoPyomo:mainfrom
michaelbynum:lin_expr_tuples

Conversation

@michaelbynum
Copy link
Copy Markdown
Contributor

Fixes #3731.

Summary/Motivation:

Currently, it is possible to modify the linear_coefs and linear_vars of a LinearExpression, but those are not kept in sync with the args. See #3731. Also, expressions are supposed to be immutable.

Changes proposed in this PR:

  • Change LinearExpression so that linear_coefs and linear_vars return tuples instead of lists.

Legal Acknowledgement

By contributing to this software project, I have read the contribution guide and agree to the following terms and conditions for my contribution:

  1. I agree my contributions are submitted under the BSD license.
  2. I represent I am authorized to make the contributions and grant the license. If my employer has rights to intellectual property that includes these contributions, I represent that I have received permission to make contributions and grant the required license on behalf of that employer.

@michaelbynum michaelbynum requested a review from jsiirola October 15, 2025 02:34
Copy link
Copy Markdown
Contributor

@mrmundt mrmundt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to add a new test based on the issue that ensures the desired behavior is actually happening as intended?

@blnicho blnicho moved this from Todo to Review In Progress in Pyomo 6.9.5 Release Oct 15, 2025
@github-project-automation github-project-automation bot moved this from Review In Progress to Reviewer Approved in Pyomo 6.9.5 Release Oct 17, 2025
@jsiirola
Copy link
Copy Markdown
Member

@mrmundt I believe that the tests are already checking that .linear_coefs and .linear_vars now return tuples, so the original issue is being checked.

@mrmundt mrmundt merged commit 68c7a11 into Pyomo:main Oct 17, 2025
38 checks passed
@github-project-automation github-project-automation bot moved this from Reviewer Approved to Done in Pyomo 6.9.5 Release Oct 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

No open projects

Development

Successfully merging this pull request may close these issues.

LinearExpression out of sync

4 participants