Skip to content

SuffixFinder: look in context for "external" data objects#3844

Merged
blnicho merged 5 commits intoPyomo:mainfrom
jsiirola:suffix-finder-out-of-tree
Feb 12, 2026
Merged

SuffixFinder: look in context for "external" data objects#3844
blnicho merged 5 commits intoPyomo:mainfrom
jsiirola:suffix-finder-out-of-tree

Conversation

@jsiirola
Copy link
Copy Markdown
Member

Fixes #3800 .

Summary/Motivation:

This updates the SuffixFinder to always look in the Suffix attached to the context (root) block for Components / ComponentDatas that are not part of the context model hierarchy.

This resolves issues finding Suffixes for components that are part of References (i.e., they look like they are part of this tree, but are actually part of another tree elsewhere), and fixes #3800.

Changes proposed in this PR:

  • SuffixFinder: When looking up components attached to blocks outside of context, always check the Suffix on context before giving up

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.

@dallan-keylogic
Copy link
Copy Markdown

I can confirm this fixes the example in #3800. However, if a suffix is on the original model, the .nl reader ignores it---it looks for suffixes only on the temporary block.

# temporary_block_not_scaled.py
import pyomo.environ as pyo
from pyomo.util.subsystems import create_subsystem_block
# import idaes to allow use of ipopt
import idaes

m = pyo.ConcreteModel()
m.x = pyo.Var(initialize=1e-4, bounds=(0, None))
m.con = pyo.Constraint(expr=m.x ** 2 == 1+1e-12)
m.scaling_factor = pyo.Suffix(direction=pyo.Suffix.EXPORT)
m.scaling_factor[m.x] = 1e4

t_block = create_subsystem_block([m.con], [m.x])

solver_obj = pyo.SolverFactory("ipopt_v2")
solver_obj.config.writer_config.scale_model = True
solver_obj.options.max_iter = 0

print(f"x value: {m.x.value}")
solver_obj.solve(t_block)
# Value of 0.00999999 ~= 0.01 means that scaling suffix on m was ignored
print(f"x value: {m.x.value}")

This is a defensible design decision---if the user wants scaling on the temporary block, they should copy the scaling factors over themselves. (Indeed, this is what we do currently for PETSc in IDAES.) If this is how things are intended to work, then we can close #3800.

Thank you so much for getting this in before the Pyomo release.

@blnicho
Copy link
Copy Markdown
Member

blnicho commented Feb 11, 2026

@dallan-keylogic thanks for checking this fix. For now you still have to manually transfer any suffixes you want over to the temporary block. We have some follow-on ideas related to "Suffix References" which could help with this in the future but that won't make it for this release.

@github-project-automation github-project-automation bot moved this from Todo to Reviewer Approved in Pyomo 6.10 Feb 11, 2026
@codecov
Copy link
Copy Markdown

codecov bot commented Feb 12, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.73%. Comparing base (463954b) to head (6aec141).
⚠️ Report is 6 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3844   +/-   ##
=======================================
  Coverage   89.73%   89.73%           
=======================================
  Files         904      904           
  Lines      105871   105871           
=======================================
+ Hits        95006    95007    +1     
+ Misses      10865    10864    -1     
Flag Coverage Δ
builders 29.03% <0.00%> (+<0.01%) ⬆️
default 83.86% <100.00%> (?)
expensive 35.50% <0.00%> (?)
linux 86.84% <100.00%> (-2.64%) ⬇️
linux_other 86.84% <100.00%> (ø)
oldsolvers 29.87% <0.00%> (+<0.01%) ⬆️
osx 83.01% <100.00%> (ø)
win 85.07% <100.00%> (ø)
win_other 85.07% <100.00%> (ø)

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 merged commit 2a9f2a0 into Pyomo:main Feb 12, 2026
62 of 65 checks passed
@github-project-automation github-project-automation bot moved this from Reviewer Approved to Done in Pyomo 6.10 Feb 12, 2026
@jsiirola jsiirola deleted the suffix-finder-out-of-tree branch February 17, 2026 05:03
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
Status: Done

Development

Successfully merging this pull request may close these issues.

nl writer does not apply scaling factors on temporary block

3 participants