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

Enforce expression immutability in expr.args #3099

Merged
merged 5 commits into from
Jan 24, 2024

Conversation

jsiirola
Copy link
Member

Fixes #3096, superceeds #3098

Summary/Motivation:

This resolves #3096 by closing a loophole in the "immutability" of expressions. For efficiency, SumExpression makes use of a mutable data structure (list) for storing the node arguments. Prior to this PR, we would return the raw underlying argument list from SumExpression.args. There are, however, edge cases where modifying either the expression or an entangled expression can cause that list to change. This PR changes the SumExpression API so that SumExpression.args always makes a copy of the _args_ list, thereby ensuring that the interface preserves the immutability that users expect.

Note that this PR has a negative effect on performance in the form of a ~1% slow-down on LP and NL writers (as observed in the performance test suite).

Changes proposed in this PR:

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.

Copy link
Contributor

@michaelbynum michaelbynum left a comment

Choose a reason for hiding this comment

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

Thank you for this @jsiirola!!! Looks great. I'm about to take a look at the failing test.

@blnicho blnicho requested a review from emma58 January 23, 2024 19:48
Copy link

codecov bot commented Jan 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (85b63ab) 88.26% compared to head (0d00410) 88.26%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3099      +/-   ##
==========================================
- Coverage   88.26%   88.26%   -0.01%     
==========================================
  Files         832      832              
  Lines       92385    92345      -40     
==========================================
- Hits        81544    81504      -40     
  Misses      10841    10841              
Flag Coverage Δ
linux 86.01% <100.00%> (-0.01%) ⬇️
osx 75.53% <100.00%> (-0.02%) ⬇️
other 86.19% <100.00%> (-0.01%) ⬇️
win 83.42% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@michaelbynum michaelbynum merged commit 6b36613 into Pyomo:main Jan 24, 2024
33 checks passed
@jsiirola jsiirola deleted the immutable-expr-args branch January 25, 2024 04:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

EXPR.differentiate() get stuck for a quadratic expression with mode=reverse_symbolic
3 participants