Scale Variable from Definition Constraint#1690
Scale Variable from Definition Constraint#1690dallan-keylogic merged 8 commits intoIDAES:scaling_toolboxfrom
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## scaling_toolbox #1690 +/- ##
================================================
Coverage 77.30% 77.30%
================================================
Files 395 395
Lines 64166 64192 +26
Branches 10730 10736 +6
================================================
+ Hits 49603 49626 +23
- Misses 12072 12073 +1
- Partials 2491 2493 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| safety_mode: Flag about whether or not to screen named expressions to see if | ||
| "variable" appears in them. Screening them takes longer (especially for | ||
| extremely deep expression trees), but if we do not screen them we run | ||
| the risk of removing "variable" from "constraint" entirely. |
There was a problem hiding this comment.
Why is this true? The screening is not actually deleting components, is it?
There was a problem hiding this comment.
The screening is not deleting components, but replace_expressions is building a new expression in which every variable and named expression in the keys of replacement_map is replaced by the expression in the values of replacement_map. Since we're going to be using calculate_variable_from_constraint in order to get the scaling factor, we still need variable to show up in the replaced expression.
| f"Variable {variable} is indexed. Call with VarData " | ||
| "children instead." |
There was a problem hiding this comment.
Listing the index keys or "children" might be helpful if this is thrown.
There was a problem hiding this comment.
You mean iterate over variable to list every single VarData child? I don't think being bombarded with a list of the form
fs.unit.control_volume.material_holdup[0,0,"H2O"]
fs.unit.control_volume.material_holdup[0,0,"NaOH"]
fs.unit.control_volume.material_holdup[0,0, "EthylAcetate"]
fs.unit.control_volume.material_holdup[0,0, "SodiumAcetate"]
fs.unit.control_volume.material_holdup[0,0, "Ethanol"]
fs.unit.control_volume.material_holdup[0,0.1,"H2O"]
fs.unit.control_volume.material_holdup[0,0.1,"NaOH"]
fs.unit.control_volume.material_holdup[0,0.1, "EthylAcetate"]
fs.unit.control_volume.material_holdup[0,0.1, "SodiumAcetate"]
fs.unit.control_volume.material_holdup[0,0.1, "Ethanol"]
etc...
is going to be particularly helpful (unless they don't know the difference between an IndexedVar and VarData in the first place).
| var_set = ComponentSet(var for var in identify_variables(replaced_expr)) | ||
| if not (len(var_set) == 1 and variable in var_set): | ||
| raise BurntToast( | ||
| "Something has gone wrong in the variable replacement scheme. " |
There was a problem hiding this comment.
Maybe make this line a bit more formal sounding, since it's exposed to users.
There was a problem hiding this comment.
Something like "An unexpected failure has occurred in the variable replacement scheme. Pleas open an issue..."
There was a problem hiding this comment.
Theoretically, the user should never see this line---we handle the case of variable not appearing in constraint using the variable_in_constraint flag, while safety_mode should make sure that a named expression containing variable is not replaced. If we end up here anyway, it's because some unknown error has occurred, so we can't be more specific with the error message.
setup.py
Outdated
| # Concrete dependencies go in requirements[-dev].txt | ||
| install_requires=[ | ||
| "pyomo >= 6.9.3", | ||
| "pyomo == 6.9.4", # Temporary pin to avoid Pylint issues |
There was a problem hiding this comment.
Should we mark a TODO here, as well?
| var_set = ComponentSet(var for var in identify_variables(replaced_expr)) | ||
| if not (len(var_set) == 1 and variable in var_set): | ||
| raise BurntToast( | ||
| "Something has gone wrong in the variable replacement scheme. " |
There was a problem hiding this comment.
Something like "An unexpected failure has occurred in the variable replacement scheme. Pleas open an issue..."
| """ | ||
| Helper function for scale_variable_by_definition_constraint. | ||
|
|
||
| Walks the constraint to build a map between Variables or Expressions |
There was a problem hiding this comment.
This doesn't sound right to me. What is meant by "walks"? A synonym for "helps"?
* tweak scale_variable_by_definition_constraint to take scaling hints into account * pin pyomo * unused import * failing test * additional coverage * expressions no hints * respond to reviewer comments * more reviewer comments
Summary/Motivation:
Changes
scale_variable_from_definition_constraintto take scaling hints into account (which are extremely useful when dealing with enthalpy and energy terms).Also pins the Pyomo version to 6.9.4 until such time as #1683 is merged.
Legal Acknowledgement
By contributing to this software project, I agree to the following terms and conditions for my contribution: