-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IX model small fix for anions in demo #1420
IX model small fix for anions in demo #1420
Conversation
This issue was likely making the Langmuir IX model unsolvable for anions since it was calculating a negative value for |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1420 +/- ##
=======================================
Coverage 94.01% 94.01%
=======================================
Files 335 335
Lines 35561 35570 +9
=======================================
+ Hits 33431 33442 +11
+ Misses 2130 2128 -2 ☔ View full report in Codecov by Sentry. |
@@ -1053,7 +1054,7 @@ def eq_partition_ratio(b): | |||
self.target_ion_set, doc="Removed total mass of ion in equivalents" | |||
) | |||
def eq_mass_removed(b, j): | |||
charge = prop_in.charge_comp[j] | |||
charge = abs(value(prop_in.charge_comp[j])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't know if this would be overkill, but would it be safer to use smooth_abs
? One potential scenario could be that the charge for a particular component is unknown, and we set it as a var to estimate. I think in that case, you'd want something like smooth_abs
. I don't know how likely that scenario is, but just thinking out loud on whether we think it's fine to just use abs
here for the long run.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe the compromise is to use pyo.environ.abs
.
If this value is fixed but the user updates it for some reason you'll still get the correct value put to the solver.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
smooth_abs
would have no effect in this case as written as you are using value
inside the abs
; i.e. it is effectively a constant and not a variable. However, that does lead me to ask if this is the intended behaviour, as with the value
in there this is now just a constant and thus will not change if the value of the variable is changed later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't know if this would be overkill, but would it be safer to use
smooth_abs
? One potential scenario could be that the charge for a particular component is unknown, and we set it as a var to estimate. I think in that case, you'd want something likesmooth_abs
. I don't know how likely that scenario is, but just thinking out loud on whether we think it's fine to just useabs
here for the long run.
A target_ion
with an unknown charge should raise a ConfigurationError
for this model. I also think if we were in a situation where we were trying to predict the charge of an unknown component, we would likely need a different model.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe the compromise is to use
pyo.environ.abs
.If this value is fixed but the user updates it for some reason you'll still get the correct value put to the solver.
I tried this initially (i.e., from pyomo.environ import abs
) and it resulted in an ImportError
. Could it exist elsewhere in pyomo?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
smooth_abs
would have no effect in this case as written as you are usingvalue
inside theabs
; i.e. it is effectively a constant and not a variable. However, that does lead me to ask if this is the intended behaviour, as with thevalue
in there this is now just a constant and thus will not change if the value of the variable is changed later.
Yes this is the intended behavior - the value of charge_comp
(a Param
) must be either positive or negative to use the model, and would be set as part of the configuration of the property package (it is checked at the beginning of the build for this model) . It is assumed it is a fundamental property of the solute and wouldn't change later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, it is currently a Param. I guess I was just thinking of a use case of my own, where I might need to set charge_comp as a Var for parameter estimation since, in that use case, the charge is unknown (just know it should be negative). But- right now charge_comp is just a Param so shouldn’t matter at this point.
@@ -1053,7 +1054,7 @@ def eq_partition_ratio(b): | |||
self.target_ion_set, doc="Removed total mass of ion in equivalents" | |||
) | |||
def eq_mass_removed(b, j): | |||
charge = prop_in.charge_comp[j] | |||
charge = abs(value(prop_in.charge_comp[j])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is prop_in.charge_comp[j]
a parameter which should never change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct, should never change and is set as part of the property package configuration.
@@ -1053,7 +1054,7 @@ def eq_partition_ratio(b): | |||
self.target_ion_set, doc="Removed total mass of ion in equivalents" | |||
) | |||
def eq_mass_removed(b, j): | |||
charge = prop_in.charge_comp[j] | |||
charge = abs(value(prop_in.charge_comp[j])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe the compromise is to use pyo.environ.abs
.
If this value is fixed but the user updates it for some reason you'll still get the correct value put to the solver.
Co-authored-by: bknueven <30801372+bknueven@users.noreply.github.com>
Fixes/Resolves:
While writing the docs for the IX flowsheet, the anion demos would not solve easily (we were not testing them). This is a quick fix for easier solvability of the anions in the IX demo flowsheet.
Summary/Motivation:
Ensure the IX demo will work for the anions.
Changes proposed in this PR:
abs(value(charge))
to calculatemass_removed
for IX langmuir modelLegal Acknowledgement
By contributing to this software project, I agree to the following terms and conditions for my contribution: