Skip to content
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

Update idaes-pse requirement in preparation to 2.1 release #1034

Merged
merged 48 commits into from
Jun 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
b56f0df
Try updating idaes-pse requirement to watertap-org/idaes-pse:main
lbianchi-lbl May 18, 2023
f9dbbc9
Try pyomo from current Pyomo/pyomo:main
lbianchi-lbl May 30, 2023
32dca48
Use 2.1.0rc0 for IDAES requirement
lbianchi-lbl May 31, 2023
ee84bc2
Try the combination IDAES 2.0, Pyomo 6.6.1
lbianchi-lbl Jun 8, 2023
951247e
dummy commit fixing a typo
adam-a-a Jun 14, 2023
79da7f4
dummy commit for demonstration
adam-a-a Jun 14, 2023
01c3045
fixing unit and prop test
agarciadiego Jun 14, 2023
ecc171a
running black
agarciadiego Jun 14, 2023
c062d94
Update setup.py
agarciadiego Jun 14, 2023
be32768
property intialize error
agarciadiego Jun 15, 2023
a42a8a4
amo 1690 add initialize
agarciadiego Jun 15, 2023
230a283
scaling asm2d
agarciadiego Jun 15, 2023
3eaa200
scaling for linux
agarciadiego Jun 15, 2023
cf8424e
turning off tee
agarciadiego Jun 15, 2023
688efe6
Merge branch 'main' into idaes-2.1
agarciadiego Jun 15, 2023
bd91cdd
electronP scaling
agarciadiego Jun 15, 2023
9a2c8f3
asm2d scaling
agarciadiego Jun 16, 2023
ca25f95
changing units of aggragate
agarciadiego Jun 19, 2023
1e27615
run black
agarciadiego Jun 19, 2023
1f64525
lssro units
agarciadiego Jun 19, 2023
20d6021
electronP deactivating constraints
agarciadiego Jun 20, 2023
809df94
electronP deactivating constraints
agarciadiego Jun 20, 2023
dd3bcf8
electronP check
agarciadiego Jun 20, 2023
bafad0d
for loop
agarciadiego Jun 20, 2023
8838a7a
new set
agarciadiego Jun 20, 2023
faabcd3
asm2d
agarciadiego Jun 20, 2023
4b7faea
asm2d rescale
agarciadiego Jun 20, 2023
aa886dc
solution 2
agarciadiego Jun 20, 2023
00f0543
rescaling testing linux
agarciadiego Jun 20, 2023
f66c7b7
rescaling equation
agarciadiego Jun 20, 2023
f8c5847
reversing
agarciadiego Jun 20, 2023
b9168f2
asm2d model solve
agarciadiego Jun 20, 2023
b5d096e
Add nbconvert as a testing requirement
lbianchi-lbl Jun 21, 2023
9e9490c
mac test skip
agarciadiego Jun 21, 2023
3463dd1
Merge branch 'idaes-2.1' of https://github.com/lbianchi-lbl/watertap …
agarciadiego Jun 21, 2023
1f08db8
running black
agarciadiego Jun 21, 2023
81c309e
test skip
agarciadiego Jun 21, 2023
bafad62
Merge branch 'main' into idaes-2.1
lbianchi-lbl Jun 23, 2023
c28f436
Merge branch 'main' into idaes-2.1
lbianchi-lbl Jun 23, 2023
2b925dc
Merge branch 'main' into idaes-2.1
lbianchi-lbl Jun 27, 2023
5d1aa7b
Merge branch 'main' into idaes-2.1
lbianchi-lbl Jun 27, 2023
7093184
Merge branch 'main' into idaes-2.1
lbianchi-lbl Jun 29, 2023
35eaab4
Add fix_initialization_states() for new NaCl_T_dep prop model
lbianchi-lbl Jun 30, 2023
5c957d2
Merge branch 'main' into idaes-2.1
lbianchi-lbl Jun 30, 2023
7e3c9c8
Merge branch 'main' into idaes-2.1
lbianchi-lbl Jun 30, 2023
528ff66
Add ad-hoc temporary workaround for solver inconsistencies on WIndows
lbianchi-lbl Jun 30, 2023
bb67779
Remove notebook with failures on Windows
lbianchi-lbl Jun 30, 2023
700b024
Update IDAES requirement to 2.1.0
lbianchi-lbl Jun 30, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,10 @@ jobs:
echo '::group::Output of "idaes get-extensions" command'
idaes get-extensions --verbose
echo '::endgroup::'
- name: Exclude notebooks that cause errors on Windows
if: startswith(matrix.os, 'win')
run: |
rm tutorials/nawi_spring_meeting2023.ipynb
- name: Run pytest with nbmake
run:
pytest --nbmake **/*.ipynb
Expand Down
7 changes: 4 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
long_description = (cwd / "README.md").read_text()

SPECIAL_DEPENDENCIES_FOR_RELEASE = [
"idaes-pse==2.0.*", # from PyPI
"idaes-pse==2.1.*", # from PyPI
]

SPECIAL_DEPENDENCIES_FOR_PRERELEASE = [
# update with a tag from the nawi-hub/idaes-pse
# when a version of IDAES newer than the latest stable release from PyPI
# will become needed for the watertap development
"idaes-pse==2.0.*",
"idaes-pse==2.1.0",
]

# Arguments marked as "Required" below must be included for upload to PyPI.
Expand Down Expand Up @@ -80,7 +80,7 @@
# primary requirements for unit and property models
# maintainers: switch to SPECIAL_DEPENDENCIES_FOR_RELEASE when cutting a release of watertap
*SPECIAL_DEPENDENCIES_FOR_PRERELEASE,
"pyomo>=6.2,<6.6", # (also needed for units in electrolyte database (edb))
"pyomo>=6.6.1", # (also needed for units in electrolyte database (edb))
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"pyomo>=6.6.1", # (also needed for units in electrolyte database (edb))
"pyomo<=6.6.1", # (also needed for units in electrolyte database (edb))

Any reason why this shouldn't be as suggested? Would tests fail using a version of pyomo below 6.6.1?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, Pyomo 6.6.0 has known issues that affect us, namely Pyomo/pyomo#2844 and IDAES/idaes-pse#1191. Both have been resolved in Pyomo 6.6.1.

# the following requirements are for the electrolyte database (edb)
"pymongo>3", # database interface
"fastjsonschema", # schema validation
Expand All @@ -103,6 +103,7 @@
"mongomock",
"pandas",
"nbmake",
"nbconvert",
],
"dev": [
"nbsphinx", # jupyter notebook support for sphinx
Expand Down
4 changes: 2 additions & 2 deletions watertap/core/tests/test_zero_order_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,9 @@ def test_CV_integration(model):

model.fs.cv.add_geometry()

model.fs.cv.add_state_blocks(has_phase_equilibrium=True)
model.fs.cv.add_state_blocks(has_phase_equilibrium=False)

model.fs.cv.add_material_balances(has_phase_equilibrium=True)
model.fs.cv.add_material_balances(has_phase_equilibrium=False)

# No energy or momentum balances, as these are not supported.

Expand Down
28 changes: 21 additions & 7 deletions watertap/costing/watertap_costing_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,13 +274,27 @@ def build_process_costs(self):
== self.factor_maintenance_labor_chemical * self.total_capital_cost
)

self.total_operating_cost_constraint = pyo.Constraint(
expr=self.total_operating_cost
== self.maintenance_labor_chemical_operating_cost
+ self.aggregate_fixed_operating_cost
+ self.aggregate_variable_operating_cost
+ sum(self.aggregate_flow_costs.values()) * self.utilization_factor
)
if (
pyo.units.get_units(sum(self.aggregate_flow_costs.values()))
) == pyo.units.dimensionless:
self.total_operating_cost_constraint = pyo.Constraint(
expr=self.total_operating_cost
== self.maintenance_labor_chemical_operating_cost
+ self.aggregate_fixed_operating_cost
+ self.aggregate_variable_operating_cost
+ sum(self.aggregate_flow_costs.values())
* self.base_currency
/ self.base_period
* self.utilization_factor
)
else:
self.total_operating_cost_constraint = pyo.Constraint(
expr=self.total_operating_cost
== self.maintenance_labor_chemical_operating_cost
+ self.aggregate_fixed_operating_cost
+ self.aggregate_variable_operating_cost
+ sum(self.aggregate_flow_costs.values()) * self.utilization_factor
)

def initialize_build(self):
calculate_variable_from_constraint(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,7 @@ def test_case_1_no_dissolution():
)


@pytest.mark.requires_idaes_solver
@pytest.mark.component
def test_case_1_high_dissolution():
model = run_case1(
Expand All @@ -494,6 +495,7 @@ def test_case_1_high_dissolution():
)


@pytest.mark.requires_idaes_solver
@pytest.mark.component
def test_case_1_mid_dissolution():
model = run_case1(
Expand All @@ -506,6 +508,7 @@ def test_case_1_mid_dissolution():
)


@pytest.mark.requires_idaes_solver
@pytest.mark.component
def test_case_1_low_dissolution():
model = run_case1(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,13 +282,11 @@ def scale_variables(m):
if "temperature" in var.name:
iscale.set_scaling_factor(var, 1e-1)
if "pressure" in var.name:
iscale.set_scaling_factor(var, 1e-3)
iscale.set_scaling_factor(var, 1e-4)
if "enth_mol" in var.name:
iscale.set_scaling_factor(var, 1e-3)
if "alkalinity" in var.name:
iscale.set_scaling_factor(var, 1e3)
if "conc_mass_comp" in var.name:
iscale.set_scaling_factor(var, 1e2)

if "conc_mass_comp[S_O2]" in var.name:
iscale.set_scaling_factor(var, 1e3)
Expand Down Expand Up @@ -398,7 +396,7 @@ def function(unit):

seq.run(m, function)

solver = get_solver(options={"bound_push": 1e-8})
solver = get_solver()
results = solver.solve(m, tee=False)
check_solve(results, checkpoint="closing recycle", logger=_log, fail_flag=True)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ def test_results(self, model):
assert value(model.fs.Treated.temperature[0]) == pytest.approx(298.15, rel=1e-4)
assert value(model.fs.Treated.pressure[0]) == pytest.approx(101325, rel=1e-4)
assert value(model.fs.Treated.conc_mass_comp[0, "S_A"]) == pytest.approx(
5.3211e-5, rel=1e-4
5.4560e-5, rel=1e-4
)
assert value(model.fs.Treated.conc_mass_comp[0, "S_F"]) == pytest.approx(
2.5618e-3, rel=1e-2
2.5736e-3, rel=1e-2
)
assert value(model.fs.Treated.conc_mass_comp[0, "S_I"]) == pytest.approx(
30e-3, rel=1e-4
Expand All @@ -69,25 +69,25 @@ def test_results(self, model):
13.837e-3, abs=1e-4
)
assert value(model.fs.Treated.conc_mass_comp[0, "S_NH4"]) == pytest.approx(
9.0286e-6, rel=1e-4
8.98349e-6, rel=1e-4
)
assert value(model.fs.Treated.conc_mass_comp[0, "S_NO3"]) == pytest.approx(
4.4784e-3, abs=1e-4
4.3924e-3, abs=1e-4
)
assert value(model.fs.Treated.conc_mass_comp[0, "S_O2"]) == pytest.approx(
7.8653e-3, abs=1e-4
7.8744e-3, abs=1e-4
)
assert value(model.fs.Treated.conc_mass_comp[0, "S_PO4"]) == pytest.approx(
2.5913e-3, rel=1e-4
2.7958e-3, rel=1e-4
)
assert value(model.fs.Treated.conc_mass_comp[0, "X_AUT"]) == pytest.approx(
1.3278e-3, abs=1e-4
1.3277e-3, abs=1e-4
)
assert value(model.fs.Treated.conc_mass_comp[0, "X_H"]) == pytest.approx(
36.313e-3, rel=1e-4
36.331e-3, rel=1e-4
)
assert value(model.fs.Treated.conc_mass_comp[0, "X_I"]) == pytest.approx(
21.178e-3, rel=1e-4
21.1808e-3, rel=1e-4
)
assert value(model.fs.Treated.conc_mass_comp[0, "X_MeOH"]) == pytest.approx(
0, abs=1e-4
Expand All @@ -96,32 +96,32 @@ def test_results(self, model):
0, abs=1e-4
)
assert value(model.fs.Treated.conc_mass_comp[0, "X_PAO"]) == pytest.approx(
2.21218e-3, abs=1e-4
2.111e-3, abs=1e-4
)
assert value(model.fs.Treated.conc_mass_comp[0, "X_PHA"]) == pytest.approx(
2.1218e-9, abs=1e-4
8.981e-5, abs=1e-4
Copy link
Contributor

Choose a reason for hiding this comment

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

X_PHA changed by 4 orders of magnitude but am unsure why.

)
assert value(model.fs.Treated.conc_mass_comp[0, "X_PP"]) == pytest.approx(
0.7773e-3, abs=1e-4
0.66913e-3, abs=1e-4
)
assert value(model.fs.Treated.conc_mass_comp[0, "X_S"]) == pytest.approx(
1.1586e-3, rel=1e-4
1.15897e-3, rel=1e-4
)
assert value(model.fs.Treated.conc_mass_comp[0, "X_TSS"]) == pytest.approx(
76.828e-3, rel=1e-4
76.489e-3, rel=1e-4
)
assert value(model.fs.Treated.alkalinity[0]) == pytest.approx(
7.2343e-3, rel=1e-4
7.243e-3, rel=1e-4
)
# Sludge stream
assert value(model.fs.Sludge.flow_vol[0]) == pytest.approx(4.2808e-3, rel=1e-4)
assert value(model.fs.Sludge.temperature[0]) == pytest.approx(298.15, rel=1e-4)
assert value(model.fs.Sludge.pressure[0]) == pytest.approx(101325, rel=1e-4)
assert value(model.fs.Sludge.conc_mass_comp[0, "S_A"]) == pytest.approx(
5.3211e-5, rel=1e-4
5.4560e-5, rel=1e-4
)
assert value(model.fs.Sludge.conc_mass_comp[0, "S_F"]) == pytest.approx(
2.5618e-3, rel=1e-2
2.5736e-3, rel=1e-2
)
assert value(model.fs.Sludge.conc_mass_comp[0, "S_I"]) == pytest.approx(
30e-3, rel=1e-4
Expand All @@ -130,25 +130,25 @@ def test_results(self, model):
13.837e-3, abs=1e-4
)
assert value(model.fs.Sludge.conc_mass_comp[0, "S_NH4"]) == pytest.approx(
9.0286e-6, rel=1e-4
8.9834e-6, rel=1e-4
)
assert value(model.fs.Sludge.conc_mass_comp[0, "S_NO3"]) == pytest.approx(
4.4784e-3, abs=1e-4
4.3924e-3, abs=1e-4
)
assert value(model.fs.Sludge.conc_mass_comp[0, "S_O2"]) == pytest.approx(
7.8653e-3, abs=1e-4
7.8744e-3, abs=1e-4
)
assert value(model.fs.Sludge.conc_mass_comp[0, "S_PO4"]) == pytest.approx(
2.5913e-3, rel=1e-4
2.7958e-3, rel=1e-4
)
assert value(model.fs.Sludge.conc_mass_comp[0, "X_AUT"]) == pytest.approx(
58.680e-3, abs=1e-4
58.6744e-3, abs=1e-4
)
assert value(model.fs.Sludge.conc_mass_comp[0, "X_H"]) == pytest.approx(
1.6193, rel=1e-4
1.6200, rel=1e-4
)
assert value(model.fs.Sludge.conc_mass_comp[0, "X_I"]) == pytest.approx(
953.56e-3, rel=1e-4
953.686e-3, rel=1e-4
)
assert value(model.fs.Sludge.conc_mass_comp[0, "X_MeOH"]) == pytest.approx(
0, abs=1e-4
Expand All @@ -157,20 +157,20 @@ def test_results(self, model):
0, abs=1e-4
)
assert value(model.fs.Sludge.conc_mass_comp[0, "X_PAO"]) == pytest.approx(
94.272e-3, abs=1e-4
93.795e-3, abs=1e-4
)
assert value(model.fs.Sludge.conc_mass_comp[0, "X_PHA"]) == pytest.approx(
3.6979e-3, abs=1e-4
4.0913e-3, abs=1e-4
)
assert value(model.fs.Sludge.conc_mass_comp[0, "X_PP"]) == pytest.approx(
35.460e-3, abs=1e-4
30.522e-3, abs=1e-4
)
assert value(model.fs.Sludge.conc_mass_comp[0, "X_S"]) == pytest.approx(
50.980e-3, rel=1e-4
50.995e-3, rel=1e-4
)
assert value(model.fs.Sludge.conc_mass_comp[0, "X_TSS"]) == pytest.approx(
3.423, rel=1e-4
3.4078, rel=1e-4
)
assert value(model.fs.Sludge.alkalinity[0]) == pytest.approx(
7.2343e-3, rel=1e-4
7.2430e-3, rel=1e-4
)
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,32 @@ def build_flowsheet():
iscale.calculate_scaling_factors(m)

iscale.set_scaling_factor(m.fs.electroNP.properties_byproduct[0.0].flow_vol, 1e7)
iscale.set_scaling_factor(m.fs.AD.vapor_phase[0].pressure_sat, 1e-3)

skip_constraint = [
"S_O2",
"S_N2",
"X_AUT",
"X_PHA",
"S_I",
"S_NO3",
"S_Mg",
"X_MeP",
"X_MeOH",
"X_PAO",
"X_TSS",
"S_F",
"S_K",
"S_A",
"X_I",
"X_H",
"X_PP",
"X_S",
]

for i in skip_constraint:
m.fs.electroNP.solute_removal_equation[0.0, "Liq", i].deactivate()
m.fs.electroNP.solute_treated_equation[0.0, "Liq", i].deactivate()
agarciadiego marked this conversation as resolved.
Show resolved Hide resolved

m.fs.AD.initialize(outlvl=idaeslog.INFO_HIGH)
propagate_state(m.fs.stream_adm1_translator)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ def set_operating_conditions(m):
m.fs.feed.conc_mass_comp[0, "acetic_acid"].fix(conc_mass_aa)
m.fs.feed.conc_mass_comp[0, "ammonium_as_nitrogen"].fix(conc_mass_nh4)

m.fs.feed.initialize()

solve(m.fs.feed, checkpoint="solve feed block")

m.fs.cmf.load_parameters_from_database(use_default_removal=True)
Expand Down
2 changes: 1 addition & 1 deletion watertap/examples/flowsheets/lsrro/lsrro.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ def stage_recovery_mass_H2O(fs, stage):
+ (
m.fs.costing.booster_pump_capex_lcow
if number_of_stages > 1
else 0 * m.fs.costing.base_currency
else 0 * m.fs.costing.base_currency / pyunits.m**3
)
+ m.fs.costing.erd_capex_lcow
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,17 @@
# information, respectively. These files are also available online at the URL
# "https://github.com/watertap-org/watertap/"
#################################################################################
import sys

import pytest
from pyomo.environ import value
from watertap.examples.flowsheets.nf_dspmde.nf_with_bypass import main


@pytest.mark.skipif(
sys.platform.startswith("win"),
reason="Known issue on Windows, see watertap-org/watertap#1072",
)
@pytest.mark.requires_idaes_solver
@pytest.mark.component
def test_main():
Expand Down
15 changes: 15 additions & 0 deletions watertap/property_models/NDMA_prop_pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,21 @@ class _NDMAStateBlock(StateBlock):
whole, rather than individual elements of indexed Property Blocks.
"""

def fix_initialization_states(self):
"""
Fixes state variables for state blocks.

Returns:
None
"""
# Fix state variables
fix_state_vars(self)

# Constraint on water concentration at outlet - unfix in these cases
for b in self.values():
if b.config.defined_state is False:
b.conc_mol_comp["H2O"].unfix()

def initialize(
self,
state_args=None,
Expand Down
15 changes: 15 additions & 0 deletions watertap/property_models/NaCl_T_dep_prop_pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,21 @@ class _NaClStateBlock(StateBlock):
whole, rather than individual elements of indexed Property Blocks.
"""

def fix_initialization_states(self):
"""
Fixes state variables for state blocks.

Returns:
None
"""
# Fix state variables
fix_state_vars(self)

# Constraint on water concentration at outlet - unfix in these cases
for b in self.values():
if b.config.defined_state is False:
b.conc_mol_comp["H2O"].unfix()

def initialize(
self,
state_args=None,
Expand Down
Loading