Skip to content

Updated parmest Estimator class to use experiments #2

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

Open
wants to merge 4 commits into
base: doe_redesign
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
exp,
value,
)
import pyomo.contrib.parmest.parmest as parmest
import pyomo.contrib.parmest.parmest_deprecated as parmest


def simple_reaction_model(data):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

import pandas as pd
from os.path import join, abspath, dirname
import pyomo.contrib.parmest.parmest as parmest
from pyomo.contrib.parmest.examples.reactor_design.reactor_design import (
import pyomo.contrib.parmest.parmest_deprecated as parmest
from pyomo.contrib.parmest.examples._deprecated.reactor_design.reactor_design import (
reactor_design_model,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

import numpy as np
import pandas as pd
import pyomo.contrib.parmest.parmest as parmest
from pyomo.contrib.parmest.examples.reactor_design.reactor_design import (
import pyomo.contrib.parmest.parmest_deprecated as parmest
from pyomo.contrib.parmest.examples._deprecated.reactor_design.reactor_design import (
reactor_design_model,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
import numpy as np
import pandas as pd
from os.path import join, abspath, dirname
import pyomo.contrib.parmest.parmest as parmest
from pyomo.contrib.parmest.examples.reactor_design.reactor_design import (
import pyomo.contrib.parmest.parmest_deprecated as parmest
from pyomo.contrib.parmest.examples._deprecated.reactor_design.reactor_design import (
reactor_design_model,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
import pandas as pd
from itertools import product
from os.path import join, abspath, dirname
import pyomo.contrib.parmest.parmest as parmest
from pyomo.contrib.parmest.examples.reactor_design.reactor_design import (
import pyomo.contrib.parmest.parmest_deprecated as parmest
from pyomo.contrib.parmest.examples._deprecated.reactor_design.reactor_design import (
reactor_design_model,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

import pandas as pd
from os.path import join, abspath, dirname
import pyomo.contrib.parmest.parmest as parmest
from pyomo.contrib.parmest.examples.reactor_design.reactor_design import (
import pyomo.contrib.parmest.parmest_deprecated as parmest
from pyomo.contrib.parmest.examples._deprecated.reactor_design.reactor_design import (
reactor_design_model,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

import pandas as pd
from os.path import join, abspath, dirname
import pyomo.contrib.parmest.parmest as parmest
from pyomo.contrib.parmest.examples.reactor_design.reactor_design import (
import pyomo.contrib.parmest.parmest_deprecated as parmest
from pyomo.contrib.parmest.examples._deprecated.reactor_design.reactor_design import (
reactor_design_model,
)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
sv,caf,ca,cb,cc,cd
1.06,10010,3407.4,945.4,1717.1,1931.9
1.11,10010,3631.6,1247.2,1694.1,1960.6
1.16,10010,3645.3,971.4,1552.3,1898.8
1.21,10002,3536.2,1225.9,1351.1,1757.0
1.26,10002,3755.6,1263.8,1562.3,1952.2
1.30,10007,3598.3,1153.4,1413.4,1903.3
1.35,10007,3939.0,971.4,1416.9,1794.9
1.41,10009,4227.9,986.3,1188.7,1821.5
1.45,10001,4163.1,972.5,1085.6,1908.7
1.50,10002,3896.3,977.3,1132.9,2080.5
1.56,10004,3801.6,1040.6,1157.7,1780.0
1.60,10008,4128.4,1198.6,1150.0,1581.9
1.66,10002,4385.4,1158.7,970.0,1629.8
1.70,10007,3960.8,1194.9,1091.2,1835.5
1.76,10007,4180.8,1244.2,1034.8,1739.5
1.80,10001,4212.3,1240.7,1010.3,1739.6
1.85,10004,4200.2,1164.0,931.5,1783.7
1.90,10009,4748.6,1037.9,1065.9,1685.6
1.96,10009,4941.3,1038.5,996.0,1855.7
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# ___________________________________________________________________________
#
# Pyomo: Python Optimization Modeling Objects
# Copyright (c) 2008-2022
# National Technology and Engineering Solutions of Sandia, LLC
# Under the terms of Contract DE-NA0003525 with National Technology and
# Engineering Solutions of Sandia, LLC, the U.S. Government retains certain
# rights in this software.
# This software is distributed under the 3-clause BSD License.
# ___________________________________________________________________________
"""
Continuously stirred tank reactor model, based on
pyomo/examples/doc/pyomobook/nonlinear-ch/react_design/ReactorDesign.py
"""
import pandas as pd
from pyomo.environ import (
ConcreteModel,
Param,
Var,
PositiveReals,
Objective,
Constraint,
maximize,
SolverFactory,
)


def reactor_design_model(data):
# Create the concrete model
model = ConcreteModel()

# Rate constants
model.k1 = Param(initialize=5.0 / 6.0, within=PositiveReals, mutable=True) # min^-1
model.k2 = Param(initialize=5.0 / 3.0, within=PositiveReals, mutable=True) # min^-1
model.k3 = Param(
initialize=1.0 / 6000.0, within=PositiveReals, mutable=True
) # m^3/(gmol min)

# Inlet concentration of A, gmol/m^3
if isinstance(data, dict) or isinstance(data, pd.Series):
model.caf = Param(initialize=float(data["caf"]), within=PositiveReals)
elif isinstance(data, pd.DataFrame):
model.caf = Param(initialize=float(data.iloc[0]["caf"]), within=PositiveReals)
else:
raise ValueError("Unrecognized data type.")

# Space velocity (flowrate/volume)
if isinstance(data, dict) or isinstance(data, pd.Series):
model.sv = Param(initialize=float(data["sv"]), within=PositiveReals)
elif isinstance(data, pd.DataFrame):
model.sv = Param(initialize=float(data.iloc[0]["sv"]), within=PositiveReals)
else:
raise ValueError("Unrecognized data type.")

# Outlet concentration of each component
model.ca = Var(initialize=5000.0, within=PositiveReals)
model.cb = Var(initialize=2000.0, within=PositiveReals)
model.cc = Var(initialize=2000.0, within=PositiveReals)
model.cd = Var(initialize=1000.0, within=PositiveReals)

# Objective
model.obj = Objective(expr=model.cb, sense=maximize)

# Constraints
model.ca_bal = Constraint(
expr=(
0
== model.sv * model.caf
- model.sv * model.ca
- model.k1 * model.ca
- 2.0 * model.k3 * model.ca**2.0
)
)

model.cb_bal = Constraint(
expr=(0 == -model.sv * model.cb + model.k1 * model.ca - model.k2 * model.cb)
)

model.cc_bal = Constraint(expr=(0 == -model.sv * model.cc + model.k2 * model.cb))

model.cd_bal = Constraint(
expr=(0 == -model.sv * model.cd + model.k3 * model.ca**2.0)
)

return model


def main():
# For a range of sv values, return ca, cb, cc, and cd
results = []
sv_values = [1.0 + v * 0.05 for v in range(1, 20)]
caf = 10000
for sv in sv_values:
model = reactor_design_model(pd.DataFrame(data={"caf": [caf], "sv": [sv]}))
solver = SolverFactory("ipopt")
solver.solve(model)
results.append([sv, caf, model.ca(), model.cb(), model.cc(), model.cd()])

results = pd.DataFrame(results, columns=["sv", "caf", "ca", "cb", "cc", "cd"])
print(results)


if __name__ == "__main__":
main()
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
import pandas as pd
from os.path import join, abspath, dirname

import pyomo.contrib.parmest.parmest as parmest
from pyomo.contrib.parmest.examples.reactor_design.reactor_design import (
import pyomo.contrib.parmest.parmest_deprecated as parmest
from pyomo.contrib.parmest.examples._deprecated.reactor_design.reactor_design import (
reactor_design_model,
)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# ___________________________________________________________________________
#
# Pyomo: Python Optimization Modeling Objects
# Copyright (c) 2008-2022
# National Technology and Engineering Solutions of Sandia, LLC
# Under the terms of Contract DE-NA0003525 with National Technology and
# Engineering Solutions of Sandia, LLC, the U.S. Government retains certain
# rights in this software.
# This software is distributed under the 3-clause BSD License.
# ___________________________________________________________________________
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
# ___________________________________________________________________________

import pandas as pd
import pyomo.contrib.parmest.parmest as parmest
from pyomo.contrib.parmest.examples.rooney_biegler.rooney_biegler import (
import pyomo.contrib.parmest.parmest_deprecated as parmest
from pyomo.contrib.parmest.examples._deprecated.rooney_biegler.rooney_biegler import (
rooney_biegler_model,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
import numpy as np
import pandas as pd
from itertools import product
import pyomo.contrib.parmest.parmest as parmest
from pyomo.contrib.parmest.examples.rooney_biegler.rooney_biegler import (
import pyomo.contrib.parmest.parmest_deprecated as parmest
from pyomo.contrib.parmest.examples._deprecated.rooney_biegler.rooney_biegler import (
rooney_biegler_model,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
# ___________________________________________________________________________

import pandas as pd
import pyomo.contrib.parmest.parmest as parmest
from pyomo.contrib.parmest.examples.rooney_biegler.rooney_biegler import (
import pyomo.contrib.parmest.parmest_deprecated as parmest
from pyomo.contrib.parmest.examples._deprecated.rooney_biegler.rooney_biegler import (
rooney_biegler_model,
)

Expand Down
10 changes: 10 additions & 0 deletions pyomo/contrib/parmest/examples/_deprecated/semibatch/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# ___________________________________________________________________________
#
# Pyomo: Python Optimization Modeling Objects
# Copyright (c) 2008-2022
# National Technology and Engineering Solutions of Sandia, LLC
# Under the terms of Contract DE-NA0003525 with National Technology and
# Engineering Solutions of Sandia, LLC, the U.S. Government retains certain
# rights in this software.
# This software is distributed under the 3-clause BSD License.
# ___________________________________________________________________________
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
import pandas as pd
from itertools import product
from os.path import join, abspath, dirname
import pyomo.contrib.parmest.parmest as parmest
from pyomo.contrib.parmest.examples.semibatch.semibatch import generate_model
import pyomo.contrib.parmest.parmest_deprecated as parmest
from pyomo.contrib.parmest.examples._deprecated.semibatch.semibatch import generate_model


def main():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

import json
from os.path import join, abspath, dirname
import pyomo.contrib.parmest.parmest as parmest
from pyomo.contrib.parmest.examples.semibatch.semibatch import generate_model
import pyomo.contrib.parmest.parmest_deprecated as parmest
from pyomo.contrib.parmest.examples._deprecated.semibatch.semibatch import generate_model


def main():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

import json
from os.path import join, abspath, dirname
import pyomo.contrib.parmest.parmest as parmest
from pyomo.contrib.parmest.examples.semibatch.semibatch import generate_model
import pyomo.contrib.parmest.parmest_deprecated as parmest
from pyomo.contrib.parmest.examples._deprecated.semibatch.semibatch import generate_model
import pyomo.contrib.parmest.scenariocreator as sc


Expand Down
Loading