Skip to content

Scaling warning#1658

Merged
dallan-keylogic merged 7 commits intoIDAES:scaling_toolboxfrom
dallan-keylogic:scaling_warning
Sep 16, 2025
Merged

Scaling warning#1658
dallan-keylogic merged 7 commits intoIDAES:scaling_toolboxfrom
dallan-keylogic:scaling_warning

Conversation

@dallan-keylogic
Copy link
Contributor

Summary/Motivation:

Add a warning when trying to get a scaling factor and it does not exist.

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 changed the base branch from main to scaling_toolbox September 8, 2025 14:41
@dallan-keylogic dallan-keylogic self-assigned this Sep 8, 2025
Copy link
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

codecov bot commented Sep 8, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.09%. Comparing base (903b71e) to head (b099061).
⚠️ Report is 30 commits behind head on scaling_toolbox.

Additional details and impacted files
@@               Coverage Diff                @@
##           scaling_toolbox    #1658   +/-   ##
================================================
  Coverage            77.09%   77.09%           
================================================
  Files                  395      395           
  Lines                63165    63167    +2     
  Branches             10370    10371    +1     
================================================
+ Hits                 48696    48698    +2     
  Misses               12021    12021           
  Partials              2448     2448           

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

except (AttributeError, KeyError):
# No scaling factor found, return the default value
if warning:
_log.warning(f"Missing scaling factor for {component.name}")
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we make the user aware that he or she can add a default, but preferably, should add an appropriate scaling factor?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because of the way the scaling toolbox is set up now, values in the default dictionary will be ignored unless the scaler object specifically calls scale_variable_by_default (see #1648 item 3).

except (AttributeError, KeyError):
# No scaling factor found, return the default value
if warning:
_log.warning(f"Missing scaling factor for {component.name}")
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm concerned this warning will result in a huge log output for many cases where users don't have scaling, or don't want/need to scale everything. Can we use this error check as a debug step, like a certain level of info reporting but otherwise don't display for every component? The current "missing scaling suffix" warnings can already get very verbose.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We thought about that, but having the log output is a lesser evil than either 1) having an exception thrown or 2) having the scaling silently fail.

There were two contributing reasons to the log spam using the old tools. First, many times the scaling routines were looking for scaling factors in the wrong places, e.g., looking for scaling factors on an indexed Var when scaling factors had been set for the VarData children of that indexed Var. Now an exception is thrown if the user tries to call get_scaling_factor on an indexed Var. Second, the old scaling tools demanded the user set scaling factors for a ton of variables at the ControlVolume level, such as for heat, mass transfer, extent of reaction, etc. The ControlVolume0DScaler provides a reasonable initial guess for those scaling factors that should work for most use cases. Finally, we're now going to raise an exception if the user doesn't provide default scaling factors for the modular properties, so they'll be forced to provide a bare minimum of scaling.

Ideally, now the warning will be shown only if something has gone seriously wrong with scaling, either because a scaler was written incorrectly or there was no scaler written for the property package in question. We'll see how it works in practice.

One thing I'd like to do is enable the Pytest option that turns warnings into exceptions to catch any issues in the main repository. We still need to 1) write a log filter object to get rid of the Pyomo warnings about elements of a suffix not being exported (so the end user of IDAES doesn't even know Pyomo is logging those warnings) and 2) figure out a way to filter out warnings from the old scaling tools when tests are run.

@ksbeattie ksbeattie added the Priority:Normal Normal Priority Issue or PR label Sep 11, 2025
@dallan-keylogic dallan-keylogic merged commit 6078e44 into IDAES:scaling_toolbox Sep 16, 2025
39 checks passed
@dallan-keylogic dallan-keylogic deleted the scaling_warning branch September 16, 2025 15:26
dallan-keylogic added a commit that referenced this pull request Nov 6, 2025
* error for unnamed expressions

* pylint

* default is warning=False

* make sure expression walker doesn't emit warnings

* rescue files from different branch

* tests for scaler base get_scaling_factor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Priority:Normal Normal Priority Issue or PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants