Skip to content

Resolve dynamic initialization of Param values - #4048

Open
jsiirola wants to merge 10 commits into
Pyomo:mainfrom
jsiirola:param-init-fixes
Open

jsiirola wants to merge 10 commits into
Pyomo:mainfrom
jsiirola:param-init-fixes

Conversation

@jsiirola

@jsiirola jsiirola commented Oct 5, 2026

Copy link
Copy Markdown
Member

Fixes #4009; supersedes #4030

Summary/Motivation:

#4009 identified a bug where some Params were not being correctly initialized when instantiated outside of Param.construct(). While Params with default values were being correctly initialized, _getitem_when_not_present was not checking if the initializer (rule= / initialize=) could have provided a value (which is the case for constant initializers and initializers that call out to general functions).

This PR resolves the issue by also checking the rule for initial values when creating / returning param values outside of construct()

Changes proposed in this PR:

  • Update Param default= handling to leverage the Initializer infrastructure
  • Update _getitem_when_not_present to check the rule before falling back on the default.
  • Add tests (including updating some DAE tests that now no longer raise exceptions)

AI-Use Disclosure

  • AI tools were NOT used during the preparation of this PR

or

  • AI tools contributed to the development of this PR

    • AI tools generated documentation (including the PR description/comments, code comments, and/or Sphinx documentation)
    • AI tools generated tests (baselines, examples, and/or code)
    • AI tools generated code (apart from tests)

    Review process (select ONE):

    • Rewritten: All AI-generated content was rewritten by me before being committed.
    • Reviewed/verified: I retained AI-generated content and verified it before committing. Verification included (as applicable):
      • Ran the code and fixed issues
      • Added and ran tests
      • Checked correctness/logic of code and tests
      • Checked for alignment with the contribution guide
      • Considered security implications
    • As-is: AI-generated content was commited directly to the repository

Notes for reviewers (optional):

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.

@codecov

codecov Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.38710% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 90.13%. Comparing base (170f653) to head (f425201).

Files with missing lines Patch % Lines
pyomo/core/base/param.py 98.38% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4048      +/-   ##
==========================================
+ Coverage   89.96%   90.13%   +0.16%     
==========================================
  Files         917      917              
  Lines      109282   109298      +16     
==========================================
+ Hits        98311    98511     +200     
+ Misses      10971    10787     -184     
Flag Coverage Δ
builders 29.12% <19.35%> (+<0.01%) ⬆️
default 86.13% <98.38%> (?)
expensive 35.09% <25.80%> (?)
linux 87.66% <98.38%> (-1.81%) ⬇️
linux_other 87.66% <98.38%> (+0.17%) ⬆️
oldsolvers 28.01% <19.35%> (-0.01%) ⬇️
osx 83.11% <98.38%> (-0.01%) ⬇️
win 85.42% <98.38%> (-0.01%) ⬇️

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

☔ View full report in Codecov by Harness.
📢 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.

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.

Params indexed by ContinuousSets are not initialized when the set is discretized.

2 participants