Skip to content

Conversation

Ryan-Hughes-8
Copy link

Summary/Motivation:

Redoing the PR for creating scalers for the pressure changer and stoichiometric reactor unit models.

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.

Copy link

codecov bot commented Oct 2, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.15%. Comparing base (42e8728) to head (eafac4d).

Additional details and impacted files
@@                 Coverage Diff                 @@
##           scaling_toolbox    #1678      +/-   ##
===================================================
+ Coverage            77.11%   77.15%   +0.03%     
===================================================
  Files                  395      395              
  Lines                63727    63765      +38     
  Branches             10555    10567      +12     
===================================================
+ Hits                 49145    49195      +50     
+ Misses               12079    12077       -2     
+ Partials              2503     2493      -10     

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

Copy link
Contributor

@dallan-keylogic dallan-keylogic left a comment

Choose a reason for hiding this comment

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

Looks good. Just a handful of comments/changes.

Comment on lines 361 to 369
# for the isentropic assumption, a duplicate properties block is created from the unit model's
# property package and can be scaled by calling the properties scaler
if hasattr(model, "properties_isentropic"):
self.call_submodel_scaler_method(
submodel=model.properties_isentropic,
method="variable_scaling_routine",
submodel_scalers=submodel_scalers,
overwrite=overwrite,
)
Copy link
Contributor

Choose a reason for hiding this comment

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

You should propagate scaling factors from control_volume.properties_in to properties_isentropic.

Comment on lines 391 to 407
if hasattr(model, "work_fluid"):
for t in model.flowsheet().time:
self.scale_variable_by_component(
model.work_fluid[t], model.control_volume.work[t]
)

if hasattr(model, "work_isentropic"):
for t in model.flowsheet().time:
self.scale_variable_by_component(
model.work_isentropic[t], model.control_volume.work[t]
)

if hasattr(model, "work_mechanical"):
for t in model.flowsheet().time:
self.scale_variable_by_component(
model.work_mechanical[t], model.control_volume.work[t]
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Are all of these Vars, or is one of them a Reference to control_volume.work?

Copy link
Author

Choose a reason for hiding this comment

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

work_mechanical is a reference and was removed. The other two are Vars

Comment on lines +431 to +437
for c in model.component_data_objects(Constraint, descend_into=False):
self.scale_constraint_by_nominal_value(
c,
overwrite=overwrite,
)


Copy link
Contributor

Choose a reason for hiding this comment

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

Are you sure that this constraint scaling scheme is appropriate for every constraint in the model?

Copy link
Author

Choose a reason for hiding this comment

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

I tested this a couple ways. For a handful of example cases that include all of the thermodynamic assumptions, I tested each scheme applied to every constraint and inverseMaximum worked the best. The diagnostics toolbox also doesn't report any extreme constraints when using inverseMaximum .

I have a version that lists each constraint instead of this method of applying to every constraint that I can use instead. That way the scheme can be changed for a specific constraint if any problem arises in the future.

assert StoichiometricReactor().default_scaler == StoichiometricReactorScaler

@pytest.mark.integration
def test_example_case(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please split this into two tests? One should be a component test that checks the scaling factors, the other should be an integration test that performs the solve. You can use a pytest fixture with a "class" scope in order to use the same concrete model object throughout the test.

Copy link
Author

Choose a reason for hiding this comment

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

Added this in new commits. The StoichiometricReactor unit model doesn't have any of its own variables or constraints to test, so I descended into control_volume , properties_in, and properties_out to test scaling factors.

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.

2 participants