Skip to content

Default scaler objects for properties and reactions#1766

Merged
dallan-keylogic merged 13 commits intoIDAES:mainfrom
dallan-keylogic:default_scaler_object
Apr 17, 2026
Merged

Default scaler objects for properties and reactions#1766
dallan-keylogic merged 13 commits intoIDAES:mainfrom
dallan-keylogic:default_scaler_object

Conversation

@dallan-keylogic
Copy link
Copy Markdown
Contributor

@dallan-keylogic dallan-keylogic commented Apr 13, 2026

Fixes

Summary/Motivation:

When using the old scaling tools, we could set default scaling factors to use for all state blocks using a property package. With the new scaling tools, heretofore we have been forced to use changing the class attribute DEFAULT_SCALING_FACTORS. Global mutation is dangerous and ought be avoided when possible.

In this PR, I allow the user to specify a default scaler object to use for all instances of a property or reaction package in a flowsheet by setting the default_state_scaler_object or default_reaction_scaler_object on their respective parameter blocks.

Additionally, I fixed the issue with the default scaler object for scaler state and reaction blocks.

Legal Acknowledgement

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

  1. I agree my contributions are submitted under the license terms described in the LICENSE.txt file at the top level of this directory.
  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 dallan-keylogic marked this pull request as ready for review April 13, 2026 20:19
Copy link
Copy Markdown
Contributor

@MarcusHolly MarcusHolly left a comment

Choose a reason for hiding this comment

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

LGTM

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 13, 2026

Codecov Report

❌ Patch coverage is 70.17544% with 17 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.81%. Comparing base (6258f28) to head (ca73fd7).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
idaes/core/base/property_base.py 61.90% 8 Missing ⚠️
idaes/core/base/reaction_base.py 61.90% 8 Missing ⚠️
idaes/core/scaling/custom_scaler_base.py 93.33% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1766      +/-   ##
==========================================
- Coverage   73.83%   73.81%   -0.02%     
==========================================
  Files         419      419              
  Lines       66225    66274      +49     
  Branches    11122    11133      +11     
==========================================
+ Hits        48894    48919      +25     
- Misses      14794    14814      +20     
- Partials     2537     2541       +4     

☔ 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.

@dallan-keylogic dallan-keylogic added the CI:run-integration triggers_workflow: Integration label Apr 15, 2026
@idaes-build idaes-build removed the CI:run-integration triggers_workflow: Integration label Apr 15, 2026
Comment thread idaes/core/base/property_base.py Outdated
Comment on lines 120 to 125
# Python catches the error and raises its own AttributeError
# with its own message. Leave the error, though, in case
# the user looks through the code and ends up here.
raise AttributeError(
"{} has not assigned a StateBlock class to be associated "
"with this property package. Please contact the developer of "
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Does that mean we know that this will never happen? In that case we should preempt the default error with our own, or remove the error since it is never happening anyways. Same with other ones in this PR, and I think that will help you on code coverage as well.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No. What happens is that, if this error is triggered, either Python or the create-on-demand property framework will intercept this error in a try block, then raise its own AttributeError. I thought about removing the error message, but thought it still might be useful for users tracking down why they're getting an error.

self.recursive_cons2 = Constraint(expr=self.recursion1 == 1)

def _raise_exception(self):
# PYLINT-TODO
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What needs to be done here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure---I copied that class from the tests for ReactionBase, which also has that TODO. I think I can strip out a significant amount of those methods for the test.

@ksbeattie ksbeattie added the Priority:High High Priority Issue or PR label Apr 16, 2026
@dallan-keylogic dallan-keylogic added the CI:run-integration triggers_workflow: Integration label Apr 16, 2026
@idaes-build idaes-build removed the CI:run-integration triggers_workflow: Integration label Apr 16, 2026
@dallan-keylogic dallan-keylogic merged commit 886bb73 into IDAES:main Apr 17, 2026
43 of 44 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Priority:High High Priority Issue or PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants