You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While attempting to alter units for properties to be used for calculation or to be returned as output, the user needs to set the oli_unit desired, which is part of a FixedKeysDict. Additionally, there is a pyomo_unit value that also needs to be updated to match the new oli_unit assigned. When changing units, the user shouldn't need to ensure that they update pyomo units in addition to setting the oli units.
If I attempt the following change, input_unit_set['molecularConcentration']['oli_unit'] = "mol/L",
I should then be able to print(input_unit_set['molecularConcentration']['pyomo_unit']) and see that "mol/L" is returned. However, as it stands now, I would need to set input_unit_set['molecularConcentration']['pyomo_unit'] = pyunits.mol/pyunits/L afterwards to avoid an erroneous mismatch between stated oli units and pyomo units.
Another issue is that for a given property, there is a set of acceptable units that OLI will be able to work with. Selecting an appropriate set of units for properties can result in erroneous results (or no results returned at all, without exceptions being raised). Thus, we should have predefined sets of valid entries for units per property, and if an invalid unit is supplied to a particular property, an exception should be raised.
Expected Behavior
What I was trying to implement (unsuccessfully so far) was the ability to automatically update new pyomo units after manually providing new oli_units. For example, I start with these defaults:
Later, if I attempt the following change, input_unit_set['molecularConcentration']['oli_unit'] = "mol/L",
I should then be able to print(input_unit_set['molecularConcentration']['pyomo_unit']) and see that "mol/L" is returned.
Steps to Reproduce
from pyomo.environ import units as pyunits
# used to execute OLI Cloud functions
from watertap.tools.oli_api.flash import Flash
from watertap.tools.oli_api.credentials import CredentialManager
from watertap.tools.oli_api.client import OLIApi
import os
if __name__ == "__main__":
credential_manager = CredentialManager(
encryption_key=os.environ["OLI_secret"],
config_file=path_to_credentials_file,
)
case= {
"Na_+": 130680,
"Cl_-": 351140,
"Mg_2+": 65940,
"Ca_2+": 21100,
"K_+": 20240,
"SO4_2-": 137250,
}
source_water = {
"temperature": 298.15,
"pressure": 101325,
"components": case,
"units": {
"temperature": pyunits.K,
"pressure": pyunits.Pa,
"molecularConcentration": pyunits.mg/pyunits.L,
},
}
f = Flash( )
print(f.input_unit_set["molecularConcentration"]["oli_unit"])
print(f.input_unit_set["molecularConcentration"]["pyomo_unit"])
# try setting new unit to oli_unit
f.input_unit_set["molecularConcentration"]["oli_unit"] = "mg"
# note that pyomo_unit will not match oli_unit, and user would have to manually correct
print(f.input_unit_set["molecularConcentration"]["pyomo_unit"])
Environment
OS: win64
Python: v3.8
WaterTAP: v0.12
Anything Else?
The relative path to where the FixedKeysDict is defined, which is what I was tinkering with to address this issue: watertap\tools\oli_api\util\fixed_keys_dict.py
The text was updated successfully, but these errors were encountered:
Description
While attempting to alter units for properties to be used for calculation or to be returned as output, the user needs to set the
oli_unit
desired, which is part of a FixedKeysDict. Additionally, there is apyomo_unit
value that also needs to be updated to match the newoli_unit
assigned. When changing units, the user shouldn't need to ensure that they update pyomo units in addition to setting the oli units.For example,
If I attempt the following change,
input_unit_set['molecularConcentration']['oli_unit'] = "mol/L"
,I should then be able to
print(input_unit_set['molecularConcentration']['pyomo_unit'])
and see that "mol/L" is returned. However, as it stands now, I would need to setinput_unit_set['molecularConcentration']['pyomo_unit'] = pyunits.mol/pyunits/L
afterwards to avoid an erroneous mismatch between stated oli units and pyomo units.Another issue is that for a given property, there is a set of acceptable units that OLI will be able to work with. Selecting an appropriate set of units for properties can result in erroneous results (or no results returned at all, without exceptions being raised). Thus, we should have predefined sets of valid entries for units per property, and if an invalid unit is supplied to a particular property, an exception should be raised.
Expected Behavior
What I was trying to implement (unsuccessfully so far) was the ability to automatically update new pyomo units after manually providing new oli_units. For example, I start with these defaults:
Later, if I attempt the following change,
input_unit_set['molecularConcentration']['oli_unit'] = "mol/L"
,I should then be able to
print(input_unit_set['molecularConcentration']['pyomo_unit'])
and see that "mol/L" is returned.Steps to Reproduce
Environment
Anything Else?
The relative path to where the FixedKeysDict is defined, which is what I was tinkering with to address this issue:
watertap\tools\oli_api\util\fixed_keys_dict.py
The text was updated successfully, but these errors were encountered: