Skip to content

Conversation

@jsiirola
Copy link
Member

Fixes # .

Summary/Motivation:

This PR is primarily adding more comprehensive testing of templatizing (and compiling) linear models. As part of flusing out the tests, this resolves a number of issues / bugs in the templatizer, the linear template compiler, and in general Pyomo:

General Pyomo changes

  • Rework Param.extract_values to return defaultdict for Params with default values
  • Provide a specialized InvalidConstraintError exception for constraints that cannot be emitted to the solvers
  • Use SetOf when iterating over IndexedComponent objects indexed by non-finite Sets
  • SetOf.dimen should return UnknownSetDimen (not 0) if the underlying reference has no data

Updates to the templatizer

  • Leverage attempt_import to break circular dependencies in template_expr
  • Catch UnknownSetDimen when iterating over template generators and treat like jagged sets
  • Expand (do not templatize) expressions with sum() that do not sum over generators
  • Expand (do not templatize) expressions with sum() whose generator doesn't create a template index
  • Expand (do not templatize) expressions with sum() that appear to iterate over things other than Pyomo Set objects

Updates to the linear template compiler

  • remove check_duplicates and remove_fixed_vars options (this is not more efficiently implementable through sparse matrix operations0
  • rework expression builders to be more testable and (slightly) more efficient
  • Support IndexedComponent.Skip
  • Resolve issue compiling constraints indexed by non-finite Sets

Changes proposed in this PR:

  • (see above)

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.

- iterate over the underlying reference when guessing the dimen
  This prevents recursion when templatizing.
- inconsistent dimen is reported as None
@codecov
Copy link

codecov bot commented Nov 11, 2025

Codecov Report

❌ Patch coverage is 96.17834% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.34%. Comparing base (4ce6049) to head (3d8e302).

Files with missing lines Patch % Lines
pyomo/core/base/param.py 86.66% 2 Missing ⚠️
pyomo/core/base/constraint.py 85.71% 1 Missing ⚠️
pyomo/repn/linear_template.py 98.70% 1 Missing ⚠️
pyomo/repn/plugins/lp_writer.py 50.00% 1 Missing ⚠️
pyomo/repn/plugins/standard_form.py 75.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3781      +/-   ##
==========================================
+ Coverage   89.24%   89.34%   +0.09%     
==========================================
  Files         907      907              
  Lines      104818   104866      +48     
==========================================
+ Hits        93548    93690     +142     
+ Misses      11270    11176      -94     
Flag Coverage Δ
builders 29.15% <16.56%> (+<0.01%) ⬆️
default 85.87% <96.17%> (?)
expensive 35.71% <21.65%> (?)
linux 86.79% <96.17%> (-2.22%) ⬇️
linux_other 86.79% <96.17%> (+0.10%) ⬆️
osx 82.92% <96.17%> (+0.10%) ⬆️
win 85.03% <96.17%> (+0.09%) ⬆️
win_other 85.03% <96.17%> (+0.09%) ⬆️

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.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@blnicho blnicho requested review from blnicho and emma58 November 11, 2025 19:51
@blnicho blnicho moved this from Todo to Review In Progress in Pyomo 6.10 Nov 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Review In Progress

Development

Successfully merging this pull request may close these issues.

1 participant