diff --git a/idaes_examples/notebooks/docs/param_est/parameter_estimation_nrtl_using_state_block.ipynb b/idaes_examples/notebooks/docs/param_est/parameter_estimation_nrtl_using_state_block.ipynb
index a9b7b17b..9cce791e 100644
--- a/idaes_examples/notebooks/docs/param_est/parameter_estimation_nrtl_using_state_block.ipynb
+++ b/idaes_examples/notebooks/docs/param_est/parameter_estimation_nrtl_using_state_block.ipynb
@@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 1,
"metadata": {
"tags": [
"header",
@@ -16,7 +16,7 @@
"# Framework (IDAES IP) was produced under the DOE Institute for the\n",
"# Design of Advanced Energy Systems (IDAES).\n",
"#\n",
- "# Copyright (c) 2018-2023 by the software owners: The Regents of the\n",
+ "# Copyright (c) 2018-2026 by the software owners: The Regents of the\n",
"# University of California, through Lawrence Berkeley National Laboratory,\n",
"# National Technology & Engineering Solutions of Sandia, LLC, Carnegie Mellon\n",
"# University, West Virginia University Research Corporation, et al.\n",
@@ -32,8 +32,8 @@
"# Parameter Estimation Using the NRTL State Block\n",
"\n",
"Author: Jaffer Ghouse \n",
- "Maintainer: Andrew Lee \n",
- "Updated: 2023-06-01 \n",
+ "Maintainer: Stephen Cini \n",
+ "Updated: 2026-06-11 \n",
"\n",
"In this module, we use Pyomo's `parmest` tool in conjunction with IDAES models for parameter estimation. We demonstrate these tools by estimating the parameters associated with the NRTL property model for a benzene-toluene mixture. The NRTL model has 2 sets of parameters: the non-randomness parameter (`alpha_ij`) and the binary interaction parameter (`tau_ij`), where `i` and `j` are the pure component species. In this example, we only estimate the binary interaction parameter (`tau_ij`) for a given dataset. When estimating parameters associated with the property package, IDAES provides the flexibility of doing the parameter estimation by just using the state block or by using a unit model with a specified property package. This module will demonstrate parameter estimation by using only the state block. \n",
"\n",
@@ -45,7 +45,7 @@
"\n",
"## Key links to documentation:\n",
"* NRTL Model - https://idaes-pse.readthedocs.io/en/stable/reference_guides/model_libraries/generic/property_models/activity_coefficient.html\n",
- "* parmest - https://pyomo.readthedocs.io/en/stable/contributed_packages/parmest/index.html\n"
+ "* parmest - https://pyomo.readthedocs.io/en/stable/explanation/analysis/parmest/index.html\n"
]
},
{
@@ -54,13 +54,13 @@
"source": [
"
\n",
"Inline Exercise:\n",
- "import `ConcreteModel` from Pyomo and `FlowsheetBlock` from IDAES. \n",
+ "import `ConcreteModel`, `value`, and `Suffix` from Pyomo, and `FlowsheetBlock`from IDAES. \n",
"
"
]
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 2,
"metadata": {
"tags": [
"exercise"
@@ -68,14 +68,14 @@
},
"outputs": [],
"source": [
- "# Todo: import ConcreteModel from pyomo.environ\n",
+ "# Todo: import ConcreteModel, value, and Suffix from pyomo.environ\n",
"\n",
"# Todo: import FlowsheetBlock from idaes.core"
]
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 3,
"metadata": {
"tags": [
"solution"
@@ -83,8 +83,8 @@
},
"outputs": [],
"source": [
- "# Todo: import ConcreteModel from pyomo.environ\n",
- "from pyomo.environ import ConcreteModel, value\n",
+ "# Todo: import ConcreteModel, value, and Suffix from pyomo.environ\n",
+ "from pyomo.environ import ConcreteModel, value, Suffix\n",
"\n",
"# Todo: import FlowsheetBlock from idaes.core\n",
"from idaes.core import FlowsheetBlock"
@@ -99,7 +99,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 4,
"metadata": {
"tags": []
},
@@ -120,7 +120,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 5,
"metadata": {
"tags": []
},
@@ -151,7 +151,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 6,
"metadata": {
"tags": [
"exercise"
@@ -217,7 +217,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 7,
"metadata": {
"tags": [
"solution"
@@ -268,7 +268,6 @@
" m.fs.state_block.initialize(outlvl=idaeslog.INFO_LOW)\n",
"\n",
" # Fix at actual temperature\n",
- " # Fix at actual temperature\n",
" if isinstance(data, dict) or isinstance(data, pd.Series):\n",
" m.fs.state_block.temperature.fix(float(data[\"temperature\"]))\n",
" elif isinstance(data, pd.DataFrame):\n",
@@ -289,7 +288,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 8,
"metadata": {
"tags": [
"testing"
@@ -337,54 +336,106 @@
"source": [
"In addition to providing a method to return an initialized model, the `parmest` tool needs the following:\n",
"\n",
- "* List of variable names to be estimated\n",
- "* Dataset\n",
- "* Expression to compute the sum of squared errors\n"
+ "* Experiment class to set up and label model with suffixes\n",
+ "* Dataset with multiple scenarios - organized into an experiment list\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
+ "Here we build an experiment class to label our model problem for parameter estimation. The labels are defined as a `Suffix`, and the main labels for our model are `experiment_outputs`, `unknown_parameters`, and `measurement_error`.\n",
+ "\n",
+ "For this problem, the error will be computed for the mole fraction of benzene in the vapor and liquid phase between the model prediction and data. The `experimental_outputs` will therefore be the mole fraction of benzene in the two phases.\n",
+ "\n",
"In this example, we only estimate the binary interaction parameter (`tau_ij`). Given that this variable is usually indexed as `tau_ij = Var(component_list, component_list)`, there are 2*2=4 degrees of freedom. However, when i=j, the binary interaction parameter is 0. Therefore, in this problem, we estimate the binary interaction parameter for the following variables only:\n",
"\n",
"* fs.properties.tau['benzene', 'toluene']\n",
"* fs.properties.tau['toluene', 'benzene']\n",
"\n",
- "\n",
- "Inline Exercise:\n",
- "Create a list called `variable_name` with the above-mentioned variables declared as strings.\n",
- "
"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {
- "tags": [
- "exercise"
- ]
- },
- "outputs": [],
- "source": [
- "# Todo: Create a list of vars to estimate"
+ "As shown below, these model components are used as our `unknown_parameters`.\n",
+ "\n",
+ "We define `measurement_error` as none so parmest calculates the value internally based on the experimental outputs. Refer to https://pyomo.readthedocs.io/en/stable/explanation/analysis/parmest/driver.html for more information. "
]
},
{
"cell_type": "code",
- "execution_count": null,
- "metadata": {
- "tags": [
- "solution"
- ]
- },
+ "execution_count": 9,
+ "metadata": {},
"outputs": [],
"source": [
- "# Todo: Create a list of vars to estimate\n",
- "variable_name = [\n",
- " \"fs.properties.tau['benzene', 'toluene']\",\n",
- " \"fs.properties.tau['toluene', 'benzene']\",\n",
- "]"
+ "# Build an experiment class to take advantage of new parmest interface\n",
+ "from pyomo.contrib.parmest.experiment import Experiment\n",
+ "\n",
+ "\n",
+ "class NRTLExperiment(Experiment):\n",
+ " \"\"\"Experiment class for parameter estimation of NRTL model using parmest\"\"\"\n",
+ "\n",
+ " def __init__(self, data, meas_error=None):\n",
+ " \"\"\"Initialize the NRTLExperiment class\n",
+ "\n",
+ " Args:\n",
+ " data: DataFrame containing the experimental data\n",
+ " meas_error: Measurement error for the data (optional)\n",
+ " \"\"\"\n",
+ " self.model = None\n",
+ " self.data = data\n",
+ " self.meas_error = meas_error\n",
+ "\n",
+ " def create_model(self):\n",
+ " \"\"\"Create the Pyomo model for the NRTL parameter estimation problem\"\"\"\n",
+ " self.model = NRTL_model(self.data)\n",
+ "\n",
+ " def label_model(self):\n",
+ " from pyomo.environ import Set, Expression\n",
+ "\n",
+ " m = self.model\n",
+ "\n",
+ " # Parmest expects the first index of experiment outputs to be the data point\n",
+ " # This is a workaround that will be addressed and corrected in a future release.\n",
+ "\n",
+ " m.data_point = Set(initialize=[0])\n",
+ "\n",
+ " # Wrap IDAES variables in Expressions indexed by data point\n",
+ " m.liq_benzene_out = Expression(\n",
+ " m.data_point,\n",
+ " rule=lambda m, i: m.fs.state_block.mole_frac_phase_comp[\"Liq\", \"benzene\"],\n",
+ " )\n",
+ "\n",
+ " m.vap_benzene_out = Expression(\n",
+ " m.data_point,\n",
+ " rule=lambda m, i: m.fs.state_block.mole_frac_phase_comp[\"Vap\", \"benzene\"],\n",
+ " )\n",
+ "\n",
+ " m.experiment_outputs = Suffix(direction=Suffix.LOCAL)\n",
+ "\n",
+ " m.experiment_outputs[m.liq_benzene_out[0]] = float(self.data[\"liq_benzene\"])\n",
+ " m.experiment_outputs[m.vap_benzene_out[0]] = float(self.data[\"vap_benzene\"])\n",
+ "\n",
+ " m.measurement_error = Suffix(direction=Suffix.LOCAL)\n",
+ " m.measurement_error.update(\n",
+ " [\n",
+ " (m.liq_benzene_out[0], self.meas_error),\n",
+ " (m.vap_benzene_out[0], self.meas_error),\n",
+ " ]\n",
+ " )\n",
+ "\n",
+ " # Add unknown parameters to the model for easier access\n",
+ " m.unknown_parameters = Suffix(direction=Suffix.LOCAL)\n",
+ " m.unknown_parameters.update(\n",
+ " (k, value(k))\n",
+ " for k in [\n",
+ " m.fs.properties.tau[\"benzene\", \"toluene\"],\n",
+ " m.fs.properties.tau[\"toluene\", \"benzene\"],\n",
+ " ]\n",
+ " )\n",
+ "\n",
+ " def get_labeled_model(self):\n",
+ " \"\"\"Return the labeled model\"\"\"\n",
+ " if self.model is None:\n",
+ " self.create_model()\n",
+ " self.label_model()\n",
+ " return self.model"
]
},
{
@@ -403,11 +454,400 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 10,
"metadata": {
"tags": []
},
- "outputs": [],
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " temperature | \n",
+ " liq_benzene | \n",
+ " vap_benzene | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 0 | \n",
+ " 365.500000 | \n",
+ " 0.480953 | \n",
+ " 0.692110 | \n",
+ "
\n",
+ " \n",
+ " | 1 | \n",
+ " 365.617647 | \n",
+ " 0.462444 | \n",
+ " 0.667699 | \n",
+ "
\n",
+ " \n",
+ " | 2 | \n",
+ " 365.735294 | \n",
+ " 0.477984 | \n",
+ " 0.692441 | \n",
+ "
\n",
+ " \n",
+ " | 3 | \n",
+ " 365.852941 | \n",
+ " 0.440547 | \n",
+ " 0.640336 | \n",
+ "
\n",
+ " \n",
+ " | 4 | \n",
+ " 365.970588 | \n",
+ " 0.427421 | \n",
+ " 0.623328 | \n",
+ "
\n",
+ " \n",
+ " | 5 | \n",
+ " 366.088235 | \n",
+ " 0.442725 | \n",
+ " 0.647796 | \n",
+ "
\n",
+ " \n",
+ " | 6 | \n",
+ " 366.205882 | \n",
+ " 0.434374 | \n",
+ " 0.637691 | \n",
+ "
\n",
+ " \n",
+ " | 7 | \n",
+ " 366.323529 | \n",
+ " 0.444642 | \n",
+ " 0.654933 | \n",
+ "
\n",
+ " \n",
+ " | 8 | \n",
+ " 366.441176 | \n",
+ " 0.427132 | \n",
+ " 0.631229 | \n",
+ "
\n",
+ " \n",
+ " | 9 | \n",
+ " 366.558824 | \n",
+ " 0.446301 | \n",
+ " 0.661743 | \n",
+ "
\n",
+ " \n",
+ " | 10 | \n",
+ " 366.676471 | \n",
+ " 0.438004 | \n",
+ " 0.651591 | \n",
+ "
\n",
+ " \n",
+ " | 11 | \n",
+ " 366.794118 | \n",
+ " 0.425320 | \n",
+ " 0.634814 | \n",
+ "
\n",
+ " \n",
+ " | 12 | \n",
+ " 366.911765 | \n",
+ " 0.439435 | \n",
+ " 0.658047 | \n",
+ "
\n",
+ " \n",
+ " | 13 | \n",
+ " 367.029412 | \n",
+ " 0.435655 | \n",
+ " 0.654539 | \n",
+ "
\n",
+ " \n",
+ " | 14 | \n",
+ " 367.147059 | \n",
+ " 0.401350 | \n",
+ " 0.604987 | \n",
+ "
\n",
+ " \n",
+ " | 15 | \n",
+ " 367.264706 | \n",
+ " 0.397862 | \n",
+ " 0.601703 | \n",
+ "
\n",
+ " \n",
+ " | 16 | \n",
+ " 367.382353 | \n",
+ " 0.415821 | \n",
+ " 0.630930 | \n",
+ "
\n",
+ " \n",
+ " | 17 | \n",
+ " 367.500000 | \n",
+ " 0.420667 | \n",
+ " 0.640380 | \n",
+ "
\n",
+ " \n",
+ " | 18 | \n",
+ " 367.617647 | \n",
+ " 0.391683 | \n",
+ " 0.598214 | \n",
+ "
\n",
+ " \n",
+ " | 19 | \n",
+ " 367.735294 | \n",
+ " 0.404903 | \n",
+ " 0.620432 | \n",
+ "
\n",
+ " \n",
+ " | 20 | \n",
+ " 367.852941 | \n",
+ " 0.409563 | \n",
+ " 0.629626 | \n",
+ "
\n",
+ " \n",
+ " | 21 | \n",
+ " 367.970588 | \n",
+ " 0.389488 | \n",
+ " 0.600722 | \n",
+ "
\n",
+ " \n",
+ " | 22 | \n",
+ " 368.000000 | \n",
+ " 0.396789 | \n",
+ " 0.612483 | \n",
+ "
\n",
+ " \n",
+ " | 23 | \n",
+ " 368.088235 | \n",
+ " 0.398162 | \n",
+ " 0.616106 | \n",
+ "
\n",
+ " \n",
+ " | 24 | \n",
+ " 368.205882 | \n",
+ " 0.362340 | \n",
+ " 0.562505 | \n",
+ "
\n",
+ " \n",
+ " | 25 | \n",
+ " 368.323529 | \n",
+ " 0.386958 | \n",
+ " 0.602680 | \n",
+ "
\n",
+ " \n",
+ " | 26 | \n",
+ " 368.441176 | \n",
+ " 0.363643 | \n",
+ " 0.568210 | \n",
+ "
\n",
+ " \n",
+ " | 27 | \n",
+ " 368.558824 | \n",
+ " 0.368118 | \n",
+ " 0.577072 | \n",
+ "
\n",
+ " \n",
+ " | 28 | \n",
+ " 368.676471 | \n",
+ " 0.384098 | \n",
+ " 0.604078 | \n",
+ "
\n",
+ " \n",
+ " | 29 | \n",
+ " 368.794118 | \n",
+ " 0.353605 | \n",
+ " 0.557925 | \n",
+ "
\n",
+ " \n",
+ " | 30 | \n",
+ " 368.911765 | \n",
+ " 0.346474 | \n",
+ " 0.548445 | \n",
+ "
\n",
+ " \n",
+ " | 31 | \n",
+ " 369.029412 | \n",
+ " 0.350741 | \n",
+ " 0.556996 | \n",
+ "
\n",
+ " \n",
+ " | 32 | \n",
+ " 369.147059 | \n",
+ " 0.362347 | \n",
+ " 0.577286 | \n",
+ "
\n",
+ " \n",
+ " | 33 | \n",
+ " 369.264706 | \n",
+ " 0.362578 | \n",
+ " 0.579519 | \n",
+ "
\n",
+ " \n",
+ " | 34 | \n",
+ " 369.382353 | \n",
+ " 0.340765 | \n",
+ " 0.546411 | \n",
+ "
\n",
+ " \n",
+ " | 35 | \n",
+ " 369.500000 | \n",
+ " 0.337462 | \n",
+ " 0.542857 | \n",
+ "
\n",
+ " \n",
+ " | 36 | \n",
+ " 369.617647 | \n",
+ " 0.355729 | \n",
+ " 0.574083 | \n",
+ "
\n",
+ " \n",
+ " | 37 | \n",
+ " 369.735294 | \n",
+ " 0.348679 | \n",
+ " 0.564513 | \n",
+ "
\n",
+ " \n",
+ " | 38 | \n",
+ " 369.852941 | \n",
+ " 0.338187 | \n",
+ " 0.549284 | \n",
+ "
\n",
+ " \n",
+ " | 39 | \n",
+ " 369.970588 | \n",
+ " 0.324360 | \n",
+ " 0.528514 | \n",
+ "
\n",
+ " \n",
+ " | 40 | \n",
+ " 370.088235 | \n",
+ " 0.310753 | \n",
+ " 0.507964 | \n",
+ "
\n",
+ " \n",
+ " | 41 | \n",
+ " 370.205882 | \n",
+ " 0.311037 | \n",
+ " 0.510055 | \n",
+ "
\n",
+ " \n",
+ " | 42 | \n",
+ " 370.323529 | \n",
+ " 0.311263 | \n",
+ " 0.512055 | \n",
+ "
\n",
+ " \n",
+ " | 43 | \n",
+ " 370.441176 | \n",
+ " 0.308081 | \n",
+ " 0.508437 | \n",
+ "
\n",
+ " \n",
+ " | 44 | \n",
+ " 370.558824 | \n",
+ " 0.308224 | \n",
+ " 0.510293 | \n",
+ "
\n",
+ " \n",
+ " | 45 | \n",
+ " 370.676471 | \n",
+ " 0.318148 | \n",
+ " 0.528399 | \n",
+ "
\n",
+ " \n",
+ " | 46 | \n",
+ " 370.794118 | \n",
+ " 0.308334 | \n",
+ " 0.513728 | \n",
+ "
\n",
+ " \n",
+ " | 47 | \n",
+ " 370.911765 | \n",
+ " 0.317937 | \n",
+ " 0.531410 | \n",
+ "
\n",
+ " \n",
+ " | 48 | \n",
+ " 371.029412 | \n",
+ " 0.289149 | \n",
+ " 0.484824 | \n",
+ "
\n",
+ " \n",
+ " | 49 | \n",
+ " 371.147059 | \n",
+ " 0.298637 | \n",
+ " 0.502318 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " temperature liq_benzene vap_benzene\n",
+ "0 365.500000 0.480953 0.692110\n",
+ "1 365.617647 0.462444 0.667699\n",
+ "2 365.735294 0.477984 0.692441\n",
+ "3 365.852941 0.440547 0.640336\n",
+ "4 365.970588 0.427421 0.623328\n",
+ "5 366.088235 0.442725 0.647796\n",
+ "6 366.205882 0.434374 0.637691\n",
+ "7 366.323529 0.444642 0.654933\n",
+ "8 366.441176 0.427132 0.631229\n",
+ "9 366.558824 0.446301 0.661743\n",
+ "10 366.676471 0.438004 0.651591\n",
+ "11 366.794118 0.425320 0.634814\n",
+ "12 366.911765 0.439435 0.658047\n",
+ "13 367.029412 0.435655 0.654539\n",
+ "14 367.147059 0.401350 0.604987\n",
+ "15 367.264706 0.397862 0.601703\n",
+ "16 367.382353 0.415821 0.630930\n",
+ "17 367.500000 0.420667 0.640380\n",
+ "18 367.617647 0.391683 0.598214\n",
+ "19 367.735294 0.404903 0.620432\n",
+ "20 367.852941 0.409563 0.629626\n",
+ "21 367.970588 0.389488 0.600722\n",
+ "22 368.000000 0.396789 0.612483\n",
+ "23 368.088235 0.398162 0.616106\n",
+ "24 368.205882 0.362340 0.562505\n",
+ "25 368.323529 0.386958 0.602680\n",
+ "26 368.441176 0.363643 0.568210\n",
+ "27 368.558824 0.368118 0.577072\n",
+ "28 368.676471 0.384098 0.604078\n",
+ "29 368.794118 0.353605 0.557925\n",
+ "30 368.911765 0.346474 0.548445\n",
+ "31 369.029412 0.350741 0.556996\n",
+ "32 369.147059 0.362347 0.577286\n",
+ "33 369.264706 0.362578 0.579519\n",
+ "34 369.382353 0.340765 0.546411\n",
+ "35 369.500000 0.337462 0.542857\n",
+ "36 369.617647 0.355729 0.574083\n",
+ "37 369.735294 0.348679 0.564513\n",
+ "38 369.852941 0.338187 0.549284\n",
+ "39 369.970588 0.324360 0.528514\n",
+ "40 370.088235 0.310753 0.507964\n",
+ "41 370.205882 0.311037 0.510055\n",
+ "42 370.323529 0.311263 0.512055\n",
+ "43 370.441176 0.308081 0.508437\n",
+ "44 370.558824 0.308224 0.510293\n",
+ "45 370.676471 0.318148 0.528399\n",
+ "46 370.794118 0.308334 0.513728\n",
+ "47 370.911765 0.317937 0.531410\n",
+ "48 371.029412 0.289149 0.484824\n",
+ "49 371.147059 0.298637 0.502318"
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ }
+ ],
"source": [
"# Load data from csv\n",
"data = pd.read_csv(\"BT_NRTL_dataset.csv\")\n",
@@ -420,94 +860,140 @@
"cell_type": "markdown",
"metadata": {},
"source": [
- "We need to provide a method to return an expression to compute the sum of squared errors that will be used as the objective in solving the parameter estimation problem. For this problem, the error will be computed for the mole fraction of benzene in the vapor and liquid phase between the model prediction and data. \n",
- "\n",
- "\n",
- "Inline Exercise:\n",
- "Complete the following cell by adding an expression to compute the sum of square errors. \n",
- "
"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {
- "tags": [
- "exercise"
- ]
- },
- "outputs": [],
- "source": [
- "# Create method to return an expression that computes the sum of squared error\n",
- "def SSE(m, data):\n",
- " # Todo: Add expression for computing the sum of squared errors in mole fraction of benzene in the liquid\n",
- " # and vapor phase. For example, the squared error for the vapor phase is:\n",
- " # (float(data[\"vap_benzene\"]) - m.fs.state_block.mole_frac_phase_comp[\"Vap\", \"benzene\"])**2\n",
- "\n",
- " return expr * 1e4"
+ "We define the `exp_list` by splitting the data into individual experiments, or data points."
]
},
{
"cell_type": "code",
- "execution_count": null,
- "metadata": {
- "tags": [
- "solution"
- ]
- },
- "outputs": [],
- "source": [
- "# Create method to return an expression that computes the sum of squared error\n",
- "def SSE(m, data):\n",
- " # Todo: Add expression for computing the sum of squared errors in mole fraction of benzene in the liquid\n",
- " # and vapor phase. For example, the squared error for the vapor phase is:\n",
- " # (float(data[\"vap_benzene\"]) - m.fs.state_block.mole_frac_phase_comp[\"Vap\", \"benzene\"])**2\n",
- " expr = (\n",
- " float(data.iloc[0][\"vap_benzene\"])\n",
- " - m.fs.state_block.mole_frac_phase_comp[\"Vap\", \"benzene\"]\n",
- " ) ** 2 + (\n",
- " float(data.iloc[0][\"liq_benzene\"])\n",
- " - m.fs.state_block.mole_frac_phase_comp[\"Liq\", \"benzene\"]\n",
- " ) ** 2\n",
- " return expr * 1e4"
- ]
- },
- {
- "cell_type": "markdown",
+ "execution_count": 11,
"metadata": {},
+ "outputs": [],
"source": [
- "\n",
- "Note:\n",
- "Notice that we have scaled the expression up by a factor of 10000 as the SSE computed here will be an extremely small number given that we are using the difference in mole fraction in our expression. This will help in using a well-scaled objective to improve solve robustness when using IPOPT. \n",
- "
\n"
+ "# Update to new interface\n",
+ "exp_list = []\n",
+ "for i in range(data.shape[0]):\n",
+ " exp_list.append(NRTLExperiment(data.iloc[i]))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
- "We are now ready to set up the parameter estimation problem. We will create a parameter estimation object called `pest`. As shown below, we pass the method that returns an initialized model, data, variable_name, and the SSE expression to the Estimator method. `tee=True` will print the solver output after solving the parameter estimation problem. "
+ "We are now ready to set up the parameter estimation problem. We will create a parameter estimation object called pest. As shown below, we pass the experiment list, and an objective function to the Estimator method. tee=True will print the solver output after solving the parameter estimation problem."
]
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 12,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Ipopt 3.13.2: \n",
+ "\n",
+ "******************************************************************************\n",
+ "This program contains Ipopt, a library for large-scale nonlinear optimization.\n",
+ " Ipopt is released as open source code under the Eclipse Public License (EPL).\n",
+ " For more information visit http://projects.coin-or.org/Ipopt\n",
+ "\n",
+ "This version of Ipopt was compiled from source code available at\n",
+ " https://github.com/IDAES/Ipopt as part of the Institute for the Design of\n",
+ " Advanced Energy Systems Process Systems Engineering Framework (IDAES PSE\n",
+ " Framework) Copyright (c) 2018-2019. See https://github.com/IDAES/idaes-pse.\n",
+ "\n",
+ "This version of Ipopt was compiled using HSL, a collection of Fortran codes\n",
+ " for large-scale scientific computation. All technical papers, sales and\n",
+ " publicity material resulting from use of the HSL codes within IPOPT must\n",
+ " contain the following acknowledgement:\n",
+ " HSL, a collection of Fortran codes for large-scale scientific\n",
+ " computation. See http://www.hsl.rl.ac.uk.\n",
+ "******************************************************************************\n",
+ "\n",
+ "This is Ipopt version 3.13.2, running with linear solver ma27.\n",
+ "\n",
+ "Number of nonzeros in equality constraint Jacobian...: 3750\n",
+ "Number of nonzeros in inequality constraint Jacobian.: 0\n",
+ "Number of nonzeros in Lagrangian Hessian.............: 2200\n",
+ "\n",
+ "Total number of variables............................: 1102\n",
+ " variables with only lower bounds: 0\n",
+ " variables with lower and upper bounds: 300\n",
+ " variables with only upper bounds: 0\n",
+ "Total number of equality constraints.................: 1100\n",
+ "Total number of inequality constraints...............: 0\n",
+ " inequality constraints with only lower bounds: 0\n",
+ " inequality constraints with lower and upper bounds: 0\n",
+ " inequality constraints with only upper bounds: 0\n",
+ "\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 0 6.0671019e-03 3.15e+00 1.97e-05 -1.0 0.00e+00 - 0.00e+00 0.00e+00 0\n",
+ " 1 8.6249856e-04 1.40e+03 2.15e-01 -1.0 1.37e+04 - 9.95e-01 1.00e+00h 1\n",
+ " 2 1.1627234e-03 9.11e+03 8.21e-01 -1.7 4.74e+02 - 8.66e-01 1.00e+00h 1\n",
+ " 3 1.0978149e-03 9.02e+03 7.99e-01 -1.7 5.89e+00 -4.0 5.44e-01 2.64e-02h 6\n",
+ " 4 8.5702670e-04 8.63e+02 3.17e-02 -1.7 6.93e-01 -2.7 1.00e+00 1.00e+00h 1\n",
+ " 5 1.3332724e-03 3.57e+03 7.92e-03 -1.7 7.75e-01 - 1.00e+00 1.00e+00h 1\n",
+ " 6 1.5692588e-03 1.64e+02 2.34e-04 -1.7 1.98e-01 - 1.00e+00 1.00e+00h 1\n",
+ " 7 1.5828905e-03 1.20e+01 1.13e-05 -1.7 4.29e-02 - 1.00e+00 1.00e+00h 1\n",
+ " 8 1.4366151e-03 9.18e-01 2.34e-04 -2.5 5.49e-02 - 1.00e+00 1.00e+00h 1\n",
+ " 9 8.9194043e-04 2.19e+01 2.00e-04 -3.8 2.51e-01 - 1.00e+00 1.00e+00h 1\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 10 5.9835646e-04 3.72e+01 2.34e-05 -3.8 3.13e-01 - 1.00e+00 1.00e+00h 1\n",
+ " 11 5.9839648e-04 1.26e+00 4.06e-08 -3.8 2.87e-02 - 1.00e+00 1.00e+00h 1\n",
+ " 12 5.9838953e-04 4.33e-05 1.60e-12 -3.8 9.40e-05 - 1.00e+00 1.00e+00h 1\n",
+ " 13 5.9077073e-04 1.21e+01 2.96e-06 -5.7 4.79e-02 - 1.00e+00 1.00e+00h 1\n",
+ " 14 5.9066394e-04 1.19e-03 4.25e-07 -5.7 5.98e-04 -3.1 1.00e+00 1.00e+00h 1\n",
+ " 15 5.9059984e-04 1.08e-02 2.96e-07 -8.6 1.25e-03 -3.6 1.00e+00 1.00e+00h 1\n",
+ " 16 5.9042438e-04 9.67e-02 2.92e-07 -8.6 3.70e-03 -4.1 1.00e+00 1.00e+00h 1\n",
+ " 17 5.8992758e-04 8.72e-01 2.91e-07 -8.6 1.11e-02 -4.6 1.00e+00 1.00e+00h 1\n",
+ " 18 5.8840706e-04 8.23e+00 3.09e-07 -8.6 3.40e-02 -5.1 1.00e+00 1.00e+00h 1\n",
+ " 19 5.8319289e-04 9.25e+01 1.97e-06 -8.6 1.15e-01 -5.5 1.00e+00 1.00e+00h 1\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 20 5.4836946e-04 3.88e+03 1.22e-04 -8.6 7.95e-01 -6.0 1.00e+00 1.00e+00h 1\n",
+ " 21 5.0847689e-04 4.45e+02 1.04e-04 -8.6 3.55e-01 -5.6 1.00e+00 1.00e+00h 1\n",
+ " 22 5.0727291e-04 4.20e+00 1.54e-05 -8.6 6.20e+02 - 1.00e+00 1.00e+00h 1\n",
+ " 23 5.0749772e-04 1.36e+00 1.44e-06 -8.6 5.13e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 24 5.0749686e-04 6.93e-06 4.21e-11 -8.6 3.55e-01 - 1.00e+00 1.00e+00h 1\n",
+ " 25 5.0749686e-04 3.36e-06 1.49e-12 -9.0 6.25e-02 - 1.00e+00 1.00e+00h 1\n",
+ " 26 5.0749686e-04 1.02e-10 2.36e-18 -9.0 5.08e-06 - 1.00e+00 1.00e+00h 1\n",
+ "\n",
+ "Number of Iterations....: 26\n",
+ "\n",
+ " (scaled) (unscaled)\n",
+ "Objective...............: 5.0749685787934424e-04 5.0749685787934424e-04\n",
+ "Dual infeasibility......: 2.3583858113882067e-18 2.3583858113882067e-18\n",
+ "Constraint violation....: 3.5405706676501683e-13 1.0186340659856796e-10\n",
+ "Complementarity.........: 9.0909090909091344e-10 9.0909090909091344e-10\n",
+ "Overall NLP error.......: 9.0909090909091344e-10 9.0909090909091344e-10\n",
+ "\n",
+ "\n",
+ "Number of objective function evaluations = 33\n",
+ "Number of objective gradient evaluations = 27\n",
+ "Number of equality constraint evaluations = 34\n",
+ "Number of inequality constraint evaluations = 0\n",
+ "Number of equality constraint Jacobian evaluations = 27\n",
+ "Number of inequality constraint Jacobian evaluations = 0\n",
+ "Number of Lagrangian Hessian evaluations = 26\n",
+ "Total CPU secs in IPOPT (w/o function evaluations) = 0.035\n",
+ "Total CPU secs in NLP function evaluations = 0.009\n",
+ "\n",
+ "EXIT: Optimal Solution Found.\n"
+ ]
+ }
+ ],
"source": [
"import logging\n",
"\n",
"idaeslog.getIdaesLogger(\"core.property_meta\").setLevel(logging.ERROR)\n",
- "# Initialize a parameter estimation object\n",
- "pest = parmest.Estimator(NRTL_model, data, variable_name, SSE, tee=True)\n",
"\n",
- "# Run parameter estimation using all data\n",
+ "pest = parmest.Estimator(exp_list, obj_function=\"SSE\", tee=True)\n",
"obj_value, parameters = pest.theta_est()"
]
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 13,
"metadata": {
"tags": [
"testing"
@@ -516,7 +1002,7 @@
"outputs": [],
"source": [
"# Check for values of the parameter estimation problem\n",
- "assert obj_value == pytest.approx(5.07496, 1e-3)\n",
+ "assert obj_value == pytest.approx(5.07496e-4, 1e-3)\n",
"assert parameters[\"fs.properties.tau[benzene,toluene]\"] == pytest.approx(-0.89876, 1e-3)\n",
"assert parameters[\"fs.properties.tau[toluene,benzene]\"] == pytest.approx(1.41048, 1e-3)"
]
@@ -530,11 +1016,23 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 14,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "The SSE at the optimal solution is 0.000507\n",
+ "\n",
+ "The values for the parameters are as follows:\n",
+ "fs.properties.tau[benzene,toluene] = -0.8987550041842163\n",
+ "fs.properties.tau[toluene,benzene] = 1.4104702103547941\n"
+ ]
+ }
+ ],
"source": [
- "print(\"The SSE at the optimal solution is %0.6f\" % (obj_value * 1e-4))\n",
+ "print(\"The SSE at the optimal solution is %0.6f\" % (obj_value))\n",
"print()\n",
"print(\"The values for the parameters are as follows:\")\n",
"for k, v in parameters.items():\n",
@@ -567,15 +1065,12 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 15,
"metadata": {},
"outputs": [],
"source": [
- "# Run parameter estimation using bootstrap resample of the data (10 samples),\n",
- "# plot results along with confidence regions\n",
- "\n",
- "# Uncomment the following code:\n",
- "# bootstrap_theta = pest.theta_est_bootstrap(4)\n",
+ "# Uncomment the following lines\n",
+ "# bootstrap_theta = pest.theta_est_bootstrap(4, seed=542)\n",
"# display(bootstrap_theta)"
]
}
@@ -583,7 +1078,7 @@
"metadata": {
"celltoolbar": "Tags",
"kernelspec": {
- "display_name": "Python 3 (ipykernel)",
+ "display_name": "idaes-examples-dev-py313-macmini",
"language": "python",
"name": "python3"
},
@@ -597,7 +1092,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.8.19"
+ "version": "3.13.13"
}
},
"nbformat": 4,
diff --git a/idaes_examples/notebooks/docs/param_est/parameter_estimation_nrtl_using_state_block_doc.ipynb b/idaes_examples/notebooks/docs/param_est/parameter_estimation_nrtl_using_state_block_doc.ipynb
index 863667af..e75daf77 100644
--- a/idaes_examples/notebooks/docs/param_est/parameter_estimation_nrtl_using_state_block_doc.ipynb
+++ b/idaes_examples/notebooks/docs/param_est/parameter_estimation_nrtl_using_state_block_doc.ipynb
@@ -1,926 +1,966 @@
{
- "cells": [
- {
- "cell_type": "code",
- "execution_count": 1,
- "metadata": {
- "tags": [
- "header",
- "hide-cell"
- ]
- },
- "outputs": [],
- "source": [
- "###############################################################################\n",
- "# The Institute for the Design of Advanced Energy Systems Integrated Platform\n",
- "# Framework (IDAES IP) was produced under the DOE Institute for the\n",
- "# Design of Advanced Energy Systems (IDAES).\n",
- "#\n",
- "# Copyright (c) 2018-2023 by the software owners: The Regents of the\n",
- "# University of California, through Lawrence Berkeley National Laboratory,\n",
- "# National Technology & Engineering Solutions of Sandia, LLC, Carnegie Mellon\n",
- "# University, West Virginia University Research Corporation, et al.\n",
- "# All rights reserved. Please see the files COPYRIGHT.md and LICENSE.md\n",
- "# for full copyright and license information.\n",
- "###############################################################################"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "# Parameter Estimation Using the NRTL State Block\n",
- "\n",
- "Author: Jaffer Ghouse \n",
- "Maintainer: Andrew Lee \n",
- "Updated: 2023-06-01 \n",
- "\n",
- "In this module, we use Pyomo's `parmest` tool in conjunction with IDAES models for parameter estimation. We demonstrate these tools by estimating the parameters associated with the NRTL property model for a benzene-toluene mixture. The NRTL model has 2 sets of parameters: the non-randomness parameter (`alpha_ij`) and the binary interaction parameter (`tau_ij`), where `i` and `j` are the pure component species. In this example, we only estimate the binary interaction parameter (`tau_ij`) for a given dataset. When estimating parameters associated with the property package, IDAES provides the flexibility of doing the parameter estimation by just using the state block or by using a unit model with a specified property package. This module will demonstrate parameter estimation by using only the state block. \n",
- "\n",
- "We will complete the following tasks:\n",
- "* Set up a method to return an initialized model\n",
- "* Set up the parameter estimation problem using `parmest`\n",
- "* Analyze the results\n",
- "* Demonstrate advanced features using `parmest`\n",
- "\n",
- "## Key links to documentation:\n",
- "* NRTL Model - https://idaes-pse.readthedocs.io/en/stable/reference_guides/model_libraries/generic/property_models/activity_coefficient.html\n",
- "* parmest - https://pyomo.readthedocs.io/en/stable/contributed_packages/parmest/index.html\n"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "\n",
- "Inline Exercise:\n",
- "import `ConcreteModel` from Pyomo and `FlowsheetBlock` from IDAES. \n",
- "
"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 2,
- "metadata": {
- "tags": [
- "solution"
- ]
- },
- "outputs": [],
- "source": [
- "# Todo: import ConcreteModel from pyomo.environ\n",
- "from pyomo.environ import ConcreteModel, value\n",
- "\n",
- "# Todo: import FlowsheetBlock from idaes.core\n",
- "from idaes.core import FlowsheetBlock"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "In the next cell, we import the parameter block used in this module and the idaes logger. "
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 3,
- "metadata": {
- "tags": []
- },
- "outputs": [],
- "source": [
- "from idaes.models.properties.activity_coeff_models.BTX_activity_coeff_VLE import (\n",
- " BTXParameterBlock,\n",
- ")\n",
- "import idaes.logger as idaeslog"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "In the next cell, we import `parmest` from Pyomo and the `pandas` package. We need `pandas` as `parmest` uses `pandas.dataframe` for handling the input data and the results."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 4,
- "metadata": {
- "tags": []
- },
- "outputs": [],
- "source": [
- "import pyomo.contrib.parmest.parmest as parmest\n",
- "import pandas as pd"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "## Setting up an initialized model\n",
- "\n",
- "We need to provide a method that returns an initialized model to the `parmest` tool in Pyomo."
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "\n",
- "Inline Exercise:\n",
- "Using what you have learned from previous modules, fill in the missing code below to return an initialized IDAES model. \n",
- "
"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 5,
- "metadata": {
- "tags": [
- "solution"
- ]
- },
- "outputs": [],
- "source": [
- "def NRTL_model(data):\n",
- "\n",
- " # Todo: Create a ConcreteModel object\n",
- " m = ConcreteModel()\n",
- "\n",
- " # Todo: Create FlowsheetBlock object\n",
- " m.fs = FlowsheetBlock(dynamic=False)\n",
- "\n",
- " # Todo: Create a properties parameter object with the following options:\n",
- " # \"valid_phase\": ('Liq', 'Vap')\n",
- " # \"activity_coeff_model\": 'NRTL'\n",
- " m.fs.properties = BTXParameterBlock(\n",
- " valid_phase=(\"Liq\", \"Vap\"), activity_coeff_model=\"NRTL\"\n",
- " )\n",
- " m.fs.state_block = m.fs.properties.build_state_block(defined_state=True)\n",
- "\n",
- " # Fix the state variables on the state block\n",
- " # hint: state variables exist on the state block i.e. on m.fs.state_block\n",
- "\n",
- " m.fs.state_block.flow_mol.fix(1)\n",
- " m.fs.state_block.temperature.fix(368)\n",
- " m.fs.state_block.pressure.fix(101325)\n",
- " m.fs.state_block.mole_frac_comp[\"benzene\"].fix(0.5)\n",
- " m.fs.state_block.mole_frac_comp[\"toluene\"].fix(0.5)\n",
- "\n",
- " # Fix NRTL specific parameters.\n",
- "\n",
- " # non-randomness parameter - alpha_ij (set at 0.3, 0 if i=j)\n",
- " m.fs.properties.alpha[\"benzene\", \"benzene\"].fix(0)\n",
- " m.fs.properties.alpha[\"benzene\", \"toluene\"].fix(0.3)\n",
- " m.fs.properties.alpha[\"toluene\", \"toluene\"].fix(0)\n",
- " m.fs.properties.alpha[\"toluene\", \"benzene\"].fix(0.3)\n",
- "\n",
- " # binary interaction parameter - tau_ij (0 if i=j, else to be estimated later but fixing to initialize)\n",
- " m.fs.properties.tau[\"benzene\", \"benzene\"].fix(0)\n",
- " m.fs.properties.tau[\"benzene\", \"toluene\"].fix(-0.9)\n",
- " m.fs.properties.tau[\"toluene\", \"toluene\"].fix(0)\n",
- " m.fs.properties.tau[\"toluene\", \"benzene\"].fix(1.4)\n",
- "\n",
- " # Initialize the flash unit\n",
- " m.fs.state_block.initialize(outlvl=idaeslog.INFO_LOW)\n",
- "\n",
- " # Fix at actual temperature\n",
- " m.fs.state_block.temperature.fix(float(data[\"temperature\"]))\n",
- "\n",
- " # Set bounds on variables to be estimated\n",
- " m.fs.properties.tau[\"benzene\", \"toluene\"].setlb(-5)\n",
- " m.fs.properties.tau[\"benzene\", \"toluene\"].setub(5)\n",
- "\n",
- " m.fs.properties.tau[\"toluene\", \"benzene\"].setlb(-5)\n",
- " m.fs.properties.tau[\"toluene\", \"benzene\"].setub(5)\n",
- "\n",
- " # Return initialized flash model\n",
- " return m"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "## Parameter estimation using parmest"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "In addition to providing a method to return an initialized model, the `parmest` tool needs the following:\n",
- "\n",
- "* List of variable names to be estimated\n",
- "* Dataset\n",
- "* Expression to compute the sum of squared errors\n"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "In this example, we only estimate the binary interaction parameter (`tau_ij`). Given that this variable is usually indexed as `tau_ij = Var(component_list, component_list)`, there are 2*2=4 degrees of freedom. However, when i=j, the binary interaction parameter is 0. Therefore, in this problem, we estimate the binary interaction parameter for the following variables only:\n",
- "\n",
- "* fs.properties.tau['benzene', 'toluene']\n",
- "* fs.properties.tau['toluene', 'benzene']\n",
- "\n",
- "\n",
- "Inline Exercise:\n",
- "Create a list called `variable_name` with the above-mentioned variables declared as strings.\n",
- "
"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 6,
- "metadata": {
- "tags": [
- "solution"
- ]
- },
- "outputs": [],
- "source": [
- "# Todo: Create a list of vars to estimate\n",
- "variable_name = [\n",
- " \"fs.properties.tau['benzene', 'toluene']\",\n",
- " \"fs.properties.tau['toluene', 'benzene']\",\n",
- "]"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "Pyomo's `parmest` tool supports the following data formats:\n",
- "- pandas dataframe\n",
- "- list of dictionaries\n",
- "- list of json file names.\n",
- "\n",
- "Please see the documentation for more details. \n",
- "\n",
- "For this example, we load data from the csv file `BT_NRTL_dataset.csv`. The dataset consists of fifty data points which provide the mole fraction of benzene in the vapor and liquid phase as a function of temperature. "
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 7,
- "metadata": {
- "tags": []
- },
- "outputs": [
+ "cells": [
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "metadata": {
+ "tags": [
+ "header",
+ "hide-cell"
+ ]
+ },
+ "outputs": [],
+ "source": [
+ "###############################################################################\n",
+ "# The Institute for the Design of Advanced Energy Systems Integrated Platform\n",
+ "# Framework (IDAES IP) was produced under the DOE Institute for the\n",
+ "# Design of Advanced Energy Systems (IDAES).\n",
+ "#\n",
+ "# Copyright (c) 2018-2026 by the software owners: The Regents of the\n",
+ "# University of California, through Lawrence Berkeley National Laboratory,\n",
+ "# National Technology & Engineering Solutions of Sandia, LLC, Carnegie Mellon\n",
+ "# University, West Virginia University Research Corporation, et al.\n",
+ "# All rights reserved. Please see the files COPYRIGHT.md and LICENSE.md\n",
+ "# for full copyright and license information.\n",
+ "###############################################################################"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Parameter Estimation Using the NRTL State Block\n",
+ "\n",
+ "Author: Jaffer Ghouse \n",
+ "Maintainer: Stephen Cini \n",
+ "Updated: 2026-06-11 \n",
+ "\n",
+ "In this module, we use Pyomo's `parmest` tool in conjunction with IDAES models for parameter estimation. We demonstrate these tools by estimating the parameters associated with the NRTL property model for a benzene-toluene mixture. The NRTL model has 2 sets of parameters: the non-randomness parameter (`alpha_ij`) and the binary interaction parameter (`tau_ij`), where `i` and `j` are the pure component species. In this example, we only estimate the binary interaction parameter (`tau_ij`) for a given dataset. When estimating parameters associated with the property package, IDAES provides the flexibility of doing the parameter estimation by just using the state block or by using a unit model with a specified property package. This module will demonstrate parameter estimation by using only the state block. \n",
+ "\n",
+ "We will complete the following tasks:\n",
+ "* Set up a method to return an initialized model\n",
+ "* Set up the parameter estimation problem using `parmest`\n",
+ "* Analyze the results\n",
+ "* Demonstrate advanced features using `parmest`\n",
+ "\n",
+ "## Key links to documentation:\n",
+ "* NRTL Model - https://idaes-pse.readthedocs.io/en/stable/reference_guides/model_libraries/generic/property_models/activity_coefficient.html\n",
+ "* parmest - https://pyomo.readthedocs.io/en/stable/explanation/analysis/parmest/index.html\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "\n",
+ "Inline Exercise:\n",
+ "import `ConcreteModel`, `value`, and `Suffix` from Pyomo, and `FlowsheetBlock`from IDAES. \n",
+ "
"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 3,
+ "metadata": {
+ "tags": [
+ "solution"
+ ]
+ },
+ "outputs": [],
+ "source": [
+ "# Todo: import ConcreteModel, value, and Suffix from pyomo.environ\n",
+ "from pyomo.environ import ConcreteModel, value, Suffix\n",
+ "\n",
+ "# Todo: import FlowsheetBlock from idaes.core\n",
+ "from idaes.core import FlowsheetBlock"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "In the next cell, we import the parameter block used in this module and the idaes logger. "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 4,
+ "metadata": {
+ "tags": []
+ },
+ "outputs": [],
+ "source": [
+ "from idaes.models.properties.activity_coeff_models.BTX_activity_coeff_VLE import (\n",
+ " BTXParameterBlock,\n",
+ ")\n",
+ "import idaes.logger as idaeslog"
+ ]
+ },
{
- "data": {
- "text/html": [
- "\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " | \n",
- " temperature | \n",
- " liq_benzene | \n",
- " vap_benzene | \n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " | 0 | \n",
- " 365.500000 | \n",
- " 0.480953 | \n",
- " 0.692110 | \n",
- "
\n",
- " \n",
- " | 1 | \n",
- " 365.617647 | \n",
- " 0.462444 | \n",
- " 0.667699 | \n",
- "
\n",
- " \n",
- " | 2 | \n",
- " 365.735294 | \n",
- " 0.477984 | \n",
- " 0.692441 | \n",
- "
\n",
- " \n",
- " | 3 | \n",
- " 365.852941 | \n",
- " 0.440547 | \n",
- " 0.640336 | \n",
- "
\n",
- " \n",
- " | 4 | \n",
- " 365.970588 | \n",
- " 0.427421 | \n",
- " 0.623328 | \n",
- "
\n",
- " \n",
- " | 5 | \n",
- " 366.088235 | \n",
- " 0.442725 | \n",
- " 0.647796 | \n",
- "
\n",
- " \n",
- " | 6 | \n",
- " 366.205882 | \n",
- " 0.434374 | \n",
- " 0.637691 | \n",
- "
\n",
- " \n",
- " | 7 | \n",
- " 366.323529 | \n",
- " 0.444642 | \n",
- " 0.654933 | \n",
- "
\n",
- " \n",
- " | 8 | \n",
- " 366.441176 | \n",
- " 0.427132 | \n",
- " 0.631229 | \n",
- "
\n",
- " \n",
- " | 9 | \n",
- " 366.558824 | \n",
- " 0.446301 | \n",
- " 0.661743 | \n",
- "
\n",
- " \n",
- " | 10 | \n",
- " 366.676471 | \n",
- " 0.438004 | \n",
- " 0.651591 | \n",
- "
\n",
- " \n",
- " | 11 | \n",
- " 366.794118 | \n",
- " 0.425320 | \n",
- " 0.634814 | \n",
- "
\n",
- " \n",
- " | 12 | \n",
- " 366.911765 | \n",
- " 0.439435 | \n",
- " 0.658047 | \n",
- "
\n",
- " \n",
- " | 13 | \n",
- " 367.029412 | \n",
- " 0.435655 | \n",
- " 0.654539 | \n",
- "
\n",
- " \n",
- " | 14 | \n",
- " 367.147059 | \n",
- " 0.401350 | \n",
- " 0.604987 | \n",
- "
\n",
- " \n",
- " | 15 | \n",
- " 367.264706 | \n",
- " 0.397862 | \n",
- " 0.601703 | \n",
- "
\n",
- " \n",
- " | 16 | \n",
- " 367.382353 | \n",
- " 0.415821 | \n",
- " 0.630930 | \n",
- "
\n",
- " \n",
- " | 17 | \n",
- " 367.500000 | \n",
- " 0.420667 | \n",
- " 0.640380 | \n",
- "
\n",
- " \n",
- " | 18 | \n",
- " 367.617647 | \n",
- " 0.391683 | \n",
- " 0.598214 | \n",
- "
\n",
- " \n",
- " | 19 | \n",
- " 367.735294 | \n",
- " 0.404903 | \n",
- " 0.620432 | \n",
- "
\n",
- " \n",
- " | 20 | \n",
- " 367.852941 | \n",
- " 0.409563 | \n",
- " 0.629626 | \n",
- "
\n",
- " \n",
- " | 21 | \n",
- " 367.970588 | \n",
- " 0.389488 | \n",
- " 0.600722 | \n",
- "
\n",
- " \n",
- " | 22 | \n",
- " 368.000000 | \n",
- " 0.396789 | \n",
- " 0.612483 | \n",
- "
\n",
- " \n",
- " | 23 | \n",
- " 368.088235 | \n",
- " 0.398162 | \n",
- " 0.616106 | \n",
- "
\n",
- " \n",
- " | 24 | \n",
- " 368.205882 | \n",
- " 0.362340 | \n",
- " 0.562505 | \n",
- "
\n",
- " \n",
- " | 25 | \n",
- " 368.323529 | \n",
- " 0.386958 | \n",
- " 0.602680 | \n",
- "
\n",
- " \n",
- " | 26 | \n",
- " 368.441176 | \n",
- " 0.363643 | \n",
- " 0.568210 | \n",
- "
\n",
- " \n",
- " | 27 | \n",
- " 368.558824 | \n",
- " 0.368118 | \n",
- " 0.577072 | \n",
- "
\n",
- " \n",
- " | 28 | \n",
- " 368.676471 | \n",
- " 0.384098 | \n",
- " 0.604078 | \n",
- "
\n",
- " \n",
- " | 29 | \n",
- " 368.794118 | \n",
- " 0.353605 | \n",
- " 0.557925 | \n",
- "
\n",
- " \n",
- " | 30 | \n",
- " 368.911765 | \n",
- " 0.346474 | \n",
- " 0.548445 | \n",
- "
\n",
- " \n",
- " | 31 | \n",
- " 369.029412 | \n",
- " 0.350741 | \n",
- " 0.556996 | \n",
- "
\n",
- " \n",
- " | 32 | \n",
- " 369.147059 | \n",
- " 0.362347 | \n",
- " 0.577286 | \n",
- "
\n",
- " \n",
- " | 33 | \n",
- " 369.264706 | \n",
- " 0.362578 | \n",
- " 0.579519 | \n",
- "
\n",
- " \n",
- " | 34 | \n",
- " 369.382353 | \n",
- " 0.340765 | \n",
- " 0.546411 | \n",
- "
\n",
- " \n",
- " | 35 | \n",
- " 369.500000 | \n",
- " 0.337462 | \n",
- " 0.542857 | \n",
- "
\n",
- " \n",
- " | 36 | \n",
- " 369.617647 | \n",
- " 0.355729 | \n",
- " 0.574083 | \n",
- "
\n",
- " \n",
- " | 37 | \n",
- " 369.735294 | \n",
- " 0.348679 | \n",
- " 0.564513 | \n",
- "
\n",
- " \n",
- " | 38 | \n",
- " 369.852941 | \n",
- " 0.338187 | \n",
- " 0.549284 | \n",
- "
\n",
- " \n",
- " | 39 | \n",
- " 369.970588 | \n",
- " 0.324360 | \n",
- " 0.528514 | \n",
- "
\n",
- " \n",
- " | 40 | \n",
- " 370.088235 | \n",
- " 0.310753 | \n",
- " 0.507964 | \n",
- "
\n",
- " \n",
- " | 41 | \n",
- " 370.205882 | \n",
- " 0.311037 | \n",
- " 0.510055 | \n",
- "
\n",
- " \n",
- " | 42 | \n",
- " 370.323529 | \n",
- " 0.311263 | \n",
- " 0.512055 | \n",
- "
\n",
- " \n",
- " | 43 | \n",
- " 370.441176 | \n",
- " 0.308081 | \n",
- " 0.508437 | \n",
- "
\n",
- " \n",
- " | 44 | \n",
- " 370.558824 | \n",
- " 0.308224 | \n",
- " 0.510293 | \n",
- "
\n",
- " \n",
- " | 45 | \n",
- " 370.676471 | \n",
- " 0.318148 | \n",
- " 0.528399 | \n",
- "
\n",
- " \n",
- " | 46 | \n",
- " 370.794118 | \n",
- " 0.308334 | \n",
- " 0.513728 | \n",
- "
\n",
- " \n",
- " | 47 | \n",
- " 370.911765 | \n",
- " 0.317937 | \n",
- " 0.531410 | \n",
- "
\n",
- " \n",
- " | 48 | \n",
- " 371.029412 | \n",
- " 0.289149 | \n",
- " 0.484824 | \n",
- "
\n",
- " \n",
- " | 49 | \n",
- " 371.147059 | \n",
- " 0.298637 | \n",
- " 0.502318 | \n",
- "
\n",
- " \n",
- "
\n",
- "
"
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "In the next cell, we import `parmest` from Pyomo and the `pandas` package. We need `pandas` as `parmest` uses `pandas.dataframe` for handling the input data and the results."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 5,
+ "metadata": {
+ "tags": []
+ },
+ "outputs": [],
+ "source": [
+ "import pyomo.contrib.parmest.parmest as parmest\n",
+ "import pandas as pd"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Setting up an initialized model\n",
+ "\n",
+ "We need to provide a method that returns an initialized model to the `parmest` tool in Pyomo."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "\n",
+ "Inline Exercise:\n",
+ "Using what you have learned from previous modules, fill in the missing code below to return an initialized IDAES model. \n",
+ "
"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 7,
+ "metadata": {
+ "tags": [
+ "solution"
+ ]
+ },
+ "outputs": [],
+ "source": [
+ "def NRTL_model(data):\n",
+ "\n",
+ " # Todo: Create a ConcreteModel object\n",
+ " m = ConcreteModel()\n",
+ "\n",
+ " # Todo: Create FlowsheetBlock object\n",
+ " m.fs = FlowsheetBlock(dynamic=False)\n",
+ "\n",
+ " # Todo: Create a properties parameter object with the following options:\n",
+ " # \"valid_phase\": ('Liq', 'Vap')\n",
+ " # \"activity_coeff_model\": 'NRTL'\n",
+ " m.fs.properties = BTXParameterBlock(\n",
+ " valid_phase=(\"Liq\", \"Vap\"), activity_coeff_model=\"NRTL\"\n",
+ " )\n",
+ " m.fs.state_block = m.fs.properties.build_state_block(defined_state=True)\n",
+ "\n",
+ " # Fix the state variables on the state block\n",
+ " # hint: state variables exist on the state block i.e. on m.fs.state_block\n",
+ "\n",
+ " m.fs.state_block.flow_mol.fix(1)\n",
+ " m.fs.state_block.temperature.fix(368)\n",
+ " m.fs.state_block.pressure.fix(101325)\n",
+ " m.fs.state_block.mole_frac_comp[\"benzene\"].fix(0.5)\n",
+ " m.fs.state_block.mole_frac_comp[\"toluene\"].fix(0.5)\n",
+ "\n",
+ " # Fix NRTL specific parameters.\n",
+ "\n",
+ " # non-randomness parameter - alpha_ij (set at 0.3, 0 if i=j)\n",
+ " m.fs.properties.alpha[\"benzene\", \"benzene\"].fix(0)\n",
+ " m.fs.properties.alpha[\"benzene\", \"toluene\"].fix(0.3)\n",
+ " m.fs.properties.alpha[\"toluene\", \"toluene\"].fix(0)\n",
+ " m.fs.properties.alpha[\"toluene\", \"benzene\"].fix(0.3)\n",
+ "\n",
+ " # binary interaction parameter - tau_ij (0 if i=j, else to be estimated later but fixing to initialize)\n",
+ " m.fs.properties.tau[\"benzene\", \"benzene\"].fix(0)\n",
+ " m.fs.properties.tau[\"benzene\", \"toluene\"].fix(-0.9)\n",
+ " m.fs.properties.tau[\"toluene\", \"toluene\"].fix(0)\n",
+ " m.fs.properties.tau[\"toluene\", \"benzene\"].fix(1.4)\n",
+ "\n",
+ " # Initialize the flash unit\n",
+ " m.fs.state_block.initialize(outlvl=idaeslog.INFO_LOW)\n",
+ "\n",
+ " # Fix at actual temperature\n",
+ " if isinstance(data, dict) or isinstance(data, pd.Series):\n",
+ " m.fs.state_block.temperature.fix(float(data[\"temperature\"]))\n",
+ " elif isinstance(data, pd.DataFrame):\n",
+ " m.fs.state_block.temperature.fix(float(data.iloc[0][\"temperature\"]))\n",
+ " else:\n",
+ " raise ValueError(\"Unrecognized data type.\")\n",
+ "\n",
+ " # Set bounds on variables to be estimated\n",
+ " m.fs.properties.tau[\"benzene\", \"toluene\"].setlb(-5)\n",
+ " m.fs.properties.tau[\"benzene\", \"toluene\"].setub(5)\n",
+ "\n",
+ " m.fs.properties.tau[\"toluene\", \"benzene\"].setlb(-5)\n",
+ " m.fs.properties.tau[\"toluene\", \"benzene\"].setub(5)\n",
+ "\n",
+ " # Return initialized flash model\n",
+ " return m"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Parameter estimation using parmest"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "In addition to providing a method to return an initialized model, the `parmest` tool needs the following:\n",
+ "\n",
+ "* Experiment class to set up and label model with suffixes\n",
+ "* Dataset with multiple scenarios - organized into an experiment list\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Here we build an experiment class to label our model problem for parameter estimation. The labels are defined as a `Suffix`, and the main labels for our model are `experiment_outputs`, `unknown_parameters`, and `measurement_error`.\n",
+ "\n",
+ "For this problem, the error will be computed for the mole fraction of benzene in the vapor and liquid phase between the model prediction and data. The `experimental_outputs` will therefore be the mole fraction of benzene in the two phases.\n",
+ "\n",
+ "In this example, we only estimate the binary interaction parameter (`tau_ij`). Given that this variable is usually indexed as `tau_ij = Var(component_list, component_list)`, there are 2*2=4 degrees of freedom. However, when i=j, the binary interaction parameter is 0. Therefore, in this problem, we estimate the binary interaction parameter for the following variables only:\n",
+ "\n",
+ "* fs.properties.tau['benzene', 'toluene']\n",
+ "* fs.properties.tau['toluene', 'benzene']\n",
+ "\n",
+ "As shown below, these model components are used as our `unknown_parameters`.\n",
+ "\n",
+ "We define `measurement_error` as none so parmest calculates the value internally based on the experimental outputs. Refer to https://pyomo.readthedocs.io/en/stable/explanation/analysis/parmest/driver.html for more information. "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 9,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Build an experiment class to take advantage of new parmest interface\n",
+ "from pyomo.contrib.parmest.experiment import Experiment\n",
+ "\n",
+ "\n",
+ "class NRTLExperiment(Experiment):\n",
+ " \"\"\"Experiment class for parameter estimation of NRTL model using parmest\"\"\"\n",
+ "\n",
+ " def __init__(self, data, meas_error=None):\n",
+ " \"\"\"Initialize the NRTLExperiment class\n",
+ "\n",
+ " Args:\n",
+ " data: DataFrame containing the experimental data\n",
+ " meas_error: Measurement error for the data (optional)\n",
+ " \"\"\"\n",
+ " self.model = None\n",
+ " self.data = data\n",
+ " self.meas_error = meas_error\n",
+ "\n",
+ " def create_model(self):\n",
+ " \"\"\"Create the Pyomo model for the NRTL parameter estimation problem\"\"\"\n",
+ " self.model = NRTL_model(self.data)\n",
+ "\n",
+ " def label_model(self):\n",
+ " from pyomo.environ import Set, Expression\n",
+ "\n",
+ " m = self.model\n",
+ "\n",
+ " # Parmest expects the first index of experiment outputs to be the data point\n",
+ " # This is a workaround that will be addressed and corrected in a future release.\n",
+ "\n",
+ " m.data_point = Set(initialize=[0])\n",
+ "\n",
+ " # Wrap IDAES variables in Expressions indexed by data point\n",
+ " m.liq_benzene_out = Expression(\n",
+ " m.data_point,\n",
+ " rule=lambda m, i: m.fs.state_block.mole_frac_phase_comp[\"Liq\", \"benzene\"],\n",
+ " )\n",
+ "\n",
+ " m.vap_benzene_out = Expression(\n",
+ " m.data_point,\n",
+ " rule=lambda m, i: m.fs.state_block.mole_frac_phase_comp[\"Vap\", \"benzene\"],\n",
+ " )\n",
+ "\n",
+ " m.experiment_outputs = Suffix(direction=Suffix.LOCAL)\n",
+ "\n",
+ " m.experiment_outputs[m.liq_benzene_out[0]] = float(self.data[\"liq_benzene\"])\n",
+ " m.experiment_outputs[m.vap_benzene_out[0]] = float(self.data[\"vap_benzene\"])\n",
+ "\n",
+ " m.measurement_error = Suffix(direction=Suffix.LOCAL)\n",
+ " m.measurement_error.update(\n",
+ " [\n",
+ " (m.liq_benzene_out[0], self.meas_error),\n",
+ " (m.vap_benzene_out[0], self.meas_error),\n",
+ " ]\n",
+ " )\n",
+ "\n",
+ " # Add unknown parameters to the model for easier access\n",
+ " m.unknown_parameters = Suffix(direction=Suffix.LOCAL)\n",
+ " m.unknown_parameters.update(\n",
+ " (k, value(k))\n",
+ " for k in [\n",
+ " m.fs.properties.tau[\"benzene\", \"toluene\"],\n",
+ " m.fs.properties.tau[\"toluene\", \"benzene\"],\n",
+ " ]\n",
+ " )\n",
+ "\n",
+ " def get_labeled_model(self):\n",
+ " \"\"\"Return the labeled model\"\"\"\n",
+ " if self.model is None:\n",
+ " self.create_model()\n",
+ " self.label_model()\n",
+ " return self.model"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Pyomo's `parmest` tool supports the following data formats:\n",
+ "- pandas dataframe\n",
+ "- list of dictionaries\n",
+ "- list of json file names.\n",
+ "\n",
+ "Please see the documentation for more details. \n",
+ "\n",
+ "For this example, we load data from the csv file `BT_NRTL_dataset.csv`. The dataset consists of fifty data points which provide the mole fraction of benzene in the vapor and liquid phase as a function of temperature. "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 10,
+ "metadata": {
+ "tags": []
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " temperature | \n",
+ " liq_benzene | \n",
+ " vap_benzene | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 0 | \n",
+ " 365.500000 | \n",
+ " 0.480953 | \n",
+ " 0.692110 | \n",
+ "
\n",
+ " \n",
+ " | 1 | \n",
+ " 365.617647 | \n",
+ " 0.462444 | \n",
+ " 0.667699 | \n",
+ "
\n",
+ " \n",
+ " | 2 | \n",
+ " 365.735294 | \n",
+ " 0.477984 | \n",
+ " 0.692441 | \n",
+ "
\n",
+ " \n",
+ " | 3 | \n",
+ " 365.852941 | \n",
+ " 0.440547 | \n",
+ " 0.640336 | \n",
+ "
\n",
+ " \n",
+ " | 4 | \n",
+ " 365.970588 | \n",
+ " 0.427421 | \n",
+ " 0.623328 | \n",
+ "
\n",
+ " \n",
+ " | 5 | \n",
+ " 366.088235 | \n",
+ " 0.442725 | \n",
+ " 0.647796 | \n",
+ "
\n",
+ " \n",
+ " | 6 | \n",
+ " 366.205882 | \n",
+ " 0.434374 | \n",
+ " 0.637691 | \n",
+ "
\n",
+ " \n",
+ " | 7 | \n",
+ " 366.323529 | \n",
+ " 0.444642 | \n",
+ " 0.654933 | \n",
+ "
\n",
+ " \n",
+ " | 8 | \n",
+ " 366.441176 | \n",
+ " 0.427132 | \n",
+ " 0.631229 | \n",
+ "
\n",
+ " \n",
+ " | 9 | \n",
+ " 366.558824 | \n",
+ " 0.446301 | \n",
+ " 0.661743 | \n",
+ "
\n",
+ " \n",
+ " | 10 | \n",
+ " 366.676471 | \n",
+ " 0.438004 | \n",
+ " 0.651591 | \n",
+ "
\n",
+ " \n",
+ " | 11 | \n",
+ " 366.794118 | \n",
+ " 0.425320 | \n",
+ " 0.634814 | \n",
+ "
\n",
+ " \n",
+ " | 12 | \n",
+ " 366.911765 | \n",
+ " 0.439435 | \n",
+ " 0.658047 | \n",
+ "
\n",
+ " \n",
+ " | 13 | \n",
+ " 367.029412 | \n",
+ " 0.435655 | \n",
+ " 0.654539 | \n",
+ "
\n",
+ " \n",
+ " | 14 | \n",
+ " 367.147059 | \n",
+ " 0.401350 | \n",
+ " 0.604987 | \n",
+ "
\n",
+ " \n",
+ " | 15 | \n",
+ " 367.264706 | \n",
+ " 0.397862 | \n",
+ " 0.601703 | \n",
+ "
\n",
+ " \n",
+ " | 16 | \n",
+ " 367.382353 | \n",
+ " 0.415821 | \n",
+ " 0.630930 | \n",
+ "
\n",
+ " \n",
+ " | 17 | \n",
+ " 367.500000 | \n",
+ " 0.420667 | \n",
+ " 0.640380 | \n",
+ "
\n",
+ " \n",
+ " | 18 | \n",
+ " 367.617647 | \n",
+ " 0.391683 | \n",
+ " 0.598214 | \n",
+ "
\n",
+ " \n",
+ " | 19 | \n",
+ " 367.735294 | \n",
+ " 0.404903 | \n",
+ " 0.620432 | \n",
+ "
\n",
+ " \n",
+ " | 20 | \n",
+ " 367.852941 | \n",
+ " 0.409563 | \n",
+ " 0.629626 | \n",
+ "
\n",
+ " \n",
+ " | 21 | \n",
+ " 367.970588 | \n",
+ " 0.389488 | \n",
+ " 0.600722 | \n",
+ "
\n",
+ " \n",
+ " | 22 | \n",
+ " 368.000000 | \n",
+ " 0.396789 | \n",
+ " 0.612483 | \n",
+ "
\n",
+ " \n",
+ " | 23 | \n",
+ " 368.088235 | \n",
+ " 0.398162 | \n",
+ " 0.616106 | \n",
+ "
\n",
+ " \n",
+ " | 24 | \n",
+ " 368.205882 | \n",
+ " 0.362340 | \n",
+ " 0.562505 | \n",
+ "
\n",
+ " \n",
+ " | 25 | \n",
+ " 368.323529 | \n",
+ " 0.386958 | \n",
+ " 0.602680 | \n",
+ "
\n",
+ " \n",
+ " | 26 | \n",
+ " 368.441176 | \n",
+ " 0.363643 | \n",
+ " 0.568210 | \n",
+ "
\n",
+ " \n",
+ " | 27 | \n",
+ " 368.558824 | \n",
+ " 0.368118 | \n",
+ " 0.577072 | \n",
+ "
\n",
+ " \n",
+ " | 28 | \n",
+ " 368.676471 | \n",
+ " 0.384098 | \n",
+ " 0.604078 | \n",
+ "
\n",
+ " \n",
+ " | 29 | \n",
+ " 368.794118 | \n",
+ " 0.353605 | \n",
+ " 0.557925 | \n",
+ "
\n",
+ " \n",
+ " | 30 | \n",
+ " 368.911765 | \n",
+ " 0.346474 | \n",
+ " 0.548445 | \n",
+ "
\n",
+ " \n",
+ " | 31 | \n",
+ " 369.029412 | \n",
+ " 0.350741 | \n",
+ " 0.556996 | \n",
+ "
\n",
+ " \n",
+ " | 32 | \n",
+ " 369.147059 | \n",
+ " 0.362347 | \n",
+ " 0.577286 | \n",
+ "
\n",
+ " \n",
+ " | 33 | \n",
+ " 369.264706 | \n",
+ " 0.362578 | \n",
+ " 0.579519 | \n",
+ "
\n",
+ " \n",
+ " | 34 | \n",
+ " 369.382353 | \n",
+ " 0.340765 | \n",
+ " 0.546411 | \n",
+ "
\n",
+ " \n",
+ " | 35 | \n",
+ " 369.500000 | \n",
+ " 0.337462 | \n",
+ " 0.542857 | \n",
+ "
\n",
+ " \n",
+ " | 36 | \n",
+ " 369.617647 | \n",
+ " 0.355729 | \n",
+ " 0.574083 | \n",
+ "
\n",
+ " \n",
+ " | 37 | \n",
+ " 369.735294 | \n",
+ " 0.348679 | \n",
+ " 0.564513 | \n",
+ "
\n",
+ " \n",
+ " | 38 | \n",
+ " 369.852941 | \n",
+ " 0.338187 | \n",
+ " 0.549284 | \n",
+ "
\n",
+ " \n",
+ " | 39 | \n",
+ " 369.970588 | \n",
+ " 0.324360 | \n",
+ " 0.528514 | \n",
+ "
\n",
+ " \n",
+ " | 40 | \n",
+ " 370.088235 | \n",
+ " 0.310753 | \n",
+ " 0.507964 | \n",
+ "
\n",
+ " \n",
+ " | 41 | \n",
+ " 370.205882 | \n",
+ " 0.311037 | \n",
+ " 0.510055 | \n",
+ "
\n",
+ " \n",
+ " | 42 | \n",
+ " 370.323529 | \n",
+ " 0.311263 | \n",
+ " 0.512055 | \n",
+ "
\n",
+ " \n",
+ " | 43 | \n",
+ " 370.441176 | \n",
+ " 0.308081 | \n",
+ " 0.508437 | \n",
+ "
\n",
+ " \n",
+ " | 44 | \n",
+ " 370.558824 | \n",
+ " 0.308224 | \n",
+ " 0.510293 | \n",
+ "
\n",
+ " \n",
+ " | 45 | \n",
+ " 370.676471 | \n",
+ " 0.318148 | \n",
+ " 0.528399 | \n",
+ "
\n",
+ " \n",
+ " | 46 | \n",
+ " 370.794118 | \n",
+ " 0.308334 | \n",
+ " 0.513728 | \n",
+ "
\n",
+ " \n",
+ " | 47 | \n",
+ " 370.911765 | \n",
+ " 0.317937 | \n",
+ " 0.531410 | \n",
+ "
\n",
+ " \n",
+ " | 48 | \n",
+ " 371.029412 | \n",
+ " 0.289149 | \n",
+ " 0.484824 | \n",
+ "
\n",
+ " \n",
+ " | 49 | \n",
+ " 371.147059 | \n",
+ " 0.298637 | \n",
+ " 0.502318 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " temperature liq_benzene vap_benzene\n",
+ "0 365.500000 0.480953 0.692110\n",
+ "1 365.617647 0.462444 0.667699\n",
+ "2 365.735294 0.477984 0.692441\n",
+ "3 365.852941 0.440547 0.640336\n",
+ "4 365.970588 0.427421 0.623328\n",
+ "5 366.088235 0.442725 0.647796\n",
+ "6 366.205882 0.434374 0.637691\n",
+ "7 366.323529 0.444642 0.654933\n",
+ "8 366.441176 0.427132 0.631229\n",
+ "9 366.558824 0.446301 0.661743\n",
+ "10 366.676471 0.438004 0.651591\n",
+ "11 366.794118 0.425320 0.634814\n",
+ "12 366.911765 0.439435 0.658047\n",
+ "13 367.029412 0.435655 0.654539\n",
+ "14 367.147059 0.401350 0.604987\n",
+ "15 367.264706 0.397862 0.601703\n",
+ "16 367.382353 0.415821 0.630930\n",
+ "17 367.500000 0.420667 0.640380\n",
+ "18 367.617647 0.391683 0.598214\n",
+ "19 367.735294 0.404903 0.620432\n",
+ "20 367.852941 0.409563 0.629626\n",
+ "21 367.970588 0.389488 0.600722\n",
+ "22 368.000000 0.396789 0.612483\n",
+ "23 368.088235 0.398162 0.616106\n",
+ "24 368.205882 0.362340 0.562505\n",
+ "25 368.323529 0.386958 0.602680\n",
+ "26 368.441176 0.363643 0.568210\n",
+ "27 368.558824 0.368118 0.577072\n",
+ "28 368.676471 0.384098 0.604078\n",
+ "29 368.794118 0.353605 0.557925\n",
+ "30 368.911765 0.346474 0.548445\n",
+ "31 369.029412 0.350741 0.556996\n",
+ "32 369.147059 0.362347 0.577286\n",
+ "33 369.264706 0.362578 0.579519\n",
+ "34 369.382353 0.340765 0.546411\n",
+ "35 369.500000 0.337462 0.542857\n",
+ "36 369.617647 0.355729 0.574083\n",
+ "37 369.735294 0.348679 0.564513\n",
+ "38 369.852941 0.338187 0.549284\n",
+ "39 369.970588 0.324360 0.528514\n",
+ "40 370.088235 0.310753 0.507964\n",
+ "41 370.205882 0.311037 0.510055\n",
+ "42 370.323529 0.311263 0.512055\n",
+ "43 370.441176 0.308081 0.508437\n",
+ "44 370.558824 0.308224 0.510293\n",
+ "45 370.676471 0.318148 0.528399\n",
+ "46 370.794118 0.308334 0.513728\n",
+ "47 370.911765 0.317937 0.531410\n",
+ "48 371.029412 0.289149 0.484824\n",
+ "49 371.147059 0.298637 0.502318"
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ }
],
- "text/plain": [
- " temperature liq_benzene vap_benzene\n",
- "0 365.500000 0.480953 0.692110\n",
- "1 365.617647 0.462444 0.667699\n",
- "2 365.735294 0.477984 0.692441\n",
- "3 365.852941 0.440547 0.640336\n",
- "4 365.970588 0.427421 0.623328\n",
- "5 366.088235 0.442725 0.647796\n",
- "6 366.205882 0.434374 0.637691\n",
- "7 366.323529 0.444642 0.654933\n",
- "8 366.441176 0.427132 0.631229\n",
- "9 366.558824 0.446301 0.661743\n",
- "10 366.676471 0.438004 0.651591\n",
- "11 366.794118 0.425320 0.634814\n",
- "12 366.911765 0.439435 0.658047\n",
- "13 367.029412 0.435655 0.654539\n",
- "14 367.147059 0.401350 0.604987\n",
- "15 367.264706 0.397862 0.601703\n",
- "16 367.382353 0.415821 0.630930\n",
- "17 367.500000 0.420667 0.640380\n",
- "18 367.617647 0.391683 0.598214\n",
- "19 367.735294 0.404903 0.620432\n",
- "20 367.852941 0.409563 0.629626\n",
- "21 367.970588 0.389488 0.600722\n",
- "22 368.000000 0.396789 0.612483\n",
- "23 368.088235 0.398162 0.616106\n",
- "24 368.205882 0.362340 0.562505\n",
- "25 368.323529 0.386958 0.602680\n",
- "26 368.441176 0.363643 0.568210\n",
- "27 368.558824 0.368118 0.577072\n",
- "28 368.676471 0.384098 0.604078\n",
- "29 368.794118 0.353605 0.557925\n",
- "30 368.911765 0.346474 0.548445\n",
- "31 369.029412 0.350741 0.556996\n",
- "32 369.147059 0.362347 0.577286\n",
- "33 369.264706 0.362578 0.579519\n",
- "34 369.382353 0.340765 0.546411\n",
- "35 369.500000 0.337462 0.542857\n",
- "36 369.617647 0.355729 0.574083\n",
- "37 369.735294 0.348679 0.564513\n",
- "38 369.852941 0.338187 0.549284\n",
- "39 369.970588 0.324360 0.528514\n",
- "40 370.088235 0.310753 0.507964\n",
- "41 370.205882 0.311037 0.510055\n",
- "42 370.323529 0.311263 0.512055\n",
- "43 370.441176 0.308081 0.508437\n",
- "44 370.558824 0.308224 0.510293\n",
- "45 370.676471 0.318148 0.528399\n",
- "46 370.794118 0.308334 0.513728\n",
- "47 370.911765 0.317937 0.531410\n",
- "48 371.029412 0.289149 0.484824\n",
- "49 371.147059 0.298637 0.502318"
+ "source": [
+ "# Load data from csv\n",
+ "data = pd.read_csv(\"BT_NRTL_dataset.csv\")\n",
+ "\n",
+ "# Display the dataset\n",
+ "display(data)"
]
- },
- "metadata": {},
- "output_type": "display_data"
- }
- ],
- "source": [
- "# Load data from csv\n",
- "data = pd.read_csv(\"BT_NRTL_dataset.csv\")\n",
- "\n",
- "# Display the dataset\n",
- "display(data)"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "We need to provide a method to return an expression to compute the sum of squared errors that will be used as the objective in solving the parameter estimation problem. For this problem, the error will be computed for the mole fraction of benzene in the vapor and liquid phase between the model prediction and data. \n",
- "\n",
- "\n",
- "Inline Exercise:\n",
- "Complete the following cell by adding an expression to compute the sum of square errors. \n",
- "
"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 8,
- "metadata": {
- "tags": [
- "solution"
- ]
- },
- "outputs": [],
- "source": [
- "# Create method to return an expression that computes the sum of squared error\n",
- "def SSE(m, data):\n",
- " # Todo: Add expression for computing the sum of squared errors in mole fraction of benzene in the liquid\n",
- " # and vapor phase. For example, the squared error for the vapor phase is:\n",
- " # (float(data[\"vap_benzene\"]) - m.fs.state_block.mole_frac_phase_comp[\"Vap\", \"benzene\"])**2\n",
- " expr = (\n",
- " float(data[\"vap_benzene\"])\n",
- " - m.fs.state_block.mole_frac_phase_comp[\"Vap\", \"benzene\"]\n",
- " ) ** 2 + (\n",
- " float(data[\"liq_benzene\"])\n",
- " - m.fs.state_block.mole_frac_phase_comp[\"Liq\", \"benzene\"]\n",
- " ) ** 2\n",
- " return expr * 1e4"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "\n",
- "Note:\n",
- "Notice that we have scaled the expression up by a factor of 10000 as the SSE computed here will be an extremely small number given that we are using the difference in mole fraction in our expression. This will help in using a well-scaled objective to improve solve robustness when using IPOPT. \n",
- "
\n"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "We are now ready to set up the parameter estimation problem. We will create a parameter estimation object called `pest`. As shown below, we pass the method that returns an initialized model, data, variable_name, and the SSE expression to the Estimator method. `tee=True` will print the solver output after solving the parameter estimation problem. "
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 9,
- "metadata": {},
- "outputs": [
+ },
{
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "C:\\Users\\dkgun\\AppData\\Local\\Temp\\ipykernel_11124\\1110609025.py:44: FutureWarning: Calling float on a single element Series is deprecated and will raise a TypeError in the future. Use float(ser.iloc[0]) instead\n",
- " m.fs.state_block.temperature.fix(float(data[\"temperature\"]))\n",
- "C:\\Users\\dkgun\\AppData\\Local\\Temp\\ipykernel_11124\\426137296.py:7: FutureWarning: Calling float on a single element Series is deprecated and will raise a TypeError in the future. Use float(ser.iloc[0]) instead\n",
- " float(data[\"vap_benzene\"])\n",
- "C:\\Users\\dkgun\\AppData\\Local\\Temp\\ipykernel_11124\\426137296.py:10: FutureWarning: Calling float on a single element Series is deprecated and will raise a TypeError in the future. Use float(ser.iloc[0]) instead\n",
- " float(data[\"liq_benzene\"])\n"
- ]
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "We define the `exp_list` by splitting the data into individual experiments, or data points."
+ ]
},
{
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Ipopt 3.13.2: \n",
- "\n",
- "******************************************************************************\n",
- "This program contains Ipopt, a library for large-scale nonlinear optimization.\n",
- " Ipopt is released as open source code under the Eclipse Public License (EPL).\n",
- " For more information visit http://projects.coin-or.org/Ipopt\n",
- "\n",
- "This version of Ipopt was compiled from source code available at\n",
- " https://github.com/IDAES/Ipopt as part of the Institute for the Design of\n",
- " Advanced Energy Systems Process Systems Engineering Framework (IDAES PSE\n",
- " Framework) Copyright (c) 2018-2019. See https://github.com/IDAES/idaes-pse.\n",
- "\n",
- "This version of Ipopt was compiled using HSL, a collection of Fortran codes\n",
- " for large-scale scientific computation. All technical papers, sales and\n",
- " publicity material resulting from use of the HSL codes within IPOPT must\n",
- " contain the following acknowledgement:\n",
- " HSL, a collection of Fortran codes for large-scale scientific\n",
- " computation. See http://www.hsl.rl.ac.uk.\n",
- "******************************************************************************\n",
- "\n",
- "This is Ipopt version 3.13.2, running with linear solver ma27.\n",
- "\n",
- "Number of nonzeros in equality constraint Jacobian...: 3746\n",
- "Number of nonzeros in inequality constraint Jacobian.: 0\n",
- "Number of nonzeros in Lagrangian Hessian.............: 2200\n",
- "\n",
- "Total number of variables............................: 1100\n",
- " variables with only lower bounds: 0\n",
- " variables with lower and upper bounds: 300\n",
- " variables with only upper bounds: 0\n",
- "Total number of equality constraints.................: 1098\n",
- "Total number of inequality constraints...............: 0\n",
- " inequality constraints with only lower bounds: 0\n",
- " inequality constraints with lower and upper bounds: 0\n",
- " inequality constraints with only upper bounds: 0\n",
- "\n",
- "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
- " 0 6.0671019e+01 3.15e+00 4.84e+01 -1.0 0.00e+00 - 0.00e+00 0.00e+00 0\n",
- " 1 5.2961050e+00 1.76e+03 5.05e+00 -1.0 1.37e+04 - 9.74e-01 1.00e+00f 1\n",
- " 2 5.2586169e+00 4.01e+02 1.09e+00 -1.0 5.15e+02 - 1.00e+00 1.00e+00h 1\n",
- " 3 5.1450958e+00 7.04e+01 2.27e-01 -1.0 4.11e+01 - 1.00e+00 1.00e+00h 1\n",
- " 4 5.0748980e+00 1.25e+02 2.08e-01 -1.7 5.74e+02 - 1.00e+00 1.00e+00h 1\n",
- " 5 5.0775194e+00 7.87e+00 1.92e-01 -1.7 8.44e+01 - 1.00e+00 1.00e+00h 1\n",
- " 6 5.0726692e+00 1.37e+01 1.90e-01 -2.5 1.38e+02 - 1.00e+00 1.00e+00h 1\n",
- " 7 5.0750377e+00 2.85e+00 2.60e-02 -2.5 6.99e+01 - 1.00e+00 1.00e+00h 1\n",
- " 8 5.0749670e+00 7.36e-02 2.81e-03 -3.8 9.72e+00 - 1.00e+00 1.00e+00h 1\n",
- " 9 5.0749687e+00 4.51e-04 4.80e-06 -3.8 1.01e+00 - 1.00e+00 1.00e+00h 1\n",
- "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
- " 10 5.0749686e+00 2.91e-04 1.36e-06 -5.7 5.81e-01 - 1.00e+00 1.00e+00h 1\n",
- " 11 5.0749686e+00 4.78e-08 2.18e-10 -8.6 7.65e-03 - 1.00e+00 1.00e+00h 1\n",
- "\n",
- "Number of Iterations....: 11\n",
- "\n",
- " (scaled) (unscaled)\n",
- "Objective...............: 5.0749685783046434e+00 5.0749685783046434e+00\n",
- "Dual infeasibility......: 2.1827409324437497e-10 2.1827409324437497e-10\n",
- "Constraint violation....: 1.6625508263665860e-10 4.7832145355641842e-08\n",
- "Complementarity.........: 2.5076274461651402e-09 2.5076274461651402e-09\n",
- "Overall NLP error.......: 2.5076274461651402e-09 4.7832145355641842e-08\n",
- "\n",
- "\n",
- "Number of objective function evaluations = 12\n",
- "Number of objective gradient evaluations = 12\n",
- "Number of equality constraint evaluations = 12\n",
- "Number of inequality constraint evaluations = 0\n",
- "Number of equality constraint Jacobian evaluations = 12\n",
- "Number of inequality constraint Jacobian evaluations = 0\n",
- "Number of Lagrangian Hessian evaluations = 11\n",
- "Total CPU secs in IPOPT (w/o function evaluations) = 0.002\n",
- "Total CPU secs in NLP function evaluations = 0.010\n",
- "\n",
- "EXIT: Optimal Solution Found.\n",
- "\b\b\b\b\b\b\b\b\b\b\b\b\b\b"
- ]
- }
- ],
- "source": [
- "import logging\n",
- "\n",
- "idaeslog.getIdaesLogger(\"core.property_meta\").setLevel(logging.ERROR)\n",
- "# Initialize a parameter estimation object\n",
- "pest = parmest.Estimator(NRTL_model, data, variable_name, SSE, tee=True)\n",
- "\n",
- "# Run parameter estimation using all data\n",
- "obj_value, parameters = pest.theta_est()"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "You will notice that the resulting parameter estimation problem will have 1102 variables and 1100 constraints. Let us display the results by running the next cell. "
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 10,
- "metadata": {},
- "outputs": [
+ "cell_type": "code",
+ "execution_count": 11,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Update to new interface\n",
+ "exp_list = []\n",
+ "for i in range(data.shape[0]):\n",
+ " exp_list.append(NRTLExperiment(data.iloc[i]))"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "We are now ready to set up the parameter estimation problem. We will create a parameter estimation object called pest. As shown below, we pass the experiment list, and an objective function to the Estimator method. tee=True will print the solver output after solving the parameter estimation problem."
+ ]
+ },
{
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "The SSE at the optimal solution is 0.000507\n",
- "\n",
- "The values for the parameters are as follows:\n",
- "fs.properties.tau[benzene,toluene] = -0.8987624036283798\n",
- "fs.properties.tau[toluene,benzene] = 1.4104861099366137\n"
- ]
+ "cell_type": "code",
+ "execution_count": 12,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Ipopt 3.13.2: \n",
+ "\n",
+ "******************************************************************************\n",
+ "This program contains Ipopt, a library for large-scale nonlinear optimization.\n",
+ " Ipopt is released as open source code under the Eclipse Public License (EPL).\n",
+ " For more information visit http://projects.coin-or.org/Ipopt\n",
+ "\n",
+ "This version of Ipopt was compiled from source code available at\n",
+ " https://github.com/IDAES/Ipopt as part of the Institute for the Design of\n",
+ " Advanced Energy Systems Process Systems Engineering Framework (IDAES PSE\n",
+ " Framework) Copyright (c) 2018-2019. See https://github.com/IDAES/idaes-pse.\n",
+ "\n",
+ "This version of Ipopt was compiled using HSL, a collection of Fortran codes\n",
+ " for large-scale scientific computation. All technical papers, sales and\n",
+ " publicity material resulting from use of the HSL codes within IPOPT must\n",
+ " contain the following acknowledgement:\n",
+ " HSL, a collection of Fortran codes for large-scale scientific\n",
+ " computation. See http://www.hsl.rl.ac.uk.\n",
+ "******************************************************************************\n",
+ "\n",
+ "This is Ipopt version 3.13.2, running with linear solver ma27.\n",
+ "\n",
+ "Number of nonzeros in equality constraint Jacobian...: 3750\n",
+ "Number of nonzeros in inequality constraint Jacobian.: 0\n",
+ "Number of nonzeros in Lagrangian Hessian.............: 2200\n",
+ "\n",
+ "Total number of variables............................: 1102\n",
+ " variables with only lower bounds: 0\n",
+ " variables with lower and upper bounds: 300\n",
+ " variables with only upper bounds: 0\n",
+ "Total number of equality constraints.................: 1100\n",
+ "Total number of inequality constraints...............: 0\n",
+ " inequality constraints with only lower bounds: 0\n",
+ " inequality constraints with lower and upper bounds: 0\n",
+ " inequality constraints with only upper bounds: 0\n",
+ "\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 0 6.0671019e-03 3.15e+00 1.97e-05 -1.0 0.00e+00 - 0.00e+00 0.00e+00 0\n",
+ " 1 8.6249856e-04 1.40e+03 2.15e-01 -1.0 1.37e+04 - 9.95e-01 1.00e+00h 1\n",
+ " 2 1.1627234e-03 9.11e+03 8.21e-01 -1.7 4.74e+02 - 8.66e-01 1.00e+00h 1\n",
+ " 3 1.0978149e-03 9.02e+03 7.99e-01 -1.7 5.89e+00 -4.0 5.44e-01 2.64e-02h 6\n",
+ " 4 8.5702670e-04 8.63e+02 3.17e-02 -1.7 6.93e-01 -2.7 1.00e+00 1.00e+00h 1\n",
+ " 5 1.3332724e-03 3.57e+03 7.92e-03 -1.7 7.75e-01 - 1.00e+00 1.00e+00h 1\n",
+ " 6 1.5692588e-03 1.64e+02 2.34e-04 -1.7 1.98e-01 - 1.00e+00 1.00e+00h 1\n",
+ " 7 1.5828905e-03 1.20e+01 1.13e-05 -1.7 4.29e-02 - 1.00e+00 1.00e+00h 1\n",
+ " 8 1.4366151e-03 9.18e-01 2.34e-04 -2.5 5.49e-02 - 1.00e+00 1.00e+00h 1\n",
+ " 9 8.9194043e-04 2.19e+01 2.00e-04 -3.8 2.51e-01 - 1.00e+00 1.00e+00h 1\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 10 5.9835646e-04 3.72e+01 2.34e-05 -3.8 3.13e-01 - 1.00e+00 1.00e+00h 1\n",
+ " 11 5.9839648e-04 1.26e+00 4.06e-08 -3.8 2.87e-02 - 1.00e+00 1.00e+00h 1\n",
+ " 12 5.9838953e-04 4.33e-05 1.60e-12 -3.8 9.40e-05 - 1.00e+00 1.00e+00h 1\n",
+ " 13 5.9077073e-04 1.21e+01 2.96e-06 -5.7 4.79e-02 - 1.00e+00 1.00e+00h 1\n",
+ " 14 5.9066394e-04 1.19e-03 4.25e-07 -5.7 5.98e-04 -3.1 1.00e+00 1.00e+00h 1\n",
+ " 15 5.9059984e-04 1.08e-02 2.96e-07 -8.6 1.25e-03 -3.6 1.00e+00 1.00e+00h 1\n",
+ " 16 5.9042438e-04 9.67e-02 2.92e-07 -8.6 3.70e-03 -4.1 1.00e+00 1.00e+00h 1\n",
+ " 17 5.8992758e-04 8.72e-01 2.91e-07 -8.6 1.11e-02 -4.6 1.00e+00 1.00e+00h 1\n",
+ " 18 5.8840706e-04 8.23e+00 3.09e-07 -8.6 3.40e-02 -5.1 1.00e+00 1.00e+00h 1\n",
+ " 19 5.8319289e-04 9.25e+01 1.97e-06 -8.6 1.15e-01 -5.5 1.00e+00 1.00e+00h 1\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 20 5.4836946e-04 3.88e+03 1.22e-04 -8.6 7.95e-01 -6.0 1.00e+00 1.00e+00h 1\n",
+ " 21 5.0847689e-04 4.45e+02 1.04e-04 -8.6 3.55e-01 -5.6 1.00e+00 1.00e+00h 1\n",
+ " 22 5.0727291e-04 4.20e+00 1.54e-05 -8.6 6.20e+02 - 1.00e+00 1.00e+00h 1\n",
+ " 23 5.0749772e-04 1.36e+00 1.44e-06 -8.6 5.13e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 24 5.0749686e-04 6.93e-06 4.21e-11 -8.6 3.55e-01 - 1.00e+00 1.00e+00h 1\n",
+ " 25 5.0749686e-04 3.36e-06 1.49e-12 -9.0 6.25e-02 - 1.00e+00 1.00e+00h 1\n",
+ " 26 5.0749686e-04 1.02e-10 2.36e-18 -9.0 5.08e-06 - 1.00e+00 1.00e+00h 1\n",
+ "\n",
+ "Number of Iterations....: 26\n",
+ "\n",
+ " (scaled) (unscaled)\n",
+ "Objective...............: 5.0749685787934424e-04 5.0749685787934424e-04\n",
+ "Dual infeasibility......: 2.3583858113882067e-18 2.3583858113882067e-18\n",
+ "Constraint violation....: 3.5405706676501683e-13 1.0186340659856796e-10\n",
+ "Complementarity.........: 9.0909090909091344e-10 9.0909090909091344e-10\n",
+ "Overall NLP error.......: 9.0909090909091344e-10 9.0909090909091344e-10\n",
+ "\n",
+ "\n",
+ "Number of objective function evaluations = 33\n",
+ "Number of objective gradient evaluations = 27\n",
+ "Number of equality constraint evaluations = 34\n",
+ "Number of inequality constraint evaluations = 0\n",
+ "Number of equality constraint Jacobian evaluations = 27\n",
+ "Number of inequality constraint Jacobian evaluations = 0\n",
+ "Number of Lagrangian Hessian evaluations = 26\n",
+ "Total CPU secs in IPOPT (w/o function evaluations) = 0.035\n",
+ "Total CPU secs in NLP function evaluations = 0.009\n",
+ "\n",
+ "EXIT: Optimal Solution Found.\n"
+ ]
+ }
+ ],
+ "source": [
+ "import logging\n",
+ "\n",
+ "idaeslog.getIdaesLogger(\"core.property_meta\").setLevel(logging.ERROR)\n",
+ "\n",
+ "pest = parmest.Estimator(exp_list, obj_function=\"SSE\", tee=True)\n",
+ "obj_value, parameters = pest.theta_est()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "You will notice that the resulting parameter estimation problem will have 1102 variables and 1100 constraints. Let us display the results by running the next cell. "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 14,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "The SSE at the optimal solution is 0.000507\n",
+ "\n",
+ "The values for the parameters are as follows:\n",
+ "fs.properties.tau[benzene,toluene] = -0.8987550041842163\n",
+ "fs.properties.tau[toluene,benzene] = 1.4104702103547941\n"
+ ]
+ }
+ ],
+ "source": [
+ "print(\"The SSE at the optimal solution is %0.6f\" % (obj_value))\n",
+ "print()\n",
+ "print(\"The values for the parameters are as follows:\")\n",
+ "for k, v in parameters.items():\n",
+ " print(k, \"=\", v)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Using the data that was provided, we have estimated the binary interaction parameters in the NRTL model for a benzene-toluene mixture. Although the dataset that was provided was temperature dependent, in this example we have estimated a single value that fits best for all temperatures."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "### Advanced options for parmest: bootstrapping\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Pyomo's `parmest` tool allows for bootstrapping where the parameter estimation is repeated over `n` samples with resampling from the original data set. Parameter estimation with bootstrap resampling can be used to identify confidence regions around each parameter estimate. This analysis can be slow given the increased number of model instances that need to be solved. Please refer to https://pyomo.readthedocs.io/en/stable/contributed_packages/parmest/driver.html for more details. \n",
+ "\n",
+ "For the example above, the bootstrapping can be run by uncommenting the code in the following cell:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 15,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Uncomment the following lines\n",
+ "# bootstrap_theta = pest.theta_est_bootstrap(4, seed=542)\n",
+ "# display(bootstrap_theta)"
+ ]
+ }
+ ],
+ "metadata": {
+ "celltoolbar": "Tags",
+ "kernelspec": {
+ "display_name": "idaes-examples-dev-py313-macmini",
+ "language": "python",
+ "name": "python3"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 3
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython3",
+ "version": "3.13.13"
}
- ],
- "source": [
- "print(\"The SSE at the optimal solution is %0.6f\" % (obj_value * 1e-4))\n",
- "print()\n",
- "print(\"The values for the parameters are as follows:\")\n",
- "for k, v in parameters.items():\n",
- " print(k, \"=\", v)"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "Using the data that was provided, we have estimated the binary interaction parameters in the NRTL model for a benzene-toluene mixture. Although the dataset that was provided was temperature dependent, in this example we have estimated a single value that fits best for all temperatures."
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "### Advanced options for parmest: bootstrapping\n",
- "\n"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "Pyomo's `parmest` tool allows for bootstrapping where the parameter estimation is repeated over `n` samples with resampling from the original data set. Parameter estimation with bootstrap resampling can be used to identify confidence regions around each parameter estimate. This analysis can be slow given the increased number of model instances that need to be solved. Please refer to https://pyomo.readthedocs.io/en/stable/contributed_packages/parmest/driver.html for more details. \n",
- "\n",
- "For the example above, the bootstrapping can be run by uncommenting the code in the following cell:"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 11,
- "metadata": {},
- "outputs": [],
- "source": [
- "# Run parameter estimation using bootstrap resample of the data (10 samples),\n",
- "# plot results along with confidence regions\n",
- "\n",
- "# Uncomment the following code:\n",
- "# bootstrap_theta = pest.theta_est_bootstrap(4)\n",
- "# display(bootstrap_theta)"
- ]
- }
- ],
- "metadata": {
- "celltoolbar": "Tags",
- "kernelspec": {
- "display_name": "Python 3 (ipykernel)",
- "language": "python",
- "name": "python3"
},
- "language_info": {
- "codemirror_mode": {
- "name": "ipython",
- "version": 3
- },
- "file_extension": ".py",
- "mimetype": "text/x-python",
- "name": "python",
- "nbconvert_exporter": "python",
- "pygments_lexer": "ipython3",
- "version": "3.11.5"
- }
- },
- "nbformat": 4,
- "nbformat_minor": 3
+ "nbformat": 4,
+ "nbformat_minor": 3
}
\ No newline at end of file
diff --git a/idaes_examples/notebooks/docs/param_est/parameter_estimation_nrtl_using_state_block_exercise.ipynb b/idaes_examples/notebooks/docs/param_est/parameter_estimation_nrtl_using_state_block_exercise.ipynb
index 23756bea..97bf86ad 100644
--- a/idaes_examples/notebooks/docs/param_est/parameter_estimation_nrtl_using_state_block_exercise.ipynb
+++ b/idaes_examples/notebooks/docs/param_est/parameter_estimation_nrtl_using_state_block_exercise.ipynb
@@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
- "execution_count": 10,
+ "execution_count": 1,
"metadata": {
"tags": [
"header",
@@ -16,7 +16,7 @@
"# Framework (IDAES IP) was produced under the DOE Institute for the\n",
"# Design of Advanced Energy Systems (IDAES).\n",
"#\n",
- "# Copyright (c) 2018-2023 by the software owners: The Regents of the\n",
+ "# Copyright (c) 2018-2026 by the software owners: The Regents of the\n",
"# University of California, through Lawrence Berkeley National Laboratory,\n",
"# National Technology & Engineering Solutions of Sandia, LLC, Carnegie Mellon\n",
"# University, West Virginia University Research Corporation, et al.\n",
@@ -32,8 +32,8 @@
"# Parameter Estimation Using the NRTL State Block\n",
"\n",
"Author: Jaffer Ghouse \n",
- "Maintainer: Andrew Lee \n",
- "Updated: 2023-06-01 \n",
+ "Maintainer: Stephen Cini \n",
+ "Updated: 2026-06-11 \n",
"\n",
"In this module, we use Pyomo's `parmest` tool in conjunction with IDAES models for parameter estimation. We demonstrate these tools by estimating the parameters associated with the NRTL property model for a benzene-toluene mixture. The NRTL model has 2 sets of parameters: the non-randomness parameter (`alpha_ij`) and the binary interaction parameter (`tau_ij`), where `i` and `j` are the pure component species. In this example, we only estimate the binary interaction parameter (`tau_ij`) for a given dataset. When estimating parameters associated with the property package, IDAES provides the flexibility of doing the parameter estimation by just using the state block or by using a unit model with a specified property package. This module will demonstrate parameter estimation by using only the state block. \n",
"\n",
@@ -45,8 +45,7 @@
"\n",
"## Key links to documentation:\n",
"* NRTL Model - https://idaes-pse.readthedocs.io/en/stable/reference_guides/model_libraries/generic/property_models/activity_coefficient.html\n",
- "* parmest - https://pyomo.readthedocs.io/en/stable/contributed_packages/parmest/index.html\n",
- ""
+ "* parmest - https://pyomo.readthedocs.io/en/stable/explanation/analysis/parmest/index.html\n"
]
},
{
@@ -55,13 +54,13 @@
"source": [
"\n",
"Inline Exercise:\n",
- "import `ConcreteModel` from Pyomo and `FlowsheetBlock` from IDAES. \n",
+ "import `ConcreteModel`, `value`, and `Suffix` from Pyomo, and `FlowsheetBlock`from IDAES. \n",
"
"
]
},
{
"cell_type": "code",
- "execution_count": 11,
+ "execution_count": 2,
"metadata": {
"tags": [
"exercise"
@@ -69,7 +68,7 @@
},
"outputs": [],
"source": [
- "# Todo: import ConcreteModel from pyomo.environ\n",
+ "# Todo: import ConcreteModel, value, and Suffix from pyomo.environ\n",
"\n",
"# Todo: import FlowsheetBlock from idaes.core"
]
@@ -83,7 +82,7 @@
},
{
"cell_type": "code",
- "execution_count": 13,
+ "execution_count": 4,
"metadata": {
"tags": []
},
@@ -104,7 +103,7 @@
},
{
"cell_type": "code",
- "execution_count": 14,
+ "execution_count": 5,
"metadata": {
"tags": []
},
@@ -135,7 +134,7 @@
},
{
"cell_type": "code",
- "execution_count": 15,
+ "execution_count": 6,
"metadata": {
"tags": [
"exercise"
@@ -181,7 +180,12 @@
" m.fs.state_block.initialize(outlvl=idaeslog.INFO)\n",
"\n",
" # Fix at actual temperature\n",
- " m.fs.state_block.temperature.fix(float(data[\"temperature\"]))\n",
+ " if isinstance(data, dict) or isinstance(data, pd.Series):\n",
+ " m.fs.state_block.temperature.fix(float(data[\"temperature\"]))\n",
+ " elif isinstance(data, pd.DataFrame):\n",
+ " m.fs.state_block.temperature.fix(float(data.iloc[0][\"temperature\"]))\n",
+ " else:\n",
+ " raise ValueError(\"Unrecognized data type.\")\n",
"\n",
" # Set bounds on variables to be estimated\n",
" m.fs.properties.tau[\"benzene\", \"toluene\"].setlb(-5)\n",
@@ -207,37 +211,106 @@
"source": [
"In addition to providing a method to return an initialized model, the `parmest` tool needs the following:\n",
"\n",
- "* List of variable names to be estimated\n",
- "* Dataset\n",
- "* Expression to compute the sum of squared errors\n"
+ "* Experiment class to set up and label model with suffixes\n",
+ "* Dataset with multiple scenarios - organized into an experiment list\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
+ "Here we build an experiment class to label our model problem for parameter estimation. The labels are defined as a `Suffix`, and the main labels for our model are `experiment_outputs`, `unknown_parameters`, and `measurement_error`.\n",
+ "\n",
+ "For this problem, the error will be computed for the mole fraction of benzene in the vapor and liquid phase between the model prediction and data. The `experimental_outputs` will therefore be the mole fraction of benzene in the two phases.\n",
+ "\n",
"In this example, we only estimate the binary interaction parameter (`tau_ij`). Given that this variable is usually indexed as `tau_ij = Var(component_list, component_list)`, there are 2*2=4 degrees of freedom. However, when i=j, the binary interaction parameter is 0. Therefore, in this problem, we estimate the binary interaction parameter for the following variables only:\n",
"\n",
"* fs.properties.tau['benzene', 'toluene']\n",
"* fs.properties.tau['toluene', 'benzene']\n",
"\n",
- "\n",
- "Inline Exercise:\n",
- "Create a list called `variable_name` with the above-mentioned variables declared as strings.\n",
- "
"
+ "As shown below, these model components are used as our `unknown_parameters`.\n",
+ "\n",
+ "We define `measurement_error` as none so parmest calculates the value internally based on the experimental outputs. Refer to https://pyomo.readthedocs.io/en/stable/explanation/analysis/parmest/driver.html for more information. "
]
},
{
"cell_type": "code",
- "execution_count": 18,
- "metadata": {
- "tags": [
- "exercise"
- ]
- },
+ "execution_count": 9,
+ "metadata": {},
"outputs": [],
"source": [
- "# Todo: Create a list of vars to estimate"
+ "# Build an experiment class to take advantage of new parmest interface\n",
+ "from pyomo.contrib.parmest.experiment import Experiment\n",
+ "\n",
+ "\n",
+ "class NRTLExperiment(Experiment):\n",
+ " \"\"\"Experiment class for parameter estimation of NRTL model using parmest\"\"\"\n",
+ "\n",
+ " def __init__(self, data, meas_error=None):\n",
+ " \"\"\"Initialize the NRTLExperiment class\n",
+ "\n",
+ " Args:\n",
+ " data: DataFrame containing the experimental data\n",
+ " meas_error: Measurement error for the data (optional)\n",
+ " \"\"\"\n",
+ " self.model = None\n",
+ " self.data = data\n",
+ " self.meas_error = meas_error\n",
+ "\n",
+ " def create_model(self):\n",
+ " \"\"\"Create the Pyomo model for the NRTL parameter estimation problem\"\"\"\n",
+ " self.model = NRTL_model(self.data)\n",
+ "\n",
+ " def label_model(self):\n",
+ " from pyomo.environ import Set, Expression\n",
+ "\n",
+ " m = self.model\n",
+ "\n",
+ " # Parmest expects the first index of experiment outputs to be the data point\n",
+ " # This is a workaround that will be addressed and corrected in a future release.\n",
+ "\n",
+ " m.data_point = Set(initialize=[0])\n",
+ "\n",
+ " # Wrap IDAES variables in Expressions indexed by data point\n",
+ " m.liq_benzene_out = Expression(\n",
+ " m.data_point,\n",
+ " rule=lambda m, i: m.fs.state_block.mole_frac_phase_comp[\"Liq\", \"benzene\"],\n",
+ " )\n",
+ "\n",
+ " m.vap_benzene_out = Expression(\n",
+ " m.data_point,\n",
+ " rule=lambda m, i: m.fs.state_block.mole_frac_phase_comp[\"Vap\", \"benzene\"],\n",
+ " )\n",
+ "\n",
+ " m.experiment_outputs = Suffix(direction=Suffix.LOCAL)\n",
+ "\n",
+ " m.experiment_outputs[m.liq_benzene_out[0]] = float(self.data[\"liq_benzene\"])\n",
+ " m.experiment_outputs[m.vap_benzene_out[0]] = float(self.data[\"vap_benzene\"])\n",
+ "\n",
+ " m.measurement_error = Suffix(direction=Suffix.LOCAL)\n",
+ " m.measurement_error.update(\n",
+ " [\n",
+ " (m.liq_benzene_out[0], self.meas_error),\n",
+ " (m.vap_benzene_out[0], self.meas_error),\n",
+ " ]\n",
+ " )\n",
+ "\n",
+ " # Add unknown parameters to the model for easier access\n",
+ " m.unknown_parameters = Suffix(direction=Suffix.LOCAL)\n",
+ " m.unknown_parameters.update(\n",
+ " (k, value(k))\n",
+ " for k in [\n",
+ " m.fs.properties.tau[\"benzene\", \"toluene\"],\n",
+ " m.fs.properties.tau[\"toluene\", \"benzene\"],\n",
+ " ]\n",
+ " )\n",
+ "\n",
+ " def get_labeled_model(self):\n",
+ " \"\"\"Return the labeled model\"\"\"\n",
+ " if self.model is None:\n",
+ " self.create_model()\n",
+ " self.label_model()\n",
+ " return self.model"
]
},
{
@@ -256,11 +329,400 @@
},
{
"cell_type": "code",
- "execution_count": 20,
+ "execution_count": 10,
"metadata": {
"tags": []
},
- "outputs": [],
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " temperature | \n",
+ " liq_benzene | \n",
+ " vap_benzene | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 0 | \n",
+ " 365.500000 | \n",
+ " 0.480953 | \n",
+ " 0.692110 | \n",
+ "
\n",
+ " \n",
+ " | 1 | \n",
+ " 365.617647 | \n",
+ " 0.462444 | \n",
+ " 0.667699 | \n",
+ "
\n",
+ " \n",
+ " | 2 | \n",
+ " 365.735294 | \n",
+ " 0.477984 | \n",
+ " 0.692441 | \n",
+ "
\n",
+ " \n",
+ " | 3 | \n",
+ " 365.852941 | \n",
+ " 0.440547 | \n",
+ " 0.640336 | \n",
+ "
\n",
+ " \n",
+ " | 4 | \n",
+ " 365.970588 | \n",
+ " 0.427421 | \n",
+ " 0.623328 | \n",
+ "
\n",
+ " \n",
+ " | 5 | \n",
+ " 366.088235 | \n",
+ " 0.442725 | \n",
+ " 0.647796 | \n",
+ "
\n",
+ " \n",
+ " | 6 | \n",
+ " 366.205882 | \n",
+ " 0.434374 | \n",
+ " 0.637691 | \n",
+ "
\n",
+ " \n",
+ " | 7 | \n",
+ " 366.323529 | \n",
+ " 0.444642 | \n",
+ " 0.654933 | \n",
+ "
\n",
+ " \n",
+ " | 8 | \n",
+ " 366.441176 | \n",
+ " 0.427132 | \n",
+ " 0.631229 | \n",
+ "
\n",
+ " \n",
+ " | 9 | \n",
+ " 366.558824 | \n",
+ " 0.446301 | \n",
+ " 0.661743 | \n",
+ "
\n",
+ " \n",
+ " | 10 | \n",
+ " 366.676471 | \n",
+ " 0.438004 | \n",
+ " 0.651591 | \n",
+ "
\n",
+ " \n",
+ " | 11 | \n",
+ " 366.794118 | \n",
+ " 0.425320 | \n",
+ " 0.634814 | \n",
+ "
\n",
+ " \n",
+ " | 12 | \n",
+ " 366.911765 | \n",
+ " 0.439435 | \n",
+ " 0.658047 | \n",
+ "
\n",
+ " \n",
+ " | 13 | \n",
+ " 367.029412 | \n",
+ " 0.435655 | \n",
+ " 0.654539 | \n",
+ "
\n",
+ " \n",
+ " | 14 | \n",
+ " 367.147059 | \n",
+ " 0.401350 | \n",
+ " 0.604987 | \n",
+ "
\n",
+ " \n",
+ " | 15 | \n",
+ " 367.264706 | \n",
+ " 0.397862 | \n",
+ " 0.601703 | \n",
+ "
\n",
+ " \n",
+ " | 16 | \n",
+ " 367.382353 | \n",
+ " 0.415821 | \n",
+ " 0.630930 | \n",
+ "
\n",
+ " \n",
+ " | 17 | \n",
+ " 367.500000 | \n",
+ " 0.420667 | \n",
+ " 0.640380 | \n",
+ "
\n",
+ " \n",
+ " | 18 | \n",
+ " 367.617647 | \n",
+ " 0.391683 | \n",
+ " 0.598214 | \n",
+ "
\n",
+ " \n",
+ " | 19 | \n",
+ " 367.735294 | \n",
+ " 0.404903 | \n",
+ " 0.620432 | \n",
+ "
\n",
+ " \n",
+ " | 20 | \n",
+ " 367.852941 | \n",
+ " 0.409563 | \n",
+ " 0.629626 | \n",
+ "
\n",
+ " \n",
+ " | 21 | \n",
+ " 367.970588 | \n",
+ " 0.389488 | \n",
+ " 0.600722 | \n",
+ "
\n",
+ " \n",
+ " | 22 | \n",
+ " 368.000000 | \n",
+ " 0.396789 | \n",
+ " 0.612483 | \n",
+ "
\n",
+ " \n",
+ " | 23 | \n",
+ " 368.088235 | \n",
+ " 0.398162 | \n",
+ " 0.616106 | \n",
+ "
\n",
+ " \n",
+ " | 24 | \n",
+ " 368.205882 | \n",
+ " 0.362340 | \n",
+ " 0.562505 | \n",
+ "
\n",
+ " \n",
+ " | 25 | \n",
+ " 368.323529 | \n",
+ " 0.386958 | \n",
+ " 0.602680 | \n",
+ "
\n",
+ " \n",
+ " | 26 | \n",
+ " 368.441176 | \n",
+ " 0.363643 | \n",
+ " 0.568210 | \n",
+ "
\n",
+ " \n",
+ " | 27 | \n",
+ " 368.558824 | \n",
+ " 0.368118 | \n",
+ " 0.577072 | \n",
+ "
\n",
+ " \n",
+ " | 28 | \n",
+ " 368.676471 | \n",
+ " 0.384098 | \n",
+ " 0.604078 | \n",
+ "
\n",
+ " \n",
+ " | 29 | \n",
+ " 368.794118 | \n",
+ " 0.353605 | \n",
+ " 0.557925 | \n",
+ "
\n",
+ " \n",
+ " | 30 | \n",
+ " 368.911765 | \n",
+ " 0.346474 | \n",
+ " 0.548445 | \n",
+ "
\n",
+ " \n",
+ " | 31 | \n",
+ " 369.029412 | \n",
+ " 0.350741 | \n",
+ " 0.556996 | \n",
+ "
\n",
+ " \n",
+ " | 32 | \n",
+ " 369.147059 | \n",
+ " 0.362347 | \n",
+ " 0.577286 | \n",
+ "
\n",
+ " \n",
+ " | 33 | \n",
+ " 369.264706 | \n",
+ " 0.362578 | \n",
+ " 0.579519 | \n",
+ "
\n",
+ " \n",
+ " | 34 | \n",
+ " 369.382353 | \n",
+ " 0.340765 | \n",
+ " 0.546411 | \n",
+ "
\n",
+ " \n",
+ " | 35 | \n",
+ " 369.500000 | \n",
+ " 0.337462 | \n",
+ " 0.542857 | \n",
+ "
\n",
+ " \n",
+ " | 36 | \n",
+ " 369.617647 | \n",
+ " 0.355729 | \n",
+ " 0.574083 | \n",
+ "
\n",
+ " \n",
+ " | 37 | \n",
+ " 369.735294 | \n",
+ " 0.348679 | \n",
+ " 0.564513 | \n",
+ "
\n",
+ " \n",
+ " | 38 | \n",
+ " 369.852941 | \n",
+ " 0.338187 | \n",
+ " 0.549284 | \n",
+ "
\n",
+ " \n",
+ " | 39 | \n",
+ " 369.970588 | \n",
+ " 0.324360 | \n",
+ " 0.528514 | \n",
+ "
\n",
+ " \n",
+ " | 40 | \n",
+ " 370.088235 | \n",
+ " 0.310753 | \n",
+ " 0.507964 | \n",
+ "
\n",
+ " \n",
+ " | 41 | \n",
+ " 370.205882 | \n",
+ " 0.311037 | \n",
+ " 0.510055 | \n",
+ "
\n",
+ " \n",
+ " | 42 | \n",
+ " 370.323529 | \n",
+ " 0.311263 | \n",
+ " 0.512055 | \n",
+ "
\n",
+ " \n",
+ " | 43 | \n",
+ " 370.441176 | \n",
+ " 0.308081 | \n",
+ " 0.508437 | \n",
+ "
\n",
+ " \n",
+ " | 44 | \n",
+ " 370.558824 | \n",
+ " 0.308224 | \n",
+ " 0.510293 | \n",
+ "
\n",
+ " \n",
+ " | 45 | \n",
+ " 370.676471 | \n",
+ " 0.318148 | \n",
+ " 0.528399 | \n",
+ "
\n",
+ " \n",
+ " | 46 | \n",
+ " 370.794118 | \n",
+ " 0.308334 | \n",
+ " 0.513728 | \n",
+ "
\n",
+ " \n",
+ " | 47 | \n",
+ " 370.911765 | \n",
+ " 0.317937 | \n",
+ " 0.531410 | \n",
+ "
\n",
+ " \n",
+ " | 48 | \n",
+ " 371.029412 | \n",
+ " 0.289149 | \n",
+ " 0.484824 | \n",
+ "
\n",
+ " \n",
+ " | 49 | \n",
+ " 371.147059 | \n",
+ " 0.298637 | \n",
+ " 0.502318 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " temperature liq_benzene vap_benzene\n",
+ "0 365.500000 0.480953 0.692110\n",
+ "1 365.617647 0.462444 0.667699\n",
+ "2 365.735294 0.477984 0.692441\n",
+ "3 365.852941 0.440547 0.640336\n",
+ "4 365.970588 0.427421 0.623328\n",
+ "5 366.088235 0.442725 0.647796\n",
+ "6 366.205882 0.434374 0.637691\n",
+ "7 366.323529 0.444642 0.654933\n",
+ "8 366.441176 0.427132 0.631229\n",
+ "9 366.558824 0.446301 0.661743\n",
+ "10 366.676471 0.438004 0.651591\n",
+ "11 366.794118 0.425320 0.634814\n",
+ "12 366.911765 0.439435 0.658047\n",
+ "13 367.029412 0.435655 0.654539\n",
+ "14 367.147059 0.401350 0.604987\n",
+ "15 367.264706 0.397862 0.601703\n",
+ "16 367.382353 0.415821 0.630930\n",
+ "17 367.500000 0.420667 0.640380\n",
+ "18 367.617647 0.391683 0.598214\n",
+ "19 367.735294 0.404903 0.620432\n",
+ "20 367.852941 0.409563 0.629626\n",
+ "21 367.970588 0.389488 0.600722\n",
+ "22 368.000000 0.396789 0.612483\n",
+ "23 368.088235 0.398162 0.616106\n",
+ "24 368.205882 0.362340 0.562505\n",
+ "25 368.323529 0.386958 0.602680\n",
+ "26 368.441176 0.363643 0.568210\n",
+ "27 368.558824 0.368118 0.577072\n",
+ "28 368.676471 0.384098 0.604078\n",
+ "29 368.794118 0.353605 0.557925\n",
+ "30 368.911765 0.346474 0.548445\n",
+ "31 369.029412 0.350741 0.556996\n",
+ "32 369.147059 0.362347 0.577286\n",
+ "33 369.264706 0.362578 0.579519\n",
+ "34 369.382353 0.340765 0.546411\n",
+ "35 369.500000 0.337462 0.542857\n",
+ "36 369.617647 0.355729 0.574083\n",
+ "37 369.735294 0.348679 0.564513\n",
+ "38 369.852941 0.338187 0.549284\n",
+ "39 369.970588 0.324360 0.528514\n",
+ "40 370.088235 0.310753 0.507964\n",
+ "41 370.205882 0.311037 0.510055\n",
+ "42 370.323529 0.311263 0.512055\n",
+ "43 370.441176 0.308081 0.508437\n",
+ "44 370.558824 0.308224 0.510293\n",
+ "45 370.676471 0.318148 0.528399\n",
+ "46 370.794118 0.308334 0.513728\n",
+ "47 370.911765 0.317937 0.531410\n",
+ "48 371.029412 0.289149 0.484824\n",
+ "49 371.147059 0.298637 0.502318"
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ }
+ ],
"source": [
"# Load data from csv\n",
"data = pd.read_csv(\"BT_NRTL_dataset.csv\")\n",
@@ -273,63 +735,134 @@
"cell_type": "markdown",
"metadata": {},
"source": [
- "We need to provide a method to return an expression to compute the sum of squared errors that will be used as the objective in solving the parameter estimation problem. For this problem, the error will be computed for the mole fraction of benzene in the vapor and liquid phase between the model prediction and data. \n",
- "\n",
- "\n",
- "Inline Exercise:\n",
- "Complete the following cell by adding an expression to compute the sum of square errors. \n",
- "
"
+ "We define the `exp_list` by splitting the data into individual experiments, or data points."
]
},
{
"cell_type": "code",
- "execution_count": null,
- "metadata": {
- "tags": [
- "exercise"
- ]
- },
- "outputs": [],
- "source": [
- "# Create method to return an expression that computes the sum of squared error\n",
- "def SSE(m, data):\n",
- " # Todo: Add expression for computing the sum of squared errors in mole fraction of benzene in the liquid\n",
- " # and vapor phase. For example, the squared error for the vapor phase is:\n",
- " # (float(data[\"vap_benzene\"]) - m.fs.state_block.mole_frac_phase_comp[\"Vap\", \"benzene\"])**2\n",
- "\n",
- " return expr * 1e4"
- ]
- },
- {
- "cell_type": "markdown",
+ "execution_count": 11,
"metadata": {},
+ "outputs": [],
"source": [
- "\n",
- "Note:\n",
- "Notice that we have scaled the expression up by a factor of 10000 as the SSE computed here will be an extremely small number given that we are using the difference in mole fraction in our expression. This will help in using a well-scaled objective to improve solve robustness when using IPOPT. \n",
- "
\n"
+ "# Update to new interface\n",
+ "exp_list = []\n",
+ "for i in range(data.shape[0]):\n",
+ " exp_list.append(NRTLExperiment(data.iloc[i]))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
- "We are now ready to set up the parameter estimation problem. We will create a parameter estimation object called `pest`. As shown below, we pass the method that returns an initialized model, data, variable_name, and the SSE expression to the Estimator method. `tee=True` will print the solver output after solving the parameter estimation problem. "
+ "We are now ready to set up the parameter estimation problem. We will create a parameter estimation object called pest. As shown below, we pass the experiment list, and an objective function to the Estimator method. tee=True will print the solver output after solving the parameter estimation problem."
]
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 12,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Ipopt 3.13.2: \n",
+ "\n",
+ "******************************************************************************\n",
+ "This program contains Ipopt, a library for large-scale nonlinear optimization.\n",
+ " Ipopt is released as open source code under the Eclipse Public License (EPL).\n",
+ " For more information visit http://projects.coin-or.org/Ipopt\n",
+ "\n",
+ "This version of Ipopt was compiled from source code available at\n",
+ " https://github.com/IDAES/Ipopt as part of the Institute for the Design of\n",
+ " Advanced Energy Systems Process Systems Engineering Framework (IDAES PSE\n",
+ " Framework) Copyright (c) 2018-2019. See https://github.com/IDAES/idaes-pse.\n",
+ "\n",
+ "This version of Ipopt was compiled using HSL, a collection of Fortran codes\n",
+ " for large-scale scientific computation. All technical papers, sales and\n",
+ " publicity material resulting from use of the HSL codes within IPOPT must\n",
+ " contain the following acknowledgement:\n",
+ " HSL, a collection of Fortran codes for large-scale scientific\n",
+ " computation. See http://www.hsl.rl.ac.uk.\n",
+ "******************************************************************************\n",
+ "\n",
+ "This is Ipopt version 3.13.2, running with linear solver ma27.\n",
+ "\n",
+ "Number of nonzeros in equality constraint Jacobian...: 3750\n",
+ "Number of nonzeros in inequality constraint Jacobian.: 0\n",
+ "Number of nonzeros in Lagrangian Hessian.............: 2200\n",
+ "\n",
+ "Total number of variables............................: 1102\n",
+ " variables with only lower bounds: 0\n",
+ " variables with lower and upper bounds: 300\n",
+ " variables with only upper bounds: 0\n",
+ "Total number of equality constraints.................: 1100\n",
+ "Total number of inequality constraints...............: 0\n",
+ " inequality constraints with only lower bounds: 0\n",
+ " inequality constraints with lower and upper bounds: 0\n",
+ " inequality constraints with only upper bounds: 0\n",
+ "\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 0 6.0671019e-03 3.15e+00 1.97e-05 -1.0 0.00e+00 - 0.00e+00 0.00e+00 0\n",
+ " 1 8.6249856e-04 1.40e+03 2.15e-01 -1.0 1.37e+04 - 9.95e-01 1.00e+00h 1\n",
+ " 2 1.1627234e-03 9.11e+03 8.21e-01 -1.7 4.74e+02 - 8.66e-01 1.00e+00h 1\n",
+ " 3 1.0978149e-03 9.02e+03 7.99e-01 -1.7 5.89e+00 -4.0 5.44e-01 2.64e-02h 6\n",
+ " 4 8.5702670e-04 8.63e+02 3.17e-02 -1.7 6.93e-01 -2.7 1.00e+00 1.00e+00h 1\n",
+ " 5 1.3332724e-03 3.57e+03 7.92e-03 -1.7 7.75e-01 - 1.00e+00 1.00e+00h 1\n",
+ " 6 1.5692588e-03 1.64e+02 2.34e-04 -1.7 1.98e-01 - 1.00e+00 1.00e+00h 1\n",
+ " 7 1.5828905e-03 1.20e+01 1.13e-05 -1.7 4.29e-02 - 1.00e+00 1.00e+00h 1\n",
+ " 8 1.4366151e-03 9.18e-01 2.34e-04 -2.5 5.49e-02 - 1.00e+00 1.00e+00h 1\n",
+ " 9 8.9194043e-04 2.19e+01 2.00e-04 -3.8 2.51e-01 - 1.00e+00 1.00e+00h 1\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 10 5.9835646e-04 3.72e+01 2.34e-05 -3.8 3.13e-01 - 1.00e+00 1.00e+00h 1\n",
+ " 11 5.9839648e-04 1.26e+00 4.06e-08 -3.8 2.87e-02 - 1.00e+00 1.00e+00h 1\n",
+ " 12 5.9838953e-04 4.33e-05 1.60e-12 -3.8 9.40e-05 - 1.00e+00 1.00e+00h 1\n",
+ " 13 5.9077073e-04 1.21e+01 2.96e-06 -5.7 4.79e-02 - 1.00e+00 1.00e+00h 1\n",
+ " 14 5.9066394e-04 1.19e-03 4.25e-07 -5.7 5.98e-04 -3.1 1.00e+00 1.00e+00h 1\n",
+ " 15 5.9059984e-04 1.08e-02 2.96e-07 -8.6 1.25e-03 -3.6 1.00e+00 1.00e+00h 1\n",
+ " 16 5.9042438e-04 9.67e-02 2.92e-07 -8.6 3.70e-03 -4.1 1.00e+00 1.00e+00h 1\n",
+ " 17 5.8992758e-04 8.72e-01 2.91e-07 -8.6 1.11e-02 -4.6 1.00e+00 1.00e+00h 1\n",
+ " 18 5.8840706e-04 8.23e+00 3.09e-07 -8.6 3.40e-02 -5.1 1.00e+00 1.00e+00h 1\n",
+ " 19 5.8319289e-04 9.25e+01 1.97e-06 -8.6 1.15e-01 -5.5 1.00e+00 1.00e+00h 1\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 20 5.4836946e-04 3.88e+03 1.22e-04 -8.6 7.95e-01 -6.0 1.00e+00 1.00e+00h 1\n",
+ " 21 5.0847689e-04 4.45e+02 1.04e-04 -8.6 3.55e-01 -5.6 1.00e+00 1.00e+00h 1\n",
+ " 22 5.0727291e-04 4.20e+00 1.54e-05 -8.6 6.20e+02 - 1.00e+00 1.00e+00h 1\n",
+ " 23 5.0749772e-04 1.36e+00 1.44e-06 -8.6 5.13e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 24 5.0749686e-04 6.93e-06 4.21e-11 -8.6 3.55e-01 - 1.00e+00 1.00e+00h 1\n",
+ " 25 5.0749686e-04 3.36e-06 1.49e-12 -9.0 6.25e-02 - 1.00e+00 1.00e+00h 1\n",
+ " 26 5.0749686e-04 1.02e-10 2.36e-18 -9.0 5.08e-06 - 1.00e+00 1.00e+00h 1\n",
+ "\n",
+ "Number of Iterations....: 26\n",
+ "\n",
+ " (scaled) (unscaled)\n",
+ "Objective...............: 5.0749685787934424e-04 5.0749685787934424e-04\n",
+ "Dual infeasibility......: 2.3583858113882067e-18 2.3583858113882067e-18\n",
+ "Constraint violation....: 3.5405706676501683e-13 1.0186340659856796e-10\n",
+ "Complementarity.........: 9.0909090909091344e-10 9.0909090909091344e-10\n",
+ "Overall NLP error.......: 9.0909090909091344e-10 9.0909090909091344e-10\n",
+ "\n",
+ "\n",
+ "Number of objective function evaluations = 33\n",
+ "Number of objective gradient evaluations = 27\n",
+ "Number of equality constraint evaluations = 34\n",
+ "Number of inequality constraint evaluations = 0\n",
+ "Number of equality constraint Jacobian evaluations = 27\n",
+ "Number of inequality constraint Jacobian evaluations = 0\n",
+ "Number of Lagrangian Hessian evaluations = 26\n",
+ "Total CPU secs in IPOPT (w/o function evaluations) = 0.035\n",
+ "Total CPU secs in NLP function evaluations = 0.009\n",
+ "\n",
+ "EXIT: Optimal Solution Found.\n"
+ ]
+ }
+ ],
"source": [
"import logging\n",
"\n",
"idaeslog.getIdaesLogger(\"core.property_meta\").setLevel(logging.ERROR)\n",
- "# Initialize a parameter estimation object\n",
- "pest = parmest.Estimator(NRTL_model, data, variable_name, SSE, tee=True)\n",
"\n",
- "# Run parameter estimation using all data\n",
+ "pest = parmest.Estimator(exp_list, obj_function=\"SSE\", tee=True)\n",
"obj_value, parameters = pest.theta_est()"
]
},
@@ -342,11 +875,23 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 14,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "The SSE at the optimal solution is 0.000507\n",
+ "\n",
+ "The values for the parameters are as follows:\n",
+ "fs.properties.tau[benzene,toluene] = -0.8987550041842163\n",
+ "fs.properties.tau[toluene,benzene] = 1.4104702103547941\n"
+ ]
+ }
+ ],
"source": [
- "print(\"The SSE at the optimal solution is %0.6f\" % (obj_value * 1e-4))\n",
+ "print(\"The SSE at the optimal solution is %0.6f\" % (obj_value))\n",
"print()\n",
"print(\"The values for the parameters are as follows:\")\n",
"for k, v in parameters.items():\n",
@@ -379,15 +924,12 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 15,
"metadata": {},
"outputs": [],
"source": [
- "# Run parameter estimation using bootstrap resample of the data (10 samples),\n",
- "# plot results along with confidence regions\n",
- "\n",
- "# Uncomment the following code:\n",
- "# bootstrap_theta = pest.theta_est_bootstrap(4)\n",
+ "# Uncomment the following lines\n",
+ "# bootstrap_theta = pest.theta_est_bootstrap(4, seed=542)\n",
"# display(bootstrap_theta)"
]
}
@@ -395,7 +937,7 @@
"metadata": {
"celltoolbar": "Tags",
"kernelspec": {
- "display_name": "Python 3 (ipykernel)",
+ "display_name": "idaes-examples-dev-py313-macmini",
"language": "python",
"name": "python3"
},
@@ -409,7 +951,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.10.9"
+ "version": "3.13.13"
}
},
"nbformat": 4,
diff --git a/idaes_examples/notebooks/docs/param_est/parameter_estimation_nrtl_using_state_block_solution.ipynb b/idaes_examples/notebooks/docs/param_est/parameter_estimation_nrtl_using_state_block_solution.ipynb
index 5bdce840..1d5d1b1e 100644
--- a/idaes_examples/notebooks/docs/param_est/parameter_estimation_nrtl_using_state_block_solution.ipynb
+++ b/idaes_examples/notebooks/docs/param_est/parameter_estimation_nrtl_using_state_block_solution.ipynb
@@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
- "execution_count": 10,
+ "execution_count": 1,
"metadata": {
"tags": [
"header",
@@ -16,7 +16,7 @@
"# Framework (IDAES IP) was produced under the DOE Institute for the\n",
"# Design of Advanced Energy Systems (IDAES).\n",
"#\n",
- "# Copyright (c) 2018-2023 by the software owners: The Regents of the\n",
+ "# Copyright (c) 2018-2026 by the software owners: The Regents of the\n",
"# University of California, through Lawrence Berkeley National Laboratory,\n",
"# National Technology & Engineering Solutions of Sandia, LLC, Carnegie Mellon\n",
"# University, West Virginia University Research Corporation, et al.\n",
@@ -32,8 +32,8 @@
"# Parameter Estimation Using the NRTL State Block\n",
"\n",
"Author: Jaffer Ghouse \n",
- "Maintainer: Andrew Lee \n",
- "Updated: 2023-06-01 \n",
+ "Maintainer: Stephen Cini \n",
+ "Updated: 2026-06-11 \n",
"\n",
"In this module, we use Pyomo's `parmest` tool in conjunction with IDAES models for parameter estimation. We demonstrate these tools by estimating the parameters associated with the NRTL property model for a benzene-toluene mixture. The NRTL model has 2 sets of parameters: the non-randomness parameter (`alpha_ij`) and the binary interaction parameter (`tau_ij`), where `i` and `j` are the pure component species. In this example, we only estimate the binary interaction parameter (`tau_ij`) for a given dataset. When estimating parameters associated with the property package, IDAES provides the flexibility of doing the parameter estimation by just using the state block or by using a unit model with a specified property package. This module will demonstrate parameter estimation by using only the state block. \n",
"\n",
@@ -45,8 +45,7 @@
"\n",
"## Key links to documentation:\n",
"* NRTL Model - https://idaes-pse.readthedocs.io/en/stable/reference_guides/model_libraries/generic/property_models/activity_coefficient.html\n",
- "* parmest - https://pyomo.readthedocs.io/en/stable/contributed_packages/parmest/index.html\n",
- ""
+ "* parmest - https://pyomo.readthedocs.io/en/stable/explanation/analysis/parmest/index.html\n"
]
},
{
@@ -55,13 +54,13 @@
"source": [
"\n",
"Inline Exercise:\n",
- "import `ConcreteModel` from Pyomo and `FlowsheetBlock` from IDAES. \n",
+ "import `ConcreteModel`, `value`, and `Suffix` from Pyomo, and `FlowsheetBlock`from IDAES. \n",
"
"
]
},
{
"cell_type": "code",
- "execution_count": 11,
+ "execution_count": 2,
"metadata": {
"tags": [
"exercise"
@@ -69,14 +68,14 @@
},
"outputs": [],
"source": [
- "# Todo: import ConcreteModel from pyomo.environ\n",
+ "# Todo: import ConcreteModel, value, and Suffix from pyomo.environ\n",
"\n",
"# Todo: import FlowsheetBlock from idaes.core"
]
},
{
"cell_type": "code",
- "execution_count": 12,
+ "execution_count": 3,
"metadata": {
"tags": [
"solution"
@@ -84,8 +83,8 @@
},
"outputs": [],
"source": [
- "# Todo: import ConcreteModel from pyomo.environ\n",
- "from pyomo.environ import ConcreteModel, value\n",
+ "# Todo: import ConcreteModel, value, and Suffix from pyomo.environ\n",
+ "from pyomo.environ import ConcreteModel, value, Suffix\n",
"\n",
"# Todo: import FlowsheetBlock from idaes.core\n",
"from idaes.core import FlowsheetBlock"
@@ -100,7 +99,7 @@
},
{
"cell_type": "code",
- "execution_count": 13,
+ "execution_count": 4,
"metadata": {
"tags": []
},
@@ -121,7 +120,7 @@
},
{
"cell_type": "code",
- "execution_count": 14,
+ "execution_count": 5,
"metadata": {
"tags": []
},
@@ -152,7 +151,7 @@
},
{
"cell_type": "code",
- "execution_count": 15,
+ "execution_count": 6,
"metadata": {
"tags": [
"exercise"
@@ -198,7 +197,12 @@
" m.fs.state_block.initialize(outlvl=idaeslog.INFO)\n",
"\n",
" # Fix at actual temperature\n",
- " m.fs.state_block.temperature.fix(float(data[\"temperature\"]))\n",
+ " if isinstance(data, dict) or isinstance(data, pd.Series):\n",
+ " m.fs.state_block.temperature.fix(float(data[\"temperature\"]))\n",
+ " elif isinstance(data, pd.DataFrame):\n",
+ " m.fs.state_block.temperature.fix(float(data.iloc[0][\"temperature\"]))\n",
+ " else:\n",
+ " raise ValueError(\"Unrecognized data type.\")\n",
"\n",
" # Set bounds on variables to be estimated\n",
" m.fs.properties.tau[\"benzene\", \"toluene\"].setlb(-5)\n",
@@ -213,7 +217,7 @@
},
{
"cell_type": "code",
- "execution_count": 16,
+ "execution_count": 7,
"metadata": {
"tags": [
"solution"
@@ -264,7 +268,12 @@
" m.fs.state_block.initialize(outlvl=idaeslog.INFO_LOW)\n",
"\n",
" # Fix at actual temperature\n",
- " m.fs.state_block.temperature.fix(float(data[\"temperature\"]))\n",
+ " if isinstance(data, dict) or isinstance(data, pd.Series):\n",
+ " m.fs.state_block.temperature.fix(float(data[\"temperature\"]))\n",
+ " elif isinstance(data, pd.DataFrame):\n",
+ " m.fs.state_block.temperature.fix(float(data.iloc[0][\"temperature\"]))\n",
+ " else:\n",
+ " raise ValueError(\"Unrecognized data type.\")\n",
"\n",
" # Set bounds on variables to be estimated\n",
" m.fs.properties.tau[\"benzene\", \"toluene\"].setlb(-5)\n",
@@ -290,54 +299,106 @@
"source": [
"In addition to providing a method to return an initialized model, the `parmest` tool needs the following:\n",
"\n",
- "* List of variable names to be estimated\n",
- "* Dataset\n",
- "* Expression to compute the sum of squared errors\n"
+ "* Experiment class to set up and label model with suffixes\n",
+ "* Dataset with multiple scenarios - organized into an experiment list\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
+ "Here we build an experiment class to label our model problem for parameter estimation. The labels are defined as a `Suffix`, and the main labels for our model are `experiment_outputs`, `unknown_parameters`, and `measurement_error`.\n",
+ "\n",
+ "For this problem, the error will be computed for the mole fraction of benzene in the vapor and liquid phase between the model prediction and data. The `experimental_outputs` will therefore be the mole fraction of benzene in the two phases.\n",
+ "\n",
"In this example, we only estimate the binary interaction parameter (`tau_ij`). Given that this variable is usually indexed as `tau_ij = Var(component_list, component_list)`, there are 2*2=4 degrees of freedom. However, when i=j, the binary interaction parameter is 0. Therefore, in this problem, we estimate the binary interaction parameter for the following variables only:\n",
"\n",
"* fs.properties.tau['benzene', 'toluene']\n",
"* fs.properties.tau['toluene', 'benzene']\n",
"\n",
- "\n",
- "Inline Exercise:\n",
- "Create a list called `variable_name` with the above-mentioned variables declared as strings.\n",
- "
"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 18,
- "metadata": {
- "tags": [
- "exercise"
- ]
- },
- "outputs": [],
- "source": [
- "# Todo: Create a list of vars to estimate"
+ "As shown below, these model components are used as our `unknown_parameters`.\n",
+ "\n",
+ "We define `measurement_error` as none so parmest calculates the value internally based on the experimental outputs. Refer to https://pyomo.readthedocs.io/en/stable/explanation/analysis/parmest/driver.html for more information. "
]
},
{
"cell_type": "code",
- "execution_count": 19,
- "metadata": {
- "tags": [
- "solution"
- ]
- },
+ "execution_count": 9,
+ "metadata": {},
"outputs": [],
"source": [
- "# Todo: Create a list of vars to estimate\n",
- "variable_name = [\n",
- " \"fs.properties.tau['benzene', 'toluene']\",\n",
- " \"fs.properties.tau['toluene', 'benzene']\",\n",
- "]"
+ "# Build an experiment class to take advantage of new parmest interface\n",
+ "from pyomo.contrib.parmest.experiment import Experiment\n",
+ "\n",
+ "\n",
+ "class NRTLExperiment(Experiment):\n",
+ " \"\"\"Experiment class for parameter estimation of NRTL model using parmest\"\"\"\n",
+ "\n",
+ " def __init__(self, data, meas_error=None):\n",
+ " \"\"\"Initialize the NRTLExperiment class\n",
+ "\n",
+ " Args:\n",
+ " data: DataFrame containing the experimental data\n",
+ " meas_error: Measurement error for the data (optional)\n",
+ " \"\"\"\n",
+ " self.model = None\n",
+ " self.data = data\n",
+ " self.meas_error = meas_error\n",
+ "\n",
+ " def create_model(self):\n",
+ " \"\"\"Create the Pyomo model for the NRTL parameter estimation problem\"\"\"\n",
+ " self.model = NRTL_model(self.data)\n",
+ "\n",
+ " def label_model(self):\n",
+ " from pyomo.environ import Set, Expression\n",
+ "\n",
+ " m = self.model\n",
+ "\n",
+ " # Parmest expects the first index of experiment outputs to be the data point\n",
+ " # This is a workaround that will be addressed and corrected in a future release.\n",
+ "\n",
+ " m.data_point = Set(initialize=[0])\n",
+ "\n",
+ " # Wrap IDAES variables in Expressions indexed by data point\n",
+ " m.liq_benzene_out = Expression(\n",
+ " m.data_point,\n",
+ " rule=lambda m, i: m.fs.state_block.mole_frac_phase_comp[\"Liq\", \"benzene\"],\n",
+ " )\n",
+ "\n",
+ " m.vap_benzene_out = Expression(\n",
+ " m.data_point,\n",
+ " rule=lambda m, i: m.fs.state_block.mole_frac_phase_comp[\"Vap\", \"benzene\"],\n",
+ " )\n",
+ "\n",
+ " m.experiment_outputs = Suffix(direction=Suffix.LOCAL)\n",
+ "\n",
+ " m.experiment_outputs[m.liq_benzene_out[0]] = float(self.data[\"liq_benzene\"])\n",
+ " m.experiment_outputs[m.vap_benzene_out[0]] = float(self.data[\"vap_benzene\"])\n",
+ "\n",
+ " m.measurement_error = Suffix(direction=Suffix.LOCAL)\n",
+ " m.measurement_error.update(\n",
+ " [\n",
+ " (m.liq_benzene_out[0], self.meas_error),\n",
+ " (m.vap_benzene_out[0], self.meas_error),\n",
+ " ]\n",
+ " )\n",
+ "\n",
+ " # Add unknown parameters to the model for easier access\n",
+ " m.unknown_parameters = Suffix(direction=Suffix.LOCAL)\n",
+ " m.unknown_parameters.update(\n",
+ " (k, value(k))\n",
+ " for k in [\n",
+ " m.fs.properties.tau[\"benzene\", \"toluene\"],\n",
+ " m.fs.properties.tau[\"toluene\", \"benzene\"],\n",
+ " ]\n",
+ " )\n",
+ "\n",
+ " def get_labeled_model(self):\n",
+ " \"\"\"Return the labeled model\"\"\"\n",
+ " if self.model is None:\n",
+ " self.create_model()\n",
+ " self.label_model()\n",
+ " return self.model"
]
},
{
@@ -356,11 +417,400 @@
},
{
"cell_type": "code",
- "execution_count": 20,
+ "execution_count": 10,
"metadata": {
"tags": []
},
- "outputs": [],
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " temperature | \n",
+ " liq_benzene | \n",
+ " vap_benzene | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 0 | \n",
+ " 365.500000 | \n",
+ " 0.480953 | \n",
+ " 0.692110 | \n",
+ "
\n",
+ " \n",
+ " | 1 | \n",
+ " 365.617647 | \n",
+ " 0.462444 | \n",
+ " 0.667699 | \n",
+ "
\n",
+ " \n",
+ " | 2 | \n",
+ " 365.735294 | \n",
+ " 0.477984 | \n",
+ " 0.692441 | \n",
+ "
\n",
+ " \n",
+ " | 3 | \n",
+ " 365.852941 | \n",
+ " 0.440547 | \n",
+ " 0.640336 | \n",
+ "
\n",
+ " \n",
+ " | 4 | \n",
+ " 365.970588 | \n",
+ " 0.427421 | \n",
+ " 0.623328 | \n",
+ "
\n",
+ " \n",
+ " | 5 | \n",
+ " 366.088235 | \n",
+ " 0.442725 | \n",
+ " 0.647796 | \n",
+ "
\n",
+ " \n",
+ " | 6 | \n",
+ " 366.205882 | \n",
+ " 0.434374 | \n",
+ " 0.637691 | \n",
+ "
\n",
+ " \n",
+ " | 7 | \n",
+ " 366.323529 | \n",
+ " 0.444642 | \n",
+ " 0.654933 | \n",
+ "
\n",
+ " \n",
+ " | 8 | \n",
+ " 366.441176 | \n",
+ " 0.427132 | \n",
+ " 0.631229 | \n",
+ "
\n",
+ " \n",
+ " | 9 | \n",
+ " 366.558824 | \n",
+ " 0.446301 | \n",
+ " 0.661743 | \n",
+ "
\n",
+ " \n",
+ " | 10 | \n",
+ " 366.676471 | \n",
+ " 0.438004 | \n",
+ " 0.651591 | \n",
+ "
\n",
+ " \n",
+ " | 11 | \n",
+ " 366.794118 | \n",
+ " 0.425320 | \n",
+ " 0.634814 | \n",
+ "
\n",
+ " \n",
+ " | 12 | \n",
+ " 366.911765 | \n",
+ " 0.439435 | \n",
+ " 0.658047 | \n",
+ "
\n",
+ " \n",
+ " | 13 | \n",
+ " 367.029412 | \n",
+ " 0.435655 | \n",
+ " 0.654539 | \n",
+ "
\n",
+ " \n",
+ " | 14 | \n",
+ " 367.147059 | \n",
+ " 0.401350 | \n",
+ " 0.604987 | \n",
+ "
\n",
+ " \n",
+ " | 15 | \n",
+ " 367.264706 | \n",
+ " 0.397862 | \n",
+ " 0.601703 | \n",
+ "
\n",
+ " \n",
+ " | 16 | \n",
+ " 367.382353 | \n",
+ " 0.415821 | \n",
+ " 0.630930 | \n",
+ "
\n",
+ " \n",
+ " | 17 | \n",
+ " 367.500000 | \n",
+ " 0.420667 | \n",
+ " 0.640380 | \n",
+ "
\n",
+ " \n",
+ " | 18 | \n",
+ " 367.617647 | \n",
+ " 0.391683 | \n",
+ " 0.598214 | \n",
+ "
\n",
+ " \n",
+ " | 19 | \n",
+ " 367.735294 | \n",
+ " 0.404903 | \n",
+ " 0.620432 | \n",
+ "
\n",
+ " \n",
+ " | 20 | \n",
+ " 367.852941 | \n",
+ " 0.409563 | \n",
+ " 0.629626 | \n",
+ "
\n",
+ " \n",
+ " | 21 | \n",
+ " 367.970588 | \n",
+ " 0.389488 | \n",
+ " 0.600722 | \n",
+ "
\n",
+ " \n",
+ " | 22 | \n",
+ " 368.000000 | \n",
+ " 0.396789 | \n",
+ " 0.612483 | \n",
+ "
\n",
+ " \n",
+ " | 23 | \n",
+ " 368.088235 | \n",
+ " 0.398162 | \n",
+ " 0.616106 | \n",
+ "
\n",
+ " \n",
+ " | 24 | \n",
+ " 368.205882 | \n",
+ " 0.362340 | \n",
+ " 0.562505 | \n",
+ "
\n",
+ " \n",
+ " | 25 | \n",
+ " 368.323529 | \n",
+ " 0.386958 | \n",
+ " 0.602680 | \n",
+ "
\n",
+ " \n",
+ " | 26 | \n",
+ " 368.441176 | \n",
+ " 0.363643 | \n",
+ " 0.568210 | \n",
+ "
\n",
+ " \n",
+ " | 27 | \n",
+ " 368.558824 | \n",
+ " 0.368118 | \n",
+ " 0.577072 | \n",
+ "
\n",
+ " \n",
+ " | 28 | \n",
+ " 368.676471 | \n",
+ " 0.384098 | \n",
+ " 0.604078 | \n",
+ "
\n",
+ " \n",
+ " | 29 | \n",
+ " 368.794118 | \n",
+ " 0.353605 | \n",
+ " 0.557925 | \n",
+ "
\n",
+ " \n",
+ " | 30 | \n",
+ " 368.911765 | \n",
+ " 0.346474 | \n",
+ " 0.548445 | \n",
+ "
\n",
+ " \n",
+ " | 31 | \n",
+ " 369.029412 | \n",
+ " 0.350741 | \n",
+ " 0.556996 | \n",
+ "
\n",
+ " \n",
+ " | 32 | \n",
+ " 369.147059 | \n",
+ " 0.362347 | \n",
+ " 0.577286 | \n",
+ "
\n",
+ " \n",
+ " | 33 | \n",
+ " 369.264706 | \n",
+ " 0.362578 | \n",
+ " 0.579519 | \n",
+ "
\n",
+ " \n",
+ " | 34 | \n",
+ " 369.382353 | \n",
+ " 0.340765 | \n",
+ " 0.546411 | \n",
+ "
\n",
+ " \n",
+ " | 35 | \n",
+ " 369.500000 | \n",
+ " 0.337462 | \n",
+ " 0.542857 | \n",
+ "
\n",
+ " \n",
+ " | 36 | \n",
+ " 369.617647 | \n",
+ " 0.355729 | \n",
+ " 0.574083 | \n",
+ "
\n",
+ " \n",
+ " | 37 | \n",
+ " 369.735294 | \n",
+ " 0.348679 | \n",
+ " 0.564513 | \n",
+ "
\n",
+ " \n",
+ " | 38 | \n",
+ " 369.852941 | \n",
+ " 0.338187 | \n",
+ " 0.549284 | \n",
+ "
\n",
+ " \n",
+ " | 39 | \n",
+ " 369.970588 | \n",
+ " 0.324360 | \n",
+ " 0.528514 | \n",
+ "
\n",
+ " \n",
+ " | 40 | \n",
+ " 370.088235 | \n",
+ " 0.310753 | \n",
+ " 0.507964 | \n",
+ "
\n",
+ " \n",
+ " | 41 | \n",
+ " 370.205882 | \n",
+ " 0.311037 | \n",
+ " 0.510055 | \n",
+ "
\n",
+ " \n",
+ " | 42 | \n",
+ " 370.323529 | \n",
+ " 0.311263 | \n",
+ " 0.512055 | \n",
+ "
\n",
+ " \n",
+ " | 43 | \n",
+ " 370.441176 | \n",
+ " 0.308081 | \n",
+ " 0.508437 | \n",
+ "
\n",
+ " \n",
+ " | 44 | \n",
+ " 370.558824 | \n",
+ " 0.308224 | \n",
+ " 0.510293 | \n",
+ "
\n",
+ " \n",
+ " | 45 | \n",
+ " 370.676471 | \n",
+ " 0.318148 | \n",
+ " 0.528399 | \n",
+ "
\n",
+ " \n",
+ " | 46 | \n",
+ " 370.794118 | \n",
+ " 0.308334 | \n",
+ " 0.513728 | \n",
+ "
\n",
+ " \n",
+ " | 47 | \n",
+ " 370.911765 | \n",
+ " 0.317937 | \n",
+ " 0.531410 | \n",
+ "
\n",
+ " \n",
+ " | 48 | \n",
+ " 371.029412 | \n",
+ " 0.289149 | \n",
+ " 0.484824 | \n",
+ "
\n",
+ " \n",
+ " | 49 | \n",
+ " 371.147059 | \n",
+ " 0.298637 | \n",
+ " 0.502318 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " temperature liq_benzene vap_benzene\n",
+ "0 365.500000 0.480953 0.692110\n",
+ "1 365.617647 0.462444 0.667699\n",
+ "2 365.735294 0.477984 0.692441\n",
+ "3 365.852941 0.440547 0.640336\n",
+ "4 365.970588 0.427421 0.623328\n",
+ "5 366.088235 0.442725 0.647796\n",
+ "6 366.205882 0.434374 0.637691\n",
+ "7 366.323529 0.444642 0.654933\n",
+ "8 366.441176 0.427132 0.631229\n",
+ "9 366.558824 0.446301 0.661743\n",
+ "10 366.676471 0.438004 0.651591\n",
+ "11 366.794118 0.425320 0.634814\n",
+ "12 366.911765 0.439435 0.658047\n",
+ "13 367.029412 0.435655 0.654539\n",
+ "14 367.147059 0.401350 0.604987\n",
+ "15 367.264706 0.397862 0.601703\n",
+ "16 367.382353 0.415821 0.630930\n",
+ "17 367.500000 0.420667 0.640380\n",
+ "18 367.617647 0.391683 0.598214\n",
+ "19 367.735294 0.404903 0.620432\n",
+ "20 367.852941 0.409563 0.629626\n",
+ "21 367.970588 0.389488 0.600722\n",
+ "22 368.000000 0.396789 0.612483\n",
+ "23 368.088235 0.398162 0.616106\n",
+ "24 368.205882 0.362340 0.562505\n",
+ "25 368.323529 0.386958 0.602680\n",
+ "26 368.441176 0.363643 0.568210\n",
+ "27 368.558824 0.368118 0.577072\n",
+ "28 368.676471 0.384098 0.604078\n",
+ "29 368.794118 0.353605 0.557925\n",
+ "30 368.911765 0.346474 0.548445\n",
+ "31 369.029412 0.350741 0.556996\n",
+ "32 369.147059 0.362347 0.577286\n",
+ "33 369.264706 0.362578 0.579519\n",
+ "34 369.382353 0.340765 0.546411\n",
+ "35 369.500000 0.337462 0.542857\n",
+ "36 369.617647 0.355729 0.574083\n",
+ "37 369.735294 0.348679 0.564513\n",
+ "38 369.852941 0.338187 0.549284\n",
+ "39 369.970588 0.324360 0.528514\n",
+ "40 370.088235 0.310753 0.507964\n",
+ "41 370.205882 0.311037 0.510055\n",
+ "42 370.323529 0.311263 0.512055\n",
+ "43 370.441176 0.308081 0.508437\n",
+ "44 370.558824 0.308224 0.510293\n",
+ "45 370.676471 0.318148 0.528399\n",
+ "46 370.794118 0.308334 0.513728\n",
+ "47 370.911765 0.317937 0.531410\n",
+ "48 371.029412 0.289149 0.484824\n",
+ "49 371.147059 0.298637 0.502318"
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ }
+ ],
"source": [
"# Load data from csv\n",
"data = pd.read_csv(\"BT_NRTL_dataset.csv\")\n",
@@ -373,88 +823,134 @@
"cell_type": "markdown",
"metadata": {},
"source": [
- "We need to provide a method to return an expression to compute the sum of squared errors that will be used as the objective in solving the parameter estimation problem. For this problem, the error will be computed for the mole fraction of benzene in the vapor and liquid phase between the model prediction and data. \n",
- "\n",
- "\n",
- "Inline Exercise:\n",
- "Complete the following cell by adding an expression to compute the sum of square errors. \n",
- "
"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {
- "tags": [
- "exercise"
- ]
- },
- "outputs": [],
- "source": [
- "# Create method to return an expression that computes the sum of squared error\n",
- "def SSE(m, data):\n",
- " # Todo: Add expression for computing the sum of squared errors in mole fraction of benzene in the liquid\n",
- " # and vapor phase. For example, the squared error for the vapor phase is:\n",
- " # (float(data[\"vap_benzene\"]) - m.fs.state_block.mole_frac_phase_comp[\"Vap\", \"benzene\"])**2\n",
- "\n",
- " return expr * 1e4"
+ "We define the `exp_list` by splitting the data into individual experiments, or data points."
]
},
{
"cell_type": "code",
- "execution_count": null,
- "metadata": {
- "tags": [
- "solution"
- ]
- },
- "outputs": [],
- "source": [
- "# Create method to return an expression that computes the sum of squared error\n",
- "def SSE(m, data):\n",
- " # Todo: Add expression for computing the sum of squared errors in mole fraction of benzene in the liquid\n",
- " # and vapor phase. For example, the squared error for the vapor phase is:\n",
- " # (float(data[\"vap_benzene\"]) - m.fs.state_block.mole_frac_phase_comp[\"Vap\", \"benzene\"])**2\n",
- " expr = (\n",
- " float(data[\"vap_benzene\"])\n",
- " - m.fs.state_block.mole_frac_phase_comp[\"Vap\", \"benzene\"]\n",
- " ) ** 2 + (\n",
- " float(data[\"liq_benzene\"])\n",
- " - m.fs.state_block.mole_frac_phase_comp[\"Liq\", \"benzene\"]\n",
- " ) ** 2\n",
- " return expr * 1e4"
- ]
- },
- {
- "cell_type": "markdown",
+ "execution_count": 11,
"metadata": {},
+ "outputs": [],
"source": [
- "\n",
- "Note:\n",
- "Notice that we have scaled the expression up by a factor of 10000 as the SSE computed here will be an extremely small number given that we are using the difference in mole fraction in our expression. This will help in using a well-scaled objective to improve solve robustness when using IPOPT. \n",
- "
\n"
+ "# Update to new interface\n",
+ "exp_list = []\n",
+ "for i in range(data.shape[0]):\n",
+ " exp_list.append(NRTLExperiment(data.iloc[i]))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
- "We are now ready to set up the parameter estimation problem. We will create a parameter estimation object called `pest`. As shown below, we pass the method that returns an initialized model, data, variable_name, and the SSE expression to the Estimator method. `tee=True` will print the solver output after solving the parameter estimation problem. "
+ "We are now ready to set up the parameter estimation problem. We will create a parameter estimation object called pest. As shown below, we pass the experiment list, and an objective function to the Estimator method. tee=True will print the solver output after solving the parameter estimation problem."
]
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 12,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Ipopt 3.13.2: \n",
+ "\n",
+ "******************************************************************************\n",
+ "This program contains Ipopt, a library for large-scale nonlinear optimization.\n",
+ " Ipopt is released as open source code under the Eclipse Public License (EPL).\n",
+ " For more information visit http://projects.coin-or.org/Ipopt\n",
+ "\n",
+ "This version of Ipopt was compiled from source code available at\n",
+ " https://github.com/IDAES/Ipopt as part of the Institute for the Design of\n",
+ " Advanced Energy Systems Process Systems Engineering Framework (IDAES PSE\n",
+ " Framework) Copyright (c) 2018-2019. See https://github.com/IDAES/idaes-pse.\n",
+ "\n",
+ "This version of Ipopt was compiled using HSL, a collection of Fortran codes\n",
+ " for large-scale scientific computation. All technical papers, sales and\n",
+ " publicity material resulting from use of the HSL codes within IPOPT must\n",
+ " contain the following acknowledgement:\n",
+ " HSL, a collection of Fortran codes for large-scale scientific\n",
+ " computation. See http://www.hsl.rl.ac.uk.\n",
+ "******************************************************************************\n",
+ "\n",
+ "This is Ipopt version 3.13.2, running with linear solver ma27.\n",
+ "\n",
+ "Number of nonzeros in equality constraint Jacobian...: 3750\n",
+ "Number of nonzeros in inequality constraint Jacobian.: 0\n",
+ "Number of nonzeros in Lagrangian Hessian.............: 2200\n",
+ "\n",
+ "Total number of variables............................: 1102\n",
+ " variables with only lower bounds: 0\n",
+ " variables with lower and upper bounds: 300\n",
+ " variables with only upper bounds: 0\n",
+ "Total number of equality constraints.................: 1100\n",
+ "Total number of inequality constraints...............: 0\n",
+ " inequality constraints with only lower bounds: 0\n",
+ " inequality constraints with lower and upper bounds: 0\n",
+ " inequality constraints with only upper bounds: 0\n",
+ "\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 0 6.0671019e-03 3.15e+00 1.97e-05 -1.0 0.00e+00 - 0.00e+00 0.00e+00 0\n",
+ " 1 8.6249856e-04 1.40e+03 2.15e-01 -1.0 1.37e+04 - 9.95e-01 1.00e+00h 1\n",
+ " 2 1.1627234e-03 9.11e+03 8.21e-01 -1.7 4.74e+02 - 8.66e-01 1.00e+00h 1\n",
+ " 3 1.0978149e-03 9.02e+03 7.99e-01 -1.7 5.89e+00 -4.0 5.44e-01 2.64e-02h 6\n",
+ " 4 8.5702670e-04 8.63e+02 3.17e-02 -1.7 6.93e-01 -2.7 1.00e+00 1.00e+00h 1\n",
+ " 5 1.3332724e-03 3.57e+03 7.92e-03 -1.7 7.75e-01 - 1.00e+00 1.00e+00h 1\n",
+ " 6 1.5692588e-03 1.64e+02 2.34e-04 -1.7 1.98e-01 - 1.00e+00 1.00e+00h 1\n",
+ " 7 1.5828905e-03 1.20e+01 1.13e-05 -1.7 4.29e-02 - 1.00e+00 1.00e+00h 1\n",
+ " 8 1.4366151e-03 9.18e-01 2.34e-04 -2.5 5.49e-02 - 1.00e+00 1.00e+00h 1\n",
+ " 9 8.9194043e-04 2.19e+01 2.00e-04 -3.8 2.51e-01 - 1.00e+00 1.00e+00h 1\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 10 5.9835646e-04 3.72e+01 2.34e-05 -3.8 3.13e-01 - 1.00e+00 1.00e+00h 1\n",
+ " 11 5.9839648e-04 1.26e+00 4.06e-08 -3.8 2.87e-02 - 1.00e+00 1.00e+00h 1\n",
+ " 12 5.9838953e-04 4.33e-05 1.60e-12 -3.8 9.40e-05 - 1.00e+00 1.00e+00h 1\n",
+ " 13 5.9077073e-04 1.21e+01 2.96e-06 -5.7 4.79e-02 - 1.00e+00 1.00e+00h 1\n",
+ " 14 5.9066394e-04 1.19e-03 4.25e-07 -5.7 5.98e-04 -3.1 1.00e+00 1.00e+00h 1\n",
+ " 15 5.9059984e-04 1.08e-02 2.96e-07 -8.6 1.25e-03 -3.6 1.00e+00 1.00e+00h 1\n",
+ " 16 5.9042438e-04 9.67e-02 2.92e-07 -8.6 3.70e-03 -4.1 1.00e+00 1.00e+00h 1\n",
+ " 17 5.8992758e-04 8.72e-01 2.91e-07 -8.6 1.11e-02 -4.6 1.00e+00 1.00e+00h 1\n",
+ " 18 5.8840706e-04 8.23e+00 3.09e-07 -8.6 3.40e-02 -5.1 1.00e+00 1.00e+00h 1\n",
+ " 19 5.8319289e-04 9.25e+01 1.97e-06 -8.6 1.15e-01 -5.5 1.00e+00 1.00e+00h 1\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 20 5.4836946e-04 3.88e+03 1.22e-04 -8.6 7.95e-01 -6.0 1.00e+00 1.00e+00h 1\n",
+ " 21 5.0847689e-04 4.45e+02 1.04e-04 -8.6 3.55e-01 -5.6 1.00e+00 1.00e+00h 1\n",
+ " 22 5.0727291e-04 4.20e+00 1.54e-05 -8.6 6.20e+02 - 1.00e+00 1.00e+00h 1\n",
+ " 23 5.0749772e-04 1.36e+00 1.44e-06 -8.6 5.13e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 24 5.0749686e-04 6.93e-06 4.21e-11 -8.6 3.55e-01 - 1.00e+00 1.00e+00h 1\n",
+ " 25 5.0749686e-04 3.36e-06 1.49e-12 -9.0 6.25e-02 - 1.00e+00 1.00e+00h 1\n",
+ " 26 5.0749686e-04 1.02e-10 2.36e-18 -9.0 5.08e-06 - 1.00e+00 1.00e+00h 1\n",
+ "\n",
+ "Number of Iterations....: 26\n",
+ "\n",
+ " (scaled) (unscaled)\n",
+ "Objective...............: 5.0749685787934424e-04 5.0749685787934424e-04\n",
+ "Dual infeasibility......: 2.3583858113882067e-18 2.3583858113882067e-18\n",
+ "Constraint violation....: 3.5405706676501683e-13 1.0186340659856796e-10\n",
+ "Complementarity.........: 9.0909090909091344e-10 9.0909090909091344e-10\n",
+ "Overall NLP error.......: 9.0909090909091344e-10 9.0909090909091344e-10\n",
+ "\n",
+ "\n",
+ "Number of objective function evaluations = 33\n",
+ "Number of objective gradient evaluations = 27\n",
+ "Number of equality constraint evaluations = 34\n",
+ "Number of inequality constraint evaluations = 0\n",
+ "Number of equality constraint Jacobian evaluations = 27\n",
+ "Number of inequality constraint Jacobian evaluations = 0\n",
+ "Number of Lagrangian Hessian evaluations = 26\n",
+ "Total CPU secs in IPOPT (w/o function evaluations) = 0.035\n",
+ "Total CPU secs in NLP function evaluations = 0.009\n",
+ "\n",
+ "EXIT: Optimal Solution Found.\n"
+ ]
+ }
+ ],
"source": [
"import logging\n",
"\n",
"idaeslog.getIdaesLogger(\"core.property_meta\").setLevel(logging.ERROR)\n",
- "# Initialize a parameter estimation object\n",
- "pest = parmest.Estimator(NRTL_model, data, variable_name, SSE, tee=True)\n",
"\n",
- "# Run parameter estimation using all data\n",
+ "pest = parmest.Estimator(exp_list, obj_function=\"SSE\", tee=True)\n",
"obj_value, parameters = pest.theta_est()"
]
},
@@ -467,11 +963,23 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 14,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "The SSE at the optimal solution is 0.000507\n",
+ "\n",
+ "The values for the parameters are as follows:\n",
+ "fs.properties.tau[benzene,toluene] = -0.8987550041842163\n",
+ "fs.properties.tau[toluene,benzene] = 1.4104702103547941\n"
+ ]
+ }
+ ],
"source": [
- "print(\"The SSE at the optimal solution is %0.6f\" % (obj_value * 1e-4))\n",
+ "print(\"The SSE at the optimal solution is %0.6f\" % (obj_value))\n",
"print()\n",
"print(\"The values for the parameters are as follows:\")\n",
"for k, v in parameters.items():\n",
@@ -504,15 +1012,12 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 15,
"metadata": {},
"outputs": [],
"source": [
- "# Run parameter estimation using bootstrap resample of the data (10 samples),\n",
- "# plot results along with confidence regions\n",
- "\n",
- "# Uncomment the following code:\n",
- "# bootstrap_theta = pest.theta_est_bootstrap(4)\n",
+ "# Uncomment the following lines\n",
+ "# bootstrap_theta = pest.theta_est_bootstrap(4, seed=542)\n",
"# display(bootstrap_theta)"
]
}
@@ -520,7 +1025,7 @@
"metadata": {
"celltoolbar": "Tags",
"kernelspec": {
- "display_name": "Python 3 (ipykernel)",
+ "display_name": "idaes-examples-dev-py313-macmini",
"language": "python",
"name": "python3"
},
@@ -534,7 +1039,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.10.9"
+ "version": "3.13.13"
}
},
"nbformat": 4,
diff --git a/idaes_examples/notebooks/docs/param_est/parameter_estimation_nrtl_using_state_block_test.ipynb b/idaes_examples/notebooks/docs/param_est/parameter_estimation_nrtl_using_state_block_test.ipynb
index 7d253335..735706d0 100644
--- a/idaes_examples/notebooks/docs/param_est/parameter_estimation_nrtl_using_state_block_test.ipynb
+++ b/idaes_examples/notebooks/docs/param_est/parameter_estimation_nrtl_using_state_block_test.ipynb
@@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
- "execution_count": 10,
+ "execution_count": 1,
"metadata": {
"tags": [
"header",
@@ -16,7 +16,7 @@
"# Framework (IDAES IP) was produced under the DOE Institute for the\n",
"# Design of Advanced Energy Systems (IDAES).\n",
"#\n",
- "# Copyright (c) 2018-2023 by the software owners: The Regents of the\n",
+ "# Copyright (c) 2018-2026 by the software owners: The Regents of the\n",
"# University of California, through Lawrence Berkeley National Laboratory,\n",
"# National Technology & Engineering Solutions of Sandia, LLC, Carnegie Mellon\n",
"# University, West Virginia University Research Corporation, et al.\n",
@@ -32,8 +32,8 @@
"# Parameter Estimation Using the NRTL State Block\n",
"\n",
"Author: Jaffer Ghouse \n",
- "Maintainer: Andrew Lee \n",
- "Updated: 2023-06-01 \n",
+ "Maintainer: Stephen Cini \n",
+ "Updated: 2026-06-11 \n",
"\n",
"In this module, we use Pyomo's `parmest` tool in conjunction with IDAES models for parameter estimation. We demonstrate these tools by estimating the parameters associated with the NRTL property model for a benzene-toluene mixture. The NRTL model has 2 sets of parameters: the non-randomness parameter (`alpha_ij`) and the binary interaction parameter (`tau_ij`), where `i` and `j` are the pure component species. In this example, we only estimate the binary interaction parameter (`tau_ij`) for a given dataset. When estimating parameters associated with the property package, IDAES provides the flexibility of doing the parameter estimation by just using the state block or by using a unit model with a specified property package. This module will demonstrate parameter estimation by using only the state block. \n",
"\n",
@@ -45,8 +45,7 @@
"\n",
"## Key links to documentation:\n",
"* NRTL Model - https://idaes-pse.readthedocs.io/en/stable/reference_guides/model_libraries/generic/property_models/activity_coefficient.html\n",
- "* parmest - https://pyomo.readthedocs.io/en/stable/contributed_packages/parmest/index.html\n",
- ""
+ "* parmest - https://pyomo.readthedocs.io/en/stable/explanation/analysis/parmest/index.html\n"
]
},
{
@@ -55,13 +54,13 @@
"source": [
"\n",
"Inline Exercise:\n",
- "import `ConcreteModel` from Pyomo and `FlowsheetBlock` from IDAES. \n",
+ "import `ConcreteModel`, `value`, and `Suffix` from Pyomo, and `FlowsheetBlock`from IDAES. \n",
"
"
]
},
{
"cell_type": "code",
- "execution_count": 12,
+ "execution_count": 3,
"metadata": {
"tags": [
"solution"
@@ -69,8 +68,8 @@
},
"outputs": [],
"source": [
- "# Todo: import ConcreteModel from pyomo.environ\n",
- "from pyomo.environ import ConcreteModel, value\n",
+ "# Todo: import ConcreteModel, value, and Suffix from pyomo.environ\n",
+ "from pyomo.environ import ConcreteModel, value, Suffix\n",
"\n",
"# Todo: import FlowsheetBlock from idaes.core\n",
"from idaes.core import FlowsheetBlock"
@@ -85,7 +84,7 @@
},
{
"cell_type": "code",
- "execution_count": 13,
+ "execution_count": 4,
"metadata": {
"tags": []
},
@@ -106,7 +105,7 @@
},
{
"cell_type": "code",
- "execution_count": 14,
+ "execution_count": 5,
"metadata": {
"tags": []
},
@@ -137,7 +136,7 @@
},
{
"cell_type": "code",
- "execution_count": 16,
+ "execution_count": 7,
"metadata": {
"tags": [
"solution"
@@ -188,7 +187,12 @@
" m.fs.state_block.initialize(outlvl=idaeslog.INFO_LOW)\n",
"\n",
" # Fix at actual temperature\n",
- " m.fs.state_block.temperature.fix(float(data[\"temperature\"]))\n",
+ " if isinstance(data, dict) or isinstance(data, pd.Series):\n",
+ " m.fs.state_block.temperature.fix(float(data[\"temperature\"]))\n",
+ " elif isinstance(data, pd.DataFrame):\n",
+ " m.fs.state_block.temperature.fix(float(data.iloc[0][\"temperature\"]))\n",
+ " else:\n",
+ " raise ValueError(\"Unrecognized data type.\")\n",
"\n",
" # Set bounds on variables to be estimated\n",
" m.fs.properties.tau[\"benzene\", \"toluene\"].setlb(-5)\n",
@@ -203,7 +207,7 @@
},
{
"cell_type": "code",
- "execution_count": 17,
+ "execution_count": 8,
"metadata": {
"tags": [
"testing"
@@ -251,41 +255,106 @@
"source": [
"In addition to providing a method to return an initialized model, the `parmest` tool needs the following:\n",
"\n",
- "* List of variable names to be estimated\n",
- "* Dataset\n",
- "* Expression to compute the sum of squared errors\n"
+ "* Experiment class to set up and label model with suffixes\n",
+ "* Dataset with multiple scenarios - organized into an experiment list\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
+ "Here we build an experiment class to label our model problem for parameter estimation. The labels are defined as a `Suffix`, and the main labels for our model are `experiment_outputs`, `unknown_parameters`, and `measurement_error`.\n",
+ "\n",
+ "For this problem, the error will be computed for the mole fraction of benzene in the vapor and liquid phase between the model prediction and data. The `experimental_outputs` will therefore be the mole fraction of benzene in the two phases.\n",
+ "\n",
"In this example, we only estimate the binary interaction parameter (`tau_ij`). Given that this variable is usually indexed as `tau_ij = Var(component_list, component_list)`, there are 2*2=4 degrees of freedom. However, when i=j, the binary interaction parameter is 0. Therefore, in this problem, we estimate the binary interaction parameter for the following variables only:\n",
"\n",
"* fs.properties.tau['benzene', 'toluene']\n",
"* fs.properties.tau['toluene', 'benzene']\n",
"\n",
- "\n",
- "Inline Exercise:\n",
- "Create a list called `variable_name` with the above-mentioned variables declared as strings.\n",
- "
"
+ "As shown below, these model components are used as our `unknown_parameters`.\n",
+ "\n",
+ "We define `measurement_error` as none so parmest calculates the value internally based on the experimental outputs. Refer to https://pyomo.readthedocs.io/en/stable/explanation/analysis/parmest/driver.html for more information. "
]
},
{
"cell_type": "code",
- "execution_count": 19,
- "metadata": {
- "tags": [
- "solution"
- ]
- },
+ "execution_count": 9,
+ "metadata": {},
"outputs": [],
"source": [
- "# Todo: Create a list of vars to estimate\n",
- "variable_name = [\n",
- " \"fs.properties.tau['benzene', 'toluene']\",\n",
- " \"fs.properties.tau['toluene', 'benzene']\",\n",
- "]"
+ "# Build an experiment class to take advantage of new parmest interface\n",
+ "from pyomo.contrib.parmest.experiment import Experiment\n",
+ "\n",
+ "\n",
+ "class NRTLExperiment(Experiment):\n",
+ " \"\"\"Experiment class for parameter estimation of NRTL model using parmest\"\"\"\n",
+ "\n",
+ " def __init__(self, data, meas_error=None):\n",
+ " \"\"\"Initialize the NRTLExperiment class\n",
+ "\n",
+ " Args:\n",
+ " data: DataFrame containing the experimental data\n",
+ " meas_error: Measurement error for the data (optional)\n",
+ " \"\"\"\n",
+ " self.model = None\n",
+ " self.data = data\n",
+ " self.meas_error = meas_error\n",
+ "\n",
+ " def create_model(self):\n",
+ " \"\"\"Create the Pyomo model for the NRTL parameter estimation problem\"\"\"\n",
+ " self.model = NRTL_model(self.data)\n",
+ "\n",
+ " def label_model(self):\n",
+ " from pyomo.environ import Set, Expression\n",
+ "\n",
+ " m = self.model\n",
+ "\n",
+ " # Parmest expects the first index of experiment outputs to be the data point\n",
+ " # This is a workaround that will be addressed and corrected in a future release.\n",
+ "\n",
+ " m.data_point = Set(initialize=[0])\n",
+ "\n",
+ " # Wrap IDAES variables in Expressions indexed by data point\n",
+ " m.liq_benzene_out = Expression(\n",
+ " m.data_point,\n",
+ " rule=lambda m, i: m.fs.state_block.mole_frac_phase_comp[\"Liq\", \"benzene\"],\n",
+ " )\n",
+ "\n",
+ " m.vap_benzene_out = Expression(\n",
+ " m.data_point,\n",
+ " rule=lambda m, i: m.fs.state_block.mole_frac_phase_comp[\"Vap\", \"benzene\"],\n",
+ " )\n",
+ "\n",
+ " m.experiment_outputs = Suffix(direction=Suffix.LOCAL)\n",
+ "\n",
+ " m.experiment_outputs[m.liq_benzene_out[0]] = float(self.data[\"liq_benzene\"])\n",
+ " m.experiment_outputs[m.vap_benzene_out[0]] = float(self.data[\"vap_benzene\"])\n",
+ "\n",
+ " m.measurement_error = Suffix(direction=Suffix.LOCAL)\n",
+ " m.measurement_error.update(\n",
+ " [\n",
+ " (m.liq_benzene_out[0], self.meas_error),\n",
+ " (m.vap_benzene_out[0], self.meas_error),\n",
+ " ]\n",
+ " )\n",
+ "\n",
+ " # Add unknown parameters to the model for easier access\n",
+ " m.unknown_parameters = Suffix(direction=Suffix.LOCAL)\n",
+ " m.unknown_parameters.update(\n",
+ " (k, value(k))\n",
+ " for k in [\n",
+ " m.fs.properties.tau[\"benzene\", \"toluene\"],\n",
+ " m.fs.properties.tau[\"toluene\", \"benzene\"],\n",
+ " ]\n",
+ " )\n",
+ "\n",
+ " def get_labeled_model(self):\n",
+ " \"\"\"Return the labeled model\"\"\"\n",
+ " if self.model is None:\n",
+ " self.create_model()\n",
+ " self.label_model()\n",
+ " return self.model"
]
},
{
@@ -304,11 +373,400 @@
},
{
"cell_type": "code",
- "execution_count": 20,
+ "execution_count": 10,
"metadata": {
"tags": []
},
- "outputs": [],
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " temperature | \n",
+ " liq_benzene | \n",
+ " vap_benzene | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 0 | \n",
+ " 365.500000 | \n",
+ " 0.480953 | \n",
+ " 0.692110 | \n",
+ "
\n",
+ " \n",
+ " | 1 | \n",
+ " 365.617647 | \n",
+ " 0.462444 | \n",
+ " 0.667699 | \n",
+ "
\n",
+ " \n",
+ " | 2 | \n",
+ " 365.735294 | \n",
+ " 0.477984 | \n",
+ " 0.692441 | \n",
+ "
\n",
+ " \n",
+ " | 3 | \n",
+ " 365.852941 | \n",
+ " 0.440547 | \n",
+ " 0.640336 | \n",
+ "
\n",
+ " \n",
+ " | 4 | \n",
+ " 365.970588 | \n",
+ " 0.427421 | \n",
+ " 0.623328 | \n",
+ "
\n",
+ " \n",
+ " | 5 | \n",
+ " 366.088235 | \n",
+ " 0.442725 | \n",
+ " 0.647796 | \n",
+ "
\n",
+ " \n",
+ " | 6 | \n",
+ " 366.205882 | \n",
+ " 0.434374 | \n",
+ " 0.637691 | \n",
+ "
\n",
+ " \n",
+ " | 7 | \n",
+ " 366.323529 | \n",
+ " 0.444642 | \n",
+ " 0.654933 | \n",
+ "
\n",
+ " \n",
+ " | 8 | \n",
+ " 366.441176 | \n",
+ " 0.427132 | \n",
+ " 0.631229 | \n",
+ "
\n",
+ " \n",
+ " | 9 | \n",
+ " 366.558824 | \n",
+ " 0.446301 | \n",
+ " 0.661743 | \n",
+ "
\n",
+ " \n",
+ " | 10 | \n",
+ " 366.676471 | \n",
+ " 0.438004 | \n",
+ " 0.651591 | \n",
+ "
\n",
+ " \n",
+ " | 11 | \n",
+ " 366.794118 | \n",
+ " 0.425320 | \n",
+ " 0.634814 | \n",
+ "
\n",
+ " \n",
+ " | 12 | \n",
+ " 366.911765 | \n",
+ " 0.439435 | \n",
+ " 0.658047 | \n",
+ "
\n",
+ " \n",
+ " | 13 | \n",
+ " 367.029412 | \n",
+ " 0.435655 | \n",
+ " 0.654539 | \n",
+ "
\n",
+ " \n",
+ " | 14 | \n",
+ " 367.147059 | \n",
+ " 0.401350 | \n",
+ " 0.604987 | \n",
+ "
\n",
+ " \n",
+ " | 15 | \n",
+ " 367.264706 | \n",
+ " 0.397862 | \n",
+ " 0.601703 | \n",
+ "
\n",
+ " \n",
+ " | 16 | \n",
+ " 367.382353 | \n",
+ " 0.415821 | \n",
+ " 0.630930 | \n",
+ "
\n",
+ " \n",
+ " | 17 | \n",
+ " 367.500000 | \n",
+ " 0.420667 | \n",
+ " 0.640380 | \n",
+ "
\n",
+ " \n",
+ " | 18 | \n",
+ " 367.617647 | \n",
+ " 0.391683 | \n",
+ " 0.598214 | \n",
+ "
\n",
+ " \n",
+ " | 19 | \n",
+ " 367.735294 | \n",
+ " 0.404903 | \n",
+ " 0.620432 | \n",
+ "
\n",
+ " \n",
+ " | 20 | \n",
+ " 367.852941 | \n",
+ " 0.409563 | \n",
+ " 0.629626 | \n",
+ "
\n",
+ " \n",
+ " | 21 | \n",
+ " 367.970588 | \n",
+ " 0.389488 | \n",
+ " 0.600722 | \n",
+ "
\n",
+ " \n",
+ " | 22 | \n",
+ " 368.000000 | \n",
+ " 0.396789 | \n",
+ " 0.612483 | \n",
+ "
\n",
+ " \n",
+ " | 23 | \n",
+ " 368.088235 | \n",
+ " 0.398162 | \n",
+ " 0.616106 | \n",
+ "
\n",
+ " \n",
+ " | 24 | \n",
+ " 368.205882 | \n",
+ " 0.362340 | \n",
+ " 0.562505 | \n",
+ "
\n",
+ " \n",
+ " | 25 | \n",
+ " 368.323529 | \n",
+ " 0.386958 | \n",
+ " 0.602680 | \n",
+ "
\n",
+ " \n",
+ " | 26 | \n",
+ " 368.441176 | \n",
+ " 0.363643 | \n",
+ " 0.568210 | \n",
+ "
\n",
+ " \n",
+ " | 27 | \n",
+ " 368.558824 | \n",
+ " 0.368118 | \n",
+ " 0.577072 | \n",
+ "
\n",
+ " \n",
+ " | 28 | \n",
+ " 368.676471 | \n",
+ " 0.384098 | \n",
+ " 0.604078 | \n",
+ "
\n",
+ " \n",
+ " | 29 | \n",
+ " 368.794118 | \n",
+ " 0.353605 | \n",
+ " 0.557925 | \n",
+ "
\n",
+ " \n",
+ " | 30 | \n",
+ " 368.911765 | \n",
+ " 0.346474 | \n",
+ " 0.548445 | \n",
+ "
\n",
+ " \n",
+ " | 31 | \n",
+ " 369.029412 | \n",
+ " 0.350741 | \n",
+ " 0.556996 | \n",
+ "
\n",
+ " \n",
+ " | 32 | \n",
+ " 369.147059 | \n",
+ " 0.362347 | \n",
+ " 0.577286 | \n",
+ "
\n",
+ " \n",
+ " | 33 | \n",
+ " 369.264706 | \n",
+ " 0.362578 | \n",
+ " 0.579519 | \n",
+ "
\n",
+ " \n",
+ " | 34 | \n",
+ " 369.382353 | \n",
+ " 0.340765 | \n",
+ " 0.546411 | \n",
+ "
\n",
+ " \n",
+ " | 35 | \n",
+ " 369.500000 | \n",
+ " 0.337462 | \n",
+ " 0.542857 | \n",
+ "
\n",
+ " \n",
+ " | 36 | \n",
+ " 369.617647 | \n",
+ " 0.355729 | \n",
+ " 0.574083 | \n",
+ "
\n",
+ " \n",
+ " | 37 | \n",
+ " 369.735294 | \n",
+ " 0.348679 | \n",
+ " 0.564513 | \n",
+ "
\n",
+ " \n",
+ " | 38 | \n",
+ " 369.852941 | \n",
+ " 0.338187 | \n",
+ " 0.549284 | \n",
+ "
\n",
+ " \n",
+ " | 39 | \n",
+ " 369.970588 | \n",
+ " 0.324360 | \n",
+ " 0.528514 | \n",
+ "
\n",
+ " \n",
+ " | 40 | \n",
+ " 370.088235 | \n",
+ " 0.310753 | \n",
+ " 0.507964 | \n",
+ "
\n",
+ " \n",
+ " | 41 | \n",
+ " 370.205882 | \n",
+ " 0.311037 | \n",
+ " 0.510055 | \n",
+ "
\n",
+ " \n",
+ " | 42 | \n",
+ " 370.323529 | \n",
+ " 0.311263 | \n",
+ " 0.512055 | \n",
+ "
\n",
+ " \n",
+ " | 43 | \n",
+ " 370.441176 | \n",
+ " 0.308081 | \n",
+ " 0.508437 | \n",
+ "
\n",
+ " \n",
+ " | 44 | \n",
+ " 370.558824 | \n",
+ " 0.308224 | \n",
+ " 0.510293 | \n",
+ "
\n",
+ " \n",
+ " | 45 | \n",
+ " 370.676471 | \n",
+ " 0.318148 | \n",
+ " 0.528399 | \n",
+ "
\n",
+ " \n",
+ " | 46 | \n",
+ " 370.794118 | \n",
+ " 0.308334 | \n",
+ " 0.513728 | \n",
+ "
\n",
+ " \n",
+ " | 47 | \n",
+ " 370.911765 | \n",
+ " 0.317937 | \n",
+ " 0.531410 | \n",
+ "
\n",
+ " \n",
+ " | 48 | \n",
+ " 371.029412 | \n",
+ " 0.289149 | \n",
+ " 0.484824 | \n",
+ "
\n",
+ " \n",
+ " | 49 | \n",
+ " 371.147059 | \n",
+ " 0.298637 | \n",
+ " 0.502318 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " temperature liq_benzene vap_benzene\n",
+ "0 365.500000 0.480953 0.692110\n",
+ "1 365.617647 0.462444 0.667699\n",
+ "2 365.735294 0.477984 0.692441\n",
+ "3 365.852941 0.440547 0.640336\n",
+ "4 365.970588 0.427421 0.623328\n",
+ "5 366.088235 0.442725 0.647796\n",
+ "6 366.205882 0.434374 0.637691\n",
+ "7 366.323529 0.444642 0.654933\n",
+ "8 366.441176 0.427132 0.631229\n",
+ "9 366.558824 0.446301 0.661743\n",
+ "10 366.676471 0.438004 0.651591\n",
+ "11 366.794118 0.425320 0.634814\n",
+ "12 366.911765 0.439435 0.658047\n",
+ "13 367.029412 0.435655 0.654539\n",
+ "14 367.147059 0.401350 0.604987\n",
+ "15 367.264706 0.397862 0.601703\n",
+ "16 367.382353 0.415821 0.630930\n",
+ "17 367.500000 0.420667 0.640380\n",
+ "18 367.617647 0.391683 0.598214\n",
+ "19 367.735294 0.404903 0.620432\n",
+ "20 367.852941 0.409563 0.629626\n",
+ "21 367.970588 0.389488 0.600722\n",
+ "22 368.000000 0.396789 0.612483\n",
+ "23 368.088235 0.398162 0.616106\n",
+ "24 368.205882 0.362340 0.562505\n",
+ "25 368.323529 0.386958 0.602680\n",
+ "26 368.441176 0.363643 0.568210\n",
+ "27 368.558824 0.368118 0.577072\n",
+ "28 368.676471 0.384098 0.604078\n",
+ "29 368.794118 0.353605 0.557925\n",
+ "30 368.911765 0.346474 0.548445\n",
+ "31 369.029412 0.350741 0.556996\n",
+ "32 369.147059 0.362347 0.577286\n",
+ "33 369.264706 0.362578 0.579519\n",
+ "34 369.382353 0.340765 0.546411\n",
+ "35 369.500000 0.337462 0.542857\n",
+ "36 369.617647 0.355729 0.574083\n",
+ "37 369.735294 0.348679 0.564513\n",
+ "38 369.852941 0.338187 0.549284\n",
+ "39 369.970588 0.324360 0.528514\n",
+ "40 370.088235 0.310753 0.507964\n",
+ "41 370.205882 0.311037 0.510055\n",
+ "42 370.323529 0.311263 0.512055\n",
+ "43 370.441176 0.308081 0.508437\n",
+ "44 370.558824 0.308224 0.510293\n",
+ "45 370.676471 0.318148 0.528399\n",
+ "46 370.794118 0.308334 0.513728\n",
+ "47 370.911765 0.317937 0.531410\n",
+ "48 371.029412 0.289149 0.484824\n",
+ "49 371.147059 0.298637 0.502318"
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ }
+ ],
"source": [
"# Load data from csv\n",
"data = pd.read_csv(\"BT_NRTL_dataset.csv\")\n",
@@ -321,75 +779,140 @@
"cell_type": "markdown",
"metadata": {},
"source": [
- "We need to provide a method to return an expression to compute the sum of squared errors that will be used as the objective in solving the parameter estimation problem. For this problem, the error will be computed for the mole fraction of benzene in the vapor and liquid phase between the model prediction and data. \n",
- "\n",
- "\n",
- "Inline Exercise:\n",
- "Complete the following cell by adding an expression to compute the sum of square errors. \n",
- "
"
+ "We define the `exp_list` by splitting the data into individual experiments, or data points."
]
},
{
"cell_type": "code",
- "execution_count": null,
- "metadata": {
- "tags": [
- "solution"
- ]
- },
- "outputs": [],
- "source": [
- "# Create method to return an expression that computes the sum of squared error\n",
- "def SSE(m, data):\n",
- " # Todo: Add expression for computing the sum of squared errors in mole fraction of benzene in the liquid\n",
- " # and vapor phase. For example, the squared error for the vapor phase is:\n",
- " # (float(data[\"vap_benzene\"]) - m.fs.state_block.mole_frac_phase_comp[\"Vap\", \"benzene\"])**2\n",
- " expr = (\n",
- " float(data[\"vap_benzene\"])\n",
- " - m.fs.state_block.mole_frac_phase_comp[\"Vap\", \"benzene\"]\n",
- " ) ** 2 + (\n",
- " float(data[\"liq_benzene\"])\n",
- " - m.fs.state_block.mole_frac_phase_comp[\"Liq\", \"benzene\"]\n",
- " ) ** 2\n",
- " return expr * 1e4"
- ]
- },
- {
- "cell_type": "markdown",
+ "execution_count": 11,
"metadata": {},
+ "outputs": [],
"source": [
- "\n",
- "Note:\n",
- "Notice that we have scaled the expression up by a factor of 10000 as the SSE computed here will be an extremely small number given that we are using the difference in mole fraction in our expression. This will help in using a well-scaled objective to improve solve robustness when using IPOPT. \n",
- "
\n"
+ "# Update to new interface\n",
+ "exp_list = []\n",
+ "for i in range(data.shape[0]):\n",
+ " exp_list.append(NRTLExperiment(data.iloc[i]))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
- "We are now ready to set up the parameter estimation problem. We will create a parameter estimation object called `pest`. As shown below, we pass the method that returns an initialized model, data, variable_name, and the SSE expression to the Estimator method. `tee=True` will print the solver output after solving the parameter estimation problem. "
+ "We are now ready to set up the parameter estimation problem. We will create a parameter estimation object called pest. As shown below, we pass the experiment list, and an objective function to the Estimator method. tee=True will print the solver output after solving the parameter estimation problem."
]
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 12,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Ipopt 3.13.2: \n",
+ "\n",
+ "******************************************************************************\n",
+ "This program contains Ipopt, a library for large-scale nonlinear optimization.\n",
+ " Ipopt is released as open source code under the Eclipse Public License (EPL).\n",
+ " For more information visit http://projects.coin-or.org/Ipopt\n",
+ "\n",
+ "This version of Ipopt was compiled from source code available at\n",
+ " https://github.com/IDAES/Ipopt as part of the Institute for the Design of\n",
+ " Advanced Energy Systems Process Systems Engineering Framework (IDAES PSE\n",
+ " Framework) Copyright (c) 2018-2019. See https://github.com/IDAES/idaes-pse.\n",
+ "\n",
+ "This version of Ipopt was compiled using HSL, a collection of Fortran codes\n",
+ " for large-scale scientific computation. All technical papers, sales and\n",
+ " publicity material resulting from use of the HSL codes within IPOPT must\n",
+ " contain the following acknowledgement:\n",
+ " HSL, a collection of Fortran codes for large-scale scientific\n",
+ " computation. See http://www.hsl.rl.ac.uk.\n",
+ "******************************************************************************\n",
+ "\n",
+ "This is Ipopt version 3.13.2, running with linear solver ma27.\n",
+ "\n",
+ "Number of nonzeros in equality constraint Jacobian...: 3750\n",
+ "Number of nonzeros in inequality constraint Jacobian.: 0\n",
+ "Number of nonzeros in Lagrangian Hessian.............: 2200\n",
+ "\n",
+ "Total number of variables............................: 1102\n",
+ " variables with only lower bounds: 0\n",
+ " variables with lower and upper bounds: 300\n",
+ " variables with only upper bounds: 0\n",
+ "Total number of equality constraints.................: 1100\n",
+ "Total number of inequality constraints...............: 0\n",
+ " inequality constraints with only lower bounds: 0\n",
+ " inequality constraints with lower and upper bounds: 0\n",
+ " inequality constraints with only upper bounds: 0\n",
+ "\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 0 6.0671019e-03 3.15e+00 1.97e-05 -1.0 0.00e+00 - 0.00e+00 0.00e+00 0\n",
+ " 1 8.6249856e-04 1.40e+03 2.15e-01 -1.0 1.37e+04 - 9.95e-01 1.00e+00h 1\n",
+ " 2 1.1627234e-03 9.11e+03 8.21e-01 -1.7 4.74e+02 - 8.66e-01 1.00e+00h 1\n",
+ " 3 1.0978149e-03 9.02e+03 7.99e-01 -1.7 5.89e+00 -4.0 5.44e-01 2.64e-02h 6\n",
+ " 4 8.5702670e-04 8.63e+02 3.17e-02 -1.7 6.93e-01 -2.7 1.00e+00 1.00e+00h 1\n",
+ " 5 1.3332724e-03 3.57e+03 7.92e-03 -1.7 7.75e-01 - 1.00e+00 1.00e+00h 1\n",
+ " 6 1.5692588e-03 1.64e+02 2.34e-04 -1.7 1.98e-01 - 1.00e+00 1.00e+00h 1\n",
+ " 7 1.5828905e-03 1.20e+01 1.13e-05 -1.7 4.29e-02 - 1.00e+00 1.00e+00h 1\n",
+ " 8 1.4366151e-03 9.18e-01 2.34e-04 -2.5 5.49e-02 - 1.00e+00 1.00e+00h 1\n",
+ " 9 8.9194043e-04 2.19e+01 2.00e-04 -3.8 2.51e-01 - 1.00e+00 1.00e+00h 1\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 10 5.9835646e-04 3.72e+01 2.34e-05 -3.8 3.13e-01 - 1.00e+00 1.00e+00h 1\n",
+ " 11 5.9839648e-04 1.26e+00 4.06e-08 -3.8 2.87e-02 - 1.00e+00 1.00e+00h 1\n",
+ " 12 5.9838953e-04 4.33e-05 1.60e-12 -3.8 9.40e-05 - 1.00e+00 1.00e+00h 1\n",
+ " 13 5.9077073e-04 1.21e+01 2.96e-06 -5.7 4.79e-02 - 1.00e+00 1.00e+00h 1\n",
+ " 14 5.9066394e-04 1.19e-03 4.25e-07 -5.7 5.98e-04 -3.1 1.00e+00 1.00e+00h 1\n",
+ " 15 5.9059984e-04 1.08e-02 2.96e-07 -8.6 1.25e-03 -3.6 1.00e+00 1.00e+00h 1\n",
+ " 16 5.9042438e-04 9.67e-02 2.92e-07 -8.6 3.70e-03 -4.1 1.00e+00 1.00e+00h 1\n",
+ " 17 5.8992758e-04 8.72e-01 2.91e-07 -8.6 1.11e-02 -4.6 1.00e+00 1.00e+00h 1\n",
+ " 18 5.8840706e-04 8.23e+00 3.09e-07 -8.6 3.40e-02 -5.1 1.00e+00 1.00e+00h 1\n",
+ " 19 5.8319289e-04 9.25e+01 1.97e-06 -8.6 1.15e-01 -5.5 1.00e+00 1.00e+00h 1\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 20 5.4836946e-04 3.88e+03 1.22e-04 -8.6 7.95e-01 -6.0 1.00e+00 1.00e+00h 1\n",
+ " 21 5.0847689e-04 4.45e+02 1.04e-04 -8.6 3.55e-01 -5.6 1.00e+00 1.00e+00h 1\n",
+ " 22 5.0727291e-04 4.20e+00 1.54e-05 -8.6 6.20e+02 - 1.00e+00 1.00e+00h 1\n",
+ " 23 5.0749772e-04 1.36e+00 1.44e-06 -8.6 5.13e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 24 5.0749686e-04 6.93e-06 4.21e-11 -8.6 3.55e-01 - 1.00e+00 1.00e+00h 1\n",
+ " 25 5.0749686e-04 3.36e-06 1.49e-12 -9.0 6.25e-02 - 1.00e+00 1.00e+00h 1\n",
+ " 26 5.0749686e-04 1.02e-10 2.36e-18 -9.0 5.08e-06 - 1.00e+00 1.00e+00h 1\n",
+ "\n",
+ "Number of Iterations....: 26\n",
+ "\n",
+ " (scaled) (unscaled)\n",
+ "Objective...............: 5.0749685787934424e-04 5.0749685787934424e-04\n",
+ "Dual infeasibility......: 2.3583858113882067e-18 2.3583858113882067e-18\n",
+ "Constraint violation....: 3.5405706676501683e-13 1.0186340659856796e-10\n",
+ "Complementarity.........: 9.0909090909091344e-10 9.0909090909091344e-10\n",
+ "Overall NLP error.......: 9.0909090909091344e-10 9.0909090909091344e-10\n",
+ "\n",
+ "\n",
+ "Number of objective function evaluations = 33\n",
+ "Number of objective gradient evaluations = 27\n",
+ "Number of equality constraint evaluations = 34\n",
+ "Number of inequality constraint evaluations = 0\n",
+ "Number of equality constraint Jacobian evaluations = 27\n",
+ "Number of inequality constraint Jacobian evaluations = 0\n",
+ "Number of Lagrangian Hessian evaluations = 26\n",
+ "Total CPU secs in IPOPT (w/o function evaluations) = 0.035\n",
+ "Total CPU secs in NLP function evaluations = 0.009\n",
+ "\n",
+ "EXIT: Optimal Solution Found.\n"
+ ]
+ }
+ ],
"source": [
"import logging\n",
"\n",
"idaeslog.getIdaesLogger(\"core.property_meta\").setLevel(logging.ERROR)\n",
- "# Initialize a parameter estimation object\n",
- "pest = parmest.Estimator(NRTL_model, data, variable_name, SSE, tee=True)\n",
"\n",
- "# Run parameter estimation using all data\n",
+ "pest = parmest.Estimator(exp_list, obj_function=\"SSE\", tee=True)\n",
"obj_value, parameters = pest.theta_est()"
]
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 13,
"metadata": {
"tags": [
"testing"
@@ -398,7 +921,7 @@
"outputs": [],
"source": [
"# Check for values of the parameter estimation problem\n",
- "assert obj_value == pytest.approx(5.07496, 1e-3)\n",
+ "assert obj_value == pytest.approx(5.07496e-4, 1e-3)\n",
"assert parameters[\"fs.properties.tau[benzene,toluene]\"] == pytest.approx(-0.89876, 1e-3)\n",
"assert parameters[\"fs.properties.tau[toluene,benzene]\"] == pytest.approx(1.41048, 1e-3)"
]
@@ -412,11 +935,23 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 14,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "The SSE at the optimal solution is 0.000507\n",
+ "\n",
+ "The values for the parameters are as follows:\n",
+ "fs.properties.tau[benzene,toluene] = -0.8987550041842163\n",
+ "fs.properties.tau[toluene,benzene] = 1.4104702103547941\n"
+ ]
+ }
+ ],
"source": [
- "print(\"The SSE at the optimal solution is %0.6f\" % (obj_value * 1e-4))\n",
+ "print(\"The SSE at the optimal solution is %0.6f\" % (obj_value))\n",
"print()\n",
"print(\"The values for the parameters are as follows:\")\n",
"for k, v in parameters.items():\n",
@@ -449,15 +984,12 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 15,
"metadata": {},
"outputs": [],
"source": [
- "# Run parameter estimation using bootstrap resample of the data (10 samples),\n",
- "# plot results along with confidence regions\n",
- "\n",
- "# Uncomment the following code:\n",
- "# bootstrap_theta = pest.theta_est_bootstrap(4)\n",
+ "# Uncomment the following lines\n",
+ "# bootstrap_theta = pest.theta_est_bootstrap(4, seed=542)\n",
"# display(bootstrap_theta)"
]
}
@@ -465,7 +997,7 @@
"metadata": {
"celltoolbar": "Tags",
"kernelspec": {
- "display_name": "Python 3 (ipykernel)",
+ "display_name": "idaes-examples-dev-py313-macmini",
"language": "python",
"name": "python3"
},
@@ -479,7 +1011,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.10.9"
+ "version": "3.13.13"
}
},
"nbformat": 4,
diff --git a/idaes_examples/notebooks/docs/param_est/parameter_estimation_nrtl_using_state_block_usr.ipynb b/idaes_examples/notebooks/docs/param_est/parameter_estimation_nrtl_using_state_block_usr.ipynb
index 5bdce840..1d5d1b1e 100644
--- a/idaes_examples/notebooks/docs/param_est/parameter_estimation_nrtl_using_state_block_usr.ipynb
+++ b/idaes_examples/notebooks/docs/param_est/parameter_estimation_nrtl_using_state_block_usr.ipynb
@@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
- "execution_count": 10,
+ "execution_count": 1,
"metadata": {
"tags": [
"header",
@@ -16,7 +16,7 @@
"# Framework (IDAES IP) was produced under the DOE Institute for the\n",
"# Design of Advanced Energy Systems (IDAES).\n",
"#\n",
- "# Copyright (c) 2018-2023 by the software owners: The Regents of the\n",
+ "# Copyright (c) 2018-2026 by the software owners: The Regents of the\n",
"# University of California, through Lawrence Berkeley National Laboratory,\n",
"# National Technology & Engineering Solutions of Sandia, LLC, Carnegie Mellon\n",
"# University, West Virginia University Research Corporation, et al.\n",
@@ -32,8 +32,8 @@
"# Parameter Estimation Using the NRTL State Block\n",
"\n",
"Author: Jaffer Ghouse \n",
- "Maintainer: Andrew Lee \n",
- "Updated: 2023-06-01 \n",
+ "Maintainer: Stephen Cini \n",
+ "Updated: 2026-06-11 \n",
"\n",
"In this module, we use Pyomo's `parmest` tool in conjunction with IDAES models for parameter estimation. We demonstrate these tools by estimating the parameters associated with the NRTL property model for a benzene-toluene mixture. The NRTL model has 2 sets of parameters: the non-randomness parameter (`alpha_ij`) and the binary interaction parameter (`tau_ij`), where `i` and `j` are the pure component species. In this example, we only estimate the binary interaction parameter (`tau_ij`) for a given dataset. When estimating parameters associated with the property package, IDAES provides the flexibility of doing the parameter estimation by just using the state block or by using a unit model with a specified property package. This module will demonstrate parameter estimation by using only the state block. \n",
"\n",
@@ -45,8 +45,7 @@
"\n",
"## Key links to documentation:\n",
"* NRTL Model - https://idaes-pse.readthedocs.io/en/stable/reference_guides/model_libraries/generic/property_models/activity_coefficient.html\n",
- "* parmest - https://pyomo.readthedocs.io/en/stable/contributed_packages/parmest/index.html\n",
- ""
+ "* parmest - https://pyomo.readthedocs.io/en/stable/explanation/analysis/parmest/index.html\n"
]
},
{
@@ -55,13 +54,13 @@
"source": [
"\n",
"Inline Exercise:\n",
- "import `ConcreteModel` from Pyomo and `FlowsheetBlock` from IDAES. \n",
+ "import `ConcreteModel`, `value`, and `Suffix` from Pyomo, and `FlowsheetBlock`from IDAES. \n",
"
"
]
},
{
"cell_type": "code",
- "execution_count": 11,
+ "execution_count": 2,
"metadata": {
"tags": [
"exercise"
@@ -69,14 +68,14 @@
},
"outputs": [],
"source": [
- "# Todo: import ConcreteModel from pyomo.environ\n",
+ "# Todo: import ConcreteModel, value, and Suffix from pyomo.environ\n",
"\n",
"# Todo: import FlowsheetBlock from idaes.core"
]
},
{
"cell_type": "code",
- "execution_count": 12,
+ "execution_count": 3,
"metadata": {
"tags": [
"solution"
@@ -84,8 +83,8 @@
},
"outputs": [],
"source": [
- "# Todo: import ConcreteModel from pyomo.environ\n",
- "from pyomo.environ import ConcreteModel, value\n",
+ "# Todo: import ConcreteModel, value, and Suffix from pyomo.environ\n",
+ "from pyomo.environ import ConcreteModel, value, Suffix\n",
"\n",
"# Todo: import FlowsheetBlock from idaes.core\n",
"from idaes.core import FlowsheetBlock"
@@ -100,7 +99,7 @@
},
{
"cell_type": "code",
- "execution_count": 13,
+ "execution_count": 4,
"metadata": {
"tags": []
},
@@ -121,7 +120,7 @@
},
{
"cell_type": "code",
- "execution_count": 14,
+ "execution_count": 5,
"metadata": {
"tags": []
},
@@ -152,7 +151,7 @@
},
{
"cell_type": "code",
- "execution_count": 15,
+ "execution_count": 6,
"metadata": {
"tags": [
"exercise"
@@ -198,7 +197,12 @@
" m.fs.state_block.initialize(outlvl=idaeslog.INFO)\n",
"\n",
" # Fix at actual temperature\n",
- " m.fs.state_block.temperature.fix(float(data[\"temperature\"]))\n",
+ " if isinstance(data, dict) or isinstance(data, pd.Series):\n",
+ " m.fs.state_block.temperature.fix(float(data[\"temperature\"]))\n",
+ " elif isinstance(data, pd.DataFrame):\n",
+ " m.fs.state_block.temperature.fix(float(data.iloc[0][\"temperature\"]))\n",
+ " else:\n",
+ " raise ValueError(\"Unrecognized data type.\")\n",
"\n",
" # Set bounds on variables to be estimated\n",
" m.fs.properties.tau[\"benzene\", \"toluene\"].setlb(-5)\n",
@@ -213,7 +217,7 @@
},
{
"cell_type": "code",
- "execution_count": 16,
+ "execution_count": 7,
"metadata": {
"tags": [
"solution"
@@ -264,7 +268,12 @@
" m.fs.state_block.initialize(outlvl=idaeslog.INFO_LOW)\n",
"\n",
" # Fix at actual temperature\n",
- " m.fs.state_block.temperature.fix(float(data[\"temperature\"]))\n",
+ " if isinstance(data, dict) or isinstance(data, pd.Series):\n",
+ " m.fs.state_block.temperature.fix(float(data[\"temperature\"]))\n",
+ " elif isinstance(data, pd.DataFrame):\n",
+ " m.fs.state_block.temperature.fix(float(data.iloc[0][\"temperature\"]))\n",
+ " else:\n",
+ " raise ValueError(\"Unrecognized data type.\")\n",
"\n",
" # Set bounds on variables to be estimated\n",
" m.fs.properties.tau[\"benzene\", \"toluene\"].setlb(-5)\n",
@@ -290,54 +299,106 @@
"source": [
"In addition to providing a method to return an initialized model, the `parmest` tool needs the following:\n",
"\n",
- "* List of variable names to be estimated\n",
- "* Dataset\n",
- "* Expression to compute the sum of squared errors\n"
+ "* Experiment class to set up and label model with suffixes\n",
+ "* Dataset with multiple scenarios - organized into an experiment list\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
+ "Here we build an experiment class to label our model problem for parameter estimation. The labels are defined as a `Suffix`, and the main labels for our model are `experiment_outputs`, `unknown_parameters`, and `measurement_error`.\n",
+ "\n",
+ "For this problem, the error will be computed for the mole fraction of benzene in the vapor and liquid phase between the model prediction and data. The `experimental_outputs` will therefore be the mole fraction of benzene in the two phases.\n",
+ "\n",
"In this example, we only estimate the binary interaction parameter (`tau_ij`). Given that this variable is usually indexed as `tau_ij = Var(component_list, component_list)`, there are 2*2=4 degrees of freedom. However, when i=j, the binary interaction parameter is 0. Therefore, in this problem, we estimate the binary interaction parameter for the following variables only:\n",
"\n",
"* fs.properties.tau['benzene', 'toluene']\n",
"* fs.properties.tau['toluene', 'benzene']\n",
"\n",
- "\n",
- "Inline Exercise:\n",
- "Create a list called `variable_name` with the above-mentioned variables declared as strings.\n",
- "
"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 18,
- "metadata": {
- "tags": [
- "exercise"
- ]
- },
- "outputs": [],
- "source": [
- "# Todo: Create a list of vars to estimate"
+ "As shown below, these model components are used as our `unknown_parameters`.\n",
+ "\n",
+ "We define `measurement_error` as none so parmest calculates the value internally based on the experimental outputs. Refer to https://pyomo.readthedocs.io/en/stable/explanation/analysis/parmest/driver.html for more information. "
]
},
{
"cell_type": "code",
- "execution_count": 19,
- "metadata": {
- "tags": [
- "solution"
- ]
- },
+ "execution_count": 9,
+ "metadata": {},
"outputs": [],
"source": [
- "# Todo: Create a list of vars to estimate\n",
- "variable_name = [\n",
- " \"fs.properties.tau['benzene', 'toluene']\",\n",
- " \"fs.properties.tau['toluene', 'benzene']\",\n",
- "]"
+ "# Build an experiment class to take advantage of new parmest interface\n",
+ "from pyomo.contrib.parmest.experiment import Experiment\n",
+ "\n",
+ "\n",
+ "class NRTLExperiment(Experiment):\n",
+ " \"\"\"Experiment class for parameter estimation of NRTL model using parmest\"\"\"\n",
+ "\n",
+ " def __init__(self, data, meas_error=None):\n",
+ " \"\"\"Initialize the NRTLExperiment class\n",
+ "\n",
+ " Args:\n",
+ " data: DataFrame containing the experimental data\n",
+ " meas_error: Measurement error for the data (optional)\n",
+ " \"\"\"\n",
+ " self.model = None\n",
+ " self.data = data\n",
+ " self.meas_error = meas_error\n",
+ "\n",
+ " def create_model(self):\n",
+ " \"\"\"Create the Pyomo model for the NRTL parameter estimation problem\"\"\"\n",
+ " self.model = NRTL_model(self.data)\n",
+ "\n",
+ " def label_model(self):\n",
+ " from pyomo.environ import Set, Expression\n",
+ "\n",
+ " m = self.model\n",
+ "\n",
+ " # Parmest expects the first index of experiment outputs to be the data point\n",
+ " # This is a workaround that will be addressed and corrected in a future release.\n",
+ "\n",
+ " m.data_point = Set(initialize=[0])\n",
+ "\n",
+ " # Wrap IDAES variables in Expressions indexed by data point\n",
+ " m.liq_benzene_out = Expression(\n",
+ " m.data_point,\n",
+ " rule=lambda m, i: m.fs.state_block.mole_frac_phase_comp[\"Liq\", \"benzene\"],\n",
+ " )\n",
+ "\n",
+ " m.vap_benzene_out = Expression(\n",
+ " m.data_point,\n",
+ " rule=lambda m, i: m.fs.state_block.mole_frac_phase_comp[\"Vap\", \"benzene\"],\n",
+ " )\n",
+ "\n",
+ " m.experiment_outputs = Suffix(direction=Suffix.LOCAL)\n",
+ "\n",
+ " m.experiment_outputs[m.liq_benzene_out[0]] = float(self.data[\"liq_benzene\"])\n",
+ " m.experiment_outputs[m.vap_benzene_out[0]] = float(self.data[\"vap_benzene\"])\n",
+ "\n",
+ " m.measurement_error = Suffix(direction=Suffix.LOCAL)\n",
+ " m.measurement_error.update(\n",
+ " [\n",
+ " (m.liq_benzene_out[0], self.meas_error),\n",
+ " (m.vap_benzene_out[0], self.meas_error),\n",
+ " ]\n",
+ " )\n",
+ "\n",
+ " # Add unknown parameters to the model for easier access\n",
+ " m.unknown_parameters = Suffix(direction=Suffix.LOCAL)\n",
+ " m.unknown_parameters.update(\n",
+ " (k, value(k))\n",
+ " for k in [\n",
+ " m.fs.properties.tau[\"benzene\", \"toluene\"],\n",
+ " m.fs.properties.tau[\"toluene\", \"benzene\"],\n",
+ " ]\n",
+ " )\n",
+ "\n",
+ " def get_labeled_model(self):\n",
+ " \"\"\"Return the labeled model\"\"\"\n",
+ " if self.model is None:\n",
+ " self.create_model()\n",
+ " self.label_model()\n",
+ " return self.model"
]
},
{
@@ -356,11 +417,400 @@
},
{
"cell_type": "code",
- "execution_count": 20,
+ "execution_count": 10,
"metadata": {
"tags": []
},
- "outputs": [],
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " temperature | \n",
+ " liq_benzene | \n",
+ " vap_benzene | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 0 | \n",
+ " 365.500000 | \n",
+ " 0.480953 | \n",
+ " 0.692110 | \n",
+ "
\n",
+ " \n",
+ " | 1 | \n",
+ " 365.617647 | \n",
+ " 0.462444 | \n",
+ " 0.667699 | \n",
+ "
\n",
+ " \n",
+ " | 2 | \n",
+ " 365.735294 | \n",
+ " 0.477984 | \n",
+ " 0.692441 | \n",
+ "
\n",
+ " \n",
+ " | 3 | \n",
+ " 365.852941 | \n",
+ " 0.440547 | \n",
+ " 0.640336 | \n",
+ "
\n",
+ " \n",
+ " | 4 | \n",
+ " 365.970588 | \n",
+ " 0.427421 | \n",
+ " 0.623328 | \n",
+ "
\n",
+ " \n",
+ " | 5 | \n",
+ " 366.088235 | \n",
+ " 0.442725 | \n",
+ " 0.647796 | \n",
+ "
\n",
+ " \n",
+ " | 6 | \n",
+ " 366.205882 | \n",
+ " 0.434374 | \n",
+ " 0.637691 | \n",
+ "
\n",
+ " \n",
+ " | 7 | \n",
+ " 366.323529 | \n",
+ " 0.444642 | \n",
+ " 0.654933 | \n",
+ "
\n",
+ " \n",
+ " | 8 | \n",
+ " 366.441176 | \n",
+ " 0.427132 | \n",
+ " 0.631229 | \n",
+ "
\n",
+ " \n",
+ " | 9 | \n",
+ " 366.558824 | \n",
+ " 0.446301 | \n",
+ " 0.661743 | \n",
+ "
\n",
+ " \n",
+ " | 10 | \n",
+ " 366.676471 | \n",
+ " 0.438004 | \n",
+ " 0.651591 | \n",
+ "
\n",
+ " \n",
+ " | 11 | \n",
+ " 366.794118 | \n",
+ " 0.425320 | \n",
+ " 0.634814 | \n",
+ "
\n",
+ " \n",
+ " | 12 | \n",
+ " 366.911765 | \n",
+ " 0.439435 | \n",
+ " 0.658047 | \n",
+ "
\n",
+ " \n",
+ " | 13 | \n",
+ " 367.029412 | \n",
+ " 0.435655 | \n",
+ " 0.654539 | \n",
+ "
\n",
+ " \n",
+ " | 14 | \n",
+ " 367.147059 | \n",
+ " 0.401350 | \n",
+ " 0.604987 | \n",
+ "
\n",
+ " \n",
+ " | 15 | \n",
+ " 367.264706 | \n",
+ " 0.397862 | \n",
+ " 0.601703 | \n",
+ "
\n",
+ " \n",
+ " | 16 | \n",
+ " 367.382353 | \n",
+ " 0.415821 | \n",
+ " 0.630930 | \n",
+ "
\n",
+ " \n",
+ " | 17 | \n",
+ " 367.500000 | \n",
+ " 0.420667 | \n",
+ " 0.640380 | \n",
+ "
\n",
+ " \n",
+ " | 18 | \n",
+ " 367.617647 | \n",
+ " 0.391683 | \n",
+ " 0.598214 | \n",
+ "
\n",
+ " \n",
+ " | 19 | \n",
+ " 367.735294 | \n",
+ " 0.404903 | \n",
+ " 0.620432 | \n",
+ "
\n",
+ " \n",
+ " | 20 | \n",
+ " 367.852941 | \n",
+ " 0.409563 | \n",
+ " 0.629626 | \n",
+ "
\n",
+ " \n",
+ " | 21 | \n",
+ " 367.970588 | \n",
+ " 0.389488 | \n",
+ " 0.600722 | \n",
+ "
\n",
+ " \n",
+ " | 22 | \n",
+ " 368.000000 | \n",
+ " 0.396789 | \n",
+ " 0.612483 | \n",
+ "
\n",
+ " \n",
+ " | 23 | \n",
+ " 368.088235 | \n",
+ " 0.398162 | \n",
+ " 0.616106 | \n",
+ "
\n",
+ " \n",
+ " | 24 | \n",
+ " 368.205882 | \n",
+ " 0.362340 | \n",
+ " 0.562505 | \n",
+ "
\n",
+ " \n",
+ " | 25 | \n",
+ " 368.323529 | \n",
+ " 0.386958 | \n",
+ " 0.602680 | \n",
+ "
\n",
+ " \n",
+ " | 26 | \n",
+ " 368.441176 | \n",
+ " 0.363643 | \n",
+ " 0.568210 | \n",
+ "
\n",
+ " \n",
+ " | 27 | \n",
+ " 368.558824 | \n",
+ " 0.368118 | \n",
+ " 0.577072 | \n",
+ "
\n",
+ " \n",
+ " | 28 | \n",
+ " 368.676471 | \n",
+ " 0.384098 | \n",
+ " 0.604078 | \n",
+ "
\n",
+ " \n",
+ " | 29 | \n",
+ " 368.794118 | \n",
+ " 0.353605 | \n",
+ " 0.557925 | \n",
+ "
\n",
+ " \n",
+ " | 30 | \n",
+ " 368.911765 | \n",
+ " 0.346474 | \n",
+ " 0.548445 | \n",
+ "
\n",
+ " \n",
+ " | 31 | \n",
+ " 369.029412 | \n",
+ " 0.350741 | \n",
+ " 0.556996 | \n",
+ "
\n",
+ " \n",
+ " | 32 | \n",
+ " 369.147059 | \n",
+ " 0.362347 | \n",
+ " 0.577286 | \n",
+ "
\n",
+ " \n",
+ " | 33 | \n",
+ " 369.264706 | \n",
+ " 0.362578 | \n",
+ " 0.579519 | \n",
+ "
\n",
+ " \n",
+ " | 34 | \n",
+ " 369.382353 | \n",
+ " 0.340765 | \n",
+ " 0.546411 | \n",
+ "
\n",
+ " \n",
+ " | 35 | \n",
+ " 369.500000 | \n",
+ " 0.337462 | \n",
+ " 0.542857 | \n",
+ "
\n",
+ " \n",
+ " | 36 | \n",
+ " 369.617647 | \n",
+ " 0.355729 | \n",
+ " 0.574083 | \n",
+ "
\n",
+ " \n",
+ " | 37 | \n",
+ " 369.735294 | \n",
+ " 0.348679 | \n",
+ " 0.564513 | \n",
+ "
\n",
+ " \n",
+ " | 38 | \n",
+ " 369.852941 | \n",
+ " 0.338187 | \n",
+ " 0.549284 | \n",
+ "
\n",
+ " \n",
+ " | 39 | \n",
+ " 369.970588 | \n",
+ " 0.324360 | \n",
+ " 0.528514 | \n",
+ "
\n",
+ " \n",
+ " | 40 | \n",
+ " 370.088235 | \n",
+ " 0.310753 | \n",
+ " 0.507964 | \n",
+ "
\n",
+ " \n",
+ " | 41 | \n",
+ " 370.205882 | \n",
+ " 0.311037 | \n",
+ " 0.510055 | \n",
+ "
\n",
+ " \n",
+ " | 42 | \n",
+ " 370.323529 | \n",
+ " 0.311263 | \n",
+ " 0.512055 | \n",
+ "
\n",
+ " \n",
+ " | 43 | \n",
+ " 370.441176 | \n",
+ " 0.308081 | \n",
+ " 0.508437 | \n",
+ "
\n",
+ " \n",
+ " | 44 | \n",
+ " 370.558824 | \n",
+ " 0.308224 | \n",
+ " 0.510293 | \n",
+ "
\n",
+ " \n",
+ " | 45 | \n",
+ " 370.676471 | \n",
+ " 0.318148 | \n",
+ " 0.528399 | \n",
+ "
\n",
+ " \n",
+ " | 46 | \n",
+ " 370.794118 | \n",
+ " 0.308334 | \n",
+ " 0.513728 | \n",
+ "
\n",
+ " \n",
+ " | 47 | \n",
+ " 370.911765 | \n",
+ " 0.317937 | \n",
+ " 0.531410 | \n",
+ "
\n",
+ " \n",
+ " | 48 | \n",
+ " 371.029412 | \n",
+ " 0.289149 | \n",
+ " 0.484824 | \n",
+ "
\n",
+ " \n",
+ " | 49 | \n",
+ " 371.147059 | \n",
+ " 0.298637 | \n",
+ " 0.502318 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " temperature liq_benzene vap_benzene\n",
+ "0 365.500000 0.480953 0.692110\n",
+ "1 365.617647 0.462444 0.667699\n",
+ "2 365.735294 0.477984 0.692441\n",
+ "3 365.852941 0.440547 0.640336\n",
+ "4 365.970588 0.427421 0.623328\n",
+ "5 366.088235 0.442725 0.647796\n",
+ "6 366.205882 0.434374 0.637691\n",
+ "7 366.323529 0.444642 0.654933\n",
+ "8 366.441176 0.427132 0.631229\n",
+ "9 366.558824 0.446301 0.661743\n",
+ "10 366.676471 0.438004 0.651591\n",
+ "11 366.794118 0.425320 0.634814\n",
+ "12 366.911765 0.439435 0.658047\n",
+ "13 367.029412 0.435655 0.654539\n",
+ "14 367.147059 0.401350 0.604987\n",
+ "15 367.264706 0.397862 0.601703\n",
+ "16 367.382353 0.415821 0.630930\n",
+ "17 367.500000 0.420667 0.640380\n",
+ "18 367.617647 0.391683 0.598214\n",
+ "19 367.735294 0.404903 0.620432\n",
+ "20 367.852941 0.409563 0.629626\n",
+ "21 367.970588 0.389488 0.600722\n",
+ "22 368.000000 0.396789 0.612483\n",
+ "23 368.088235 0.398162 0.616106\n",
+ "24 368.205882 0.362340 0.562505\n",
+ "25 368.323529 0.386958 0.602680\n",
+ "26 368.441176 0.363643 0.568210\n",
+ "27 368.558824 0.368118 0.577072\n",
+ "28 368.676471 0.384098 0.604078\n",
+ "29 368.794118 0.353605 0.557925\n",
+ "30 368.911765 0.346474 0.548445\n",
+ "31 369.029412 0.350741 0.556996\n",
+ "32 369.147059 0.362347 0.577286\n",
+ "33 369.264706 0.362578 0.579519\n",
+ "34 369.382353 0.340765 0.546411\n",
+ "35 369.500000 0.337462 0.542857\n",
+ "36 369.617647 0.355729 0.574083\n",
+ "37 369.735294 0.348679 0.564513\n",
+ "38 369.852941 0.338187 0.549284\n",
+ "39 369.970588 0.324360 0.528514\n",
+ "40 370.088235 0.310753 0.507964\n",
+ "41 370.205882 0.311037 0.510055\n",
+ "42 370.323529 0.311263 0.512055\n",
+ "43 370.441176 0.308081 0.508437\n",
+ "44 370.558824 0.308224 0.510293\n",
+ "45 370.676471 0.318148 0.528399\n",
+ "46 370.794118 0.308334 0.513728\n",
+ "47 370.911765 0.317937 0.531410\n",
+ "48 371.029412 0.289149 0.484824\n",
+ "49 371.147059 0.298637 0.502318"
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ }
+ ],
"source": [
"# Load data from csv\n",
"data = pd.read_csv(\"BT_NRTL_dataset.csv\")\n",
@@ -373,88 +823,134 @@
"cell_type": "markdown",
"metadata": {},
"source": [
- "We need to provide a method to return an expression to compute the sum of squared errors that will be used as the objective in solving the parameter estimation problem. For this problem, the error will be computed for the mole fraction of benzene in the vapor and liquid phase between the model prediction and data. \n",
- "\n",
- "\n",
- "Inline Exercise:\n",
- "Complete the following cell by adding an expression to compute the sum of square errors. \n",
- "
"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {
- "tags": [
- "exercise"
- ]
- },
- "outputs": [],
- "source": [
- "# Create method to return an expression that computes the sum of squared error\n",
- "def SSE(m, data):\n",
- " # Todo: Add expression for computing the sum of squared errors in mole fraction of benzene in the liquid\n",
- " # and vapor phase. For example, the squared error for the vapor phase is:\n",
- " # (float(data[\"vap_benzene\"]) - m.fs.state_block.mole_frac_phase_comp[\"Vap\", \"benzene\"])**2\n",
- "\n",
- " return expr * 1e4"
+ "We define the `exp_list` by splitting the data into individual experiments, or data points."
]
},
{
"cell_type": "code",
- "execution_count": null,
- "metadata": {
- "tags": [
- "solution"
- ]
- },
- "outputs": [],
- "source": [
- "# Create method to return an expression that computes the sum of squared error\n",
- "def SSE(m, data):\n",
- " # Todo: Add expression for computing the sum of squared errors in mole fraction of benzene in the liquid\n",
- " # and vapor phase. For example, the squared error for the vapor phase is:\n",
- " # (float(data[\"vap_benzene\"]) - m.fs.state_block.mole_frac_phase_comp[\"Vap\", \"benzene\"])**2\n",
- " expr = (\n",
- " float(data[\"vap_benzene\"])\n",
- " - m.fs.state_block.mole_frac_phase_comp[\"Vap\", \"benzene\"]\n",
- " ) ** 2 + (\n",
- " float(data[\"liq_benzene\"])\n",
- " - m.fs.state_block.mole_frac_phase_comp[\"Liq\", \"benzene\"]\n",
- " ) ** 2\n",
- " return expr * 1e4"
- ]
- },
- {
- "cell_type": "markdown",
+ "execution_count": 11,
"metadata": {},
+ "outputs": [],
"source": [
- "\n",
- "Note:\n",
- "Notice that we have scaled the expression up by a factor of 10000 as the SSE computed here will be an extremely small number given that we are using the difference in mole fraction in our expression. This will help in using a well-scaled objective to improve solve robustness when using IPOPT. \n",
- "
\n"
+ "# Update to new interface\n",
+ "exp_list = []\n",
+ "for i in range(data.shape[0]):\n",
+ " exp_list.append(NRTLExperiment(data.iloc[i]))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
- "We are now ready to set up the parameter estimation problem. We will create a parameter estimation object called `pest`. As shown below, we pass the method that returns an initialized model, data, variable_name, and the SSE expression to the Estimator method. `tee=True` will print the solver output after solving the parameter estimation problem. "
+ "We are now ready to set up the parameter estimation problem. We will create a parameter estimation object called pest. As shown below, we pass the experiment list, and an objective function to the Estimator method. tee=True will print the solver output after solving the parameter estimation problem."
]
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 12,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Ipopt 3.13.2: \n",
+ "\n",
+ "******************************************************************************\n",
+ "This program contains Ipopt, a library for large-scale nonlinear optimization.\n",
+ " Ipopt is released as open source code under the Eclipse Public License (EPL).\n",
+ " For more information visit http://projects.coin-or.org/Ipopt\n",
+ "\n",
+ "This version of Ipopt was compiled from source code available at\n",
+ " https://github.com/IDAES/Ipopt as part of the Institute for the Design of\n",
+ " Advanced Energy Systems Process Systems Engineering Framework (IDAES PSE\n",
+ " Framework) Copyright (c) 2018-2019. See https://github.com/IDAES/idaes-pse.\n",
+ "\n",
+ "This version of Ipopt was compiled using HSL, a collection of Fortran codes\n",
+ " for large-scale scientific computation. All technical papers, sales and\n",
+ " publicity material resulting from use of the HSL codes within IPOPT must\n",
+ " contain the following acknowledgement:\n",
+ " HSL, a collection of Fortran codes for large-scale scientific\n",
+ " computation. See http://www.hsl.rl.ac.uk.\n",
+ "******************************************************************************\n",
+ "\n",
+ "This is Ipopt version 3.13.2, running with linear solver ma27.\n",
+ "\n",
+ "Number of nonzeros in equality constraint Jacobian...: 3750\n",
+ "Number of nonzeros in inequality constraint Jacobian.: 0\n",
+ "Number of nonzeros in Lagrangian Hessian.............: 2200\n",
+ "\n",
+ "Total number of variables............................: 1102\n",
+ " variables with only lower bounds: 0\n",
+ " variables with lower and upper bounds: 300\n",
+ " variables with only upper bounds: 0\n",
+ "Total number of equality constraints.................: 1100\n",
+ "Total number of inequality constraints...............: 0\n",
+ " inequality constraints with only lower bounds: 0\n",
+ " inequality constraints with lower and upper bounds: 0\n",
+ " inequality constraints with only upper bounds: 0\n",
+ "\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 0 6.0671019e-03 3.15e+00 1.97e-05 -1.0 0.00e+00 - 0.00e+00 0.00e+00 0\n",
+ " 1 8.6249856e-04 1.40e+03 2.15e-01 -1.0 1.37e+04 - 9.95e-01 1.00e+00h 1\n",
+ " 2 1.1627234e-03 9.11e+03 8.21e-01 -1.7 4.74e+02 - 8.66e-01 1.00e+00h 1\n",
+ " 3 1.0978149e-03 9.02e+03 7.99e-01 -1.7 5.89e+00 -4.0 5.44e-01 2.64e-02h 6\n",
+ " 4 8.5702670e-04 8.63e+02 3.17e-02 -1.7 6.93e-01 -2.7 1.00e+00 1.00e+00h 1\n",
+ " 5 1.3332724e-03 3.57e+03 7.92e-03 -1.7 7.75e-01 - 1.00e+00 1.00e+00h 1\n",
+ " 6 1.5692588e-03 1.64e+02 2.34e-04 -1.7 1.98e-01 - 1.00e+00 1.00e+00h 1\n",
+ " 7 1.5828905e-03 1.20e+01 1.13e-05 -1.7 4.29e-02 - 1.00e+00 1.00e+00h 1\n",
+ " 8 1.4366151e-03 9.18e-01 2.34e-04 -2.5 5.49e-02 - 1.00e+00 1.00e+00h 1\n",
+ " 9 8.9194043e-04 2.19e+01 2.00e-04 -3.8 2.51e-01 - 1.00e+00 1.00e+00h 1\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 10 5.9835646e-04 3.72e+01 2.34e-05 -3.8 3.13e-01 - 1.00e+00 1.00e+00h 1\n",
+ " 11 5.9839648e-04 1.26e+00 4.06e-08 -3.8 2.87e-02 - 1.00e+00 1.00e+00h 1\n",
+ " 12 5.9838953e-04 4.33e-05 1.60e-12 -3.8 9.40e-05 - 1.00e+00 1.00e+00h 1\n",
+ " 13 5.9077073e-04 1.21e+01 2.96e-06 -5.7 4.79e-02 - 1.00e+00 1.00e+00h 1\n",
+ " 14 5.9066394e-04 1.19e-03 4.25e-07 -5.7 5.98e-04 -3.1 1.00e+00 1.00e+00h 1\n",
+ " 15 5.9059984e-04 1.08e-02 2.96e-07 -8.6 1.25e-03 -3.6 1.00e+00 1.00e+00h 1\n",
+ " 16 5.9042438e-04 9.67e-02 2.92e-07 -8.6 3.70e-03 -4.1 1.00e+00 1.00e+00h 1\n",
+ " 17 5.8992758e-04 8.72e-01 2.91e-07 -8.6 1.11e-02 -4.6 1.00e+00 1.00e+00h 1\n",
+ " 18 5.8840706e-04 8.23e+00 3.09e-07 -8.6 3.40e-02 -5.1 1.00e+00 1.00e+00h 1\n",
+ " 19 5.8319289e-04 9.25e+01 1.97e-06 -8.6 1.15e-01 -5.5 1.00e+00 1.00e+00h 1\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 20 5.4836946e-04 3.88e+03 1.22e-04 -8.6 7.95e-01 -6.0 1.00e+00 1.00e+00h 1\n",
+ " 21 5.0847689e-04 4.45e+02 1.04e-04 -8.6 3.55e-01 -5.6 1.00e+00 1.00e+00h 1\n",
+ " 22 5.0727291e-04 4.20e+00 1.54e-05 -8.6 6.20e+02 - 1.00e+00 1.00e+00h 1\n",
+ " 23 5.0749772e-04 1.36e+00 1.44e-06 -8.6 5.13e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 24 5.0749686e-04 6.93e-06 4.21e-11 -8.6 3.55e-01 - 1.00e+00 1.00e+00h 1\n",
+ " 25 5.0749686e-04 3.36e-06 1.49e-12 -9.0 6.25e-02 - 1.00e+00 1.00e+00h 1\n",
+ " 26 5.0749686e-04 1.02e-10 2.36e-18 -9.0 5.08e-06 - 1.00e+00 1.00e+00h 1\n",
+ "\n",
+ "Number of Iterations....: 26\n",
+ "\n",
+ " (scaled) (unscaled)\n",
+ "Objective...............: 5.0749685787934424e-04 5.0749685787934424e-04\n",
+ "Dual infeasibility......: 2.3583858113882067e-18 2.3583858113882067e-18\n",
+ "Constraint violation....: 3.5405706676501683e-13 1.0186340659856796e-10\n",
+ "Complementarity.........: 9.0909090909091344e-10 9.0909090909091344e-10\n",
+ "Overall NLP error.......: 9.0909090909091344e-10 9.0909090909091344e-10\n",
+ "\n",
+ "\n",
+ "Number of objective function evaluations = 33\n",
+ "Number of objective gradient evaluations = 27\n",
+ "Number of equality constraint evaluations = 34\n",
+ "Number of inequality constraint evaluations = 0\n",
+ "Number of equality constraint Jacobian evaluations = 27\n",
+ "Number of inequality constraint Jacobian evaluations = 0\n",
+ "Number of Lagrangian Hessian evaluations = 26\n",
+ "Total CPU secs in IPOPT (w/o function evaluations) = 0.035\n",
+ "Total CPU secs in NLP function evaluations = 0.009\n",
+ "\n",
+ "EXIT: Optimal Solution Found.\n"
+ ]
+ }
+ ],
"source": [
"import logging\n",
"\n",
"idaeslog.getIdaesLogger(\"core.property_meta\").setLevel(logging.ERROR)\n",
- "# Initialize a parameter estimation object\n",
- "pest = parmest.Estimator(NRTL_model, data, variable_name, SSE, tee=True)\n",
"\n",
- "# Run parameter estimation using all data\n",
+ "pest = parmest.Estimator(exp_list, obj_function=\"SSE\", tee=True)\n",
"obj_value, parameters = pest.theta_est()"
]
},
@@ -467,11 +963,23 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 14,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "The SSE at the optimal solution is 0.000507\n",
+ "\n",
+ "The values for the parameters are as follows:\n",
+ "fs.properties.tau[benzene,toluene] = -0.8987550041842163\n",
+ "fs.properties.tau[toluene,benzene] = 1.4104702103547941\n"
+ ]
+ }
+ ],
"source": [
- "print(\"The SSE at the optimal solution is %0.6f\" % (obj_value * 1e-4))\n",
+ "print(\"The SSE at the optimal solution is %0.6f\" % (obj_value))\n",
"print()\n",
"print(\"The values for the parameters are as follows:\")\n",
"for k, v in parameters.items():\n",
@@ -504,15 +1012,12 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 15,
"metadata": {},
"outputs": [],
"source": [
- "# Run parameter estimation using bootstrap resample of the data (10 samples),\n",
- "# plot results along with confidence regions\n",
- "\n",
- "# Uncomment the following code:\n",
- "# bootstrap_theta = pest.theta_est_bootstrap(4)\n",
+ "# Uncomment the following lines\n",
+ "# bootstrap_theta = pest.theta_est_bootstrap(4, seed=542)\n",
"# display(bootstrap_theta)"
]
}
@@ -520,7 +1025,7 @@
"metadata": {
"celltoolbar": "Tags",
"kernelspec": {
- "display_name": "Python 3 (ipykernel)",
+ "display_name": "idaes-examples-dev-py313-macmini",
"language": "python",
"name": "python3"
},
@@ -534,7 +1039,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.10.9"
+ "version": "3.13.13"
}
},
"nbformat": 4,
diff --git a/idaes_examples/notebooks/docs/param_est/parameter_estimation_nrtl_using_unit_model.ipynb b/idaes_examples/notebooks/docs/param_est/parameter_estimation_nrtl_using_unit_model.ipynb
index 495b6540..4bb23c01 100644
--- a/idaes_examples/notebooks/docs/param_est/parameter_estimation_nrtl_using_unit_model.ipynb
+++ b/idaes_examples/notebooks/docs/param_est/parameter_estimation_nrtl_using_unit_model.ipynb
@@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 1,
"metadata": {
"tags": [
"header",
@@ -16,7 +16,7 @@
"# Framework (IDAES IP) was produced under the DOE Institute for the\n",
"# Design of Advanced Energy Systems (IDAES).\n",
"#\n",
- "# Copyright (c) 2018-2023 by the software owners: The Regents of the\n",
+ "# Copyright (c) 2018-2026 by the software owners: The Regents of the\n",
"# University of California, through Lawrence Berkeley National Laboratory,\n",
"# National Technology & Engineering Solutions of Sandia, LLC, Carnegie Mellon\n",
"# University, West Virginia University Research Corporation, et al.\n",
@@ -32,8 +32,8 @@
"# Parameter Estimation Using Flash Unit Model\n",
"\n",
"Author: Jaffer Ghouse \n",
- "Maintainer: Andrew Lee \n",
- "Updated: 2023-06-01 \n",
+ "Maintainer: Stephen Cini \n",
+ "Updated: 2026-06-11 \n",
"\n",
"In this module, we will be using Pyomo's `parmest` tool in conjunction with IDAES models for parameter estimation. We demonstrate these tools by estimating the parameters associated with the NRTL property model for a benzene-toluene mixture. The NRTL model has 2 sets of parameters: the non-randomness parameter (`alpha_ij`) and the binary interaction parameter (`tau_ij`), where `i` and `j` is the pure component species. In this example, we will be only estimate the binary interaction parameter (`tau_ij`) for a given dataset. When estimating parameters associated with the property package, IDAES provides the flexibility of doing the parameter estimation by just using the state block or by using a unit model with a specified property package. This module will demonstrate parameter estimation by using the flash unit model with the NRTL property package. \n",
"\n",
@@ -45,7 +45,7 @@
"\n",
"## Key links to documentation:\n",
"* NRTL Model - https://idaes-pse.readthedocs.io/en/stable/reference_guides/model_libraries/generic/property_models/activity_coefficient.html\n",
- "* parmest - https://pyomo.readthedocs.io/en/stable/contributed_packages/parmest/index.html\n"
+ "* parmest - https://pyomo.readthedocs.io/en/stable/explanation/analysis/parmest/index.html"
]
},
{
@@ -54,13 +54,13 @@
"source": [
"\n",
"Inline Exercise:\n",
- "import `ConcreteModel` from Pyomo, `FlowsheetBlock` and `Flash` from IDAES. \n",
+ "import `ConcreteModel`, `value`, and `Suffix` from Pyomo, `FlowsheetBlock` and `Flash` from IDAES. \n",
"
"
]
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 2,
"metadata": {
"tags": [
"exercise"
@@ -68,7 +68,7 @@
},
"outputs": [],
"source": [
- "# Todo: import ConcreteModel from pyomo.environ\n",
+ "# Todo: import ConcreteModel, value, and Suffix from pyomo.environ\n",
"\n",
"# Todo: import FlowsheetBlock from idaes.core\n",
"\n",
@@ -77,7 +77,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 3,
"metadata": {
"tags": [
"solution"
@@ -85,8 +85,8 @@
},
"outputs": [],
"source": [
- "# Todo: import ConcreteModel from pyomo.environ\n",
- "from pyomo.environ import ConcreteModel, value\n",
+ "# Todo: import ConcreteModel, value, and Suffix from pyomo.environ\n",
+ "from pyomo.environ import ConcreteModel, value, Suffix\n",
"\n",
"# Todo: import FlowsheetBlock from idaes.core\n",
"from idaes.core import FlowsheetBlock\n",
@@ -104,7 +104,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
@@ -123,7 +123,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
@@ -152,7 +152,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 6,
"metadata": {
"tags": [
"exercise"
@@ -220,7 +220,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 7,
"metadata": {
"tags": [
"solution"
@@ -292,7 +292,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 8,
"metadata": {
"tags": [
"testing"
@@ -340,55 +340,98 @@
"source": [
"In addition to providing a method to return an initialized model, the `parmest` tool needs the following:\n",
"\n",
- "* List of variable names to be estimated\n",
- "* Dataset with multiple scenarios\n",
- "* Expression to compute the sum of squared errors\n",
- "\n"
+ "* Experiment class to set up and label model with suffixes\n",
+ "* Dataset with multiple scenarios - organized into an experiment list"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
+ "Here we build an experiment class to label our model problem for parameter estimation. The labels are defined as a `Suffix`, and the main labels for our model are `experiment_outputs`, `unknown_parameters`, and `measurement_error`.\n",
+ "\n",
+ "For this problem, the error will be computed for the mole fraction of benzene in the vapor and liquid phase between the model prediction and data. The `experimental_outputs` will therefore be the mole fraction of benzene in the two phases.\n",
+ "\n",
"In this example, we only estimate the binary interaction parameter (`tau_ij`). Given that this variable is usually indexed as `tau_ij = Var(component_list, component_list)`, there are 2*2=4 degrees of freedom. However, when i=j, the binary interaction parameter is 0. Therefore, in this problem, we estimate the binary interaction parameter for the following variables only:\n",
"\n",
"* fs.properties.tau['benzene', 'toluene']\n",
"* fs.properties.tau['toluene', 'benzene']\n",
"\n",
- "\n",
- "Inline Exercise:\n",
- "Create a list called `variable_name` with the above-mentioned variables declared as strings.\n",
- "
"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {
- "tags": [
- "exercise"
- ]
- },
- "outputs": [],
- "source": [
- "# Todo: Create a list of vars to estimate"
+ "As shown below, these model components are used as our `unknown_parameters`.\n",
+ "\n",
+ "We define `measurement_error` as none so parmest calculates the value internally based on the experimental outputs. Refer to https://pyomo.readthedocs.io/en/stable/explanation/analysis/parmest/driver.html for more information. "
]
},
{
"cell_type": "code",
- "execution_count": null,
- "metadata": {
- "tags": [
- "solution"
- ]
- },
+ "execution_count": 9,
+ "metadata": {},
"outputs": [],
"source": [
- "# Todo: Create a list of vars to estimate\n",
- "variable_name = [\n",
- " \"fs.properties.tau['benzene', 'toluene']\",\n",
- " \"fs.properties.tau['toluene', 'benzene']\",\n",
- "]"
+ "# Build an experiment class to take advantage of new parmest interface\n",
+ "from pyomo.contrib.parmest.experiment import Experiment\n",
+ "\n",
+ "\n",
+ "class NRTLExperiment(Experiment):\n",
+ " \"\"\"Experiment class for parameter estimation of NRTL model using parmest\"\"\"\n",
+ "\n",
+ " def __init__(self, data, meas_error=None):\n",
+ " \"\"\"Initialize the NRTLExperiment class\n",
+ "\n",
+ " Args:\n",
+ " data: DataFrame containing the experimental data\n",
+ " meas_error: Measurement error for the data (optional)\n",
+ " \"\"\"\n",
+ " self.model = None\n",
+ " self.data = data\n",
+ " self.meas_error = meas_error\n",
+ "\n",
+ " def create_model(self):\n",
+ " \"\"\"Create the Pyomo model for the NRTL parameter estimation problem\"\"\"\n",
+ " self.model = NRTL_model(self.data)\n",
+ "\n",
+ " def label_model(self):\n",
+ " m = self.model\n",
+ "\n",
+ " # Add experiment outputs to the model for easier access\n",
+ " m.experiment_outputs = Suffix(direction=Suffix.LOCAL)\n",
+ " m.experiment_outputs.update(\n",
+ " [\n",
+ " (\n",
+ " m.fs.flash.liq_outlet.mole_frac_comp[0, \"benzene\"],\n",
+ " self.data[\"liq_benzene\"],\n",
+ " ),\n",
+ " (\n",
+ " m.fs.flash.vap_outlet.mole_frac_comp[0, \"benzene\"],\n",
+ " self.data[\"vap_benzene\"],\n",
+ " ),\n",
+ " ]\n",
+ " )\n",
+ "\n",
+ " m.measurement_error = Suffix(direction=Suffix.LOCAL)\n",
+ " m.measurement_error.update(\n",
+ " [\n",
+ " (m.fs.flash.liq_outlet.mole_frac_comp[0, \"benzene\"], self.meas_error),\n",
+ " (m.fs.flash.vap_outlet.mole_frac_comp[0, \"benzene\"], self.meas_error),\n",
+ " ]\n",
+ " )\n",
+ "\n",
+ " # Add unknown parameters to the model for easier access\n",
+ " m.unknown_parameters = Suffix(direction=Suffix.LOCAL)\n",
+ " m.unknown_parameters.update(\n",
+ " (k, value(k))\n",
+ " for k in [\n",
+ " m.fs.properties.tau[\"benzene\", \"toluene\"],\n",
+ " m.fs.properties.tau[\"toluene\", \"benzene\"],\n",
+ " ]\n",
+ " )\n",
+ "\n",
+ " def get_labeled_model(self):\n",
+ " \"\"\"Return the labeled model\"\"\"\n",
+ " if self.model is None:\n",
+ " self.create_model()\n",
+ " self.label_model()\n",
+ " return self.model"
]
},
{
@@ -407,9 +450,398 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 10,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " temperature | \n",
+ " liq_benzene | \n",
+ " vap_benzene | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 0 | \n",
+ " 365.500000 | \n",
+ " 0.480953 | \n",
+ " 0.692110 | \n",
+ "
\n",
+ " \n",
+ " | 1 | \n",
+ " 365.617647 | \n",
+ " 0.462444 | \n",
+ " 0.667699 | \n",
+ "
\n",
+ " \n",
+ " | 2 | \n",
+ " 365.735294 | \n",
+ " 0.477984 | \n",
+ " 0.692441 | \n",
+ "
\n",
+ " \n",
+ " | 3 | \n",
+ " 365.852941 | \n",
+ " 0.440547 | \n",
+ " 0.640336 | \n",
+ "
\n",
+ " \n",
+ " | 4 | \n",
+ " 365.970588 | \n",
+ " 0.427421 | \n",
+ " 0.623328 | \n",
+ "
\n",
+ " \n",
+ " | 5 | \n",
+ " 366.088235 | \n",
+ " 0.442725 | \n",
+ " 0.647796 | \n",
+ "
\n",
+ " \n",
+ " | 6 | \n",
+ " 366.205882 | \n",
+ " 0.434374 | \n",
+ " 0.637691 | \n",
+ "
\n",
+ " \n",
+ " | 7 | \n",
+ " 366.323529 | \n",
+ " 0.444642 | \n",
+ " 0.654933 | \n",
+ "
\n",
+ " \n",
+ " | 8 | \n",
+ " 366.441176 | \n",
+ " 0.427132 | \n",
+ " 0.631229 | \n",
+ "
\n",
+ " \n",
+ " | 9 | \n",
+ " 366.558824 | \n",
+ " 0.446301 | \n",
+ " 0.661743 | \n",
+ "
\n",
+ " \n",
+ " | 10 | \n",
+ " 366.676471 | \n",
+ " 0.438004 | \n",
+ " 0.651591 | \n",
+ "
\n",
+ " \n",
+ " | 11 | \n",
+ " 366.794118 | \n",
+ " 0.425320 | \n",
+ " 0.634814 | \n",
+ "
\n",
+ " \n",
+ " | 12 | \n",
+ " 366.911765 | \n",
+ " 0.439435 | \n",
+ " 0.658047 | \n",
+ "
\n",
+ " \n",
+ " | 13 | \n",
+ " 367.029412 | \n",
+ " 0.435655 | \n",
+ " 0.654539 | \n",
+ "
\n",
+ " \n",
+ " | 14 | \n",
+ " 367.147059 | \n",
+ " 0.401350 | \n",
+ " 0.604987 | \n",
+ "
\n",
+ " \n",
+ " | 15 | \n",
+ " 367.264706 | \n",
+ " 0.397862 | \n",
+ " 0.601703 | \n",
+ "
\n",
+ " \n",
+ " | 16 | \n",
+ " 367.382353 | \n",
+ " 0.415821 | \n",
+ " 0.630930 | \n",
+ "
\n",
+ " \n",
+ " | 17 | \n",
+ " 367.500000 | \n",
+ " 0.420667 | \n",
+ " 0.640380 | \n",
+ "
\n",
+ " \n",
+ " | 18 | \n",
+ " 367.617647 | \n",
+ " 0.391683 | \n",
+ " 0.598214 | \n",
+ "
\n",
+ " \n",
+ " | 19 | \n",
+ " 367.735294 | \n",
+ " 0.404903 | \n",
+ " 0.620432 | \n",
+ "
\n",
+ " \n",
+ " | 20 | \n",
+ " 367.852941 | \n",
+ " 0.409563 | \n",
+ " 0.629626 | \n",
+ "
\n",
+ " \n",
+ " | 21 | \n",
+ " 367.970588 | \n",
+ " 0.389488 | \n",
+ " 0.600722 | \n",
+ "
\n",
+ " \n",
+ " | 22 | \n",
+ " 368.000000 | \n",
+ " 0.396789 | \n",
+ " 0.612483 | \n",
+ "
\n",
+ " \n",
+ " | 23 | \n",
+ " 368.088235 | \n",
+ " 0.398162 | \n",
+ " 0.616106 | \n",
+ "
\n",
+ " \n",
+ " | 24 | \n",
+ " 368.205882 | \n",
+ " 0.362340 | \n",
+ " 0.562505 | \n",
+ "
\n",
+ " \n",
+ " | 25 | \n",
+ " 368.323529 | \n",
+ " 0.386958 | \n",
+ " 0.602680 | \n",
+ "
\n",
+ " \n",
+ " | 26 | \n",
+ " 368.441176 | \n",
+ " 0.363643 | \n",
+ " 0.568210 | \n",
+ "
\n",
+ " \n",
+ " | 27 | \n",
+ " 368.558824 | \n",
+ " 0.368118 | \n",
+ " 0.577072 | \n",
+ "
\n",
+ " \n",
+ " | 28 | \n",
+ " 368.676471 | \n",
+ " 0.384098 | \n",
+ " 0.604078 | \n",
+ "
\n",
+ " \n",
+ " | 29 | \n",
+ " 368.794118 | \n",
+ " 0.353605 | \n",
+ " 0.557925 | \n",
+ "
\n",
+ " \n",
+ " | 30 | \n",
+ " 368.911765 | \n",
+ " 0.346474 | \n",
+ " 0.548445 | \n",
+ "
\n",
+ " \n",
+ " | 31 | \n",
+ " 369.029412 | \n",
+ " 0.350741 | \n",
+ " 0.556996 | \n",
+ "
\n",
+ " \n",
+ " | 32 | \n",
+ " 369.147059 | \n",
+ " 0.362347 | \n",
+ " 0.577286 | \n",
+ "
\n",
+ " \n",
+ " | 33 | \n",
+ " 369.264706 | \n",
+ " 0.362578 | \n",
+ " 0.579519 | \n",
+ "
\n",
+ " \n",
+ " | 34 | \n",
+ " 369.382353 | \n",
+ " 0.340765 | \n",
+ " 0.546411 | \n",
+ "
\n",
+ " \n",
+ " | 35 | \n",
+ " 369.500000 | \n",
+ " 0.337462 | \n",
+ " 0.542857 | \n",
+ "
\n",
+ " \n",
+ " | 36 | \n",
+ " 369.617647 | \n",
+ " 0.355729 | \n",
+ " 0.574083 | \n",
+ "
\n",
+ " \n",
+ " | 37 | \n",
+ " 369.735294 | \n",
+ " 0.348679 | \n",
+ " 0.564513 | \n",
+ "
\n",
+ " \n",
+ " | 38 | \n",
+ " 369.852941 | \n",
+ " 0.338187 | \n",
+ " 0.549284 | \n",
+ "
\n",
+ " \n",
+ " | 39 | \n",
+ " 369.970588 | \n",
+ " 0.324360 | \n",
+ " 0.528514 | \n",
+ "
\n",
+ " \n",
+ " | 40 | \n",
+ " 370.088235 | \n",
+ " 0.310753 | \n",
+ " 0.507964 | \n",
+ "
\n",
+ " \n",
+ " | 41 | \n",
+ " 370.205882 | \n",
+ " 0.311037 | \n",
+ " 0.510055 | \n",
+ "
\n",
+ " \n",
+ " | 42 | \n",
+ " 370.323529 | \n",
+ " 0.311263 | \n",
+ " 0.512055 | \n",
+ "
\n",
+ " \n",
+ " | 43 | \n",
+ " 370.441176 | \n",
+ " 0.308081 | \n",
+ " 0.508437 | \n",
+ "
\n",
+ " \n",
+ " | 44 | \n",
+ " 370.558824 | \n",
+ " 0.308224 | \n",
+ " 0.510293 | \n",
+ "
\n",
+ " \n",
+ " | 45 | \n",
+ " 370.676471 | \n",
+ " 0.318148 | \n",
+ " 0.528399 | \n",
+ "
\n",
+ " \n",
+ " | 46 | \n",
+ " 370.794118 | \n",
+ " 0.308334 | \n",
+ " 0.513728 | \n",
+ "
\n",
+ " \n",
+ " | 47 | \n",
+ " 370.911765 | \n",
+ " 0.317937 | \n",
+ " 0.531410 | \n",
+ "
\n",
+ " \n",
+ " | 48 | \n",
+ " 371.029412 | \n",
+ " 0.289149 | \n",
+ " 0.484824 | \n",
+ "
\n",
+ " \n",
+ " | 49 | \n",
+ " 371.147059 | \n",
+ " 0.298637 | \n",
+ " 0.502318 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " temperature liq_benzene vap_benzene\n",
+ "0 365.500000 0.480953 0.692110\n",
+ "1 365.617647 0.462444 0.667699\n",
+ "2 365.735294 0.477984 0.692441\n",
+ "3 365.852941 0.440547 0.640336\n",
+ "4 365.970588 0.427421 0.623328\n",
+ "5 366.088235 0.442725 0.647796\n",
+ "6 366.205882 0.434374 0.637691\n",
+ "7 366.323529 0.444642 0.654933\n",
+ "8 366.441176 0.427132 0.631229\n",
+ "9 366.558824 0.446301 0.661743\n",
+ "10 366.676471 0.438004 0.651591\n",
+ "11 366.794118 0.425320 0.634814\n",
+ "12 366.911765 0.439435 0.658047\n",
+ "13 367.029412 0.435655 0.654539\n",
+ "14 367.147059 0.401350 0.604987\n",
+ "15 367.264706 0.397862 0.601703\n",
+ "16 367.382353 0.415821 0.630930\n",
+ "17 367.500000 0.420667 0.640380\n",
+ "18 367.617647 0.391683 0.598214\n",
+ "19 367.735294 0.404903 0.620432\n",
+ "20 367.852941 0.409563 0.629626\n",
+ "21 367.970588 0.389488 0.600722\n",
+ "22 368.000000 0.396789 0.612483\n",
+ "23 368.088235 0.398162 0.616106\n",
+ "24 368.205882 0.362340 0.562505\n",
+ "25 368.323529 0.386958 0.602680\n",
+ "26 368.441176 0.363643 0.568210\n",
+ "27 368.558824 0.368118 0.577072\n",
+ "28 368.676471 0.384098 0.604078\n",
+ "29 368.794118 0.353605 0.557925\n",
+ "30 368.911765 0.346474 0.548445\n",
+ "31 369.029412 0.350741 0.556996\n",
+ "32 369.147059 0.362347 0.577286\n",
+ "33 369.264706 0.362578 0.579519\n",
+ "34 369.382353 0.340765 0.546411\n",
+ "35 369.500000 0.337462 0.542857\n",
+ "36 369.617647 0.355729 0.574083\n",
+ "37 369.735294 0.348679 0.564513\n",
+ "38 369.852941 0.338187 0.549284\n",
+ "39 369.970588 0.324360 0.528514\n",
+ "40 370.088235 0.310753 0.507964\n",
+ "41 370.205882 0.311037 0.510055\n",
+ "42 370.323529 0.311263 0.512055\n",
+ "43 370.441176 0.308081 0.508437\n",
+ "44 370.558824 0.308224 0.510293\n",
+ "45 370.676471 0.318148 0.528399\n",
+ "46 370.794118 0.308334 0.513728\n",
+ "47 370.911765 0.317937 0.531410\n",
+ "48 371.029412 0.289149 0.484824\n",
+ "49 371.147059 0.298637 0.502318"
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ }
+ ],
"source": [
"# Load data from csv\n",
"data = pd.read_csv(\"BT_NRTL_dataset.csv\")\n",
@@ -422,91 +854,204 @@
"cell_type": "markdown",
"metadata": {},
"source": [
- "We need to provide a method to return an expression to compute the sum of squared errors that will be used as the objective in solving the parameter estimation problem. For this problem, the error will be computed for the mole fraction of benzene in the vapor and liquid phase between the model prediction and data. \n",
- "\n",
- "\n",
- "Inline Exercise:\n",
- "Complete the following cell by adding an expression to compute the sum of square errors. \n",
- "
"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {
- "tags": [
- "exercise"
- ]
- },
- "outputs": [],
- "source": [
- "# Create method to return an expression that computes the sum of squared error\n",
- "def SSE(m, data):\n",
- " # Todo: Add expression for computing the sum of squared errors in mole fraction of benzene in the liquid\n",
- " # and vapor phase. For example, the squared error for the vapor phase is:\n",
- " # (float(data.iloc[0][\"vap_benzene\"]) - m.fs.flash.vap_outlet.mole_frac_comp[0, \"benzene\"])**2\n",
- "\n",
- " return expr * 1e4"
+ "We define the `exp_list` by splitting the data into individual experiments, or data points."
]
},
{
"cell_type": "code",
- "execution_count": null,
- "metadata": {
- "tags": [
- "solution"
- ]
- },
- "outputs": [],
- "source": [
- "# Create method to return an expression that computes the sum of squared error\n",
- "def SSE(m, data):\n",
- " # Todo: Add expression for computing the sum of squared errors in mole fraction of benzene in the liquid\n",
- " # and vapor phase. For example, the squared error for the vapor phase is:\n",
- " # (float(data[\"vap_benzene\"]) - m.fs.flash.vap_outlet.mole_frac_comp[0, \"benzene\"])**2\n",
- " expr = (\n",
- " float(data.iloc[0][\"vap_benzene\"])\n",
- " - m.fs.flash.vap_outlet.mole_frac_comp[0, \"benzene\"]\n",
- " ) ** 2 + (\n",
- " float(data.iloc[0][\"liq_benzene\"])\n",
- " - m.fs.flash.liq_outlet.mole_frac_comp[0, \"benzene\"]\n",
- " ) ** 2\n",
- " return expr * 1e4"
- ]
- },
- {
- "cell_type": "markdown",
+ "execution_count": 11,
"metadata": {},
+ "outputs": [],
"source": [
- "\n",
- "Note:\n",
- "Notice that we have scaled the expression up by a factor of 10000 as the SSE computed here will be an extremely small number given that we are using the difference in mole fraction in our expression. A well-scaled objective will help improve solve robustness when using IPOPT. \n",
- "
\n"
+ "# Loop through the dataset and create an experiment for each row of data\n",
+ "exp_list = []\n",
+ "for i in range(data.shape[0]):\n",
+ " exp_list.append(NRTLExperiment(data.iloc[i]))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
- "We are now ready to set up the parameter estimation problem. We will create a parameter estimation object called `pest`. As shown below, we pass the method that returns an initialized model, dataset, list of variable names to estimate, and the SSE expression to the Estimator object. `tee=True` will print the solver output after solving the parameter estimation problem."
+ "We are now ready to set up the parameter estimation problem. We will create a parameter estimation object called pest. As shown below, we pass the experiment list, and an objective function to the Estimator method. tee=True will print the solver output after solving the parameter estimation problem."
]
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 12,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Ipopt 3.13.2: \n",
+ "\n",
+ "******************************************************************************\n",
+ "This program contains Ipopt, a library for large-scale nonlinear optimization.\n",
+ " Ipopt is released as open source code under the Eclipse Public License (EPL).\n",
+ " For more information visit http://projects.coin-or.org/Ipopt\n",
+ "\n",
+ "This version of Ipopt was compiled from source code available at\n",
+ " https://github.com/IDAES/Ipopt as part of the Institute for the Design of\n",
+ " Advanced Energy Systems Process Systems Engineering Framework (IDAES PSE\n",
+ " Framework) Copyright (c) 2018-2019. See https://github.com/IDAES/idaes-pse.\n",
+ "\n",
+ "This version of Ipopt was compiled using HSL, a collection of Fortran codes\n",
+ " for large-scale scientific computation. All technical papers, sales and\n",
+ " publicity material resulting from use of the HSL codes within IPOPT must\n",
+ " contain the following acknowledgement:\n",
+ " HSL, a collection of Fortran codes for large-scale scientific\n",
+ " computation. See http://www.hsl.rl.ac.uk.\n",
+ "******************************************************************************\n",
+ "\n",
+ "This is Ipopt version 3.13.2, running with linear solver ma27.\n",
+ "\n",
+ "Number of nonzeros in equality constraint Jacobian...: 10950\n",
+ "Number of nonzeros in inequality constraint Jacobian.: 0\n",
+ "Number of nonzeros in Lagrangian Hessian.............: 6600\n",
+ "\n",
+ "Total number of variables............................: 2952\n",
+ " variables with only lower bounds: 150\n",
+ " variables with lower and upper bounds: 600\n",
+ " variables with only upper bounds: 0\n",
+ "Total number of equality constraints.................: 2950\n",
+ "Total number of inequality constraints...............: 0\n",
+ " inequality constraints with only lower bounds: 0\n",
+ " inequality constraints with lower and upper bounds: 0\n",
+ " inequality constraints with only upper bounds: 0\n",
+ "\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 0 6.0671019e-03 5.63e+02 1.20e-08 -1.0 0.00e+00 - 0.00e+00 0.00e+00 0\n",
+ " 1 9.0714942e-04 1.37e+03 1.61e+01 -1.0 1.37e+04 - 9.82e-01 1.00e+00h 1\n",
+ " 2 1.3219937e-03 1.17e+04 1.62e+01 -1.0 5.23e+03 - 3.41e-01 1.65e-01h 3\n",
+ " 3 1.3161671e-03 1.11e+04 4.02e+01 -1.0 3.96e+02 -4.0 8.19e-01 1.25e-01h 4\n",
+ " 4 1.3154170e-03 1.11e+04 4.32e+01 -1.0 3.47e+02 -4.5 9.90e-01 4.43e-02h 5\n",
+ " 5 9.4424343e-04 1.04e+04 4.05e+01 -1.0 1.16e+04 - 9.33e-01 5.61e-02h 5\n",
+ " 6 9.4571258e-04 1.11e+04 4.85e+01 -1.0 3.13e+02 -5.0 8.74e-01 1.25e-01h 4\n",
+ " 7 9.4862862e-04 1.11e+04 4.84e+01 -1.0 2.41e+03 -5.4 1.72e-01 1.50e-03h 8\n",
+ " 8 9.5448936e-04 1.10e+04 4.81e+01 -1.0 4.11e+02 -5.0 1.00e+00 1.97e-02h 6\n",
+ " 9 9.5650047e-04 1.10e+04 4.81e+01 -1.0 5.14e+02 -4.6 3.46e-01 5.24e-03h 7\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 10 9.5730419e-04 1.10e+04 4.81e+01 -1.0 9.78e+02 -4.2 4.40e-01 1.08e-03h 8\n",
+ " 11 9.5774182e-04 1.10e+04 4.84e+01 -1.0 2.76e+02 -3.7 2.91e-01 2.99e-03h 7\n",
+ " 12 9.4292855e-04 7.77e+04 4.09e+04 -1.0 5.38e+02 -2.4 5.48e-02 6.44e-02w 1\n",
+ " 13 2.4318219e-01 2.38e+07 4.22e+14 -1.0 1.28e+06 - 2.55e-02 3.49e-02w 1\n",
+ " 14 2.8902019e-01 1.64e+07 2.92e+14 -1.0 1.11e+05 -2.9 9.54e-01 3.01e-01w 1\n",
+ " 15 9.5768293e-04 1.10e+04 4.85e+01 -1.0 2.80e+05 -3.4 5.48e-02 2.52e-04h 8\n",
+ " 16 9.5769345e-04 1.10e+04 4.85e+01 -1.0 4.33e+02 -2.9 7.95e-02 1.91e-04h 9\n",
+ " 17 9.5763809e-04 1.10e+04 4.85e+01 -1.0 6.35e+02 -2.5 4.94e-02 2.08e-04h 9\n",
+ " 18 9.5734836e-04 1.10e+04 4.87e+01 -1.0 3.22e+02 -3.0 1.00e+00 1.22e-03h 8\n",
+ " 19 9.3628114e-04 1.09e+04 4.62e+01 -1.0 4.22e+02 -3.5 5.16e-01 5.87e-02h 5\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 20 7.1894543e-04 4.02e+03 4.95e+02 -1.0 3.49e+02 -3.9 1.00e+00 1.00e+00h 1\n",
+ " 21 6.7062834e-04 1.58e+02 2.21e+02 -1.0 1.78e+02 -4.4 1.00e+00 1.00e+00h 1\n",
+ " 22 6.6635123e-04 4.17e+01 1.12e+01 -1.0 2.44e+02 -4.9 1.00e+00 1.00e+00h 1\n",
+ " 23 6.6729070e-04 1.43e+00 9.69e-01 -1.0 1.08e+01 -5.4 1.00e+00 1.00e+00h 1\n",
+ " 24 6.6785681e-04 3.58e-01 5.25e-03 -1.7 6.65e+00 -5.8 1.00e+00 1.00e+00h 1\n",
+ " 25 6.2552355e-04 9.80e+02 6.48e-02 -3.8 7.92e+02 - 9.22e-01 1.00e+00h 1\n",
+ " 26 5.9105707e-04 8.13e+00 6.13e-04 -3.8 5.66e+02 - 1.00e+00 1.00e+00h 1\n",
+ " 27 6.1313801e-04 6.24e+01 8.08e-06 -3.8 1.70e+02 - 1.00e+00 1.00e+00h 1\n",
+ " 28 6.1208051e-04 3.58e-01 1.18e-08 -3.8 1.88e+00 - 1.00e+00 1.00e+00h 1\n",
+ " 29 5.9010560e-04 1.58e+01 1.00e-05 -5.7 1.08e+02 - 1.00e+00 1.00e+00h 1\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 30 5.9008319e-04 2.74e-02 7.90e-07 -5.7 7.54e-02 -6.3 1.00e+00 1.00e+00h 1\n",
+ " 31 5.3570104e-04 1.48e+04 8.70e-04 -5.7 1.81e+02 - 1.00e+00 1.00e+00h 1\n",
+ " 32 5.1618763e-04 6.29e+02 8.06e-05 -5.7 2.55e+02 - 1.00e+00 1.00e+00h 1\n",
+ " 33 5.5250565e-04 2.88e+01 2.58e-04 -5.7 1.81e+04 - 6.26e-01 6.25e-02h 5\n",
+ " 34 5.2209909e-04 2.88e+02 2.02e-04 -5.7 1.89e+03 - 1.00e+00 1.00e+00h 1\n",
+ " 35 5.0707798e-04 5.60e+01 2.02e-04 -5.7 2.93e+03 - 1.00e+00 1.00e+00h 1\n",
+ " 36 5.0765648e-04 7.87e+00 1.91e-05 -5.7 1.02e+02 - 1.00e+00 1.00e+00h 1\n",
+ " 37 5.0740606e-04 2.57e+00 1.88e-05 -5.7 6.96e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 38 5.0764164e-04 2.55e+00 1.76e-05 -5.7 6.81e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 39 5.0740672e-04 2.55e+00 1.88e-05 -5.7 6.80e+01 - 1.00e+00 1.00e+00h 1\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 40 5.0764162e-04 2.54e+00 1.76e-05 -5.7 6.80e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 41 5.0740672e-04 2.55e+00 1.88e-05 -5.7 6.80e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 42 5.0782847e-04 1.43e-01 1.83e-05 -5.7 6.80e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 43 5.0751252e-04 1.58e-02 1.93e-05 -5.7 6.88e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 44 5.0783218e-04 4.79e-03 1.85e-05 -5.7 6.92e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 45 5.0751252e-04 1.60e-02 1.93e-05 -5.7 6.89e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 46 5.0783222e-04 1.23e-04 1.85e-05 -5.7 6.92e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 47 5.0751252e-04 1.60e-02 1.93e-05 -5.7 6.89e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 48 5.0783216e-04 1.24e-04 1.85e-05 -5.7 6.92e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 49 5.0751765e-04 3.20e-03 1.93e-05 -5.7 6.89e+01 - 1.00e+00 1.00e+00H 1\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 50 5.0764151e-04 2.56e+00 1.77e-05 -5.7 6.93e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 51 5.0740671e-04 2.55e+00 1.88e-05 -5.7 6.81e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 52 5.0764162e-04 2.54e+00 1.76e-05 -5.7 6.80e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 53 5.0740672e-04 2.55e+00 1.88e-05 -5.7 6.80e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 54 5.0764162e-04 2.54e+00 1.76e-05 -5.7 6.80e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 55 5.0748886e-04 1.91e+00 8.64e-06 -5.7 6.80e+01 - 1.00e+00 5.00e-01h 2\n",
+ " 56 5.0744550e-04 3.37e-01 1.64e-05 -5.7 2.54e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 57 5.0763613e-04 1.82e+00 1.43e-05 -5.7 5.79e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 58 5.0751252e-04 2.25e-02 1.93e-05 -5.7 6.65e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 59 5.0783220e-04 1.23e-04 1.85e-05 -5.7 6.92e+01 - 1.00e+00 1.00e+00H 1\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 60 5.0751252e-04 1.60e-02 1.93e-05 -5.7 6.89e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 61 5.0783207e-04 3.26e-04 1.85e-05 -5.7 6.92e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 62 5.0751786e-04 7.95e-05 1.93e-05 -5.7 6.89e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 63 5.0754291e-04 6.40e-01 8.69e-06 -5.7 6.93e+01 - 1.00e+00 5.00e-01h 2\n",
+ " 64 5.0745167e-04 3.00e-01 1.61e-05 -5.7 2.35e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 65 5.0763437e-04 1.71e+00 1.33e-05 -5.7 5.61e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 66 5.0751762e-04 2.91e-03 1.93e-05 -5.7 6.60e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 67 5.0752104e-04 1.62e-01 1.43e-05 -5.7 6.92e+01 - 1.00e+00 2.50e-01h 3\n",
+ " 68 5.0761295e-04 1.03e+00 2.18e-05 -5.7 4.35e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 69 5.0751251e-04 2.38e-02 1.92e-05 -5.7 5.95e+01 - 1.00e+00 1.00e+00H 1\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 70 5.0783210e-04 3.29e-06 1.85e-05 -5.7 6.90e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 71 5.0751786e-04 7.94e-05 1.93e-05 -5.7 6.89e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 72 5.0754292e-04 6.40e-01 8.69e-06 -5.7 6.93e+01 - 1.00e+00 5.00e-01h 2\n",
+ " 73 5.0749299e-04 3.95e-01 1.21e-05 -5.7 2.35e+01 - 1.00e+00 5.00e-01h 2\n",
+ " 74 5.0755524e-04 1.36e-01 3.09e-05 -5.7 1.57e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 75 5.0751308e-04 1.96e-02 1.80e-05 -5.7 3.30e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 76 5.0754492e-04 5.62e-01 8.19e-06 -5.7 6.42e+01 - 1.00e+00 5.00e-01h 2\n",
+ " 77 5.0748301e-04 3.98e-01 1.25e-05 -5.7 2.93e+01 - 1.00e+00 5.00e-01h 2\n",
+ " 78 5.0756455e-04 2.42e-01 3.07e-05 -5.7 2.09e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 79 5.0751710e-04 1.38e-03 1.87e-05 -5.7 3.98e+01 - 1.00e+00 1.00e+00H 1\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 80 5.0783077e-04 3.26e-06 1.84e-05 -5.7 6.70e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 81 5.0726420e-04 1.24e+01 1.85e-05 -8.6 1.34e+02 - 9.93e-01 1.00e+00h 1\n",
+ " 82 5.0749897e-04 2.75e+00 2.53e-06 -8.6 6.93e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 83 5.0749686e-04 3.64e-04 6.40e-10 -8.6 4.69e-02 - 1.00e+00 1.00e+00h 1\n",
+ " 84 5.0749686e-04 7.28e-11 2.51e-14 -8.6 6.86e-05 - 1.00e+00 1.00e+00h 1\n",
+ "\n",
+ "Number of Iterations....: 84\n",
+ "\n",
+ " (scaled) (unscaled)\n",
+ "Objective...............: 5.0749685809243843e-04 5.0749685809243843e-04\n",
+ "Dual infeasibility......: 2.5059195074646584e-14 2.5059195074646584e-14\n",
+ "Constraint violation....: 1.4104644499482425e-11 7.2759576141834259e-11\n",
+ "Complementarity.........: 2.5059035596800647e-09 2.5059035596800647e-09\n",
+ "Overall NLP error.......: 2.5059035596800647e-09 2.5059035596800647e-09\n",
+ "\n",
+ "\n",
+ "Number of objective function evaluations = 260\n",
+ "Number of objective gradient evaluations = 85\n",
+ "Number of equality constraint evaluations = 260\n",
+ "Number of inequality constraint evaluations = 0\n",
+ "Number of equality constraint Jacobian evaluations = 85\n",
+ "Number of inequality constraint Jacobian evaluations = 0\n",
+ "Number of Lagrangian Hessian evaluations = 84\n",
+ "Total CPU secs in IPOPT (w/o function evaluations) = 0.338\n",
+ "Total CPU secs in NLP function evaluations = 0.092\n",
+ "\n",
+ "EXIT: Optimal Solution Found.\n"
+ ]
+ }
+ ],
"source": [
- "# Initialize a parameter estimation object\n",
- "pest = parmest.Estimator(NRTL_model, data, variable_name, SSE, tee=True)\n",
+ "import logging\n",
+ "\n",
+ "idaeslog.getIdaesLogger(\"core.property_meta\").setLevel(logging.ERROR)\n",
"\n",
- "# Run parameter estimation using all data\n",
+ "pest = parmest.Estimator(exp_list, obj_function=\"SSE\", tee=True)\n",
"obj_value, parameters = pest.theta_est()"
]
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 13,
"metadata": {
"tags": [
"testing"
@@ -515,7 +1060,7 @@
"outputs": [],
"source": [
"# Check for values of the parameter estimation problem\n",
- "assert obj_value == pytest.approx(5.07496, abs=1e-1)\n",
+ "assert obj_value == pytest.approx(5.07496e-4, abs=1e-1)\n",
"assert parameters[\"fs.properties.tau[benzene,toluene]\"] == pytest.approx(-0.89876, 1e-3)\n",
"assert parameters[\"fs.properties.tau[toluene,benzene]\"] == pytest.approx(1.410486, 1e-3)"
]
@@ -531,11 +1076,23 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 14,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "The SSE at the optimal solution is 0.000507\n",
+ "\n",
+ "The values for the parameters are as follows:\n",
+ "fs.properties.tau[benzene,toluene] = -0.8987454466579063\n",
+ "fs.properties.tau[toluene,benzene] = 1.410449514796474\n"
+ ]
+ }
+ ],
"source": [
- "print(\"The SSE at the optimal solution is %0.6f\" % (obj_value * 1e-4))\n",
+ "print(\"The SSE at the optimal solution is %0.6f\" % (obj_value))\n",
"print()\n",
"print(\"The values for the parameters are as follows:\")\n",
"for k, v in parameters.items():\n",
@@ -561,7 +1118,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
- "Pyomo's `parmest` tool allows for bootstrapping where the parameter estimation is repeated over `n` samples with resampling from the original data set. Parameter estimation with bootstrap resampling can be used to identify confidence regions around each parameter estimate. This analysis can be slow given the increased number of model instances that need to be solved. Please refer to https://pyomo.readthedocs.io/en/stable/contributed_packages/parmest/driver.html for more details. \n",
+ "Pyomo's `parmest` tool allows for bootstrapping where the parameter estimation is repeated over `n` samples with resampling from the original data set. Parameter estimation with bootstrap resampling can be used to identify confidence regions around each parameter estimate. This analysis can be slow given the increased number of model instances that need to be solved. Please refer to https://pyomo.readthedocs.io/en/stable/explanation/analysis/parmest/covariance.html#bootstrapping for more details. \n",
"\n",
"For the example above, the bootstrapping can be run by uncommenting the code in the following cell:"
]
@@ -572,12 +1129,8 @@
"metadata": {},
"outputs": [],
"source": [
- "# Run parameter estimation using bootstrap resample of the data (10 samples),\n",
- "# plot results along with confidence regions\n",
- "\n",
"# Uncomment the following lines\n",
- "\n",
- "# bootstrap_theta = pest.theta_est_bootstrap(4)\n",
+ "# bootstrap_theta = pest.theta_est_bootstrap(4, seed=542)\n",
"# display(bootstrap_theta)"
]
}
@@ -585,7 +1138,7 @@
"metadata": {
"celltoolbar": "Tags",
"kernelspec": {
- "display_name": "Python 3 (ipykernel)",
+ "display_name": "idaes-pse-and-examples-dev-py313-macmini",
"language": "python",
"name": "python3"
},
@@ -599,7 +1152,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.8.19"
+ "version": "3.13.13"
}
},
"nbformat": 4,
diff --git a/idaes_examples/notebooks/docs/param_est/parameter_estimation_nrtl_using_unit_model_doc.ipynb b/idaes_examples/notebooks/docs/param_est/parameter_estimation_nrtl_using_unit_model_doc.ipynb
index edb05ee6..20914a4d 100644
--- a/idaes_examples/notebooks/docs/param_est/parameter_estimation_nrtl_using_unit_model_doc.ipynb
+++ b/idaes_examples/notebooks/docs/param_est/parameter_estimation_nrtl_using_unit_model_doc.ipynb
@@ -1,923 +1,1022 @@
{
- "cells": [
- {
- "cell_type": "code",
- "execution_count": 1,
- "metadata": {
- "tags": [
- "header",
- "hide-cell"
- ]
- },
- "outputs": [],
- "source": [
- "###############################################################################\n",
- "# The Institute for the Design of Advanced Energy Systems Integrated Platform\n",
- "# Framework (IDAES IP) was produced under the DOE Institute for the\n",
- "# Design of Advanced Energy Systems (IDAES).\n",
- "#\n",
- "# Copyright (c) 2018-2023 by the software owners: The Regents of the\n",
- "# University of California, through Lawrence Berkeley National Laboratory,\n",
- "# National Technology & Engineering Solutions of Sandia, LLC, Carnegie Mellon\n",
- "# University, West Virginia University Research Corporation, et al.\n",
- "# All rights reserved. Please see the files COPYRIGHT.md and LICENSE.md\n",
- "# for full copyright and license information.\n",
- "###############################################################################"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "# Parameter Estimation Using Flash Unit Model\n",
- "\n",
- "Author: Jaffer Ghouse \n",
- "Maintainer: Andrew Lee \n",
- "Updated: 2023-06-01 \n",
- "\n",
- "In this module, we will be using Pyomo's `parmest` tool in conjunction with IDAES models for parameter estimation. We demonstrate these tools by estimating the parameters associated with the NRTL property model for a benzene-toluene mixture. The NRTL model has 2 sets of parameters: the non-randomness parameter (`alpha_ij`) and the binary interaction parameter (`tau_ij`), where `i` and `j` is the pure component species. In this example, we will be only estimate the binary interaction parameter (`tau_ij`) for a given dataset. When estimating parameters associated with the property package, IDAES provides the flexibility of doing the parameter estimation by just using the state block or by using a unit model with a specified property package. This module will demonstrate parameter estimation by using the flash unit model with the NRTL property package. \n",
- "\n",
- "We will complete the following tasks:\n",
- "* Set up a method to return an initialized model\n",
- "* Set up the parameter estimation problem using `parmest`\n",
- "* Analyze the results\n",
- "* Demonstrate advanced features from `parmest`\n",
- "\n",
- "## Key links to documentation:\n",
- "* NRTL Model - https://idaes-pse.readthedocs.io/en/stable/reference_guides/model_libraries/generic/property_models/activity_coefficient.html\n",
- "* parmest - https://pyomo.readthedocs.io/en/stable/contributed_packages/parmest/index.html\n"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "\n",
- "Inline Exercise:\n",
- "import `ConcreteModel` from Pyomo, `FlowsheetBlock` and `Flash` from IDAES. \n",
- "
"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 2,
- "metadata": {
- "tags": [
- "solution"
- ]
- },
- "outputs": [],
- "source": [
- "# Todo: import ConcreteModel from pyomo.environ\n",
- "from pyomo.environ import ConcreteModel, value\n",
- "\n",
- "# Todo: import FlowsheetBlock from idaes.core\n",
- "from idaes.core import FlowsheetBlock\n",
- "\n",
- "# Todo: import Flash unit model from idaes.models.unit_models\n",
- "from idaes.models.unit_models import Flash"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "In the next cell, we will be importing the parameter block that we will be using in this module and the idaes logger. "
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 3,
- "metadata": {},
- "outputs": [],
- "source": [
- "from idaes.models.properties.activity_coeff_models.BTX_activity_coeff_VLE import (\n",
- " BTXParameterBlock,\n",
- ")\n",
- "import idaes.logger as idaeslog"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "In the next cell, we import `parmest` from Pyomo and the `pandas` package. We need `pandas` as `parmest` uses `pandas.dataframe` for handling the input data and the results."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 4,
- "metadata": {},
- "outputs": [],
- "source": [
- "import pyomo.contrib.parmest.parmest as parmest\n",
- "import pandas as pd"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "## Setting up an initialized model\n",
- "\n",
- "We need to provide a method that returns an initialized model to the `parmest` tool in Pyomo."
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "\n",
- "Inline Exercise:\n",
- "Using what you have learned from previous modules, fill in the missing code below to return an initialized IDAES model. \n",
- "
"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 5,
- "metadata": {
- "tags": [
- "solution"
- ]
- },
- "outputs": [],
- "source": [
- "def NRTL_model(data):\n",
- "\n",
- " # Todo: Create a ConcreteModel object\n",
- " m = ConcreteModel()\n",
- "\n",
- " # Todo: Create FlowsheetBlock object\n",
- " m.fs = FlowsheetBlock(dynamic=False)\n",
- "\n",
- " # Todo: Create a properties parameter object with the following options:\n",
- " # \"valid_phase\": ('Liq', 'Vap')\n",
- " # \"activity_coeff_model\": 'NRTL'\n",
- " m.fs.properties = BTXParameterBlock(\n",
- " valid_phase=(\"Liq\", \"Vap\"), activity_coeff_model=\"NRTL\"\n",
- " )\n",
- " m.fs.flash = Flash(property_package=m.fs.properties)\n",
- "\n",
- " # Initialize at a certain inlet condition\n",
- " m.fs.flash.inlet.flow_mol.fix(1)\n",
- " m.fs.flash.inlet.temperature.fix(368)\n",
- " m.fs.flash.inlet.pressure.fix(101325)\n",
- " m.fs.flash.inlet.mole_frac_comp[0, \"benzene\"].fix(0.5)\n",
- " m.fs.flash.inlet.mole_frac_comp[0, \"toluene\"].fix(0.5)\n",
- "\n",
- " # Set Flash unit specifications\n",
- " m.fs.flash.heat_duty.fix(0)\n",
- " m.fs.flash.deltaP.fix(0)\n",
- "\n",
- " # Fix NRTL specific variables\n",
- " # alpha values (set at 0.3)\n",
- " m.fs.properties.alpha[\"benzene\", \"benzene\"].fix(0)\n",
- " m.fs.properties.alpha[\"benzene\", \"toluene\"].fix(0.3)\n",
- " m.fs.properties.alpha[\"toluene\", \"toluene\"].fix(0)\n",
- " m.fs.properties.alpha[\"toluene\", \"benzene\"].fix(0.3)\n",
- "\n",
- " # initial tau values\n",
- " m.fs.properties.tau[\"benzene\", \"benzene\"].fix(0)\n",
- " m.fs.properties.tau[\"benzene\", \"toluene\"].fix(-0.9)\n",
- " m.fs.properties.tau[\"toluene\", \"toluene\"].fix(0)\n",
- " m.fs.properties.tau[\"toluene\", \"benzene\"].fix(1.4)\n",
- "\n",
- " # Initialize the flash unit\n",
- " m.fs.flash.initialize(outlvl=idaeslog.INFO_LOW)\n",
- "\n",
- " # Fix at actual temperature\n",
- " m.fs.flash.inlet.temperature.fix(float(data[\"temperature\"]))\n",
- "\n",
- " # Set bounds on variables to be estimated\n",
- " m.fs.properties.tau[\"benzene\", \"toluene\"].setlb(-5)\n",
- " m.fs.properties.tau[\"benzene\", \"toluene\"].setub(5)\n",
- "\n",
- " m.fs.properties.tau[\"toluene\", \"benzene\"].setlb(-5)\n",
- " m.fs.properties.tau[\"toluene\", \"benzene\"].setub(5)\n",
- "\n",
- " # Return initialized flash model\n",
- " return m"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "## Parameter estimation using parmest"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "In addition to providing a method to return an initialized model, the `parmest` tool needs the following:\n",
- "\n",
- "* List of variable names to be estimated\n",
- "* Dataset with multiple scenarios\n",
- "* Expression to compute the sum of squared errors\n",
- "\n"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "In this example, we only estimate the binary interaction parameter (`tau_ij`). Given that this variable is usually indexed as `tau_ij = Var(component_list, component_list)`, there are 2*2=4 degrees of freedom. However, when i=j, the binary interaction parameter is 0. Therefore, in this problem, we estimate the binary interaction parameter for the following variables only:\n",
- "\n",
- "* fs.properties.tau['benzene', 'toluene']\n",
- "* fs.properties.tau['toluene', 'benzene']\n",
- "\n",
- "\n",
- "Inline Exercise:\n",
- "Create a list called `variable_name` with the above-mentioned variables declared as strings.\n",
- "
"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 6,
- "metadata": {
- "tags": [
- "solution"
- ]
- },
- "outputs": [],
- "source": [
- "# Todo: Create a list of vars to estimate\n",
- "variable_name = [\n",
- " \"fs.properties.tau['benzene', 'toluene']\",\n",
- " \"fs.properties.tau['toluene', 'benzene']\",\n",
- "]"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "Pyomo's `parmest` tool supports the following data formats:\n",
- "- pandas dataframe\n",
- "- list of dictionaries\n",
- "- list of json file names.\n",
- "\n",
- "Please see the documentation for more details. \n",
- "\n",
- "For this example, we load data from the csv file `BT_NRTL_dataset.csv`. The dataset consists of fifty data points which provide the mole fraction of benzene in the vapor and liquid phase as a function of temperature. "
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 7,
- "metadata": {},
- "outputs": [
+ "cells": [
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "metadata": {
+ "tags": [
+ "header",
+ "hide-cell"
+ ]
+ },
+ "outputs": [],
+ "source": [
+ "###############################################################################\n",
+ "# The Institute for the Design of Advanced Energy Systems Integrated Platform\n",
+ "# Framework (IDAES IP) was produced under the DOE Institute for the\n",
+ "# Design of Advanced Energy Systems (IDAES).\n",
+ "#\n",
+ "# Copyright (c) 2018-2026 by the software owners: The Regents of the\n",
+ "# University of California, through Lawrence Berkeley National Laboratory,\n",
+ "# National Technology & Engineering Solutions of Sandia, LLC, Carnegie Mellon\n",
+ "# University, West Virginia University Research Corporation, et al.\n",
+ "# All rights reserved. Please see the files COPYRIGHT.md and LICENSE.md\n",
+ "# for full copyright and license information.\n",
+ "###############################################################################"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Parameter Estimation Using Flash Unit Model\n",
+ "\n",
+ "Author: Jaffer Ghouse \n",
+ "Maintainer: Stephen Cini \n",
+ "Updated: 2026-06-11 \n",
+ "\n",
+ "In this module, we will be using Pyomo's `parmest` tool in conjunction with IDAES models for parameter estimation. We demonstrate these tools by estimating the parameters associated with the NRTL property model for a benzene-toluene mixture. The NRTL model has 2 sets of parameters: the non-randomness parameter (`alpha_ij`) and the binary interaction parameter (`tau_ij`), where `i` and `j` is the pure component species. In this example, we will be only estimate the binary interaction parameter (`tau_ij`) for a given dataset. When estimating parameters associated with the property package, IDAES provides the flexibility of doing the parameter estimation by just using the state block or by using a unit model with a specified property package. This module will demonstrate parameter estimation by using the flash unit model with the NRTL property package. \n",
+ "\n",
+ "We will complete the following tasks:\n",
+ "* Set up a method to return an initialized model\n",
+ "* Set up the parameter estimation problem using `parmest`\n",
+ "* Analyze the results\n",
+ "* Demonstrate advanced features from `parmest`\n",
+ "\n",
+ "## Key links to documentation:\n",
+ "* NRTL Model - https://idaes-pse.readthedocs.io/en/stable/reference_guides/model_libraries/generic/property_models/activity_coefficient.html\n",
+ "* parmest - https://pyomo.readthedocs.io/en/stable/explanation/analysis/parmest/index.html"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "\n",
+ "Inline Exercise:\n",
+ "import `ConcreteModel`, `value`, and `Suffix` from Pyomo, `FlowsheetBlock` and `Flash` from IDAES. \n",
+ "
"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 3,
+ "metadata": {
+ "tags": [
+ "solution"
+ ]
+ },
+ "outputs": [],
+ "source": [
+ "# Todo: import ConcreteModel, value, and Suffix from pyomo.environ\n",
+ "from pyomo.environ import ConcreteModel, value, Suffix\n",
+ "\n",
+ "# Todo: import FlowsheetBlock from idaes.core\n",
+ "from idaes.core import FlowsheetBlock\n",
+ "\n",
+ "# Todo: import Flash unit model from idaes.models.unit_models\n",
+ "from idaes.models.unit_models import Flash"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "In the next cell, we will be importing the parameter block that we will be using in this module and the idaes logger. "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 4,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "from idaes.models.properties.activity_coeff_models.BTX_activity_coeff_VLE import (\n",
+ " BTXParameterBlock,\n",
+ ")\n",
+ "import idaes.logger as idaeslog"
+ ]
+ },
{
- "data": {
- "text/html": [
- "\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " | \n",
- " temperature | \n",
- " liq_benzene | \n",
- " vap_benzene | \n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " | 0 | \n",
- " 365.500000 | \n",
- " 0.480953 | \n",
- " 0.692110 | \n",
- "
\n",
- " \n",
- " | 1 | \n",
- " 365.617647 | \n",
- " 0.462444 | \n",
- " 0.667699 | \n",
- "
\n",
- " \n",
- " | 2 | \n",
- " 365.735294 | \n",
- " 0.477984 | \n",
- " 0.692441 | \n",
- "
\n",
- " \n",
- " | 3 | \n",
- " 365.852941 | \n",
- " 0.440547 | \n",
- " 0.640336 | \n",
- "
\n",
- " \n",
- " | 4 | \n",
- " 365.970588 | \n",
- " 0.427421 | \n",
- " 0.623328 | \n",
- "
\n",
- " \n",
- " | 5 | \n",
- " 366.088235 | \n",
- " 0.442725 | \n",
- " 0.647796 | \n",
- "
\n",
- " \n",
- " | 6 | \n",
- " 366.205882 | \n",
- " 0.434374 | \n",
- " 0.637691 | \n",
- "
\n",
- " \n",
- " | 7 | \n",
- " 366.323529 | \n",
- " 0.444642 | \n",
- " 0.654933 | \n",
- "
\n",
- " \n",
- " | 8 | \n",
- " 366.441176 | \n",
- " 0.427132 | \n",
- " 0.631229 | \n",
- "
\n",
- " \n",
- " | 9 | \n",
- " 366.558824 | \n",
- " 0.446301 | \n",
- " 0.661743 | \n",
- "
\n",
- " \n",
- " | 10 | \n",
- " 366.676471 | \n",
- " 0.438004 | \n",
- " 0.651591 | \n",
- "
\n",
- " \n",
- " | 11 | \n",
- " 366.794118 | \n",
- " 0.425320 | \n",
- " 0.634814 | \n",
- "
\n",
- " \n",
- " | 12 | \n",
- " 366.911765 | \n",
- " 0.439435 | \n",
- " 0.658047 | \n",
- "
\n",
- " \n",
- " | 13 | \n",
- " 367.029412 | \n",
- " 0.435655 | \n",
- " 0.654539 | \n",
- "
\n",
- " \n",
- " | 14 | \n",
- " 367.147059 | \n",
- " 0.401350 | \n",
- " 0.604987 | \n",
- "
\n",
- " \n",
- " | 15 | \n",
- " 367.264706 | \n",
- " 0.397862 | \n",
- " 0.601703 | \n",
- "
\n",
- " \n",
- " | 16 | \n",
- " 367.382353 | \n",
- " 0.415821 | \n",
- " 0.630930 | \n",
- "
\n",
- " \n",
- " | 17 | \n",
- " 367.500000 | \n",
- " 0.420667 | \n",
- " 0.640380 | \n",
- "
\n",
- " \n",
- " | 18 | \n",
- " 367.617647 | \n",
- " 0.391683 | \n",
- " 0.598214 | \n",
- "
\n",
- " \n",
- " | 19 | \n",
- " 367.735294 | \n",
- " 0.404903 | \n",
- " 0.620432 | \n",
- "
\n",
- " \n",
- " | 20 | \n",
- " 367.852941 | \n",
- " 0.409563 | \n",
- " 0.629626 | \n",
- "
\n",
- " \n",
- " | 21 | \n",
- " 367.970588 | \n",
- " 0.389488 | \n",
- " 0.600722 | \n",
- "
\n",
- " \n",
- " | 22 | \n",
- " 368.000000 | \n",
- " 0.396789 | \n",
- " 0.612483 | \n",
- "
\n",
- " \n",
- " | 23 | \n",
- " 368.088235 | \n",
- " 0.398162 | \n",
- " 0.616106 | \n",
- "
\n",
- " \n",
- " | 24 | \n",
- " 368.205882 | \n",
- " 0.362340 | \n",
- " 0.562505 | \n",
- "
\n",
- " \n",
- " | 25 | \n",
- " 368.323529 | \n",
- " 0.386958 | \n",
- " 0.602680 | \n",
- "
\n",
- " \n",
- " | 26 | \n",
- " 368.441176 | \n",
- " 0.363643 | \n",
- " 0.568210 | \n",
- "
\n",
- " \n",
- " | 27 | \n",
- " 368.558824 | \n",
- " 0.368118 | \n",
- " 0.577072 | \n",
- "
\n",
- " \n",
- " | 28 | \n",
- " 368.676471 | \n",
- " 0.384098 | \n",
- " 0.604078 | \n",
- "
\n",
- " \n",
- " | 29 | \n",
- " 368.794118 | \n",
- " 0.353605 | \n",
- " 0.557925 | \n",
- "
\n",
- " \n",
- " | 30 | \n",
- " 368.911765 | \n",
- " 0.346474 | \n",
- " 0.548445 | \n",
- "
\n",
- " \n",
- " | 31 | \n",
- " 369.029412 | \n",
- " 0.350741 | \n",
- " 0.556996 | \n",
- "
\n",
- " \n",
- " | 32 | \n",
- " 369.147059 | \n",
- " 0.362347 | \n",
- " 0.577286 | \n",
- "
\n",
- " \n",
- " | 33 | \n",
- " 369.264706 | \n",
- " 0.362578 | \n",
- " 0.579519 | \n",
- "
\n",
- " \n",
- " | 34 | \n",
- " 369.382353 | \n",
- " 0.340765 | \n",
- " 0.546411 | \n",
- "
\n",
- " \n",
- " | 35 | \n",
- " 369.500000 | \n",
- " 0.337462 | \n",
- " 0.542857 | \n",
- "
\n",
- " \n",
- " | 36 | \n",
- " 369.617647 | \n",
- " 0.355729 | \n",
- " 0.574083 | \n",
- "
\n",
- " \n",
- " | 37 | \n",
- " 369.735294 | \n",
- " 0.348679 | \n",
- " 0.564513 | \n",
- "
\n",
- " \n",
- " | 38 | \n",
- " 369.852941 | \n",
- " 0.338187 | \n",
- " 0.549284 | \n",
- "
\n",
- " \n",
- " | 39 | \n",
- " 369.970588 | \n",
- " 0.324360 | \n",
- " 0.528514 | \n",
- "
\n",
- " \n",
- " | 40 | \n",
- " 370.088235 | \n",
- " 0.310753 | \n",
- " 0.507964 | \n",
- "
\n",
- " \n",
- " | 41 | \n",
- " 370.205882 | \n",
- " 0.311037 | \n",
- " 0.510055 | \n",
- "
\n",
- " \n",
- " | 42 | \n",
- " 370.323529 | \n",
- " 0.311263 | \n",
- " 0.512055 | \n",
- "
\n",
- " \n",
- " | 43 | \n",
- " 370.441176 | \n",
- " 0.308081 | \n",
- " 0.508437 | \n",
- "
\n",
- " \n",
- " | 44 | \n",
- " 370.558824 | \n",
- " 0.308224 | \n",
- " 0.510293 | \n",
- "
\n",
- " \n",
- " | 45 | \n",
- " 370.676471 | \n",
- " 0.318148 | \n",
- " 0.528399 | \n",
- "
\n",
- " \n",
- " | 46 | \n",
- " 370.794118 | \n",
- " 0.308334 | \n",
- " 0.513728 | \n",
- "
\n",
- " \n",
- " | 47 | \n",
- " 370.911765 | \n",
- " 0.317937 | \n",
- " 0.531410 | \n",
- "
\n",
- " \n",
- " | 48 | \n",
- " 371.029412 | \n",
- " 0.289149 | \n",
- " 0.484824 | \n",
- "
\n",
- " \n",
- " | 49 | \n",
- " 371.147059 | \n",
- " 0.298637 | \n",
- " 0.502318 | \n",
- "
\n",
- " \n",
- "
\n",
- "
"
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "In the next cell, we import `parmest` from Pyomo and the `pandas` package. We need `pandas` as `parmest` uses `pandas.dataframe` for handling the input data and the results."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 5,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "import pyomo.contrib.parmest.parmest as parmest\n",
+ "import pandas as pd"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Setting up an initialized model\n",
+ "\n",
+ "We need to provide a method that returns an initialized model to the `parmest` tool in Pyomo."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "\n",
+ "Inline Exercise:\n",
+ "Using what you have learned from previous modules, fill in the missing code below to return an initialized IDAES model. \n",
+ "
"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 7,
+ "metadata": {
+ "tags": [
+ "solution"
+ ]
+ },
+ "outputs": [],
+ "source": [
+ "def NRTL_model(data):\n",
+ "\n",
+ " # Todo: Create a ConcreteModel object\n",
+ " m = ConcreteModel()\n",
+ "\n",
+ " # Todo: Create FlowsheetBlock object\n",
+ " m.fs = FlowsheetBlock(dynamic=False)\n",
+ "\n",
+ " # Todo: Create a properties parameter object with the following options:\n",
+ " # \"valid_phase\": ('Liq', 'Vap')\n",
+ " # \"activity_coeff_model\": 'NRTL'\n",
+ " m.fs.properties = BTXParameterBlock(\n",
+ " valid_phase=(\"Liq\", \"Vap\"), activity_coeff_model=\"NRTL\"\n",
+ " )\n",
+ " m.fs.flash = Flash(property_package=m.fs.properties)\n",
+ "\n",
+ " # Initialize at a certain inlet condition\n",
+ " m.fs.flash.inlet.flow_mol.fix(1)\n",
+ " m.fs.flash.inlet.temperature.fix(368)\n",
+ " m.fs.flash.inlet.pressure.fix(101325)\n",
+ " m.fs.flash.inlet.mole_frac_comp[0, \"benzene\"].fix(0.5)\n",
+ " m.fs.flash.inlet.mole_frac_comp[0, \"toluene\"].fix(0.5)\n",
+ "\n",
+ " # Set Flash unit specifications\n",
+ " m.fs.flash.heat_duty.fix(0)\n",
+ " m.fs.flash.deltaP.fix(0)\n",
+ "\n",
+ " # Fix NRTL specific variables\n",
+ " # alpha values (set at 0.3)\n",
+ " m.fs.properties.alpha[\"benzene\", \"benzene\"].fix(0)\n",
+ " m.fs.properties.alpha[\"benzene\", \"toluene\"].fix(0.3)\n",
+ " m.fs.properties.alpha[\"toluene\", \"toluene\"].fix(0)\n",
+ " m.fs.properties.alpha[\"toluene\", \"benzene\"].fix(0.3)\n",
+ "\n",
+ " # initial tau values\n",
+ " m.fs.properties.tau[\"benzene\", \"benzene\"].fix(0)\n",
+ " m.fs.properties.tau[\"benzene\", \"toluene\"].fix(-0.9)\n",
+ " m.fs.properties.tau[\"toluene\", \"toluene\"].fix(0)\n",
+ " m.fs.properties.tau[\"toluene\", \"benzene\"].fix(1.4)\n",
+ "\n",
+ " # Initialize the flash unit\n",
+ " m.fs.flash.initialize(outlvl=idaeslog.INFO_LOW)\n",
+ "\n",
+ " # Fix at actual temperature\n",
+ " if isinstance(data, dict) or isinstance(data, pd.Series):\n",
+ " m.fs.flash.inlet.temperature.fix(float(data[\"temperature\"]))\n",
+ " elif isinstance(data, pd.DataFrame):\n",
+ " m.fs.flash.inlet.temperature.fix(float(data.iloc[0][\"temperature\"]))\n",
+ " else:\n",
+ " raise ValueError(\"Unrecognized data type.\")\n",
+ "\n",
+ " # Set bounds on variables to be estimated\n",
+ " m.fs.properties.tau[\"benzene\", \"toluene\"].setlb(-5)\n",
+ " m.fs.properties.tau[\"benzene\", \"toluene\"].setub(5)\n",
+ "\n",
+ " m.fs.properties.tau[\"toluene\", \"benzene\"].setlb(-5)\n",
+ " m.fs.properties.tau[\"toluene\", \"benzene\"].setub(5)\n",
+ "\n",
+ " # Return initialized flash model\n",
+ " return m"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Parameter estimation using parmest"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "In addition to providing a method to return an initialized model, the `parmest` tool needs the following:\n",
+ "\n",
+ "* Experiment class to set up and label model with suffixes\n",
+ "* Dataset with multiple scenarios - organized into an experiment list"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Here we build an experiment class to label our model problem for parameter estimation. The labels are defined as a `Suffix`, and the main labels for our model are `experiment_outputs`, `unknown_parameters`, and `measurement_error`.\n",
+ "\n",
+ "For this problem, the error will be computed for the mole fraction of benzene in the vapor and liquid phase between the model prediction and data. The `experimental_outputs` will therefore be the mole fraction of benzene in the two phases.\n",
+ "\n",
+ "In this example, we only estimate the binary interaction parameter (`tau_ij`). Given that this variable is usually indexed as `tau_ij = Var(component_list, component_list)`, there are 2*2=4 degrees of freedom. However, when i=j, the binary interaction parameter is 0. Therefore, in this problem, we estimate the binary interaction parameter for the following variables only:\n",
+ "\n",
+ "* fs.properties.tau['benzene', 'toluene']\n",
+ "* fs.properties.tau['toluene', 'benzene']\n",
+ "\n",
+ "As shown below, these model components are used as our `unknown_parameters`.\n",
+ "\n",
+ "We define `measurement_error` as none so parmest calculates the value internally based on the experimental outputs. Refer to https://pyomo.readthedocs.io/en/stable/explanation/analysis/parmest/driver.html for more information. "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 9,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Build an experiment class to take advantage of new parmest interface\n",
+ "from pyomo.contrib.parmest.experiment import Experiment\n",
+ "\n",
+ "\n",
+ "class NRTLExperiment(Experiment):\n",
+ " \"\"\"Experiment class for parameter estimation of NRTL model using parmest\"\"\"\n",
+ "\n",
+ " def __init__(self, data, meas_error=None):\n",
+ " \"\"\"Initialize the NRTLExperiment class\n",
+ "\n",
+ " Args:\n",
+ " data: DataFrame containing the experimental data\n",
+ " meas_error: Measurement error for the data (optional)\n",
+ " \"\"\"\n",
+ " self.model = None\n",
+ " self.data = data\n",
+ " self.meas_error = meas_error\n",
+ "\n",
+ " def create_model(self):\n",
+ " \"\"\"Create the Pyomo model for the NRTL parameter estimation problem\"\"\"\n",
+ " self.model = NRTL_model(self.data)\n",
+ "\n",
+ " def label_model(self):\n",
+ " m = self.model\n",
+ "\n",
+ " # Add experiment outputs to the model for easier access\n",
+ " m.experiment_outputs = Suffix(direction=Suffix.LOCAL)\n",
+ " m.experiment_outputs.update(\n",
+ " [\n",
+ " (\n",
+ " m.fs.flash.liq_outlet.mole_frac_comp[0, \"benzene\"],\n",
+ " self.data[\"liq_benzene\"],\n",
+ " ),\n",
+ " (\n",
+ " m.fs.flash.vap_outlet.mole_frac_comp[0, \"benzene\"],\n",
+ " self.data[\"vap_benzene\"],\n",
+ " ),\n",
+ " ]\n",
+ " )\n",
+ "\n",
+ " m.measurement_error = Suffix(direction=Suffix.LOCAL)\n",
+ " m.measurement_error.update(\n",
+ " [\n",
+ " (m.fs.flash.liq_outlet.mole_frac_comp[0, \"benzene\"], self.meas_error),\n",
+ " (m.fs.flash.vap_outlet.mole_frac_comp[0, \"benzene\"], self.meas_error),\n",
+ " ]\n",
+ " )\n",
+ "\n",
+ " # Add unknown parameters to the model for easier access\n",
+ " m.unknown_parameters = Suffix(direction=Suffix.LOCAL)\n",
+ " m.unknown_parameters.update(\n",
+ " (k, value(k))\n",
+ " for k in [\n",
+ " m.fs.properties.tau[\"benzene\", \"toluene\"],\n",
+ " m.fs.properties.tau[\"toluene\", \"benzene\"],\n",
+ " ]\n",
+ " )\n",
+ "\n",
+ " def get_labeled_model(self):\n",
+ " \"\"\"Return the labeled model\"\"\"\n",
+ " if self.model is None:\n",
+ " self.create_model()\n",
+ " self.label_model()\n",
+ " return self.model"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Pyomo's `parmest` tool supports the following data formats:\n",
+ "- pandas dataframe\n",
+ "- list of dictionaries\n",
+ "- list of json file names.\n",
+ "\n",
+ "Please see the documentation for more details. \n",
+ "\n",
+ "For this example, we load data from the csv file `BT_NRTL_dataset.csv`. The dataset consists of fifty data points which provide the mole fraction of benzene in the vapor and liquid phase as a function of temperature. "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 10,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " temperature | \n",
+ " liq_benzene | \n",
+ " vap_benzene | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 0 | \n",
+ " 365.500000 | \n",
+ " 0.480953 | \n",
+ " 0.692110 | \n",
+ "
\n",
+ " \n",
+ " | 1 | \n",
+ " 365.617647 | \n",
+ " 0.462444 | \n",
+ " 0.667699 | \n",
+ "
\n",
+ " \n",
+ " | 2 | \n",
+ " 365.735294 | \n",
+ " 0.477984 | \n",
+ " 0.692441 | \n",
+ "
\n",
+ " \n",
+ " | 3 | \n",
+ " 365.852941 | \n",
+ " 0.440547 | \n",
+ " 0.640336 | \n",
+ "
\n",
+ " \n",
+ " | 4 | \n",
+ " 365.970588 | \n",
+ " 0.427421 | \n",
+ " 0.623328 | \n",
+ "
\n",
+ " \n",
+ " | 5 | \n",
+ " 366.088235 | \n",
+ " 0.442725 | \n",
+ " 0.647796 | \n",
+ "
\n",
+ " \n",
+ " | 6 | \n",
+ " 366.205882 | \n",
+ " 0.434374 | \n",
+ " 0.637691 | \n",
+ "
\n",
+ " \n",
+ " | 7 | \n",
+ " 366.323529 | \n",
+ " 0.444642 | \n",
+ " 0.654933 | \n",
+ "
\n",
+ " \n",
+ " | 8 | \n",
+ " 366.441176 | \n",
+ " 0.427132 | \n",
+ " 0.631229 | \n",
+ "
\n",
+ " \n",
+ " | 9 | \n",
+ " 366.558824 | \n",
+ " 0.446301 | \n",
+ " 0.661743 | \n",
+ "
\n",
+ " \n",
+ " | 10 | \n",
+ " 366.676471 | \n",
+ " 0.438004 | \n",
+ " 0.651591 | \n",
+ "
\n",
+ " \n",
+ " | 11 | \n",
+ " 366.794118 | \n",
+ " 0.425320 | \n",
+ " 0.634814 | \n",
+ "
\n",
+ " \n",
+ " | 12 | \n",
+ " 366.911765 | \n",
+ " 0.439435 | \n",
+ " 0.658047 | \n",
+ "
\n",
+ " \n",
+ " | 13 | \n",
+ " 367.029412 | \n",
+ " 0.435655 | \n",
+ " 0.654539 | \n",
+ "
\n",
+ " \n",
+ " | 14 | \n",
+ " 367.147059 | \n",
+ " 0.401350 | \n",
+ " 0.604987 | \n",
+ "
\n",
+ " \n",
+ " | 15 | \n",
+ " 367.264706 | \n",
+ " 0.397862 | \n",
+ " 0.601703 | \n",
+ "
\n",
+ " \n",
+ " | 16 | \n",
+ " 367.382353 | \n",
+ " 0.415821 | \n",
+ " 0.630930 | \n",
+ "
\n",
+ " \n",
+ " | 17 | \n",
+ " 367.500000 | \n",
+ " 0.420667 | \n",
+ " 0.640380 | \n",
+ "
\n",
+ " \n",
+ " | 18 | \n",
+ " 367.617647 | \n",
+ " 0.391683 | \n",
+ " 0.598214 | \n",
+ "
\n",
+ " \n",
+ " | 19 | \n",
+ " 367.735294 | \n",
+ " 0.404903 | \n",
+ " 0.620432 | \n",
+ "
\n",
+ " \n",
+ " | 20 | \n",
+ " 367.852941 | \n",
+ " 0.409563 | \n",
+ " 0.629626 | \n",
+ "
\n",
+ " \n",
+ " | 21 | \n",
+ " 367.970588 | \n",
+ " 0.389488 | \n",
+ " 0.600722 | \n",
+ "
\n",
+ " \n",
+ " | 22 | \n",
+ " 368.000000 | \n",
+ " 0.396789 | \n",
+ " 0.612483 | \n",
+ "
\n",
+ " \n",
+ " | 23 | \n",
+ " 368.088235 | \n",
+ " 0.398162 | \n",
+ " 0.616106 | \n",
+ "
\n",
+ " \n",
+ " | 24 | \n",
+ " 368.205882 | \n",
+ " 0.362340 | \n",
+ " 0.562505 | \n",
+ "
\n",
+ " \n",
+ " | 25 | \n",
+ " 368.323529 | \n",
+ " 0.386958 | \n",
+ " 0.602680 | \n",
+ "
\n",
+ " \n",
+ " | 26 | \n",
+ " 368.441176 | \n",
+ " 0.363643 | \n",
+ " 0.568210 | \n",
+ "
\n",
+ " \n",
+ " | 27 | \n",
+ " 368.558824 | \n",
+ " 0.368118 | \n",
+ " 0.577072 | \n",
+ "
\n",
+ " \n",
+ " | 28 | \n",
+ " 368.676471 | \n",
+ " 0.384098 | \n",
+ " 0.604078 | \n",
+ "
\n",
+ " \n",
+ " | 29 | \n",
+ " 368.794118 | \n",
+ " 0.353605 | \n",
+ " 0.557925 | \n",
+ "
\n",
+ " \n",
+ " | 30 | \n",
+ " 368.911765 | \n",
+ " 0.346474 | \n",
+ " 0.548445 | \n",
+ "
\n",
+ " \n",
+ " | 31 | \n",
+ " 369.029412 | \n",
+ " 0.350741 | \n",
+ " 0.556996 | \n",
+ "
\n",
+ " \n",
+ " | 32 | \n",
+ " 369.147059 | \n",
+ " 0.362347 | \n",
+ " 0.577286 | \n",
+ "
\n",
+ " \n",
+ " | 33 | \n",
+ " 369.264706 | \n",
+ " 0.362578 | \n",
+ " 0.579519 | \n",
+ "
\n",
+ " \n",
+ " | 34 | \n",
+ " 369.382353 | \n",
+ " 0.340765 | \n",
+ " 0.546411 | \n",
+ "
\n",
+ " \n",
+ " | 35 | \n",
+ " 369.500000 | \n",
+ " 0.337462 | \n",
+ " 0.542857 | \n",
+ "
\n",
+ " \n",
+ " | 36 | \n",
+ " 369.617647 | \n",
+ " 0.355729 | \n",
+ " 0.574083 | \n",
+ "
\n",
+ " \n",
+ " | 37 | \n",
+ " 369.735294 | \n",
+ " 0.348679 | \n",
+ " 0.564513 | \n",
+ "
\n",
+ " \n",
+ " | 38 | \n",
+ " 369.852941 | \n",
+ " 0.338187 | \n",
+ " 0.549284 | \n",
+ "
\n",
+ " \n",
+ " | 39 | \n",
+ " 369.970588 | \n",
+ " 0.324360 | \n",
+ " 0.528514 | \n",
+ "
\n",
+ " \n",
+ " | 40 | \n",
+ " 370.088235 | \n",
+ " 0.310753 | \n",
+ " 0.507964 | \n",
+ "
\n",
+ " \n",
+ " | 41 | \n",
+ " 370.205882 | \n",
+ " 0.311037 | \n",
+ " 0.510055 | \n",
+ "
\n",
+ " \n",
+ " | 42 | \n",
+ " 370.323529 | \n",
+ " 0.311263 | \n",
+ " 0.512055 | \n",
+ "
\n",
+ " \n",
+ " | 43 | \n",
+ " 370.441176 | \n",
+ " 0.308081 | \n",
+ " 0.508437 | \n",
+ "
\n",
+ " \n",
+ " | 44 | \n",
+ " 370.558824 | \n",
+ " 0.308224 | \n",
+ " 0.510293 | \n",
+ "
\n",
+ " \n",
+ " | 45 | \n",
+ " 370.676471 | \n",
+ " 0.318148 | \n",
+ " 0.528399 | \n",
+ "
\n",
+ " \n",
+ " | 46 | \n",
+ " 370.794118 | \n",
+ " 0.308334 | \n",
+ " 0.513728 | \n",
+ "
\n",
+ " \n",
+ " | 47 | \n",
+ " 370.911765 | \n",
+ " 0.317937 | \n",
+ " 0.531410 | \n",
+ "
\n",
+ " \n",
+ " | 48 | \n",
+ " 371.029412 | \n",
+ " 0.289149 | \n",
+ " 0.484824 | \n",
+ "
\n",
+ " \n",
+ " | 49 | \n",
+ " 371.147059 | \n",
+ " 0.298637 | \n",
+ " 0.502318 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " temperature liq_benzene vap_benzene\n",
+ "0 365.500000 0.480953 0.692110\n",
+ "1 365.617647 0.462444 0.667699\n",
+ "2 365.735294 0.477984 0.692441\n",
+ "3 365.852941 0.440547 0.640336\n",
+ "4 365.970588 0.427421 0.623328\n",
+ "5 366.088235 0.442725 0.647796\n",
+ "6 366.205882 0.434374 0.637691\n",
+ "7 366.323529 0.444642 0.654933\n",
+ "8 366.441176 0.427132 0.631229\n",
+ "9 366.558824 0.446301 0.661743\n",
+ "10 366.676471 0.438004 0.651591\n",
+ "11 366.794118 0.425320 0.634814\n",
+ "12 366.911765 0.439435 0.658047\n",
+ "13 367.029412 0.435655 0.654539\n",
+ "14 367.147059 0.401350 0.604987\n",
+ "15 367.264706 0.397862 0.601703\n",
+ "16 367.382353 0.415821 0.630930\n",
+ "17 367.500000 0.420667 0.640380\n",
+ "18 367.617647 0.391683 0.598214\n",
+ "19 367.735294 0.404903 0.620432\n",
+ "20 367.852941 0.409563 0.629626\n",
+ "21 367.970588 0.389488 0.600722\n",
+ "22 368.000000 0.396789 0.612483\n",
+ "23 368.088235 0.398162 0.616106\n",
+ "24 368.205882 0.362340 0.562505\n",
+ "25 368.323529 0.386958 0.602680\n",
+ "26 368.441176 0.363643 0.568210\n",
+ "27 368.558824 0.368118 0.577072\n",
+ "28 368.676471 0.384098 0.604078\n",
+ "29 368.794118 0.353605 0.557925\n",
+ "30 368.911765 0.346474 0.548445\n",
+ "31 369.029412 0.350741 0.556996\n",
+ "32 369.147059 0.362347 0.577286\n",
+ "33 369.264706 0.362578 0.579519\n",
+ "34 369.382353 0.340765 0.546411\n",
+ "35 369.500000 0.337462 0.542857\n",
+ "36 369.617647 0.355729 0.574083\n",
+ "37 369.735294 0.348679 0.564513\n",
+ "38 369.852941 0.338187 0.549284\n",
+ "39 369.970588 0.324360 0.528514\n",
+ "40 370.088235 0.310753 0.507964\n",
+ "41 370.205882 0.311037 0.510055\n",
+ "42 370.323529 0.311263 0.512055\n",
+ "43 370.441176 0.308081 0.508437\n",
+ "44 370.558824 0.308224 0.510293\n",
+ "45 370.676471 0.318148 0.528399\n",
+ "46 370.794118 0.308334 0.513728\n",
+ "47 370.911765 0.317937 0.531410\n",
+ "48 371.029412 0.289149 0.484824\n",
+ "49 371.147059 0.298637 0.502318"
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ }
],
- "text/plain": [
- " temperature liq_benzene vap_benzene\n",
- "0 365.500000 0.480953 0.692110\n",
- "1 365.617647 0.462444 0.667699\n",
- "2 365.735294 0.477984 0.692441\n",
- "3 365.852941 0.440547 0.640336\n",
- "4 365.970588 0.427421 0.623328\n",
- "5 366.088235 0.442725 0.647796\n",
- "6 366.205882 0.434374 0.637691\n",
- "7 366.323529 0.444642 0.654933\n",
- "8 366.441176 0.427132 0.631229\n",
- "9 366.558824 0.446301 0.661743\n",
- "10 366.676471 0.438004 0.651591\n",
- "11 366.794118 0.425320 0.634814\n",
- "12 366.911765 0.439435 0.658047\n",
- "13 367.029412 0.435655 0.654539\n",
- "14 367.147059 0.401350 0.604987\n",
- "15 367.264706 0.397862 0.601703\n",
- "16 367.382353 0.415821 0.630930\n",
- "17 367.500000 0.420667 0.640380\n",
- "18 367.617647 0.391683 0.598214\n",
- "19 367.735294 0.404903 0.620432\n",
- "20 367.852941 0.409563 0.629626\n",
- "21 367.970588 0.389488 0.600722\n",
- "22 368.000000 0.396789 0.612483\n",
- "23 368.088235 0.398162 0.616106\n",
- "24 368.205882 0.362340 0.562505\n",
- "25 368.323529 0.386958 0.602680\n",
- "26 368.441176 0.363643 0.568210\n",
- "27 368.558824 0.368118 0.577072\n",
- "28 368.676471 0.384098 0.604078\n",
- "29 368.794118 0.353605 0.557925\n",
- "30 368.911765 0.346474 0.548445\n",
- "31 369.029412 0.350741 0.556996\n",
- "32 369.147059 0.362347 0.577286\n",
- "33 369.264706 0.362578 0.579519\n",
- "34 369.382353 0.340765 0.546411\n",
- "35 369.500000 0.337462 0.542857\n",
- "36 369.617647 0.355729 0.574083\n",
- "37 369.735294 0.348679 0.564513\n",
- "38 369.852941 0.338187 0.549284\n",
- "39 369.970588 0.324360 0.528514\n",
- "40 370.088235 0.310753 0.507964\n",
- "41 370.205882 0.311037 0.510055\n",
- "42 370.323529 0.311263 0.512055\n",
- "43 370.441176 0.308081 0.508437\n",
- "44 370.558824 0.308224 0.510293\n",
- "45 370.676471 0.318148 0.528399\n",
- "46 370.794118 0.308334 0.513728\n",
- "47 370.911765 0.317937 0.531410\n",
- "48 371.029412 0.289149 0.484824\n",
- "49 371.147059 0.298637 0.502318"
+ "source": [
+ "# Load data from csv\n",
+ "data = pd.read_csv(\"BT_NRTL_dataset.csv\")\n",
+ "\n",
+ "# Display the dataset\n",
+ "display(data)"
]
- },
- "metadata": {},
- "output_type": "display_data"
- }
- ],
- "source": [
- "# Load data from csv\n",
- "data = pd.read_csv(\"BT_NRTL_dataset.csv\")\n",
- "\n",
- "# Display the dataset\n",
- "display(data)"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "We need to provide a method to return an expression to compute the sum of squared errors that will be used as the objective in solving the parameter estimation problem. For this problem, the error will be computed for the mole fraction of benzene in the vapor and liquid phase between the model prediction and data. \n",
- "\n",
- "\n",
- "Inline Exercise:\n",
- "Complete the following cell by adding an expression to compute the sum of square errors. \n",
- "
"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 8,
- "metadata": {
- "tags": [
- "solution"
- ]
- },
- "outputs": [],
- "source": [
- "# Create method to return an expression that computes the sum of squared error\n",
- "def SSE(m, data):\n",
- " # Todo: Add expression for computing the sum of squared errors in mole fraction of benzene in the liquid\n",
- " # and vapor phase. For example, the squared error for the vapor phase is:\n",
- " # (float(data[\"vap_benzene\"]) - m.fs.flash.vap_outlet.mole_frac_comp[0, \"benzene\"])**2\n",
- " expr = (\n",
- " float(data[\"vap_benzene\"]) - m.fs.flash.vap_outlet.mole_frac_comp[0, \"benzene\"]\n",
- " ) ** 2 + (\n",
- " float(data[\"liq_benzene\"]) - m.fs.flash.liq_outlet.mole_frac_comp[0, \"benzene\"]\n",
- " ) ** 2\n",
- " return expr * 1e4"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "\n",
- "Note:\n",
- "Notice that we have scaled the expression up by a factor of 10000 as the SSE computed here will be an extremely small number given that we are using the difference in mole fraction in our expression. A well-scaled objective will help improve solve robustness when using IPOPT. \n",
- "
\n"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "We are now ready to set up the parameter estimation problem. We will create a parameter estimation object called `pest`. As shown below, we pass the method that returns an initialized model, dataset, list of variable names to estimate, and the SSE expression to the Estimator object. `tee=True` will print the solver output after solving the parameter estimation problem."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 9,
- "metadata": {},
- "outputs": [
+ },
{
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "C:\\Users\\dkgun\\AppData\\Local\\Temp\\ipykernel_36352\\1862275024.py:45: FutureWarning: Calling float on a single element Series is deprecated and will raise a TypeError in the future. Use float(ser.iloc[0]) instead\n",
- " m.fs.flash.inlet.temperature.fix(float(data[\"temperature\"]))\n",
- "C:\\Users\\dkgun\\AppData\\Local\\Temp\\ipykernel_36352\\2860104238.py:7: FutureWarning: Calling float on a single element Series is deprecated and will raise a TypeError in the future. Use float(ser.iloc[0]) instead\n",
- " float(data[\"vap_benzene\"]) - m.fs.flash.vap_outlet.mole_frac_comp[0, \"benzene\"]\n",
- "C:\\Users\\dkgun\\AppData\\Local\\Temp\\ipykernel_36352\\2860104238.py:9: FutureWarning: Calling float on a single element Series is deprecated and will raise a TypeError in the future. Use float(ser.iloc[0]) instead\n",
- " float(data[\"liq_benzene\"]) - m.fs.flash.liq_outlet.mole_frac_comp[0, \"benzene\"]\n"
- ]
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "We define the `exp_list` by splitting the data into individual experiments, or data points."
+ ]
},
{
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Ipopt 3.13.2: \n",
- "\n",
- "******************************************************************************\n",
- "This program contains Ipopt, a library for large-scale nonlinear optimization.\n",
- " Ipopt is released as open source code under the Eclipse Public License (EPL).\n",
- " For more information visit http://projects.coin-or.org/Ipopt\n",
- "\n",
- "This version of Ipopt was compiled from source code available at\n",
- " https://github.com/IDAES/Ipopt as part of the Institute for the Design of\n",
- " Advanced Energy Systems Process Systems Engineering Framework (IDAES PSE\n",
- " Framework) Copyright (c) 2018-2019. See https://github.com/IDAES/idaes-pse.\n",
- "\n",
- "This version of Ipopt was compiled using HSL, a collection of Fortran codes\n",
- " for large-scale scientific computation. All technical papers, sales and\n",
- " publicity material resulting from use of the HSL codes within IPOPT must\n",
- " contain the following acknowledgement:\n",
- " HSL, a collection of Fortran codes for large-scale scientific\n",
- " computation. See http://www.hsl.rl.ac.uk.\n",
- "******************************************************************************\n",
- "\n",
- "This is Ipopt version 3.13.2, running with linear solver ma27.\n",
- "\n",
- "Number of nonzeros in equality constraint Jacobian...: 10946\n",
- "Number of nonzeros in inequality constraint Jacobian.: 0\n",
- "Number of nonzeros in Lagrangian Hessian.............: 6600\n",
- "\n",
- "Total number of variables............................: 2950\n",
- " variables with only lower bounds: 150\n",
- " variables with lower and upper bounds: 600\n",
- " variables with only upper bounds: 0\n",
- "Total number of equality constraints.................: 2948\n",
- "Total number of inequality constraints...............: 0\n",
- " inequality constraints with only lower bounds: 0\n",
- " inequality constraints with lower and upper bounds: 0\n",
- " inequality constraints with only upper bounds: 0\n",
- "\n",
- "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
- " 0 6.0671019e+01 5.63e+02 1.08e-04 -1.0 0.00e+00 - 0.00e+00 0.00e+00 0\n",
- " 1 5.0339335e+00 1.57e+03 7.47e+01 -1.0 1.37e+04 - 9.45e-01 1.00e+00h 1\n",
- " 2 5.1535704e+00 1.93e+02 4.59e+02 -1.0 5.54e+02 -4.0 9.90e-01 1.00e+00h 1\n",
- " 3 5.1392848e+00 1.07e+00 3.40e+01 -1.0 6.17e+01 -4.5 9.92e-01 1.00e+00h 1\n",
- " 4 5.1359488e+00 3.65e+02 2.24e+01 -1.0 8.41e+02 - 1.00e+00 1.00e+00h 1\n",
- " 5 5.1198699e+00 1.64e+00 1.32e-01 -1.0 3.65e+02 - 1.00e+00 1.00e+00h 1\n",
- " 6 5.0735545e+00 1.54e+02 1.83e-01 -2.5 3.80e+02 - 9.96e-01 1.00e+00h 1\n",
- " 7 5.0752210e+00 1.03e+01 5.00e-02 -2.5 9.51e+01 - 1.00e+00 1.00e+00h 1\n",
- " 8 5.0750012e+00 5.57e-03 2.07e-05 -2.5 2.09e-01 - 1.00e+00 1.00e+00h 1\n",
- " 9 5.0749679e+00 5.85e-02 7.21e-04 -3.8 8.43e+00 - 1.00e+00 1.00e+00h 1\n",
- "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
- " 10 5.0749686e+00 5.59e-04 1.05e-05 -5.7 9.63e-01 - 1.00e+00 1.00e+00h 1\n",
- " 11 5.0749686e+00 3.98e-08 1.56e-09 -8.6 7.56e-03 - 1.00e+00 1.00e+00h 1\n",
- "\n",
- "Number of Iterations....: 11\n",
- "\n",
- " (scaled) (unscaled)\n",
- "Objective...............: 5.0749685783045084e+00 5.0749685783045084e+00\n",
- "Dual infeasibility......: 1.5648775501801708e-09 1.5648775501801708e-09\n",
- "Constraint violation....: 1.3843631310512158e-10 3.9843143895268440e-08\n",
- "Complementarity.........: 2.5074825419922871e-09 2.5074825419922871e-09\n",
- "Overall NLP error.......: 2.5074825419922871e-09 3.9843143895268440e-08\n",
- "\n",
- "\n",
- "Number of objective function evaluations = 12\n",
- "Number of objective gradient evaluations = 12\n",
- "Number of equality constraint evaluations = 12\n",
- "Number of inequality constraint evaluations = 0\n",
- "Number of equality constraint Jacobian evaluations = 12\n",
- "Number of inequality constraint Jacobian evaluations = 0\n",
- "Number of Lagrangian Hessian evaluations = 11\n",
- "Total CPU secs in IPOPT (w/o function evaluations) = 0.053\n",
- "Total CPU secs in NLP function evaluations = 0.010\n",
- "\n",
- "EXIT: Optimal Solution Found.\n",
- "\b\b\b\b\b\b\b\b\b\b\b\b\b\b"
- ]
- }
- ],
- "source": [
- "# Initialize a parameter estimation object\n",
- "pest = parmest.Estimator(NRTL_model, data, variable_name, SSE, tee=True)\n",
- "\n",
- "# Run parameter estimation using all data\n",
- "obj_value, parameters = pest.theta_est()"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "You will notice that the resulting parameter estimation problem, when using the flash unit model, will have 2952 variables and 2950 constraints. This is because the unit models in IDAES use control volume blocks which have two state blocks attached; one at the inlet and one at the outlet. Even though there are two state blocks, they still use the same parameter block i.e. `m.fs.properties` in our example which is where our parameters that need to be estimated exist. \n",
- "\n",
- "Let us display the results by running the next cell. "
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 10,
- "metadata": {},
- "outputs": [
+ "cell_type": "code",
+ "execution_count": 11,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Loop through the dataset and create an experiment for each row of data\n",
+ "exp_list = []\n",
+ "for i in range(data.shape[0]):\n",
+ " exp_list.append(NRTLExperiment(data.iloc[i]))"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "We are now ready to set up the parameter estimation problem. We will create a parameter estimation object called pest. As shown below, we pass the experiment list, and an objective function to the Estimator method. tee=True will print the solver output after solving the parameter estimation problem."
+ ]
+ },
{
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "The SSE at the optimal solution is 0.000507\n",
- "\n",
- "The values for the parameters are as follows:\n",
- "fs.properties.tau[benzene,toluene] = -0.8987624039723903\n",
- "fs.properties.tau[toluene,benzene] = 1.410486110660486\n"
- ]
+ "cell_type": "code",
+ "execution_count": 12,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Ipopt 3.13.2: \n",
+ "\n",
+ "******************************************************************************\n",
+ "This program contains Ipopt, a library for large-scale nonlinear optimization.\n",
+ " Ipopt is released as open source code under the Eclipse Public License (EPL).\n",
+ " For more information visit http://projects.coin-or.org/Ipopt\n",
+ "\n",
+ "This version of Ipopt was compiled from source code available at\n",
+ " https://github.com/IDAES/Ipopt as part of the Institute for the Design of\n",
+ " Advanced Energy Systems Process Systems Engineering Framework (IDAES PSE\n",
+ " Framework) Copyright (c) 2018-2019. See https://github.com/IDAES/idaes-pse.\n",
+ "\n",
+ "This version of Ipopt was compiled using HSL, a collection of Fortran codes\n",
+ " for large-scale scientific computation. All technical papers, sales and\n",
+ " publicity material resulting from use of the HSL codes within IPOPT must\n",
+ " contain the following acknowledgement:\n",
+ " HSL, a collection of Fortran codes for large-scale scientific\n",
+ " computation. See http://www.hsl.rl.ac.uk.\n",
+ "******************************************************************************\n",
+ "\n",
+ "This is Ipopt version 3.13.2, running with linear solver ma27.\n",
+ "\n",
+ "Number of nonzeros in equality constraint Jacobian...: 10950\n",
+ "Number of nonzeros in inequality constraint Jacobian.: 0\n",
+ "Number of nonzeros in Lagrangian Hessian.............: 6600\n",
+ "\n",
+ "Total number of variables............................: 2952\n",
+ " variables with only lower bounds: 150\n",
+ " variables with lower and upper bounds: 600\n",
+ " variables with only upper bounds: 0\n",
+ "Total number of equality constraints.................: 2950\n",
+ "Total number of inequality constraints...............: 0\n",
+ " inequality constraints with only lower bounds: 0\n",
+ " inequality constraints with lower and upper bounds: 0\n",
+ " inequality constraints with only upper bounds: 0\n",
+ "\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 0 6.0671019e-03 5.63e+02 1.20e-08 -1.0 0.00e+00 - 0.00e+00 0.00e+00 0\n",
+ " 1 9.0714942e-04 1.37e+03 1.61e+01 -1.0 1.37e+04 - 9.82e-01 1.00e+00h 1\n",
+ " 2 1.3219937e-03 1.17e+04 1.62e+01 -1.0 5.23e+03 - 3.41e-01 1.65e-01h 3\n",
+ " 3 1.3161671e-03 1.11e+04 4.02e+01 -1.0 3.96e+02 -4.0 8.19e-01 1.25e-01h 4\n",
+ " 4 1.3154170e-03 1.11e+04 4.32e+01 -1.0 3.47e+02 -4.5 9.90e-01 4.43e-02h 5\n",
+ " 5 9.4424343e-04 1.04e+04 4.05e+01 -1.0 1.16e+04 - 9.33e-01 5.61e-02h 5\n",
+ " 6 9.4571258e-04 1.11e+04 4.85e+01 -1.0 3.13e+02 -5.0 8.74e-01 1.25e-01h 4\n",
+ " 7 9.4862862e-04 1.11e+04 4.84e+01 -1.0 2.41e+03 -5.4 1.72e-01 1.50e-03h 8\n",
+ " 8 9.5448936e-04 1.10e+04 4.81e+01 -1.0 4.11e+02 -5.0 1.00e+00 1.97e-02h 6\n",
+ " 9 9.5650047e-04 1.10e+04 4.81e+01 -1.0 5.14e+02 -4.6 3.46e-01 5.24e-03h 7\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 10 9.5730419e-04 1.10e+04 4.81e+01 -1.0 9.78e+02 -4.2 4.40e-01 1.08e-03h 8\n",
+ " 11 9.5774182e-04 1.10e+04 4.84e+01 -1.0 2.76e+02 -3.7 2.91e-01 2.99e-03h 7\n",
+ " 12 9.4292855e-04 7.77e+04 4.09e+04 -1.0 5.38e+02 -2.4 5.48e-02 6.44e-02w 1\n",
+ " 13 2.4318219e-01 2.38e+07 4.22e+14 -1.0 1.28e+06 - 2.55e-02 3.49e-02w 1\n",
+ " 14 2.8902019e-01 1.64e+07 2.92e+14 -1.0 1.11e+05 -2.9 9.54e-01 3.01e-01w 1\n",
+ " 15 9.5768293e-04 1.10e+04 4.85e+01 -1.0 2.80e+05 -3.4 5.48e-02 2.52e-04h 8\n",
+ " 16 9.5769345e-04 1.10e+04 4.85e+01 -1.0 4.33e+02 -2.9 7.95e-02 1.91e-04h 9\n",
+ " 17 9.5763809e-04 1.10e+04 4.85e+01 -1.0 6.35e+02 -2.5 4.94e-02 2.08e-04h 9\n",
+ " 18 9.5734836e-04 1.10e+04 4.87e+01 -1.0 3.22e+02 -3.0 1.00e+00 1.22e-03h 8\n",
+ " 19 9.3628114e-04 1.09e+04 4.62e+01 -1.0 4.22e+02 -3.5 5.16e-01 5.87e-02h 5\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 20 7.1894543e-04 4.02e+03 4.95e+02 -1.0 3.49e+02 -3.9 1.00e+00 1.00e+00h 1\n",
+ " 21 6.7062834e-04 1.58e+02 2.21e+02 -1.0 1.78e+02 -4.4 1.00e+00 1.00e+00h 1\n",
+ " 22 6.6635123e-04 4.17e+01 1.12e+01 -1.0 2.44e+02 -4.9 1.00e+00 1.00e+00h 1\n",
+ " 23 6.6729070e-04 1.43e+00 9.69e-01 -1.0 1.08e+01 -5.4 1.00e+00 1.00e+00h 1\n",
+ " 24 6.6785681e-04 3.58e-01 5.25e-03 -1.7 6.65e+00 -5.8 1.00e+00 1.00e+00h 1\n",
+ " 25 6.2552355e-04 9.80e+02 6.48e-02 -3.8 7.92e+02 - 9.22e-01 1.00e+00h 1\n",
+ " 26 5.9105707e-04 8.13e+00 6.13e-04 -3.8 5.66e+02 - 1.00e+00 1.00e+00h 1\n",
+ " 27 6.1313801e-04 6.24e+01 8.08e-06 -3.8 1.70e+02 - 1.00e+00 1.00e+00h 1\n",
+ " 28 6.1208051e-04 3.58e-01 1.18e-08 -3.8 1.88e+00 - 1.00e+00 1.00e+00h 1\n",
+ " 29 5.9010560e-04 1.58e+01 1.00e-05 -5.7 1.08e+02 - 1.00e+00 1.00e+00h 1\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 30 5.9008319e-04 2.74e-02 7.90e-07 -5.7 7.54e-02 -6.3 1.00e+00 1.00e+00h 1\n",
+ " 31 5.3570104e-04 1.48e+04 8.70e-04 -5.7 1.81e+02 - 1.00e+00 1.00e+00h 1\n",
+ " 32 5.1618763e-04 6.29e+02 8.06e-05 -5.7 2.55e+02 - 1.00e+00 1.00e+00h 1\n",
+ " 33 5.5250565e-04 2.88e+01 2.58e-04 -5.7 1.81e+04 - 6.26e-01 6.25e-02h 5\n",
+ " 34 5.2209909e-04 2.88e+02 2.02e-04 -5.7 1.89e+03 - 1.00e+00 1.00e+00h 1\n",
+ " 35 5.0707798e-04 5.60e+01 2.02e-04 -5.7 2.93e+03 - 1.00e+00 1.00e+00h 1\n",
+ " 36 5.0765648e-04 7.87e+00 1.91e-05 -5.7 1.02e+02 - 1.00e+00 1.00e+00h 1\n",
+ " 37 5.0740606e-04 2.57e+00 1.88e-05 -5.7 6.96e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 38 5.0764164e-04 2.55e+00 1.76e-05 -5.7 6.81e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 39 5.0740672e-04 2.55e+00 1.88e-05 -5.7 6.80e+01 - 1.00e+00 1.00e+00h 1\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 40 5.0764162e-04 2.54e+00 1.76e-05 -5.7 6.80e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 41 5.0740672e-04 2.55e+00 1.88e-05 -5.7 6.80e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 42 5.0782847e-04 1.43e-01 1.83e-05 -5.7 6.80e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 43 5.0751252e-04 1.58e-02 1.93e-05 -5.7 6.88e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 44 5.0783218e-04 4.79e-03 1.85e-05 -5.7 6.92e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 45 5.0751252e-04 1.60e-02 1.93e-05 -5.7 6.89e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 46 5.0783222e-04 1.23e-04 1.85e-05 -5.7 6.92e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 47 5.0751252e-04 1.60e-02 1.93e-05 -5.7 6.89e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 48 5.0783216e-04 1.24e-04 1.85e-05 -5.7 6.92e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 49 5.0751765e-04 3.20e-03 1.93e-05 -5.7 6.89e+01 - 1.00e+00 1.00e+00H 1\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 50 5.0764151e-04 2.56e+00 1.77e-05 -5.7 6.93e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 51 5.0740671e-04 2.55e+00 1.88e-05 -5.7 6.81e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 52 5.0764162e-04 2.54e+00 1.76e-05 -5.7 6.80e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 53 5.0740672e-04 2.55e+00 1.88e-05 -5.7 6.80e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 54 5.0764162e-04 2.54e+00 1.76e-05 -5.7 6.80e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 55 5.0748886e-04 1.91e+00 8.64e-06 -5.7 6.80e+01 - 1.00e+00 5.00e-01h 2\n",
+ " 56 5.0744550e-04 3.37e-01 1.64e-05 -5.7 2.54e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 57 5.0763613e-04 1.82e+00 1.43e-05 -5.7 5.79e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 58 5.0751252e-04 2.25e-02 1.93e-05 -5.7 6.65e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 59 5.0783220e-04 1.23e-04 1.85e-05 -5.7 6.92e+01 - 1.00e+00 1.00e+00H 1\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 60 5.0751252e-04 1.60e-02 1.93e-05 -5.7 6.89e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 61 5.0783207e-04 3.26e-04 1.85e-05 -5.7 6.92e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 62 5.0751786e-04 7.95e-05 1.93e-05 -5.7 6.89e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 63 5.0754291e-04 6.40e-01 8.69e-06 -5.7 6.93e+01 - 1.00e+00 5.00e-01h 2\n",
+ " 64 5.0745167e-04 3.00e-01 1.61e-05 -5.7 2.35e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 65 5.0763437e-04 1.71e+00 1.33e-05 -5.7 5.61e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 66 5.0751762e-04 2.91e-03 1.93e-05 -5.7 6.60e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 67 5.0752104e-04 1.62e-01 1.43e-05 -5.7 6.92e+01 - 1.00e+00 2.50e-01h 3\n",
+ " 68 5.0761295e-04 1.03e+00 2.18e-05 -5.7 4.35e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 69 5.0751251e-04 2.38e-02 1.92e-05 -5.7 5.95e+01 - 1.00e+00 1.00e+00H 1\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 70 5.0783210e-04 3.29e-06 1.85e-05 -5.7 6.90e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 71 5.0751786e-04 7.94e-05 1.93e-05 -5.7 6.89e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 72 5.0754292e-04 6.40e-01 8.69e-06 -5.7 6.93e+01 - 1.00e+00 5.00e-01h 2\n",
+ " 73 5.0749299e-04 3.95e-01 1.21e-05 -5.7 2.35e+01 - 1.00e+00 5.00e-01h 2\n",
+ " 74 5.0755524e-04 1.36e-01 3.09e-05 -5.7 1.57e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 75 5.0751308e-04 1.96e-02 1.80e-05 -5.7 3.30e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 76 5.0754492e-04 5.62e-01 8.19e-06 -5.7 6.42e+01 - 1.00e+00 5.00e-01h 2\n",
+ " 77 5.0748301e-04 3.98e-01 1.25e-05 -5.7 2.93e+01 - 1.00e+00 5.00e-01h 2\n",
+ " 78 5.0756455e-04 2.42e-01 3.07e-05 -5.7 2.09e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 79 5.0751710e-04 1.38e-03 1.87e-05 -5.7 3.98e+01 - 1.00e+00 1.00e+00H 1\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 80 5.0783077e-04 3.26e-06 1.84e-05 -5.7 6.70e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 81 5.0726420e-04 1.24e+01 1.85e-05 -8.6 1.34e+02 - 9.93e-01 1.00e+00h 1\n",
+ " 82 5.0749897e-04 2.75e+00 2.53e-06 -8.6 6.93e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 83 5.0749686e-04 3.64e-04 6.40e-10 -8.6 4.69e-02 - 1.00e+00 1.00e+00h 1\n",
+ " 84 5.0749686e-04 7.28e-11 2.51e-14 -8.6 6.86e-05 - 1.00e+00 1.00e+00h 1\n",
+ "\n",
+ "Number of Iterations....: 84\n",
+ "\n",
+ " (scaled) (unscaled)\n",
+ "Objective...............: 5.0749685809243843e-04 5.0749685809243843e-04\n",
+ "Dual infeasibility......: 2.5059195074646584e-14 2.5059195074646584e-14\n",
+ "Constraint violation....: 1.4104644499482425e-11 7.2759576141834259e-11\n",
+ "Complementarity.........: 2.5059035596800647e-09 2.5059035596800647e-09\n",
+ "Overall NLP error.......: 2.5059035596800647e-09 2.5059035596800647e-09\n",
+ "\n",
+ "\n",
+ "Number of objective function evaluations = 260\n",
+ "Number of objective gradient evaluations = 85\n",
+ "Number of equality constraint evaluations = 260\n",
+ "Number of inequality constraint evaluations = 0\n",
+ "Number of equality constraint Jacobian evaluations = 85\n",
+ "Number of inequality constraint Jacobian evaluations = 0\n",
+ "Number of Lagrangian Hessian evaluations = 84\n",
+ "Total CPU secs in IPOPT (w/o function evaluations) = 0.338\n",
+ "Total CPU secs in NLP function evaluations = 0.092\n",
+ "\n",
+ "EXIT: Optimal Solution Found.\n"
+ ]
+ }
+ ],
+ "source": [
+ "import logging\n",
+ "\n",
+ "idaeslog.getIdaesLogger(\"core.property_meta\").setLevel(logging.ERROR)\n",
+ "\n",
+ "pest = parmest.Estimator(exp_list, obj_function=\"SSE\", tee=True)\n",
+ "obj_value, parameters = pest.theta_est()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "You will notice that the resulting parameter estimation problem, when using the flash unit model, will have 2952 variables and 2950 constraints. This is because the unit models in IDAES use control volume blocks which have two state blocks attached; one at the inlet and one at the outlet. Even though there are two state blocks, they still use the same parameter block i.e. `m.fs.properties` in our example which is where our parameters that need to be estimated exist. \n",
+ "\n",
+ "Let us display the results by running the next cell. "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 14,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "The SSE at the optimal solution is 0.000507\n",
+ "\n",
+ "The values for the parameters are as follows:\n",
+ "fs.properties.tau[benzene,toluene] = -0.8987454466579063\n",
+ "fs.properties.tau[toluene,benzene] = 1.410449514796474\n"
+ ]
+ }
+ ],
+ "source": [
+ "print(\"The SSE at the optimal solution is %0.6f\" % (obj_value))\n",
+ "print()\n",
+ "print(\"The values for the parameters are as follows:\")\n",
+ "for k, v in parameters.items():\n",
+ " print(k, \"=\", v)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Using the data that was provided, we have estimated the binary interaction parameters in the NRTL model for a benzene-toluene mixture. Although the dataset that was provided was temperature dependent, in this example we have estimated a single value that fits best for all temperatures."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "### Advanced options for parmest: bootstrapping\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Pyomo's `parmest` tool allows for bootstrapping where the parameter estimation is repeated over `n` samples with resampling from the original data set. Parameter estimation with bootstrap resampling can be used to identify confidence regions around each parameter estimate. This analysis can be slow given the increased number of model instances that need to be solved. Please refer to https://pyomo.readthedocs.io/en/stable/explanation/analysis/parmest/covariance.html#bootstrapping for more details. \n",
+ "\n",
+ "For the example above, the bootstrapping can be run by uncommenting the code in the following cell:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Uncomment the following lines\n",
+ "# bootstrap_theta = pest.theta_est_bootstrap(4, seed=542)\n",
+ "# display(bootstrap_theta)"
+ ]
+ }
+ ],
+ "metadata": {
+ "celltoolbar": "Tags",
+ "kernelspec": {
+ "display_name": "idaes-pse-and-examples-dev-py313-macmini",
+ "language": "python",
+ "name": "python3"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 3
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython3",
+ "version": "3.13.13"
}
- ],
- "source": [
- "print(\"The SSE at the optimal solution is %0.6f\" % (obj_value * 1e-4))\n",
- "print()\n",
- "print(\"The values for the parameters are as follows:\")\n",
- "for k, v in parameters.items():\n",
- " print(k, \"=\", v)"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "Using the data that was provided, we have estimated the binary interaction parameters in the NRTL model for a benzene-toluene mixture. Although the dataset that was provided was temperature dependent, in this example we have estimated a single value that fits best for all temperatures."
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "### Advanced options for parmest: bootstrapping\n",
- "\n"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "Pyomo's `parmest` tool allows for bootstrapping where the parameter estimation is repeated over `n` samples with resampling from the original data set. Parameter estimation with bootstrap resampling can be used to identify confidence regions around each parameter estimate. This analysis can be slow given the increased number of model instances that need to be solved. Please refer to https://pyomo.readthedocs.io/en/stable/contributed_packages/parmest/driver.html for more details. \n",
- "\n",
- "For the example above, the bootstrapping can be run by uncommenting the code in the following cell:"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 11,
- "metadata": {},
- "outputs": [],
- "source": [
- "# Run parameter estimation using bootstrap resample of the data (10 samples),\n",
- "# plot results along with confidence regions\n",
- "\n",
- "# Uncomment the following lines\n",
- "\n",
- "# bootstrap_theta = pest.theta_est_bootstrap(4)\n",
- "# display(bootstrap_theta)"
- ]
- }
- ],
- "metadata": {
- "celltoolbar": "Tags",
- "kernelspec": {
- "display_name": "Python 3 (ipykernel)",
- "language": "python",
- "name": "python3"
},
- "language_info": {
- "codemirror_mode": {
- "name": "ipython",
- "version": 3
- },
- "file_extension": ".py",
- "mimetype": "text/x-python",
- "name": "python",
- "nbconvert_exporter": "python",
- "pygments_lexer": "ipython3",
- "version": "3.11.5"
- }
- },
- "nbformat": 4,
- "nbformat_minor": 3
-}
+ "nbformat": 4,
+ "nbformat_minor": 3
+}
\ No newline at end of file
diff --git a/idaes_examples/notebooks/docs/param_est/parameter_estimation_nrtl_using_unit_model_exercise.ipynb b/idaes_examples/notebooks/docs/param_est/parameter_estimation_nrtl_using_unit_model_exercise.ipynb
index 9ebb2bbd..6eb2aa0a 100644
--- a/idaes_examples/notebooks/docs/param_est/parameter_estimation_nrtl_using_unit_model_exercise.ipynb
+++ b/idaes_examples/notebooks/docs/param_est/parameter_estimation_nrtl_using_unit_model_exercise.ipynb
@@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 1,
"metadata": {
"tags": [
"header",
@@ -16,7 +16,7 @@
"# Framework (IDAES IP) was produced under the DOE Institute for the\n",
"# Design of Advanced Energy Systems (IDAES).\n",
"#\n",
- "# Copyright (c) 2018-2023 by the software owners: The Regents of the\n",
+ "# Copyright (c) 2018-2026 by the software owners: The Regents of the\n",
"# University of California, through Lawrence Berkeley National Laboratory,\n",
"# National Technology & Engineering Solutions of Sandia, LLC, Carnegie Mellon\n",
"# University, West Virginia University Research Corporation, et al.\n",
@@ -32,8 +32,8 @@
"# Parameter Estimation Using Flash Unit Model\n",
"\n",
"Author: Jaffer Ghouse \n",
- "Maintainer: Andrew Lee \n",
- "Updated: 2023-06-01 \n",
+ "Maintainer: Stephen Cini \n",
+ "Updated: 2026-06-11 \n",
"\n",
"In this module, we will be using Pyomo's `parmest` tool in conjunction with IDAES models for parameter estimation. We demonstrate these tools by estimating the parameters associated with the NRTL property model for a benzene-toluene mixture. The NRTL model has 2 sets of parameters: the non-randomness parameter (`alpha_ij`) and the binary interaction parameter (`tau_ij`), where `i` and `j` is the pure component species. In this example, we will be only estimate the binary interaction parameter (`tau_ij`) for a given dataset. When estimating parameters associated with the property package, IDAES provides the flexibility of doing the parameter estimation by just using the state block or by using a unit model with a specified property package. This module will demonstrate parameter estimation by using the flash unit model with the NRTL property package. \n",
"\n",
@@ -45,7 +45,7 @@
"\n",
"## Key links to documentation:\n",
"* NRTL Model - https://idaes-pse.readthedocs.io/en/stable/reference_guides/model_libraries/generic/property_models/activity_coefficient.html\n",
- "* parmest - https://pyomo.readthedocs.io/en/stable/contributed_packages/parmest/index.html\n"
+ "* parmest - https://pyomo.readthedocs.io/en/stable/explanation/analysis/parmest/index.html"
]
},
{
@@ -54,13 +54,13 @@
"source": [
"\n",
"Inline Exercise:\n",
- "import `ConcreteModel` from Pyomo, `FlowsheetBlock` and `Flash` from IDAES. \n",
+ "import `ConcreteModel`, `value`, and `Suffix` from Pyomo, `FlowsheetBlock` and `Flash` from IDAES. \n",
"
"
]
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 2,
"metadata": {
"tags": [
"exercise"
@@ -68,7 +68,7 @@
},
"outputs": [],
"source": [
- "# Todo: import ConcreteModel from pyomo.environ\n",
+ "# Todo: import ConcreteModel, value, and Suffix from pyomo.environ\n",
"\n",
"# Todo: import FlowsheetBlock from idaes.core\n",
"\n",
@@ -84,7 +84,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
@@ -103,7 +103,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
@@ -132,7 +132,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 6,
"metadata": {
"tags": [
"exercise"
@@ -180,7 +180,12 @@
" m.fs.flash.initialize(outlvl=idaeslog.INFO_LOW)\n",
"\n",
" # Fix at actual temperature\n",
- " m.fs.flash.inlet.temperature.fix(float(data[\"temperature\"]))\n",
+ " if isinstance(data, dict) or isinstance(data, pd.Series):\n",
+ " m.fs.state_block.temperature.fix(float(data[\"temperature\"]))\n",
+ " elif isinstance(data, pd.DataFrame):\n",
+ " m.fs.state_block.temperature.fix(float(data.iloc[0][\"temperature\"]))\n",
+ " else:\n",
+ " raise ValueError(\"Unrecognized data type.\")\n",
"\n",
" # Set bounds on variables to be estimated\n",
" m.fs.properties.tau[\"benzene\", \"toluene\"].setlb(-5)\n",
@@ -206,38 +211,98 @@
"source": [
"In addition to providing a method to return an initialized model, the `parmest` tool needs the following:\n",
"\n",
- "* List of variable names to be estimated\n",
- "* Dataset with multiple scenarios\n",
- "* Expression to compute the sum of squared errors\n",
- "\n"
+ "* Experiment class to set up and label model with suffixes\n",
+ "* Dataset with multiple scenarios - organized into an experiment list"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
+ "Here we build an experiment class to label our model problem for parameter estimation. The labels are defined as a `Suffix`, and the main labels for our model are `experiment_outputs`, `unknown_parameters`, and `measurement_error`.\n",
+ "\n",
+ "For this problem, the error will be computed for the mole fraction of benzene in the vapor and liquid phase between the model prediction and data. The `experimental_outputs` will therefore be the mole fraction of benzene in the two phases.\n",
+ "\n",
"In this example, we only estimate the binary interaction parameter (`tau_ij`). Given that this variable is usually indexed as `tau_ij = Var(component_list, component_list)`, there are 2*2=4 degrees of freedom. However, when i=j, the binary interaction parameter is 0. Therefore, in this problem, we estimate the binary interaction parameter for the following variables only:\n",
"\n",
"* fs.properties.tau['benzene', 'toluene']\n",
"* fs.properties.tau['toluene', 'benzene']\n",
"\n",
- "\n",
- "Inline Exercise:\n",
- "Create a list called `variable_name` with the above-mentioned variables declared as strings.\n",
- "
"
+ "As shown below, these model components are used as our `unknown_parameters`.\n",
+ "\n",
+ "We define `measurement_error` as none so parmest calculates the value internally based on the experimental outputs. Refer to https://pyomo.readthedocs.io/en/stable/explanation/analysis/parmest/driver.html for more information. "
]
},
{
"cell_type": "code",
- "execution_count": null,
- "metadata": {
- "tags": [
- "exercise"
- ]
- },
+ "execution_count": 9,
+ "metadata": {},
"outputs": [],
"source": [
- "# Todo: Create a list of vars to estimate"
+ "# Build an experiment class to take advantage of new parmest interface\n",
+ "from pyomo.contrib.parmest.experiment import Experiment\n",
+ "\n",
+ "\n",
+ "class NRTLExperiment(Experiment):\n",
+ " \"\"\"Experiment class for parameter estimation of NRTL model using parmest\"\"\"\n",
+ "\n",
+ " def __init__(self, data, meas_error=None):\n",
+ " \"\"\"Initialize the NRTLExperiment class\n",
+ "\n",
+ " Args:\n",
+ " data: DataFrame containing the experimental data\n",
+ " meas_error: Measurement error for the data (optional)\n",
+ " \"\"\"\n",
+ " self.model = None\n",
+ " self.data = data\n",
+ " self.meas_error = meas_error\n",
+ "\n",
+ " def create_model(self):\n",
+ " \"\"\"Create the Pyomo model for the NRTL parameter estimation problem\"\"\"\n",
+ " self.model = NRTL_model(self.data)\n",
+ "\n",
+ " def label_model(self):\n",
+ " m = self.model\n",
+ "\n",
+ " # Add experiment outputs to the model for easier access\n",
+ " m.experiment_outputs = Suffix(direction=Suffix.LOCAL)\n",
+ " m.experiment_outputs.update(\n",
+ " [\n",
+ " (\n",
+ " m.fs.flash.liq_outlet.mole_frac_comp[0, \"benzene\"],\n",
+ " self.data[\"liq_benzene\"],\n",
+ " ),\n",
+ " (\n",
+ " m.fs.flash.vap_outlet.mole_frac_comp[0, \"benzene\"],\n",
+ " self.data[\"vap_benzene\"],\n",
+ " ),\n",
+ " ]\n",
+ " )\n",
+ "\n",
+ " m.measurement_error = Suffix(direction=Suffix.LOCAL)\n",
+ " m.measurement_error.update(\n",
+ " [\n",
+ " (m.fs.flash.liq_outlet.mole_frac_comp[0, \"benzene\"], self.meas_error),\n",
+ " (m.fs.flash.vap_outlet.mole_frac_comp[0, \"benzene\"], self.meas_error),\n",
+ " ]\n",
+ " )\n",
+ "\n",
+ " # Add unknown parameters to the model for easier access\n",
+ " m.unknown_parameters = Suffix(direction=Suffix.LOCAL)\n",
+ " m.unknown_parameters.update(\n",
+ " (k, value(k))\n",
+ " for k in [\n",
+ " m.fs.properties.tau[\"benzene\", \"toluene\"],\n",
+ " m.fs.properties.tau[\"toluene\", \"benzene\"],\n",
+ " ]\n",
+ " )\n",
+ "\n",
+ " def get_labeled_model(self):\n",
+ " \"\"\"Return the labeled model\"\"\"\n",
+ " if self.model is None:\n",
+ " self.create_model()\n",
+ " self.label_model()\n",
+ " return self.model"
]
},
{
@@ -256,9 +321,398 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 10,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " temperature | \n",
+ " liq_benzene | \n",
+ " vap_benzene | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 0 | \n",
+ " 365.500000 | \n",
+ " 0.480953 | \n",
+ " 0.692110 | \n",
+ "
\n",
+ " \n",
+ " | 1 | \n",
+ " 365.617647 | \n",
+ " 0.462444 | \n",
+ " 0.667699 | \n",
+ "
\n",
+ " \n",
+ " | 2 | \n",
+ " 365.735294 | \n",
+ " 0.477984 | \n",
+ " 0.692441 | \n",
+ "
\n",
+ " \n",
+ " | 3 | \n",
+ " 365.852941 | \n",
+ " 0.440547 | \n",
+ " 0.640336 | \n",
+ "
\n",
+ " \n",
+ " | 4 | \n",
+ " 365.970588 | \n",
+ " 0.427421 | \n",
+ " 0.623328 | \n",
+ "
\n",
+ " \n",
+ " | 5 | \n",
+ " 366.088235 | \n",
+ " 0.442725 | \n",
+ " 0.647796 | \n",
+ "
\n",
+ " \n",
+ " | 6 | \n",
+ " 366.205882 | \n",
+ " 0.434374 | \n",
+ " 0.637691 | \n",
+ "
\n",
+ " \n",
+ " | 7 | \n",
+ " 366.323529 | \n",
+ " 0.444642 | \n",
+ " 0.654933 | \n",
+ "
\n",
+ " \n",
+ " | 8 | \n",
+ " 366.441176 | \n",
+ " 0.427132 | \n",
+ " 0.631229 | \n",
+ "
\n",
+ " \n",
+ " | 9 | \n",
+ " 366.558824 | \n",
+ " 0.446301 | \n",
+ " 0.661743 | \n",
+ "
\n",
+ " \n",
+ " | 10 | \n",
+ " 366.676471 | \n",
+ " 0.438004 | \n",
+ " 0.651591 | \n",
+ "
\n",
+ " \n",
+ " | 11 | \n",
+ " 366.794118 | \n",
+ " 0.425320 | \n",
+ " 0.634814 | \n",
+ "
\n",
+ " \n",
+ " | 12 | \n",
+ " 366.911765 | \n",
+ " 0.439435 | \n",
+ " 0.658047 | \n",
+ "
\n",
+ " \n",
+ " | 13 | \n",
+ " 367.029412 | \n",
+ " 0.435655 | \n",
+ " 0.654539 | \n",
+ "
\n",
+ " \n",
+ " | 14 | \n",
+ " 367.147059 | \n",
+ " 0.401350 | \n",
+ " 0.604987 | \n",
+ "
\n",
+ " \n",
+ " | 15 | \n",
+ " 367.264706 | \n",
+ " 0.397862 | \n",
+ " 0.601703 | \n",
+ "
\n",
+ " \n",
+ " | 16 | \n",
+ " 367.382353 | \n",
+ " 0.415821 | \n",
+ " 0.630930 | \n",
+ "
\n",
+ " \n",
+ " | 17 | \n",
+ " 367.500000 | \n",
+ " 0.420667 | \n",
+ " 0.640380 | \n",
+ "
\n",
+ " \n",
+ " | 18 | \n",
+ " 367.617647 | \n",
+ " 0.391683 | \n",
+ " 0.598214 | \n",
+ "
\n",
+ " \n",
+ " | 19 | \n",
+ " 367.735294 | \n",
+ " 0.404903 | \n",
+ " 0.620432 | \n",
+ "
\n",
+ " \n",
+ " | 20 | \n",
+ " 367.852941 | \n",
+ " 0.409563 | \n",
+ " 0.629626 | \n",
+ "
\n",
+ " \n",
+ " | 21 | \n",
+ " 367.970588 | \n",
+ " 0.389488 | \n",
+ " 0.600722 | \n",
+ "
\n",
+ " \n",
+ " | 22 | \n",
+ " 368.000000 | \n",
+ " 0.396789 | \n",
+ " 0.612483 | \n",
+ "
\n",
+ " \n",
+ " | 23 | \n",
+ " 368.088235 | \n",
+ " 0.398162 | \n",
+ " 0.616106 | \n",
+ "
\n",
+ " \n",
+ " | 24 | \n",
+ " 368.205882 | \n",
+ " 0.362340 | \n",
+ " 0.562505 | \n",
+ "
\n",
+ " \n",
+ " | 25 | \n",
+ " 368.323529 | \n",
+ " 0.386958 | \n",
+ " 0.602680 | \n",
+ "
\n",
+ " \n",
+ " | 26 | \n",
+ " 368.441176 | \n",
+ " 0.363643 | \n",
+ " 0.568210 | \n",
+ "
\n",
+ " \n",
+ " | 27 | \n",
+ " 368.558824 | \n",
+ " 0.368118 | \n",
+ " 0.577072 | \n",
+ "
\n",
+ " \n",
+ " | 28 | \n",
+ " 368.676471 | \n",
+ " 0.384098 | \n",
+ " 0.604078 | \n",
+ "
\n",
+ " \n",
+ " | 29 | \n",
+ " 368.794118 | \n",
+ " 0.353605 | \n",
+ " 0.557925 | \n",
+ "
\n",
+ " \n",
+ " | 30 | \n",
+ " 368.911765 | \n",
+ " 0.346474 | \n",
+ " 0.548445 | \n",
+ "
\n",
+ " \n",
+ " | 31 | \n",
+ " 369.029412 | \n",
+ " 0.350741 | \n",
+ " 0.556996 | \n",
+ "
\n",
+ " \n",
+ " | 32 | \n",
+ " 369.147059 | \n",
+ " 0.362347 | \n",
+ " 0.577286 | \n",
+ "
\n",
+ " \n",
+ " | 33 | \n",
+ " 369.264706 | \n",
+ " 0.362578 | \n",
+ " 0.579519 | \n",
+ "
\n",
+ " \n",
+ " | 34 | \n",
+ " 369.382353 | \n",
+ " 0.340765 | \n",
+ " 0.546411 | \n",
+ "
\n",
+ " \n",
+ " | 35 | \n",
+ " 369.500000 | \n",
+ " 0.337462 | \n",
+ " 0.542857 | \n",
+ "
\n",
+ " \n",
+ " | 36 | \n",
+ " 369.617647 | \n",
+ " 0.355729 | \n",
+ " 0.574083 | \n",
+ "
\n",
+ " \n",
+ " | 37 | \n",
+ " 369.735294 | \n",
+ " 0.348679 | \n",
+ " 0.564513 | \n",
+ "
\n",
+ " \n",
+ " | 38 | \n",
+ " 369.852941 | \n",
+ " 0.338187 | \n",
+ " 0.549284 | \n",
+ "
\n",
+ " \n",
+ " | 39 | \n",
+ " 369.970588 | \n",
+ " 0.324360 | \n",
+ " 0.528514 | \n",
+ "
\n",
+ " \n",
+ " | 40 | \n",
+ " 370.088235 | \n",
+ " 0.310753 | \n",
+ " 0.507964 | \n",
+ "
\n",
+ " \n",
+ " | 41 | \n",
+ " 370.205882 | \n",
+ " 0.311037 | \n",
+ " 0.510055 | \n",
+ "
\n",
+ " \n",
+ " | 42 | \n",
+ " 370.323529 | \n",
+ " 0.311263 | \n",
+ " 0.512055 | \n",
+ "
\n",
+ " \n",
+ " | 43 | \n",
+ " 370.441176 | \n",
+ " 0.308081 | \n",
+ " 0.508437 | \n",
+ "
\n",
+ " \n",
+ " | 44 | \n",
+ " 370.558824 | \n",
+ " 0.308224 | \n",
+ " 0.510293 | \n",
+ "
\n",
+ " \n",
+ " | 45 | \n",
+ " 370.676471 | \n",
+ " 0.318148 | \n",
+ " 0.528399 | \n",
+ "
\n",
+ " \n",
+ " | 46 | \n",
+ " 370.794118 | \n",
+ " 0.308334 | \n",
+ " 0.513728 | \n",
+ "
\n",
+ " \n",
+ " | 47 | \n",
+ " 370.911765 | \n",
+ " 0.317937 | \n",
+ " 0.531410 | \n",
+ "
\n",
+ " \n",
+ " | 48 | \n",
+ " 371.029412 | \n",
+ " 0.289149 | \n",
+ " 0.484824 | \n",
+ "
\n",
+ " \n",
+ " | 49 | \n",
+ " 371.147059 | \n",
+ " 0.298637 | \n",
+ " 0.502318 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " temperature liq_benzene vap_benzene\n",
+ "0 365.500000 0.480953 0.692110\n",
+ "1 365.617647 0.462444 0.667699\n",
+ "2 365.735294 0.477984 0.692441\n",
+ "3 365.852941 0.440547 0.640336\n",
+ "4 365.970588 0.427421 0.623328\n",
+ "5 366.088235 0.442725 0.647796\n",
+ "6 366.205882 0.434374 0.637691\n",
+ "7 366.323529 0.444642 0.654933\n",
+ "8 366.441176 0.427132 0.631229\n",
+ "9 366.558824 0.446301 0.661743\n",
+ "10 366.676471 0.438004 0.651591\n",
+ "11 366.794118 0.425320 0.634814\n",
+ "12 366.911765 0.439435 0.658047\n",
+ "13 367.029412 0.435655 0.654539\n",
+ "14 367.147059 0.401350 0.604987\n",
+ "15 367.264706 0.397862 0.601703\n",
+ "16 367.382353 0.415821 0.630930\n",
+ "17 367.500000 0.420667 0.640380\n",
+ "18 367.617647 0.391683 0.598214\n",
+ "19 367.735294 0.404903 0.620432\n",
+ "20 367.852941 0.409563 0.629626\n",
+ "21 367.970588 0.389488 0.600722\n",
+ "22 368.000000 0.396789 0.612483\n",
+ "23 368.088235 0.398162 0.616106\n",
+ "24 368.205882 0.362340 0.562505\n",
+ "25 368.323529 0.386958 0.602680\n",
+ "26 368.441176 0.363643 0.568210\n",
+ "27 368.558824 0.368118 0.577072\n",
+ "28 368.676471 0.384098 0.604078\n",
+ "29 368.794118 0.353605 0.557925\n",
+ "30 368.911765 0.346474 0.548445\n",
+ "31 369.029412 0.350741 0.556996\n",
+ "32 369.147059 0.362347 0.577286\n",
+ "33 369.264706 0.362578 0.579519\n",
+ "34 369.382353 0.340765 0.546411\n",
+ "35 369.500000 0.337462 0.542857\n",
+ "36 369.617647 0.355729 0.574083\n",
+ "37 369.735294 0.348679 0.564513\n",
+ "38 369.852941 0.338187 0.549284\n",
+ "39 369.970588 0.324360 0.528514\n",
+ "40 370.088235 0.310753 0.507964\n",
+ "41 370.205882 0.311037 0.510055\n",
+ "42 370.323529 0.311263 0.512055\n",
+ "43 370.441176 0.308081 0.508437\n",
+ "44 370.558824 0.308224 0.510293\n",
+ "45 370.676471 0.318148 0.528399\n",
+ "46 370.794118 0.308334 0.513728\n",
+ "47 370.911765 0.317937 0.531410\n",
+ "48 371.029412 0.289149 0.484824\n",
+ "49 371.147059 0.298637 0.502318"
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ }
+ ],
"source": [
"# Load data from csv\n",
"data = pd.read_csv(\"BT_NRTL_dataset.csv\")\n",
@@ -271,60 +725,198 @@
"cell_type": "markdown",
"metadata": {},
"source": [
- "We need to provide a method to return an expression to compute the sum of squared errors that will be used as the objective in solving the parameter estimation problem. For this problem, the error will be computed for the mole fraction of benzene in the vapor and liquid phase between the model prediction and data. \n",
- "\n",
- "\n",
- "Inline Exercise:\n",
- "Complete the following cell by adding an expression to compute the sum of square errors. \n",
- "
"
+ "We define the `exp_list` by splitting the data into individual experiments, or data points."
]
},
{
"cell_type": "code",
- "execution_count": null,
- "metadata": {
- "tags": [
- "exercise"
- ]
- },
- "outputs": [],
- "source": [
- "# Create method to return an expression that computes the sum of squared error\n",
- "def SSE(m, data):\n",
- " # Todo: Add expression for computing the sum of squared errors in mole fraction of benzene in the liquid\n",
- " # and vapor phase. For example, the squared error for the vapor phase is:\n",
- " # (float(data[\"vap_benzene\"]) - m.fs.flash.vap_outlet.mole_frac_comp[0, \"benzene\"])**2\n",
- "\n",
- " return expr * 1e4"
- ]
- },
- {
- "cell_type": "markdown",
+ "execution_count": 11,
"metadata": {},
+ "outputs": [],
"source": [
- "\n",
- "Note:\n",
- "Notice that we have scaled the expression up by a factor of 10000 as the SSE computed here will be an extremely small number given that we are using the difference in mole fraction in our expression. A well-scaled objective will help improve solve robustness when using IPOPT. \n",
- "
\n"
+ "# Loop through the dataset and create an experiment for each row of data\n",
+ "exp_list = []\n",
+ "for i in range(data.shape[0]):\n",
+ " exp_list.append(NRTLExperiment(data.iloc[i]))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
- "We are now ready to set up the parameter estimation problem. We will create a parameter estimation object called `pest`. As shown below, we pass the method that returns an initialized model, dataset, list of variable names to estimate, and the SSE expression to the Estimator object. `tee=True` will print the solver output after solving the parameter estimation problem."
+ "We are now ready to set up the parameter estimation problem. We will create a parameter estimation object called pest. As shown below, we pass the experiment list, and an objective function to the Estimator method. tee=True will print the solver output after solving the parameter estimation problem."
]
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 12,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Ipopt 3.13.2: \n",
+ "\n",
+ "******************************************************************************\n",
+ "This program contains Ipopt, a library for large-scale nonlinear optimization.\n",
+ " Ipopt is released as open source code under the Eclipse Public License (EPL).\n",
+ " For more information visit http://projects.coin-or.org/Ipopt\n",
+ "\n",
+ "This version of Ipopt was compiled from source code available at\n",
+ " https://github.com/IDAES/Ipopt as part of the Institute for the Design of\n",
+ " Advanced Energy Systems Process Systems Engineering Framework (IDAES PSE\n",
+ " Framework) Copyright (c) 2018-2019. See https://github.com/IDAES/idaes-pse.\n",
+ "\n",
+ "This version of Ipopt was compiled using HSL, a collection of Fortran codes\n",
+ " for large-scale scientific computation. All technical papers, sales and\n",
+ " publicity material resulting from use of the HSL codes within IPOPT must\n",
+ " contain the following acknowledgement:\n",
+ " HSL, a collection of Fortran codes for large-scale scientific\n",
+ " computation. See http://www.hsl.rl.ac.uk.\n",
+ "******************************************************************************\n",
+ "\n",
+ "This is Ipopt version 3.13.2, running with linear solver ma27.\n",
+ "\n",
+ "Number of nonzeros in equality constraint Jacobian...: 10950\n",
+ "Number of nonzeros in inequality constraint Jacobian.: 0\n",
+ "Number of nonzeros in Lagrangian Hessian.............: 6600\n",
+ "\n",
+ "Total number of variables............................: 2952\n",
+ " variables with only lower bounds: 150\n",
+ " variables with lower and upper bounds: 600\n",
+ " variables with only upper bounds: 0\n",
+ "Total number of equality constraints.................: 2950\n",
+ "Total number of inequality constraints...............: 0\n",
+ " inequality constraints with only lower bounds: 0\n",
+ " inequality constraints with lower and upper bounds: 0\n",
+ " inequality constraints with only upper bounds: 0\n",
+ "\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 0 6.0671019e-03 5.63e+02 1.20e-08 -1.0 0.00e+00 - 0.00e+00 0.00e+00 0\n",
+ " 1 9.0714942e-04 1.37e+03 1.61e+01 -1.0 1.37e+04 - 9.82e-01 1.00e+00h 1\n",
+ " 2 1.3219937e-03 1.17e+04 1.62e+01 -1.0 5.23e+03 - 3.41e-01 1.65e-01h 3\n",
+ " 3 1.3161671e-03 1.11e+04 4.02e+01 -1.0 3.96e+02 -4.0 8.19e-01 1.25e-01h 4\n",
+ " 4 1.3154170e-03 1.11e+04 4.32e+01 -1.0 3.47e+02 -4.5 9.90e-01 4.43e-02h 5\n",
+ " 5 9.4424343e-04 1.04e+04 4.05e+01 -1.0 1.16e+04 - 9.33e-01 5.61e-02h 5\n",
+ " 6 9.4571258e-04 1.11e+04 4.85e+01 -1.0 3.13e+02 -5.0 8.74e-01 1.25e-01h 4\n",
+ " 7 9.4862862e-04 1.11e+04 4.84e+01 -1.0 2.41e+03 -5.4 1.72e-01 1.50e-03h 8\n",
+ " 8 9.5448936e-04 1.10e+04 4.81e+01 -1.0 4.11e+02 -5.0 1.00e+00 1.97e-02h 6\n",
+ " 9 9.5650047e-04 1.10e+04 4.81e+01 -1.0 5.14e+02 -4.6 3.46e-01 5.24e-03h 7\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 10 9.5730419e-04 1.10e+04 4.81e+01 -1.0 9.78e+02 -4.2 4.40e-01 1.08e-03h 8\n",
+ " 11 9.5774182e-04 1.10e+04 4.84e+01 -1.0 2.76e+02 -3.7 2.91e-01 2.99e-03h 7\n",
+ " 12 9.4292855e-04 7.77e+04 4.09e+04 -1.0 5.38e+02 -2.4 5.48e-02 6.44e-02w 1\n",
+ " 13 2.4318219e-01 2.38e+07 4.22e+14 -1.0 1.28e+06 - 2.55e-02 3.49e-02w 1\n",
+ " 14 2.8902019e-01 1.64e+07 2.92e+14 -1.0 1.11e+05 -2.9 9.54e-01 3.01e-01w 1\n",
+ " 15 9.5768293e-04 1.10e+04 4.85e+01 -1.0 2.80e+05 -3.4 5.48e-02 2.52e-04h 8\n",
+ " 16 9.5769345e-04 1.10e+04 4.85e+01 -1.0 4.33e+02 -2.9 7.95e-02 1.91e-04h 9\n",
+ " 17 9.5763809e-04 1.10e+04 4.85e+01 -1.0 6.35e+02 -2.5 4.94e-02 2.08e-04h 9\n",
+ " 18 9.5734836e-04 1.10e+04 4.87e+01 -1.0 3.22e+02 -3.0 1.00e+00 1.22e-03h 8\n",
+ " 19 9.3628114e-04 1.09e+04 4.62e+01 -1.0 4.22e+02 -3.5 5.16e-01 5.87e-02h 5\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 20 7.1894543e-04 4.02e+03 4.95e+02 -1.0 3.49e+02 -3.9 1.00e+00 1.00e+00h 1\n",
+ " 21 6.7062834e-04 1.58e+02 2.21e+02 -1.0 1.78e+02 -4.4 1.00e+00 1.00e+00h 1\n",
+ " 22 6.6635123e-04 4.17e+01 1.12e+01 -1.0 2.44e+02 -4.9 1.00e+00 1.00e+00h 1\n",
+ " 23 6.6729070e-04 1.43e+00 9.69e-01 -1.0 1.08e+01 -5.4 1.00e+00 1.00e+00h 1\n",
+ " 24 6.6785681e-04 3.58e-01 5.25e-03 -1.7 6.65e+00 -5.8 1.00e+00 1.00e+00h 1\n",
+ " 25 6.2552355e-04 9.80e+02 6.48e-02 -3.8 7.92e+02 - 9.22e-01 1.00e+00h 1\n",
+ " 26 5.9105707e-04 8.13e+00 6.13e-04 -3.8 5.66e+02 - 1.00e+00 1.00e+00h 1\n",
+ " 27 6.1313801e-04 6.24e+01 8.08e-06 -3.8 1.70e+02 - 1.00e+00 1.00e+00h 1\n",
+ " 28 6.1208051e-04 3.58e-01 1.18e-08 -3.8 1.88e+00 - 1.00e+00 1.00e+00h 1\n",
+ " 29 5.9010560e-04 1.58e+01 1.00e-05 -5.7 1.08e+02 - 1.00e+00 1.00e+00h 1\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 30 5.9008319e-04 2.74e-02 7.90e-07 -5.7 7.54e-02 -6.3 1.00e+00 1.00e+00h 1\n",
+ " 31 5.3570104e-04 1.48e+04 8.70e-04 -5.7 1.81e+02 - 1.00e+00 1.00e+00h 1\n",
+ " 32 5.1618763e-04 6.29e+02 8.06e-05 -5.7 2.55e+02 - 1.00e+00 1.00e+00h 1\n",
+ " 33 5.5250565e-04 2.88e+01 2.58e-04 -5.7 1.81e+04 - 6.26e-01 6.25e-02h 5\n",
+ " 34 5.2209909e-04 2.88e+02 2.02e-04 -5.7 1.89e+03 - 1.00e+00 1.00e+00h 1\n",
+ " 35 5.0707798e-04 5.60e+01 2.02e-04 -5.7 2.93e+03 - 1.00e+00 1.00e+00h 1\n",
+ " 36 5.0765648e-04 7.87e+00 1.91e-05 -5.7 1.02e+02 - 1.00e+00 1.00e+00h 1\n",
+ " 37 5.0740606e-04 2.57e+00 1.88e-05 -5.7 6.96e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 38 5.0764164e-04 2.55e+00 1.76e-05 -5.7 6.81e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 39 5.0740672e-04 2.55e+00 1.88e-05 -5.7 6.80e+01 - 1.00e+00 1.00e+00h 1\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 40 5.0764162e-04 2.54e+00 1.76e-05 -5.7 6.80e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 41 5.0740672e-04 2.55e+00 1.88e-05 -5.7 6.80e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 42 5.0782847e-04 1.43e-01 1.83e-05 -5.7 6.80e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 43 5.0751252e-04 1.58e-02 1.93e-05 -5.7 6.88e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 44 5.0783218e-04 4.79e-03 1.85e-05 -5.7 6.92e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 45 5.0751252e-04 1.60e-02 1.93e-05 -5.7 6.89e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 46 5.0783222e-04 1.23e-04 1.85e-05 -5.7 6.92e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 47 5.0751252e-04 1.60e-02 1.93e-05 -5.7 6.89e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 48 5.0783216e-04 1.24e-04 1.85e-05 -5.7 6.92e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 49 5.0751765e-04 3.20e-03 1.93e-05 -5.7 6.89e+01 - 1.00e+00 1.00e+00H 1\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 50 5.0764151e-04 2.56e+00 1.77e-05 -5.7 6.93e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 51 5.0740671e-04 2.55e+00 1.88e-05 -5.7 6.81e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 52 5.0764162e-04 2.54e+00 1.76e-05 -5.7 6.80e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 53 5.0740672e-04 2.55e+00 1.88e-05 -5.7 6.80e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 54 5.0764162e-04 2.54e+00 1.76e-05 -5.7 6.80e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 55 5.0748886e-04 1.91e+00 8.64e-06 -5.7 6.80e+01 - 1.00e+00 5.00e-01h 2\n",
+ " 56 5.0744550e-04 3.37e-01 1.64e-05 -5.7 2.54e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 57 5.0763613e-04 1.82e+00 1.43e-05 -5.7 5.79e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 58 5.0751252e-04 2.25e-02 1.93e-05 -5.7 6.65e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 59 5.0783220e-04 1.23e-04 1.85e-05 -5.7 6.92e+01 - 1.00e+00 1.00e+00H 1\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 60 5.0751252e-04 1.60e-02 1.93e-05 -5.7 6.89e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 61 5.0783207e-04 3.26e-04 1.85e-05 -5.7 6.92e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 62 5.0751786e-04 7.95e-05 1.93e-05 -5.7 6.89e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 63 5.0754291e-04 6.40e-01 8.69e-06 -5.7 6.93e+01 - 1.00e+00 5.00e-01h 2\n",
+ " 64 5.0745167e-04 3.00e-01 1.61e-05 -5.7 2.35e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 65 5.0763437e-04 1.71e+00 1.33e-05 -5.7 5.61e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 66 5.0751762e-04 2.91e-03 1.93e-05 -5.7 6.60e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 67 5.0752104e-04 1.62e-01 1.43e-05 -5.7 6.92e+01 - 1.00e+00 2.50e-01h 3\n",
+ " 68 5.0761295e-04 1.03e+00 2.18e-05 -5.7 4.35e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 69 5.0751251e-04 2.38e-02 1.92e-05 -5.7 5.95e+01 - 1.00e+00 1.00e+00H 1\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 70 5.0783210e-04 3.29e-06 1.85e-05 -5.7 6.90e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 71 5.0751786e-04 7.94e-05 1.93e-05 -5.7 6.89e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 72 5.0754292e-04 6.40e-01 8.69e-06 -5.7 6.93e+01 - 1.00e+00 5.00e-01h 2\n",
+ " 73 5.0749299e-04 3.95e-01 1.21e-05 -5.7 2.35e+01 - 1.00e+00 5.00e-01h 2\n",
+ " 74 5.0755524e-04 1.36e-01 3.09e-05 -5.7 1.57e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 75 5.0751308e-04 1.96e-02 1.80e-05 -5.7 3.30e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 76 5.0754492e-04 5.62e-01 8.19e-06 -5.7 6.42e+01 - 1.00e+00 5.00e-01h 2\n",
+ " 77 5.0748301e-04 3.98e-01 1.25e-05 -5.7 2.93e+01 - 1.00e+00 5.00e-01h 2\n",
+ " 78 5.0756455e-04 2.42e-01 3.07e-05 -5.7 2.09e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 79 5.0751710e-04 1.38e-03 1.87e-05 -5.7 3.98e+01 - 1.00e+00 1.00e+00H 1\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 80 5.0783077e-04 3.26e-06 1.84e-05 -5.7 6.70e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 81 5.0726420e-04 1.24e+01 1.85e-05 -8.6 1.34e+02 - 9.93e-01 1.00e+00h 1\n",
+ " 82 5.0749897e-04 2.75e+00 2.53e-06 -8.6 6.93e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 83 5.0749686e-04 3.64e-04 6.40e-10 -8.6 4.69e-02 - 1.00e+00 1.00e+00h 1\n",
+ " 84 5.0749686e-04 7.28e-11 2.51e-14 -8.6 6.86e-05 - 1.00e+00 1.00e+00h 1\n",
+ "\n",
+ "Number of Iterations....: 84\n",
+ "\n",
+ " (scaled) (unscaled)\n",
+ "Objective...............: 5.0749685809243843e-04 5.0749685809243843e-04\n",
+ "Dual infeasibility......: 2.5059195074646584e-14 2.5059195074646584e-14\n",
+ "Constraint violation....: 1.4104644499482425e-11 7.2759576141834259e-11\n",
+ "Complementarity.........: 2.5059035596800647e-09 2.5059035596800647e-09\n",
+ "Overall NLP error.......: 2.5059035596800647e-09 2.5059035596800647e-09\n",
+ "\n",
+ "\n",
+ "Number of objective function evaluations = 260\n",
+ "Number of objective gradient evaluations = 85\n",
+ "Number of equality constraint evaluations = 260\n",
+ "Number of inequality constraint evaluations = 0\n",
+ "Number of equality constraint Jacobian evaluations = 85\n",
+ "Number of inequality constraint Jacobian evaluations = 0\n",
+ "Number of Lagrangian Hessian evaluations = 84\n",
+ "Total CPU secs in IPOPT (w/o function evaluations) = 0.338\n",
+ "Total CPU secs in NLP function evaluations = 0.092\n",
+ "\n",
+ "EXIT: Optimal Solution Found.\n"
+ ]
+ }
+ ],
"source": [
- "# Initialize a parameter estimation object\n",
- "pest = parmest.Estimator(NRTL_model, data, variable_name, SSE, tee=True)\n",
+ "import logging\n",
"\n",
- "# Run parameter estimation using all data\n",
+ "idaeslog.getIdaesLogger(\"core.property_meta\").setLevel(logging.ERROR)\n",
+ "\n",
+ "pest = parmest.Estimator(exp_list, obj_function=\"SSE\", tee=True)\n",
"obj_value, parameters = pest.theta_est()"
]
},
@@ -339,11 +931,23 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 14,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "The SSE at the optimal solution is 0.000507\n",
+ "\n",
+ "The values for the parameters are as follows:\n",
+ "fs.properties.tau[benzene,toluene] = -0.8987454466579063\n",
+ "fs.properties.tau[toluene,benzene] = 1.410449514796474\n"
+ ]
+ }
+ ],
"source": [
- "print(\"The SSE at the optimal solution is %0.6f\" % (obj_value * 1e-4))\n",
+ "print(\"The SSE at the optimal solution is %0.6f\" % (obj_value))\n",
"print()\n",
"print(\"The values for the parameters are as follows:\")\n",
"for k, v in parameters.items():\n",
@@ -369,7 +973,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
- "Pyomo's `parmest` tool allows for bootstrapping where the parameter estimation is repeated over `n` samples with resampling from the original data set. Parameter estimation with bootstrap resampling can be used to identify confidence regions around each parameter estimate. This analysis can be slow given the increased number of model instances that need to be solved. Please refer to https://pyomo.readthedocs.io/en/stable/contributed_packages/parmest/driver.html for more details. \n",
+ "Pyomo's `parmest` tool allows for bootstrapping where the parameter estimation is repeated over `n` samples with resampling from the original data set. Parameter estimation with bootstrap resampling can be used to identify confidence regions around each parameter estimate. This analysis can be slow given the increased number of model instances that need to be solved. Please refer to https://pyomo.readthedocs.io/en/stable/explanation/analysis/parmest/covariance.html#bootstrapping for more details. \n",
"\n",
"For the example above, the bootstrapping can be run by uncommenting the code in the following cell:"
]
@@ -380,12 +984,8 @@
"metadata": {},
"outputs": [],
"source": [
- "# Run parameter estimation using bootstrap resample of the data (10 samples),\n",
- "# plot results along with confidence regions\n",
- "\n",
"# Uncomment the following lines\n",
- "\n",
- "# bootstrap_theta = pest.theta_est_bootstrap(4)\n",
+ "# bootstrap_theta = pest.theta_est_bootstrap(4, seed=542)\n",
"# display(bootstrap_theta)"
]
}
@@ -393,7 +993,7 @@
"metadata": {
"celltoolbar": "Tags",
"kernelspec": {
- "display_name": "Python 3 (ipykernel)",
+ "display_name": "idaes-pse-and-examples-dev-py313-macmini",
"language": "python",
"name": "python3"
},
@@ -407,9 +1007,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.9.12"
+ "version": "3.13.13"
}
},
"nbformat": 4,
"nbformat_minor": 3
-}
+}
\ No newline at end of file
diff --git a/idaes_examples/notebooks/docs/param_est/parameter_estimation_nrtl_using_unit_model_solution.ipynb b/idaes_examples/notebooks/docs/param_est/parameter_estimation_nrtl_using_unit_model_solution.ipynb
index d70ff27d..ad88977a 100644
--- a/idaes_examples/notebooks/docs/param_est/parameter_estimation_nrtl_using_unit_model_solution.ipynb
+++ b/idaes_examples/notebooks/docs/param_est/parameter_estimation_nrtl_using_unit_model_solution.ipynb
@@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 1,
"metadata": {
"tags": [
"header",
@@ -16,7 +16,7 @@
"# Framework (IDAES IP) was produced under the DOE Institute for the\n",
"# Design of Advanced Energy Systems (IDAES).\n",
"#\n",
- "# Copyright (c) 2018-2023 by the software owners: The Regents of the\n",
+ "# Copyright (c) 2018-2026 by the software owners: The Regents of the\n",
"# University of California, through Lawrence Berkeley National Laboratory,\n",
"# National Technology & Engineering Solutions of Sandia, LLC, Carnegie Mellon\n",
"# University, West Virginia University Research Corporation, et al.\n",
@@ -32,8 +32,8 @@
"# Parameter Estimation Using Flash Unit Model\n",
"\n",
"Author: Jaffer Ghouse \n",
- "Maintainer: Andrew Lee \n",
- "Updated: 2023-06-01 \n",
+ "Maintainer: Stephen Cini \n",
+ "Updated: 2026-06-11 \n",
"\n",
"In this module, we will be using Pyomo's `parmest` tool in conjunction with IDAES models for parameter estimation. We demonstrate these tools by estimating the parameters associated with the NRTL property model for a benzene-toluene mixture. The NRTL model has 2 sets of parameters: the non-randomness parameter (`alpha_ij`) and the binary interaction parameter (`tau_ij`), where `i` and `j` is the pure component species. In this example, we will be only estimate the binary interaction parameter (`tau_ij`) for a given dataset. When estimating parameters associated with the property package, IDAES provides the flexibility of doing the parameter estimation by just using the state block or by using a unit model with a specified property package. This module will demonstrate parameter estimation by using the flash unit model with the NRTL property package. \n",
"\n",
@@ -45,7 +45,7 @@
"\n",
"## Key links to documentation:\n",
"* NRTL Model - https://idaes-pse.readthedocs.io/en/stable/reference_guides/model_libraries/generic/property_models/activity_coefficient.html\n",
- "* parmest - https://pyomo.readthedocs.io/en/stable/contributed_packages/parmest/index.html\n"
+ "* parmest - https://pyomo.readthedocs.io/en/stable/explanation/analysis/parmest/index.html"
]
},
{
@@ -54,13 +54,13 @@
"source": [
"\n",
"Inline Exercise:\n",
- "import `ConcreteModel` from Pyomo, `FlowsheetBlock` and `Flash` from IDAES. \n",
+ "import `ConcreteModel`, `value`, and `Suffix` from Pyomo, `FlowsheetBlock` and `Flash` from IDAES. \n",
"
"
]
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 2,
"metadata": {
"tags": [
"exercise"
@@ -68,7 +68,7 @@
},
"outputs": [],
"source": [
- "# Todo: import ConcreteModel from pyomo.environ\n",
+ "# Todo: import ConcreteModel, value, and Suffix from pyomo.environ\n",
"\n",
"# Todo: import FlowsheetBlock from idaes.core\n",
"\n",
@@ -77,7 +77,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 3,
"metadata": {
"tags": [
"solution"
@@ -85,8 +85,8 @@
},
"outputs": [],
"source": [
- "# Todo: import ConcreteModel from pyomo.environ\n",
- "from pyomo.environ import ConcreteModel, value\n",
+ "# Todo: import ConcreteModel, value, and Suffix from pyomo.environ\n",
+ "from pyomo.environ import ConcreteModel, value, Suffix\n",
"\n",
"# Todo: import FlowsheetBlock from idaes.core\n",
"from idaes.core import FlowsheetBlock\n",
@@ -104,7 +104,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
@@ -123,7 +123,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
@@ -152,7 +152,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 6,
"metadata": {
"tags": [
"exercise"
@@ -200,7 +200,12 @@
" m.fs.flash.initialize(outlvl=idaeslog.INFO_LOW)\n",
"\n",
" # Fix at actual temperature\n",
- " m.fs.flash.inlet.temperature.fix(float(data[\"temperature\"]))\n",
+ " if isinstance(data, dict) or isinstance(data, pd.Series):\n",
+ " m.fs.state_block.temperature.fix(float(data[\"temperature\"]))\n",
+ " elif isinstance(data, pd.DataFrame):\n",
+ " m.fs.state_block.temperature.fix(float(data.iloc[0][\"temperature\"]))\n",
+ " else:\n",
+ " raise ValueError(\"Unrecognized data type.\")\n",
"\n",
" # Set bounds on variables to be estimated\n",
" m.fs.properties.tau[\"benzene\", \"toluene\"].setlb(-5)\n",
@@ -215,7 +220,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 7,
"metadata": {
"tags": [
"solution"
@@ -267,7 +272,12 @@
" m.fs.flash.initialize(outlvl=idaeslog.INFO_LOW)\n",
"\n",
" # Fix at actual temperature\n",
- " m.fs.flash.inlet.temperature.fix(float(data[\"temperature\"]))\n",
+ " if isinstance(data, dict) or isinstance(data, pd.Series):\n",
+ " m.fs.flash.inlet.temperature.fix(float(data[\"temperature\"]))\n",
+ " elif isinstance(data, pd.DataFrame):\n",
+ " m.fs.flash.inlet.temperature.fix(float(data.iloc[0][\"temperature\"]))\n",
+ " else:\n",
+ " raise ValueError(\"Unrecognized data type.\")\n",
"\n",
" # Set bounds on variables to be estimated\n",
" m.fs.properties.tau[\"benzene\", \"toluene\"].setlb(-5)\n",
@@ -293,55 +303,98 @@
"source": [
"In addition to providing a method to return an initialized model, the `parmest` tool needs the following:\n",
"\n",
- "* List of variable names to be estimated\n",
- "* Dataset with multiple scenarios\n",
- "* Expression to compute the sum of squared errors\n",
- "\n"
+ "* Experiment class to set up and label model with suffixes\n",
+ "* Dataset with multiple scenarios - organized into an experiment list"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
+ "Here we build an experiment class to label our model problem for parameter estimation. The labels are defined as a `Suffix`, and the main labels for our model are `experiment_outputs`, `unknown_parameters`, and `measurement_error`.\n",
+ "\n",
+ "For this problem, the error will be computed for the mole fraction of benzene in the vapor and liquid phase between the model prediction and data. The `experimental_outputs` will therefore be the mole fraction of benzene in the two phases.\n",
+ "\n",
"In this example, we only estimate the binary interaction parameter (`tau_ij`). Given that this variable is usually indexed as `tau_ij = Var(component_list, component_list)`, there are 2*2=4 degrees of freedom. However, when i=j, the binary interaction parameter is 0. Therefore, in this problem, we estimate the binary interaction parameter for the following variables only:\n",
"\n",
"* fs.properties.tau['benzene', 'toluene']\n",
"* fs.properties.tau['toluene', 'benzene']\n",
"\n",
- "\n",
- "Inline Exercise:\n",
- "Create a list called `variable_name` with the above-mentioned variables declared as strings.\n",
- "
"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {
- "tags": [
- "exercise"
- ]
- },
- "outputs": [],
- "source": [
- "# Todo: Create a list of vars to estimate"
+ "As shown below, these model components are used as our `unknown_parameters`.\n",
+ "\n",
+ "We define `measurement_error` as none so parmest calculates the value internally based on the experimental outputs. Refer to https://pyomo.readthedocs.io/en/stable/explanation/analysis/parmest/driver.html for more information. "
]
},
{
"cell_type": "code",
- "execution_count": null,
- "metadata": {
- "tags": [
- "solution"
- ]
- },
+ "execution_count": 9,
+ "metadata": {},
"outputs": [],
"source": [
- "# Todo: Create a list of vars to estimate\n",
- "variable_name = [\n",
- " \"fs.properties.tau['benzene', 'toluene']\",\n",
- " \"fs.properties.tau['toluene', 'benzene']\",\n",
- "]"
+ "# Build an experiment class to take advantage of new parmest interface\n",
+ "from pyomo.contrib.parmest.experiment import Experiment\n",
+ "\n",
+ "\n",
+ "class NRTLExperiment(Experiment):\n",
+ " \"\"\"Experiment class for parameter estimation of NRTL model using parmest\"\"\"\n",
+ "\n",
+ " def __init__(self, data, meas_error=None):\n",
+ " \"\"\"Initialize the NRTLExperiment class\n",
+ "\n",
+ " Args:\n",
+ " data: DataFrame containing the experimental data\n",
+ " meas_error: Measurement error for the data (optional)\n",
+ " \"\"\"\n",
+ " self.model = None\n",
+ " self.data = data\n",
+ " self.meas_error = meas_error\n",
+ "\n",
+ " def create_model(self):\n",
+ " \"\"\"Create the Pyomo model for the NRTL parameter estimation problem\"\"\"\n",
+ " self.model = NRTL_model(self.data)\n",
+ "\n",
+ " def label_model(self):\n",
+ " m = self.model\n",
+ "\n",
+ " # Add experiment outputs to the model for easier access\n",
+ " m.experiment_outputs = Suffix(direction=Suffix.LOCAL)\n",
+ " m.experiment_outputs.update(\n",
+ " [\n",
+ " (\n",
+ " m.fs.flash.liq_outlet.mole_frac_comp[0, \"benzene\"],\n",
+ " self.data[\"liq_benzene\"],\n",
+ " ),\n",
+ " (\n",
+ " m.fs.flash.vap_outlet.mole_frac_comp[0, \"benzene\"],\n",
+ " self.data[\"vap_benzene\"],\n",
+ " ),\n",
+ " ]\n",
+ " )\n",
+ "\n",
+ " m.measurement_error = Suffix(direction=Suffix.LOCAL)\n",
+ " m.measurement_error.update(\n",
+ " [\n",
+ " (m.fs.flash.liq_outlet.mole_frac_comp[0, \"benzene\"], self.meas_error),\n",
+ " (m.fs.flash.vap_outlet.mole_frac_comp[0, \"benzene\"], self.meas_error),\n",
+ " ]\n",
+ " )\n",
+ "\n",
+ " # Add unknown parameters to the model for easier access\n",
+ " m.unknown_parameters = Suffix(direction=Suffix.LOCAL)\n",
+ " m.unknown_parameters.update(\n",
+ " (k, value(k))\n",
+ " for k in [\n",
+ " m.fs.properties.tau[\"benzene\", \"toluene\"],\n",
+ " m.fs.properties.tau[\"toluene\", \"benzene\"],\n",
+ " ]\n",
+ " )\n",
+ "\n",
+ " def get_labeled_model(self):\n",
+ " \"\"\"Return the labeled model\"\"\"\n",
+ " if self.model is None:\n",
+ " self.create_model()\n",
+ " self.label_model()\n",
+ " return self.model"
]
},
{
@@ -360,9 +413,398 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 10,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " temperature | \n",
+ " liq_benzene | \n",
+ " vap_benzene | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 0 | \n",
+ " 365.500000 | \n",
+ " 0.480953 | \n",
+ " 0.692110 | \n",
+ "
\n",
+ " \n",
+ " | 1 | \n",
+ " 365.617647 | \n",
+ " 0.462444 | \n",
+ " 0.667699 | \n",
+ "
\n",
+ " \n",
+ " | 2 | \n",
+ " 365.735294 | \n",
+ " 0.477984 | \n",
+ " 0.692441 | \n",
+ "
\n",
+ " \n",
+ " | 3 | \n",
+ " 365.852941 | \n",
+ " 0.440547 | \n",
+ " 0.640336 | \n",
+ "
\n",
+ " \n",
+ " | 4 | \n",
+ " 365.970588 | \n",
+ " 0.427421 | \n",
+ " 0.623328 | \n",
+ "
\n",
+ " \n",
+ " | 5 | \n",
+ " 366.088235 | \n",
+ " 0.442725 | \n",
+ " 0.647796 | \n",
+ "
\n",
+ " \n",
+ " | 6 | \n",
+ " 366.205882 | \n",
+ " 0.434374 | \n",
+ " 0.637691 | \n",
+ "
\n",
+ " \n",
+ " | 7 | \n",
+ " 366.323529 | \n",
+ " 0.444642 | \n",
+ " 0.654933 | \n",
+ "
\n",
+ " \n",
+ " | 8 | \n",
+ " 366.441176 | \n",
+ " 0.427132 | \n",
+ " 0.631229 | \n",
+ "
\n",
+ " \n",
+ " | 9 | \n",
+ " 366.558824 | \n",
+ " 0.446301 | \n",
+ " 0.661743 | \n",
+ "
\n",
+ " \n",
+ " | 10 | \n",
+ " 366.676471 | \n",
+ " 0.438004 | \n",
+ " 0.651591 | \n",
+ "
\n",
+ " \n",
+ " | 11 | \n",
+ " 366.794118 | \n",
+ " 0.425320 | \n",
+ " 0.634814 | \n",
+ "
\n",
+ " \n",
+ " | 12 | \n",
+ " 366.911765 | \n",
+ " 0.439435 | \n",
+ " 0.658047 | \n",
+ "
\n",
+ " \n",
+ " | 13 | \n",
+ " 367.029412 | \n",
+ " 0.435655 | \n",
+ " 0.654539 | \n",
+ "
\n",
+ " \n",
+ " | 14 | \n",
+ " 367.147059 | \n",
+ " 0.401350 | \n",
+ " 0.604987 | \n",
+ "
\n",
+ " \n",
+ " | 15 | \n",
+ " 367.264706 | \n",
+ " 0.397862 | \n",
+ " 0.601703 | \n",
+ "
\n",
+ " \n",
+ " | 16 | \n",
+ " 367.382353 | \n",
+ " 0.415821 | \n",
+ " 0.630930 | \n",
+ "
\n",
+ " \n",
+ " | 17 | \n",
+ " 367.500000 | \n",
+ " 0.420667 | \n",
+ " 0.640380 | \n",
+ "
\n",
+ " \n",
+ " | 18 | \n",
+ " 367.617647 | \n",
+ " 0.391683 | \n",
+ " 0.598214 | \n",
+ "
\n",
+ " \n",
+ " | 19 | \n",
+ " 367.735294 | \n",
+ " 0.404903 | \n",
+ " 0.620432 | \n",
+ "
\n",
+ " \n",
+ " | 20 | \n",
+ " 367.852941 | \n",
+ " 0.409563 | \n",
+ " 0.629626 | \n",
+ "
\n",
+ " \n",
+ " | 21 | \n",
+ " 367.970588 | \n",
+ " 0.389488 | \n",
+ " 0.600722 | \n",
+ "
\n",
+ " \n",
+ " | 22 | \n",
+ " 368.000000 | \n",
+ " 0.396789 | \n",
+ " 0.612483 | \n",
+ "
\n",
+ " \n",
+ " | 23 | \n",
+ " 368.088235 | \n",
+ " 0.398162 | \n",
+ " 0.616106 | \n",
+ "
\n",
+ " \n",
+ " | 24 | \n",
+ " 368.205882 | \n",
+ " 0.362340 | \n",
+ " 0.562505 | \n",
+ "
\n",
+ " \n",
+ " | 25 | \n",
+ " 368.323529 | \n",
+ " 0.386958 | \n",
+ " 0.602680 | \n",
+ "
\n",
+ " \n",
+ " | 26 | \n",
+ " 368.441176 | \n",
+ " 0.363643 | \n",
+ " 0.568210 | \n",
+ "
\n",
+ " \n",
+ " | 27 | \n",
+ " 368.558824 | \n",
+ " 0.368118 | \n",
+ " 0.577072 | \n",
+ "
\n",
+ " \n",
+ " | 28 | \n",
+ " 368.676471 | \n",
+ " 0.384098 | \n",
+ " 0.604078 | \n",
+ "
\n",
+ " \n",
+ " | 29 | \n",
+ " 368.794118 | \n",
+ " 0.353605 | \n",
+ " 0.557925 | \n",
+ "
\n",
+ " \n",
+ " | 30 | \n",
+ " 368.911765 | \n",
+ " 0.346474 | \n",
+ " 0.548445 | \n",
+ "
\n",
+ " \n",
+ " | 31 | \n",
+ " 369.029412 | \n",
+ " 0.350741 | \n",
+ " 0.556996 | \n",
+ "
\n",
+ " \n",
+ " | 32 | \n",
+ " 369.147059 | \n",
+ " 0.362347 | \n",
+ " 0.577286 | \n",
+ "
\n",
+ " \n",
+ " | 33 | \n",
+ " 369.264706 | \n",
+ " 0.362578 | \n",
+ " 0.579519 | \n",
+ "
\n",
+ " \n",
+ " | 34 | \n",
+ " 369.382353 | \n",
+ " 0.340765 | \n",
+ " 0.546411 | \n",
+ "
\n",
+ " \n",
+ " | 35 | \n",
+ " 369.500000 | \n",
+ " 0.337462 | \n",
+ " 0.542857 | \n",
+ "
\n",
+ " \n",
+ " | 36 | \n",
+ " 369.617647 | \n",
+ " 0.355729 | \n",
+ " 0.574083 | \n",
+ "
\n",
+ " \n",
+ " | 37 | \n",
+ " 369.735294 | \n",
+ " 0.348679 | \n",
+ " 0.564513 | \n",
+ "
\n",
+ " \n",
+ " | 38 | \n",
+ " 369.852941 | \n",
+ " 0.338187 | \n",
+ " 0.549284 | \n",
+ "
\n",
+ " \n",
+ " | 39 | \n",
+ " 369.970588 | \n",
+ " 0.324360 | \n",
+ " 0.528514 | \n",
+ "
\n",
+ " \n",
+ " | 40 | \n",
+ " 370.088235 | \n",
+ " 0.310753 | \n",
+ " 0.507964 | \n",
+ "
\n",
+ " \n",
+ " | 41 | \n",
+ " 370.205882 | \n",
+ " 0.311037 | \n",
+ " 0.510055 | \n",
+ "
\n",
+ " \n",
+ " | 42 | \n",
+ " 370.323529 | \n",
+ " 0.311263 | \n",
+ " 0.512055 | \n",
+ "
\n",
+ " \n",
+ " | 43 | \n",
+ " 370.441176 | \n",
+ " 0.308081 | \n",
+ " 0.508437 | \n",
+ "
\n",
+ " \n",
+ " | 44 | \n",
+ " 370.558824 | \n",
+ " 0.308224 | \n",
+ " 0.510293 | \n",
+ "
\n",
+ " \n",
+ " | 45 | \n",
+ " 370.676471 | \n",
+ " 0.318148 | \n",
+ " 0.528399 | \n",
+ "
\n",
+ " \n",
+ " | 46 | \n",
+ " 370.794118 | \n",
+ " 0.308334 | \n",
+ " 0.513728 | \n",
+ "
\n",
+ " \n",
+ " | 47 | \n",
+ " 370.911765 | \n",
+ " 0.317937 | \n",
+ " 0.531410 | \n",
+ "
\n",
+ " \n",
+ " | 48 | \n",
+ " 371.029412 | \n",
+ " 0.289149 | \n",
+ " 0.484824 | \n",
+ "
\n",
+ " \n",
+ " | 49 | \n",
+ " 371.147059 | \n",
+ " 0.298637 | \n",
+ " 0.502318 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " temperature liq_benzene vap_benzene\n",
+ "0 365.500000 0.480953 0.692110\n",
+ "1 365.617647 0.462444 0.667699\n",
+ "2 365.735294 0.477984 0.692441\n",
+ "3 365.852941 0.440547 0.640336\n",
+ "4 365.970588 0.427421 0.623328\n",
+ "5 366.088235 0.442725 0.647796\n",
+ "6 366.205882 0.434374 0.637691\n",
+ "7 366.323529 0.444642 0.654933\n",
+ "8 366.441176 0.427132 0.631229\n",
+ "9 366.558824 0.446301 0.661743\n",
+ "10 366.676471 0.438004 0.651591\n",
+ "11 366.794118 0.425320 0.634814\n",
+ "12 366.911765 0.439435 0.658047\n",
+ "13 367.029412 0.435655 0.654539\n",
+ "14 367.147059 0.401350 0.604987\n",
+ "15 367.264706 0.397862 0.601703\n",
+ "16 367.382353 0.415821 0.630930\n",
+ "17 367.500000 0.420667 0.640380\n",
+ "18 367.617647 0.391683 0.598214\n",
+ "19 367.735294 0.404903 0.620432\n",
+ "20 367.852941 0.409563 0.629626\n",
+ "21 367.970588 0.389488 0.600722\n",
+ "22 368.000000 0.396789 0.612483\n",
+ "23 368.088235 0.398162 0.616106\n",
+ "24 368.205882 0.362340 0.562505\n",
+ "25 368.323529 0.386958 0.602680\n",
+ "26 368.441176 0.363643 0.568210\n",
+ "27 368.558824 0.368118 0.577072\n",
+ "28 368.676471 0.384098 0.604078\n",
+ "29 368.794118 0.353605 0.557925\n",
+ "30 368.911765 0.346474 0.548445\n",
+ "31 369.029412 0.350741 0.556996\n",
+ "32 369.147059 0.362347 0.577286\n",
+ "33 369.264706 0.362578 0.579519\n",
+ "34 369.382353 0.340765 0.546411\n",
+ "35 369.500000 0.337462 0.542857\n",
+ "36 369.617647 0.355729 0.574083\n",
+ "37 369.735294 0.348679 0.564513\n",
+ "38 369.852941 0.338187 0.549284\n",
+ "39 369.970588 0.324360 0.528514\n",
+ "40 370.088235 0.310753 0.507964\n",
+ "41 370.205882 0.311037 0.510055\n",
+ "42 370.323529 0.311263 0.512055\n",
+ "43 370.441176 0.308081 0.508437\n",
+ "44 370.558824 0.308224 0.510293\n",
+ "45 370.676471 0.318148 0.528399\n",
+ "46 370.794118 0.308334 0.513728\n",
+ "47 370.911765 0.317937 0.531410\n",
+ "48 371.029412 0.289149 0.484824\n",
+ "49 371.147059 0.298637 0.502318"
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ }
+ ],
"source": [
"# Load data from csv\n",
"data = pd.read_csv(\"BT_NRTL_dataset.csv\")\n",
@@ -375,83 +817,198 @@
"cell_type": "markdown",
"metadata": {},
"source": [
- "We need to provide a method to return an expression to compute the sum of squared errors that will be used as the objective in solving the parameter estimation problem. For this problem, the error will be computed for the mole fraction of benzene in the vapor and liquid phase between the model prediction and data. \n",
- "\n",
- "\n",
- "Inline Exercise:\n",
- "Complete the following cell by adding an expression to compute the sum of square errors. \n",
- "
"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {
- "tags": [
- "exercise"
- ]
- },
- "outputs": [],
- "source": [
- "# Create method to return an expression that computes the sum of squared error\n",
- "def SSE(m, data):\n",
- " # Todo: Add expression for computing the sum of squared errors in mole fraction of benzene in the liquid\n",
- " # and vapor phase. For example, the squared error for the vapor phase is:\n",
- " # (float(data[\"vap_benzene\"]) - m.fs.flash.vap_outlet.mole_frac_comp[0, \"benzene\"])**2\n",
- "\n",
- " return expr * 1e4"
+ "We define the `exp_list` by splitting the data into individual experiments, or data points."
]
},
{
"cell_type": "code",
- "execution_count": null,
- "metadata": {
- "tags": [
- "solution"
- ]
- },
- "outputs": [],
- "source": [
- "# Create method to return an expression that computes the sum of squared error\n",
- "def SSE(m, data):\n",
- " # Todo: Add expression for computing the sum of squared errors in mole fraction of benzene in the liquid\n",
- " # and vapor phase. For example, the squared error for the vapor phase is:\n",
- " # (float(data[\"vap_benzene\"]) - m.fs.flash.vap_outlet.mole_frac_comp[0, \"benzene\"])**2\n",
- " expr = (\n",
- " float(data[\"vap_benzene\"]) - m.fs.flash.vap_outlet.mole_frac_comp[0, \"benzene\"]\n",
- " ) ** 2 + (\n",
- " float(data[\"liq_benzene\"]) - m.fs.flash.liq_outlet.mole_frac_comp[0, \"benzene\"]\n",
- " ) ** 2\n",
- " return expr * 1e4"
- ]
- },
- {
- "cell_type": "markdown",
+ "execution_count": 11,
"metadata": {},
+ "outputs": [],
"source": [
- "\n",
- "Note:\n",
- "Notice that we have scaled the expression up by a factor of 10000 as the SSE computed here will be an extremely small number given that we are using the difference in mole fraction in our expression. A well-scaled objective will help improve solve robustness when using IPOPT. \n",
- "
\n"
+ "# Loop through the dataset and create an experiment for each row of data\n",
+ "exp_list = []\n",
+ "for i in range(data.shape[0]):\n",
+ " exp_list.append(NRTLExperiment(data.iloc[i]))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
- "We are now ready to set up the parameter estimation problem. We will create a parameter estimation object called `pest`. As shown below, we pass the method that returns an initialized model, dataset, list of variable names to estimate, and the SSE expression to the Estimator object. `tee=True` will print the solver output after solving the parameter estimation problem."
+ "We are now ready to set up the parameter estimation problem. We will create a parameter estimation object called pest. As shown below, we pass the experiment list, and an objective function to the Estimator method. tee=True will print the solver output after solving the parameter estimation problem."
]
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 12,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Ipopt 3.13.2: \n",
+ "\n",
+ "******************************************************************************\n",
+ "This program contains Ipopt, a library for large-scale nonlinear optimization.\n",
+ " Ipopt is released as open source code under the Eclipse Public License (EPL).\n",
+ " For more information visit http://projects.coin-or.org/Ipopt\n",
+ "\n",
+ "This version of Ipopt was compiled from source code available at\n",
+ " https://github.com/IDAES/Ipopt as part of the Institute for the Design of\n",
+ " Advanced Energy Systems Process Systems Engineering Framework (IDAES PSE\n",
+ " Framework) Copyright (c) 2018-2019. See https://github.com/IDAES/idaes-pse.\n",
+ "\n",
+ "This version of Ipopt was compiled using HSL, a collection of Fortran codes\n",
+ " for large-scale scientific computation. All technical papers, sales and\n",
+ " publicity material resulting from use of the HSL codes within IPOPT must\n",
+ " contain the following acknowledgement:\n",
+ " HSL, a collection of Fortran codes for large-scale scientific\n",
+ " computation. See http://www.hsl.rl.ac.uk.\n",
+ "******************************************************************************\n",
+ "\n",
+ "This is Ipopt version 3.13.2, running with linear solver ma27.\n",
+ "\n",
+ "Number of nonzeros in equality constraint Jacobian...: 10950\n",
+ "Number of nonzeros in inequality constraint Jacobian.: 0\n",
+ "Number of nonzeros in Lagrangian Hessian.............: 6600\n",
+ "\n",
+ "Total number of variables............................: 2952\n",
+ " variables with only lower bounds: 150\n",
+ " variables with lower and upper bounds: 600\n",
+ " variables with only upper bounds: 0\n",
+ "Total number of equality constraints.................: 2950\n",
+ "Total number of inequality constraints...............: 0\n",
+ " inequality constraints with only lower bounds: 0\n",
+ " inequality constraints with lower and upper bounds: 0\n",
+ " inequality constraints with only upper bounds: 0\n",
+ "\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 0 6.0671019e-03 5.63e+02 1.20e-08 -1.0 0.00e+00 - 0.00e+00 0.00e+00 0\n",
+ " 1 9.0714942e-04 1.37e+03 1.61e+01 -1.0 1.37e+04 - 9.82e-01 1.00e+00h 1\n",
+ " 2 1.3219937e-03 1.17e+04 1.62e+01 -1.0 5.23e+03 - 3.41e-01 1.65e-01h 3\n",
+ " 3 1.3161671e-03 1.11e+04 4.02e+01 -1.0 3.96e+02 -4.0 8.19e-01 1.25e-01h 4\n",
+ " 4 1.3154170e-03 1.11e+04 4.32e+01 -1.0 3.47e+02 -4.5 9.90e-01 4.43e-02h 5\n",
+ " 5 9.4424343e-04 1.04e+04 4.05e+01 -1.0 1.16e+04 - 9.33e-01 5.61e-02h 5\n",
+ " 6 9.4571258e-04 1.11e+04 4.85e+01 -1.0 3.13e+02 -5.0 8.74e-01 1.25e-01h 4\n",
+ " 7 9.4862862e-04 1.11e+04 4.84e+01 -1.0 2.41e+03 -5.4 1.72e-01 1.50e-03h 8\n",
+ " 8 9.5448936e-04 1.10e+04 4.81e+01 -1.0 4.11e+02 -5.0 1.00e+00 1.97e-02h 6\n",
+ " 9 9.5650047e-04 1.10e+04 4.81e+01 -1.0 5.14e+02 -4.6 3.46e-01 5.24e-03h 7\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 10 9.5730419e-04 1.10e+04 4.81e+01 -1.0 9.78e+02 -4.2 4.40e-01 1.08e-03h 8\n",
+ " 11 9.5774182e-04 1.10e+04 4.84e+01 -1.0 2.76e+02 -3.7 2.91e-01 2.99e-03h 7\n",
+ " 12 9.4292855e-04 7.77e+04 4.09e+04 -1.0 5.38e+02 -2.4 5.48e-02 6.44e-02w 1\n",
+ " 13 2.4318219e-01 2.38e+07 4.22e+14 -1.0 1.28e+06 - 2.55e-02 3.49e-02w 1\n",
+ " 14 2.8902019e-01 1.64e+07 2.92e+14 -1.0 1.11e+05 -2.9 9.54e-01 3.01e-01w 1\n",
+ " 15 9.5768293e-04 1.10e+04 4.85e+01 -1.0 2.80e+05 -3.4 5.48e-02 2.52e-04h 8\n",
+ " 16 9.5769345e-04 1.10e+04 4.85e+01 -1.0 4.33e+02 -2.9 7.95e-02 1.91e-04h 9\n",
+ " 17 9.5763809e-04 1.10e+04 4.85e+01 -1.0 6.35e+02 -2.5 4.94e-02 2.08e-04h 9\n",
+ " 18 9.5734836e-04 1.10e+04 4.87e+01 -1.0 3.22e+02 -3.0 1.00e+00 1.22e-03h 8\n",
+ " 19 9.3628114e-04 1.09e+04 4.62e+01 -1.0 4.22e+02 -3.5 5.16e-01 5.87e-02h 5\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 20 7.1894543e-04 4.02e+03 4.95e+02 -1.0 3.49e+02 -3.9 1.00e+00 1.00e+00h 1\n",
+ " 21 6.7062834e-04 1.58e+02 2.21e+02 -1.0 1.78e+02 -4.4 1.00e+00 1.00e+00h 1\n",
+ " 22 6.6635123e-04 4.17e+01 1.12e+01 -1.0 2.44e+02 -4.9 1.00e+00 1.00e+00h 1\n",
+ " 23 6.6729070e-04 1.43e+00 9.69e-01 -1.0 1.08e+01 -5.4 1.00e+00 1.00e+00h 1\n",
+ " 24 6.6785681e-04 3.58e-01 5.25e-03 -1.7 6.65e+00 -5.8 1.00e+00 1.00e+00h 1\n",
+ " 25 6.2552355e-04 9.80e+02 6.48e-02 -3.8 7.92e+02 - 9.22e-01 1.00e+00h 1\n",
+ " 26 5.9105707e-04 8.13e+00 6.13e-04 -3.8 5.66e+02 - 1.00e+00 1.00e+00h 1\n",
+ " 27 6.1313801e-04 6.24e+01 8.08e-06 -3.8 1.70e+02 - 1.00e+00 1.00e+00h 1\n",
+ " 28 6.1208051e-04 3.58e-01 1.18e-08 -3.8 1.88e+00 - 1.00e+00 1.00e+00h 1\n",
+ " 29 5.9010560e-04 1.58e+01 1.00e-05 -5.7 1.08e+02 - 1.00e+00 1.00e+00h 1\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 30 5.9008319e-04 2.74e-02 7.90e-07 -5.7 7.54e-02 -6.3 1.00e+00 1.00e+00h 1\n",
+ " 31 5.3570104e-04 1.48e+04 8.70e-04 -5.7 1.81e+02 - 1.00e+00 1.00e+00h 1\n",
+ " 32 5.1618763e-04 6.29e+02 8.06e-05 -5.7 2.55e+02 - 1.00e+00 1.00e+00h 1\n",
+ " 33 5.5250565e-04 2.88e+01 2.58e-04 -5.7 1.81e+04 - 6.26e-01 6.25e-02h 5\n",
+ " 34 5.2209909e-04 2.88e+02 2.02e-04 -5.7 1.89e+03 - 1.00e+00 1.00e+00h 1\n",
+ " 35 5.0707798e-04 5.60e+01 2.02e-04 -5.7 2.93e+03 - 1.00e+00 1.00e+00h 1\n",
+ " 36 5.0765648e-04 7.87e+00 1.91e-05 -5.7 1.02e+02 - 1.00e+00 1.00e+00h 1\n",
+ " 37 5.0740606e-04 2.57e+00 1.88e-05 -5.7 6.96e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 38 5.0764164e-04 2.55e+00 1.76e-05 -5.7 6.81e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 39 5.0740672e-04 2.55e+00 1.88e-05 -5.7 6.80e+01 - 1.00e+00 1.00e+00h 1\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 40 5.0764162e-04 2.54e+00 1.76e-05 -5.7 6.80e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 41 5.0740672e-04 2.55e+00 1.88e-05 -5.7 6.80e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 42 5.0782847e-04 1.43e-01 1.83e-05 -5.7 6.80e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 43 5.0751252e-04 1.58e-02 1.93e-05 -5.7 6.88e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 44 5.0783218e-04 4.79e-03 1.85e-05 -5.7 6.92e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 45 5.0751252e-04 1.60e-02 1.93e-05 -5.7 6.89e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 46 5.0783222e-04 1.23e-04 1.85e-05 -5.7 6.92e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 47 5.0751252e-04 1.60e-02 1.93e-05 -5.7 6.89e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 48 5.0783216e-04 1.24e-04 1.85e-05 -5.7 6.92e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 49 5.0751765e-04 3.20e-03 1.93e-05 -5.7 6.89e+01 - 1.00e+00 1.00e+00H 1\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 50 5.0764151e-04 2.56e+00 1.77e-05 -5.7 6.93e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 51 5.0740671e-04 2.55e+00 1.88e-05 -5.7 6.81e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 52 5.0764162e-04 2.54e+00 1.76e-05 -5.7 6.80e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 53 5.0740672e-04 2.55e+00 1.88e-05 -5.7 6.80e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 54 5.0764162e-04 2.54e+00 1.76e-05 -5.7 6.80e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 55 5.0748886e-04 1.91e+00 8.64e-06 -5.7 6.80e+01 - 1.00e+00 5.00e-01h 2\n",
+ " 56 5.0744550e-04 3.37e-01 1.64e-05 -5.7 2.54e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 57 5.0763613e-04 1.82e+00 1.43e-05 -5.7 5.79e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 58 5.0751252e-04 2.25e-02 1.93e-05 -5.7 6.65e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 59 5.0783220e-04 1.23e-04 1.85e-05 -5.7 6.92e+01 - 1.00e+00 1.00e+00H 1\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 60 5.0751252e-04 1.60e-02 1.93e-05 -5.7 6.89e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 61 5.0783207e-04 3.26e-04 1.85e-05 -5.7 6.92e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 62 5.0751786e-04 7.95e-05 1.93e-05 -5.7 6.89e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 63 5.0754291e-04 6.40e-01 8.69e-06 -5.7 6.93e+01 - 1.00e+00 5.00e-01h 2\n",
+ " 64 5.0745167e-04 3.00e-01 1.61e-05 -5.7 2.35e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 65 5.0763437e-04 1.71e+00 1.33e-05 -5.7 5.61e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 66 5.0751762e-04 2.91e-03 1.93e-05 -5.7 6.60e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 67 5.0752104e-04 1.62e-01 1.43e-05 -5.7 6.92e+01 - 1.00e+00 2.50e-01h 3\n",
+ " 68 5.0761295e-04 1.03e+00 2.18e-05 -5.7 4.35e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 69 5.0751251e-04 2.38e-02 1.92e-05 -5.7 5.95e+01 - 1.00e+00 1.00e+00H 1\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 70 5.0783210e-04 3.29e-06 1.85e-05 -5.7 6.90e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 71 5.0751786e-04 7.94e-05 1.93e-05 -5.7 6.89e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 72 5.0754292e-04 6.40e-01 8.69e-06 -5.7 6.93e+01 - 1.00e+00 5.00e-01h 2\n",
+ " 73 5.0749299e-04 3.95e-01 1.21e-05 -5.7 2.35e+01 - 1.00e+00 5.00e-01h 2\n",
+ " 74 5.0755524e-04 1.36e-01 3.09e-05 -5.7 1.57e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 75 5.0751308e-04 1.96e-02 1.80e-05 -5.7 3.30e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 76 5.0754492e-04 5.62e-01 8.19e-06 -5.7 6.42e+01 - 1.00e+00 5.00e-01h 2\n",
+ " 77 5.0748301e-04 3.98e-01 1.25e-05 -5.7 2.93e+01 - 1.00e+00 5.00e-01h 2\n",
+ " 78 5.0756455e-04 2.42e-01 3.07e-05 -5.7 2.09e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 79 5.0751710e-04 1.38e-03 1.87e-05 -5.7 3.98e+01 - 1.00e+00 1.00e+00H 1\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 80 5.0783077e-04 3.26e-06 1.84e-05 -5.7 6.70e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 81 5.0726420e-04 1.24e+01 1.85e-05 -8.6 1.34e+02 - 9.93e-01 1.00e+00h 1\n",
+ " 82 5.0749897e-04 2.75e+00 2.53e-06 -8.6 6.93e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 83 5.0749686e-04 3.64e-04 6.40e-10 -8.6 4.69e-02 - 1.00e+00 1.00e+00h 1\n",
+ " 84 5.0749686e-04 7.28e-11 2.51e-14 -8.6 6.86e-05 - 1.00e+00 1.00e+00h 1\n",
+ "\n",
+ "Number of Iterations....: 84\n",
+ "\n",
+ " (scaled) (unscaled)\n",
+ "Objective...............: 5.0749685809243843e-04 5.0749685809243843e-04\n",
+ "Dual infeasibility......: 2.5059195074646584e-14 2.5059195074646584e-14\n",
+ "Constraint violation....: 1.4104644499482425e-11 7.2759576141834259e-11\n",
+ "Complementarity.........: 2.5059035596800647e-09 2.5059035596800647e-09\n",
+ "Overall NLP error.......: 2.5059035596800647e-09 2.5059035596800647e-09\n",
+ "\n",
+ "\n",
+ "Number of objective function evaluations = 260\n",
+ "Number of objective gradient evaluations = 85\n",
+ "Number of equality constraint evaluations = 260\n",
+ "Number of inequality constraint evaluations = 0\n",
+ "Number of equality constraint Jacobian evaluations = 85\n",
+ "Number of inequality constraint Jacobian evaluations = 0\n",
+ "Number of Lagrangian Hessian evaluations = 84\n",
+ "Total CPU secs in IPOPT (w/o function evaluations) = 0.338\n",
+ "Total CPU secs in NLP function evaluations = 0.092\n",
+ "\n",
+ "EXIT: Optimal Solution Found.\n"
+ ]
+ }
+ ],
"source": [
- "# Initialize a parameter estimation object\n",
- "pest = parmest.Estimator(NRTL_model, data, variable_name, SSE, tee=True)\n",
+ "import logging\n",
"\n",
- "# Run parameter estimation using all data\n",
+ "idaeslog.getIdaesLogger(\"core.property_meta\").setLevel(logging.ERROR)\n",
+ "\n",
+ "pest = parmest.Estimator(exp_list, obj_function=\"SSE\", tee=True)\n",
"obj_value, parameters = pest.theta_est()"
]
},
@@ -466,11 +1023,23 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 14,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "The SSE at the optimal solution is 0.000507\n",
+ "\n",
+ "The values for the parameters are as follows:\n",
+ "fs.properties.tau[benzene,toluene] = -0.8987454466579063\n",
+ "fs.properties.tau[toluene,benzene] = 1.410449514796474\n"
+ ]
+ }
+ ],
"source": [
- "print(\"The SSE at the optimal solution is %0.6f\" % (obj_value * 1e-4))\n",
+ "print(\"The SSE at the optimal solution is %0.6f\" % (obj_value))\n",
"print()\n",
"print(\"The values for the parameters are as follows:\")\n",
"for k, v in parameters.items():\n",
@@ -496,7 +1065,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
- "Pyomo's `parmest` tool allows for bootstrapping where the parameter estimation is repeated over `n` samples with resampling from the original data set. Parameter estimation with bootstrap resampling can be used to identify confidence regions around each parameter estimate. This analysis can be slow given the increased number of model instances that need to be solved. Please refer to https://pyomo.readthedocs.io/en/stable/contributed_packages/parmest/driver.html for more details. \n",
+ "Pyomo's `parmest` tool allows for bootstrapping where the parameter estimation is repeated over `n` samples with resampling from the original data set. Parameter estimation with bootstrap resampling can be used to identify confidence regions around each parameter estimate. This analysis can be slow given the increased number of model instances that need to be solved. Please refer to https://pyomo.readthedocs.io/en/stable/explanation/analysis/parmest/covariance.html#bootstrapping for more details. \n",
"\n",
"For the example above, the bootstrapping can be run by uncommenting the code in the following cell:"
]
@@ -507,12 +1076,8 @@
"metadata": {},
"outputs": [],
"source": [
- "# Run parameter estimation using bootstrap resample of the data (10 samples),\n",
- "# plot results along with confidence regions\n",
- "\n",
"# Uncomment the following lines\n",
- "\n",
- "# bootstrap_theta = pest.theta_est_bootstrap(4)\n",
+ "# bootstrap_theta = pest.theta_est_bootstrap(4, seed=542)\n",
"# display(bootstrap_theta)"
]
}
@@ -520,7 +1085,7 @@
"metadata": {
"celltoolbar": "Tags",
"kernelspec": {
- "display_name": "Python 3 (ipykernel)",
+ "display_name": "idaes-pse-and-examples-dev-py313-macmini",
"language": "python",
"name": "python3"
},
@@ -534,9 +1099,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.9.12"
+ "version": "3.13.13"
}
},
"nbformat": 4,
"nbformat_minor": 3
-}
+}
\ No newline at end of file
diff --git a/idaes_examples/notebooks/docs/param_est/parameter_estimation_nrtl_using_unit_model_test.ipynb b/idaes_examples/notebooks/docs/param_est/parameter_estimation_nrtl_using_unit_model_test.ipynb
index 7add77ff..26cc82ee 100644
--- a/idaes_examples/notebooks/docs/param_est/parameter_estimation_nrtl_using_unit_model_test.ipynb
+++ b/idaes_examples/notebooks/docs/param_est/parameter_estimation_nrtl_using_unit_model_test.ipynb
@@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 1,
"metadata": {
"tags": [
"header",
@@ -16,7 +16,7 @@
"# Framework (IDAES IP) was produced under the DOE Institute for the\n",
"# Design of Advanced Energy Systems (IDAES).\n",
"#\n",
- "# Copyright (c) 2018-2023 by the software owners: The Regents of the\n",
+ "# Copyright (c) 2018-2026 by the software owners: The Regents of the\n",
"# University of California, through Lawrence Berkeley National Laboratory,\n",
"# National Technology & Engineering Solutions of Sandia, LLC, Carnegie Mellon\n",
"# University, West Virginia University Research Corporation, et al.\n",
@@ -32,8 +32,8 @@
"# Parameter Estimation Using Flash Unit Model\n",
"\n",
"Author: Jaffer Ghouse \n",
- "Maintainer: Andrew Lee \n",
- "Updated: 2023-06-01 \n",
+ "Maintainer: Stephen Cini \n",
+ "Updated: 2026-06-11 \n",
"\n",
"In this module, we will be using Pyomo's `parmest` tool in conjunction with IDAES models for parameter estimation. We demonstrate these tools by estimating the parameters associated with the NRTL property model for a benzene-toluene mixture. The NRTL model has 2 sets of parameters: the non-randomness parameter (`alpha_ij`) and the binary interaction parameter (`tau_ij`), where `i` and `j` is the pure component species. In this example, we will be only estimate the binary interaction parameter (`tau_ij`) for a given dataset. When estimating parameters associated with the property package, IDAES provides the flexibility of doing the parameter estimation by just using the state block or by using a unit model with a specified property package. This module will demonstrate parameter estimation by using the flash unit model with the NRTL property package. \n",
"\n",
@@ -45,7 +45,7 @@
"\n",
"## Key links to documentation:\n",
"* NRTL Model - https://idaes-pse.readthedocs.io/en/stable/reference_guides/model_libraries/generic/property_models/activity_coefficient.html\n",
- "* parmest - https://pyomo.readthedocs.io/en/stable/contributed_packages/parmest/index.html\n"
+ "* parmest - https://pyomo.readthedocs.io/en/stable/explanation/analysis/parmest/index.html"
]
},
{
@@ -54,13 +54,13 @@
"source": [
"\n",
"Inline Exercise:\n",
- "import `ConcreteModel` from Pyomo, `FlowsheetBlock` and `Flash` from IDAES. \n",
+ "import `ConcreteModel`, `value`, and `Suffix` from Pyomo, `FlowsheetBlock` and `Flash` from IDAES. \n",
"
"
]
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 3,
"metadata": {
"tags": [
"solution"
@@ -68,8 +68,8 @@
},
"outputs": [],
"source": [
- "# Todo: import ConcreteModel from pyomo.environ\n",
- "from pyomo.environ import ConcreteModel, value\n",
+ "# Todo: import ConcreteModel, value, and Suffix from pyomo.environ\n",
+ "from pyomo.environ import ConcreteModel, value, Suffix\n",
"\n",
"# Todo: import FlowsheetBlock from idaes.core\n",
"from idaes.core import FlowsheetBlock\n",
@@ -87,7 +87,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
@@ -106,7 +106,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
@@ -135,7 +135,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 7,
"metadata": {
"tags": [
"solution"
@@ -187,7 +187,12 @@
" m.fs.flash.initialize(outlvl=idaeslog.INFO_LOW)\n",
"\n",
" # Fix at actual temperature\n",
- " m.fs.flash.inlet.temperature.fix(float(data[\"temperature\"]))\n",
+ " if isinstance(data, dict) or isinstance(data, pd.Series):\n",
+ " m.fs.flash.inlet.temperature.fix(float(data[\"temperature\"]))\n",
+ " elif isinstance(data, pd.DataFrame):\n",
+ " m.fs.flash.inlet.temperature.fix(float(data.iloc[0][\"temperature\"]))\n",
+ " else:\n",
+ " raise ValueError(\"Unrecognized data type.\")\n",
"\n",
" # Set bounds on variables to be estimated\n",
" m.fs.properties.tau[\"benzene\", \"toluene\"].setlb(-5)\n",
@@ -202,7 +207,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 8,
"metadata": {
"tags": [
"testing"
@@ -250,42 +255,98 @@
"source": [
"In addition to providing a method to return an initialized model, the `parmest` tool needs the following:\n",
"\n",
- "* List of variable names to be estimated\n",
- "* Dataset with multiple scenarios\n",
- "* Expression to compute the sum of squared errors\n",
- "\n"
+ "* Experiment class to set up and label model with suffixes\n",
+ "* Dataset with multiple scenarios - organized into an experiment list"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
+ "Here we build an experiment class to label our model problem for parameter estimation. The labels are defined as a `Suffix`, and the main labels for our model are `experiment_outputs`, `unknown_parameters`, and `measurement_error`.\n",
+ "\n",
+ "For this problem, the error will be computed for the mole fraction of benzene in the vapor and liquid phase between the model prediction and data. The `experimental_outputs` will therefore be the mole fraction of benzene in the two phases.\n",
+ "\n",
"In this example, we only estimate the binary interaction parameter (`tau_ij`). Given that this variable is usually indexed as `tau_ij = Var(component_list, component_list)`, there are 2*2=4 degrees of freedom. However, when i=j, the binary interaction parameter is 0. Therefore, in this problem, we estimate the binary interaction parameter for the following variables only:\n",
"\n",
"* fs.properties.tau['benzene', 'toluene']\n",
"* fs.properties.tau['toluene', 'benzene']\n",
"\n",
- "\n",
- "Inline Exercise:\n",
- "Create a list called `variable_name` with the above-mentioned variables declared as strings.\n",
- "
"
+ "As shown below, these model components are used as our `unknown_parameters`.\n",
+ "\n",
+ "We define `measurement_error` as none so parmest calculates the value internally based on the experimental outputs. Refer to https://pyomo.readthedocs.io/en/stable/explanation/analysis/parmest/driver.html for more information. "
]
},
{
"cell_type": "code",
- "execution_count": null,
- "metadata": {
- "tags": [
- "solution"
- ]
- },
+ "execution_count": 9,
+ "metadata": {},
"outputs": [],
"source": [
- "# Todo: Create a list of vars to estimate\n",
- "variable_name = [\n",
- " \"fs.properties.tau['benzene', 'toluene']\",\n",
- " \"fs.properties.tau['toluene', 'benzene']\",\n",
- "]"
+ "# Build an experiment class to take advantage of new parmest interface\n",
+ "from pyomo.contrib.parmest.experiment import Experiment\n",
+ "\n",
+ "\n",
+ "class NRTLExperiment(Experiment):\n",
+ " \"\"\"Experiment class for parameter estimation of NRTL model using parmest\"\"\"\n",
+ "\n",
+ " def __init__(self, data, meas_error=None):\n",
+ " \"\"\"Initialize the NRTLExperiment class\n",
+ "\n",
+ " Args:\n",
+ " data: DataFrame containing the experimental data\n",
+ " meas_error: Measurement error for the data (optional)\n",
+ " \"\"\"\n",
+ " self.model = None\n",
+ " self.data = data\n",
+ " self.meas_error = meas_error\n",
+ "\n",
+ " def create_model(self):\n",
+ " \"\"\"Create the Pyomo model for the NRTL parameter estimation problem\"\"\"\n",
+ " self.model = NRTL_model(self.data)\n",
+ "\n",
+ " def label_model(self):\n",
+ " m = self.model\n",
+ "\n",
+ " # Add experiment outputs to the model for easier access\n",
+ " m.experiment_outputs = Suffix(direction=Suffix.LOCAL)\n",
+ " m.experiment_outputs.update(\n",
+ " [\n",
+ " (\n",
+ " m.fs.flash.liq_outlet.mole_frac_comp[0, \"benzene\"],\n",
+ " self.data[\"liq_benzene\"],\n",
+ " ),\n",
+ " (\n",
+ " m.fs.flash.vap_outlet.mole_frac_comp[0, \"benzene\"],\n",
+ " self.data[\"vap_benzene\"],\n",
+ " ),\n",
+ " ]\n",
+ " )\n",
+ "\n",
+ " m.measurement_error = Suffix(direction=Suffix.LOCAL)\n",
+ " m.measurement_error.update(\n",
+ " [\n",
+ " (m.fs.flash.liq_outlet.mole_frac_comp[0, \"benzene\"], self.meas_error),\n",
+ " (m.fs.flash.vap_outlet.mole_frac_comp[0, \"benzene\"], self.meas_error),\n",
+ " ]\n",
+ " )\n",
+ "\n",
+ " # Add unknown parameters to the model for easier access\n",
+ " m.unknown_parameters = Suffix(direction=Suffix.LOCAL)\n",
+ " m.unknown_parameters.update(\n",
+ " (k, value(k))\n",
+ " for k in [\n",
+ " m.fs.properties.tau[\"benzene\", \"toluene\"],\n",
+ " m.fs.properties.tau[\"toluene\", \"benzene\"],\n",
+ " ]\n",
+ " )\n",
+ "\n",
+ " def get_labeled_model(self):\n",
+ " \"\"\"Return the labeled model\"\"\"\n",
+ " if self.model is None:\n",
+ " self.create_model()\n",
+ " self.label_model()\n",
+ " return self.model"
]
},
{
@@ -304,9 +365,398 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 10,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " temperature | \n",
+ " liq_benzene | \n",
+ " vap_benzene | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 0 | \n",
+ " 365.500000 | \n",
+ " 0.480953 | \n",
+ " 0.692110 | \n",
+ "
\n",
+ " \n",
+ " | 1 | \n",
+ " 365.617647 | \n",
+ " 0.462444 | \n",
+ " 0.667699 | \n",
+ "
\n",
+ " \n",
+ " | 2 | \n",
+ " 365.735294 | \n",
+ " 0.477984 | \n",
+ " 0.692441 | \n",
+ "
\n",
+ " \n",
+ " | 3 | \n",
+ " 365.852941 | \n",
+ " 0.440547 | \n",
+ " 0.640336 | \n",
+ "
\n",
+ " \n",
+ " | 4 | \n",
+ " 365.970588 | \n",
+ " 0.427421 | \n",
+ " 0.623328 | \n",
+ "
\n",
+ " \n",
+ " | 5 | \n",
+ " 366.088235 | \n",
+ " 0.442725 | \n",
+ " 0.647796 | \n",
+ "
\n",
+ " \n",
+ " | 6 | \n",
+ " 366.205882 | \n",
+ " 0.434374 | \n",
+ " 0.637691 | \n",
+ "
\n",
+ " \n",
+ " | 7 | \n",
+ " 366.323529 | \n",
+ " 0.444642 | \n",
+ " 0.654933 | \n",
+ "
\n",
+ " \n",
+ " | 8 | \n",
+ " 366.441176 | \n",
+ " 0.427132 | \n",
+ " 0.631229 | \n",
+ "
\n",
+ " \n",
+ " | 9 | \n",
+ " 366.558824 | \n",
+ " 0.446301 | \n",
+ " 0.661743 | \n",
+ "
\n",
+ " \n",
+ " | 10 | \n",
+ " 366.676471 | \n",
+ " 0.438004 | \n",
+ " 0.651591 | \n",
+ "
\n",
+ " \n",
+ " | 11 | \n",
+ " 366.794118 | \n",
+ " 0.425320 | \n",
+ " 0.634814 | \n",
+ "
\n",
+ " \n",
+ " | 12 | \n",
+ " 366.911765 | \n",
+ " 0.439435 | \n",
+ " 0.658047 | \n",
+ "
\n",
+ " \n",
+ " | 13 | \n",
+ " 367.029412 | \n",
+ " 0.435655 | \n",
+ " 0.654539 | \n",
+ "
\n",
+ " \n",
+ " | 14 | \n",
+ " 367.147059 | \n",
+ " 0.401350 | \n",
+ " 0.604987 | \n",
+ "
\n",
+ " \n",
+ " | 15 | \n",
+ " 367.264706 | \n",
+ " 0.397862 | \n",
+ " 0.601703 | \n",
+ "
\n",
+ " \n",
+ " | 16 | \n",
+ " 367.382353 | \n",
+ " 0.415821 | \n",
+ " 0.630930 | \n",
+ "
\n",
+ " \n",
+ " | 17 | \n",
+ " 367.500000 | \n",
+ " 0.420667 | \n",
+ " 0.640380 | \n",
+ "
\n",
+ " \n",
+ " | 18 | \n",
+ " 367.617647 | \n",
+ " 0.391683 | \n",
+ " 0.598214 | \n",
+ "
\n",
+ " \n",
+ " | 19 | \n",
+ " 367.735294 | \n",
+ " 0.404903 | \n",
+ " 0.620432 | \n",
+ "
\n",
+ " \n",
+ " | 20 | \n",
+ " 367.852941 | \n",
+ " 0.409563 | \n",
+ " 0.629626 | \n",
+ "
\n",
+ " \n",
+ " | 21 | \n",
+ " 367.970588 | \n",
+ " 0.389488 | \n",
+ " 0.600722 | \n",
+ "
\n",
+ " \n",
+ " | 22 | \n",
+ " 368.000000 | \n",
+ " 0.396789 | \n",
+ " 0.612483 | \n",
+ "
\n",
+ " \n",
+ " | 23 | \n",
+ " 368.088235 | \n",
+ " 0.398162 | \n",
+ " 0.616106 | \n",
+ "
\n",
+ " \n",
+ " | 24 | \n",
+ " 368.205882 | \n",
+ " 0.362340 | \n",
+ " 0.562505 | \n",
+ "
\n",
+ " \n",
+ " | 25 | \n",
+ " 368.323529 | \n",
+ " 0.386958 | \n",
+ " 0.602680 | \n",
+ "
\n",
+ " \n",
+ " | 26 | \n",
+ " 368.441176 | \n",
+ " 0.363643 | \n",
+ " 0.568210 | \n",
+ "
\n",
+ " \n",
+ " | 27 | \n",
+ " 368.558824 | \n",
+ " 0.368118 | \n",
+ " 0.577072 | \n",
+ "
\n",
+ " \n",
+ " | 28 | \n",
+ " 368.676471 | \n",
+ " 0.384098 | \n",
+ " 0.604078 | \n",
+ "
\n",
+ " \n",
+ " | 29 | \n",
+ " 368.794118 | \n",
+ " 0.353605 | \n",
+ " 0.557925 | \n",
+ "
\n",
+ " \n",
+ " | 30 | \n",
+ " 368.911765 | \n",
+ " 0.346474 | \n",
+ " 0.548445 | \n",
+ "
\n",
+ " \n",
+ " | 31 | \n",
+ " 369.029412 | \n",
+ " 0.350741 | \n",
+ " 0.556996 | \n",
+ "
\n",
+ " \n",
+ " | 32 | \n",
+ " 369.147059 | \n",
+ " 0.362347 | \n",
+ " 0.577286 | \n",
+ "
\n",
+ " \n",
+ " | 33 | \n",
+ " 369.264706 | \n",
+ " 0.362578 | \n",
+ " 0.579519 | \n",
+ "
\n",
+ " \n",
+ " | 34 | \n",
+ " 369.382353 | \n",
+ " 0.340765 | \n",
+ " 0.546411 | \n",
+ "
\n",
+ " \n",
+ " | 35 | \n",
+ " 369.500000 | \n",
+ " 0.337462 | \n",
+ " 0.542857 | \n",
+ "
\n",
+ " \n",
+ " | 36 | \n",
+ " 369.617647 | \n",
+ " 0.355729 | \n",
+ " 0.574083 | \n",
+ "
\n",
+ " \n",
+ " | 37 | \n",
+ " 369.735294 | \n",
+ " 0.348679 | \n",
+ " 0.564513 | \n",
+ "
\n",
+ " \n",
+ " | 38 | \n",
+ " 369.852941 | \n",
+ " 0.338187 | \n",
+ " 0.549284 | \n",
+ "
\n",
+ " \n",
+ " | 39 | \n",
+ " 369.970588 | \n",
+ " 0.324360 | \n",
+ " 0.528514 | \n",
+ "
\n",
+ " \n",
+ " | 40 | \n",
+ " 370.088235 | \n",
+ " 0.310753 | \n",
+ " 0.507964 | \n",
+ "
\n",
+ " \n",
+ " | 41 | \n",
+ " 370.205882 | \n",
+ " 0.311037 | \n",
+ " 0.510055 | \n",
+ "
\n",
+ " \n",
+ " | 42 | \n",
+ " 370.323529 | \n",
+ " 0.311263 | \n",
+ " 0.512055 | \n",
+ "
\n",
+ " \n",
+ " | 43 | \n",
+ " 370.441176 | \n",
+ " 0.308081 | \n",
+ " 0.508437 | \n",
+ "
\n",
+ " \n",
+ " | 44 | \n",
+ " 370.558824 | \n",
+ " 0.308224 | \n",
+ " 0.510293 | \n",
+ "
\n",
+ " \n",
+ " | 45 | \n",
+ " 370.676471 | \n",
+ " 0.318148 | \n",
+ " 0.528399 | \n",
+ "
\n",
+ " \n",
+ " | 46 | \n",
+ " 370.794118 | \n",
+ " 0.308334 | \n",
+ " 0.513728 | \n",
+ "
\n",
+ " \n",
+ " | 47 | \n",
+ " 370.911765 | \n",
+ " 0.317937 | \n",
+ " 0.531410 | \n",
+ "
\n",
+ " \n",
+ " | 48 | \n",
+ " 371.029412 | \n",
+ " 0.289149 | \n",
+ " 0.484824 | \n",
+ "
\n",
+ " \n",
+ " | 49 | \n",
+ " 371.147059 | \n",
+ " 0.298637 | \n",
+ " 0.502318 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " temperature liq_benzene vap_benzene\n",
+ "0 365.500000 0.480953 0.692110\n",
+ "1 365.617647 0.462444 0.667699\n",
+ "2 365.735294 0.477984 0.692441\n",
+ "3 365.852941 0.440547 0.640336\n",
+ "4 365.970588 0.427421 0.623328\n",
+ "5 366.088235 0.442725 0.647796\n",
+ "6 366.205882 0.434374 0.637691\n",
+ "7 366.323529 0.444642 0.654933\n",
+ "8 366.441176 0.427132 0.631229\n",
+ "9 366.558824 0.446301 0.661743\n",
+ "10 366.676471 0.438004 0.651591\n",
+ "11 366.794118 0.425320 0.634814\n",
+ "12 366.911765 0.439435 0.658047\n",
+ "13 367.029412 0.435655 0.654539\n",
+ "14 367.147059 0.401350 0.604987\n",
+ "15 367.264706 0.397862 0.601703\n",
+ "16 367.382353 0.415821 0.630930\n",
+ "17 367.500000 0.420667 0.640380\n",
+ "18 367.617647 0.391683 0.598214\n",
+ "19 367.735294 0.404903 0.620432\n",
+ "20 367.852941 0.409563 0.629626\n",
+ "21 367.970588 0.389488 0.600722\n",
+ "22 368.000000 0.396789 0.612483\n",
+ "23 368.088235 0.398162 0.616106\n",
+ "24 368.205882 0.362340 0.562505\n",
+ "25 368.323529 0.386958 0.602680\n",
+ "26 368.441176 0.363643 0.568210\n",
+ "27 368.558824 0.368118 0.577072\n",
+ "28 368.676471 0.384098 0.604078\n",
+ "29 368.794118 0.353605 0.557925\n",
+ "30 368.911765 0.346474 0.548445\n",
+ "31 369.029412 0.350741 0.556996\n",
+ "32 369.147059 0.362347 0.577286\n",
+ "33 369.264706 0.362578 0.579519\n",
+ "34 369.382353 0.340765 0.546411\n",
+ "35 369.500000 0.337462 0.542857\n",
+ "36 369.617647 0.355729 0.574083\n",
+ "37 369.735294 0.348679 0.564513\n",
+ "38 369.852941 0.338187 0.549284\n",
+ "39 369.970588 0.324360 0.528514\n",
+ "40 370.088235 0.310753 0.507964\n",
+ "41 370.205882 0.311037 0.510055\n",
+ "42 370.323529 0.311263 0.512055\n",
+ "43 370.441176 0.308081 0.508437\n",
+ "44 370.558824 0.308224 0.510293\n",
+ "45 370.676471 0.318148 0.528399\n",
+ "46 370.794118 0.308334 0.513728\n",
+ "47 370.911765 0.317937 0.531410\n",
+ "48 371.029412 0.289149 0.484824\n",
+ "49 371.147059 0.298637 0.502318"
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ }
+ ],
"source": [
"# Load data from csv\n",
"data = pd.read_csv(\"BT_NRTL_dataset.csv\")\n",
@@ -319,70 +769,204 @@
"cell_type": "markdown",
"metadata": {},
"source": [
- "We need to provide a method to return an expression to compute the sum of squared errors that will be used as the objective in solving the parameter estimation problem. For this problem, the error will be computed for the mole fraction of benzene in the vapor and liquid phase between the model prediction and data. \n",
- "\n",
- "\n",
- "Inline Exercise:\n",
- "Complete the following cell by adding an expression to compute the sum of square errors. \n",
- "
"
+ "We define the `exp_list` by splitting the data into individual experiments, or data points."
]
},
{
"cell_type": "code",
- "execution_count": null,
- "metadata": {
- "tags": [
- "solution"
- ]
- },
- "outputs": [],
- "source": [
- "# Create method to return an expression that computes the sum of squared error\n",
- "def SSE(m, data):\n",
- " # Todo: Add expression for computing the sum of squared errors in mole fraction of benzene in the liquid\n",
- " # and vapor phase. For example, the squared error for the vapor phase is:\n",
- " # (float(data[\"vap_benzene\"]) - m.fs.flash.vap_outlet.mole_frac_comp[0, \"benzene\"])**2\n",
- " expr = (\n",
- " float(data[\"vap_benzene\"]) - m.fs.flash.vap_outlet.mole_frac_comp[0, \"benzene\"]\n",
- " ) ** 2 + (\n",
- " float(data[\"liq_benzene\"]) - m.fs.flash.liq_outlet.mole_frac_comp[0, \"benzene\"]\n",
- " ) ** 2\n",
- " return expr * 1e4"
- ]
- },
- {
- "cell_type": "markdown",
+ "execution_count": 11,
"metadata": {},
+ "outputs": [],
"source": [
- "\n",
- "Note:\n",
- "Notice that we have scaled the expression up by a factor of 10000 as the SSE computed here will be an extremely small number given that we are using the difference in mole fraction in our expression. A well-scaled objective will help improve solve robustness when using IPOPT. \n",
- "
\n"
+ "# Loop through the dataset and create an experiment for each row of data\n",
+ "exp_list = []\n",
+ "for i in range(data.shape[0]):\n",
+ " exp_list.append(NRTLExperiment(data.iloc[i]))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
- "We are now ready to set up the parameter estimation problem. We will create a parameter estimation object called `pest`. As shown below, we pass the method that returns an initialized model, dataset, list of variable names to estimate, and the SSE expression to the Estimator object. `tee=True` will print the solver output after solving the parameter estimation problem."
+ "We are now ready to set up the parameter estimation problem. We will create a parameter estimation object called pest. As shown below, we pass the experiment list, and an objective function to the Estimator method. tee=True will print the solver output after solving the parameter estimation problem."
]
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 12,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Ipopt 3.13.2: \n",
+ "\n",
+ "******************************************************************************\n",
+ "This program contains Ipopt, a library for large-scale nonlinear optimization.\n",
+ " Ipopt is released as open source code under the Eclipse Public License (EPL).\n",
+ " For more information visit http://projects.coin-or.org/Ipopt\n",
+ "\n",
+ "This version of Ipopt was compiled from source code available at\n",
+ " https://github.com/IDAES/Ipopt as part of the Institute for the Design of\n",
+ " Advanced Energy Systems Process Systems Engineering Framework (IDAES PSE\n",
+ " Framework) Copyright (c) 2018-2019. See https://github.com/IDAES/idaes-pse.\n",
+ "\n",
+ "This version of Ipopt was compiled using HSL, a collection of Fortran codes\n",
+ " for large-scale scientific computation. All technical papers, sales and\n",
+ " publicity material resulting from use of the HSL codes within IPOPT must\n",
+ " contain the following acknowledgement:\n",
+ " HSL, a collection of Fortran codes for large-scale scientific\n",
+ " computation. See http://www.hsl.rl.ac.uk.\n",
+ "******************************************************************************\n",
+ "\n",
+ "This is Ipopt version 3.13.2, running with linear solver ma27.\n",
+ "\n",
+ "Number of nonzeros in equality constraint Jacobian...: 10950\n",
+ "Number of nonzeros in inequality constraint Jacobian.: 0\n",
+ "Number of nonzeros in Lagrangian Hessian.............: 6600\n",
+ "\n",
+ "Total number of variables............................: 2952\n",
+ " variables with only lower bounds: 150\n",
+ " variables with lower and upper bounds: 600\n",
+ " variables with only upper bounds: 0\n",
+ "Total number of equality constraints.................: 2950\n",
+ "Total number of inequality constraints...............: 0\n",
+ " inequality constraints with only lower bounds: 0\n",
+ " inequality constraints with lower and upper bounds: 0\n",
+ " inequality constraints with only upper bounds: 0\n",
+ "\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 0 6.0671019e-03 5.63e+02 1.20e-08 -1.0 0.00e+00 - 0.00e+00 0.00e+00 0\n",
+ " 1 9.0714942e-04 1.37e+03 1.61e+01 -1.0 1.37e+04 - 9.82e-01 1.00e+00h 1\n",
+ " 2 1.3219937e-03 1.17e+04 1.62e+01 -1.0 5.23e+03 - 3.41e-01 1.65e-01h 3\n",
+ " 3 1.3161671e-03 1.11e+04 4.02e+01 -1.0 3.96e+02 -4.0 8.19e-01 1.25e-01h 4\n",
+ " 4 1.3154170e-03 1.11e+04 4.32e+01 -1.0 3.47e+02 -4.5 9.90e-01 4.43e-02h 5\n",
+ " 5 9.4424343e-04 1.04e+04 4.05e+01 -1.0 1.16e+04 - 9.33e-01 5.61e-02h 5\n",
+ " 6 9.4571258e-04 1.11e+04 4.85e+01 -1.0 3.13e+02 -5.0 8.74e-01 1.25e-01h 4\n",
+ " 7 9.4862862e-04 1.11e+04 4.84e+01 -1.0 2.41e+03 -5.4 1.72e-01 1.50e-03h 8\n",
+ " 8 9.5448936e-04 1.10e+04 4.81e+01 -1.0 4.11e+02 -5.0 1.00e+00 1.97e-02h 6\n",
+ " 9 9.5650047e-04 1.10e+04 4.81e+01 -1.0 5.14e+02 -4.6 3.46e-01 5.24e-03h 7\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 10 9.5730419e-04 1.10e+04 4.81e+01 -1.0 9.78e+02 -4.2 4.40e-01 1.08e-03h 8\n",
+ " 11 9.5774182e-04 1.10e+04 4.84e+01 -1.0 2.76e+02 -3.7 2.91e-01 2.99e-03h 7\n",
+ " 12 9.4292855e-04 7.77e+04 4.09e+04 -1.0 5.38e+02 -2.4 5.48e-02 6.44e-02w 1\n",
+ " 13 2.4318219e-01 2.38e+07 4.22e+14 -1.0 1.28e+06 - 2.55e-02 3.49e-02w 1\n",
+ " 14 2.8902019e-01 1.64e+07 2.92e+14 -1.0 1.11e+05 -2.9 9.54e-01 3.01e-01w 1\n",
+ " 15 9.5768293e-04 1.10e+04 4.85e+01 -1.0 2.80e+05 -3.4 5.48e-02 2.52e-04h 8\n",
+ " 16 9.5769345e-04 1.10e+04 4.85e+01 -1.0 4.33e+02 -2.9 7.95e-02 1.91e-04h 9\n",
+ " 17 9.5763809e-04 1.10e+04 4.85e+01 -1.0 6.35e+02 -2.5 4.94e-02 2.08e-04h 9\n",
+ " 18 9.5734836e-04 1.10e+04 4.87e+01 -1.0 3.22e+02 -3.0 1.00e+00 1.22e-03h 8\n",
+ " 19 9.3628114e-04 1.09e+04 4.62e+01 -1.0 4.22e+02 -3.5 5.16e-01 5.87e-02h 5\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 20 7.1894543e-04 4.02e+03 4.95e+02 -1.0 3.49e+02 -3.9 1.00e+00 1.00e+00h 1\n",
+ " 21 6.7062834e-04 1.58e+02 2.21e+02 -1.0 1.78e+02 -4.4 1.00e+00 1.00e+00h 1\n",
+ " 22 6.6635123e-04 4.17e+01 1.12e+01 -1.0 2.44e+02 -4.9 1.00e+00 1.00e+00h 1\n",
+ " 23 6.6729070e-04 1.43e+00 9.69e-01 -1.0 1.08e+01 -5.4 1.00e+00 1.00e+00h 1\n",
+ " 24 6.6785681e-04 3.58e-01 5.25e-03 -1.7 6.65e+00 -5.8 1.00e+00 1.00e+00h 1\n",
+ " 25 6.2552355e-04 9.80e+02 6.48e-02 -3.8 7.92e+02 - 9.22e-01 1.00e+00h 1\n",
+ " 26 5.9105707e-04 8.13e+00 6.13e-04 -3.8 5.66e+02 - 1.00e+00 1.00e+00h 1\n",
+ " 27 6.1313801e-04 6.24e+01 8.08e-06 -3.8 1.70e+02 - 1.00e+00 1.00e+00h 1\n",
+ " 28 6.1208051e-04 3.58e-01 1.18e-08 -3.8 1.88e+00 - 1.00e+00 1.00e+00h 1\n",
+ " 29 5.9010560e-04 1.58e+01 1.00e-05 -5.7 1.08e+02 - 1.00e+00 1.00e+00h 1\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 30 5.9008319e-04 2.74e-02 7.90e-07 -5.7 7.54e-02 -6.3 1.00e+00 1.00e+00h 1\n",
+ " 31 5.3570104e-04 1.48e+04 8.70e-04 -5.7 1.81e+02 - 1.00e+00 1.00e+00h 1\n",
+ " 32 5.1618763e-04 6.29e+02 8.06e-05 -5.7 2.55e+02 - 1.00e+00 1.00e+00h 1\n",
+ " 33 5.5250565e-04 2.88e+01 2.58e-04 -5.7 1.81e+04 - 6.26e-01 6.25e-02h 5\n",
+ " 34 5.2209909e-04 2.88e+02 2.02e-04 -5.7 1.89e+03 - 1.00e+00 1.00e+00h 1\n",
+ " 35 5.0707798e-04 5.60e+01 2.02e-04 -5.7 2.93e+03 - 1.00e+00 1.00e+00h 1\n",
+ " 36 5.0765648e-04 7.87e+00 1.91e-05 -5.7 1.02e+02 - 1.00e+00 1.00e+00h 1\n",
+ " 37 5.0740606e-04 2.57e+00 1.88e-05 -5.7 6.96e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 38 5.0764164e-04 2.55e+00 1.76e-05 -5.7 6.81e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 39 5.0740672e-04 2.55e+00 1.88e-05 -5.7 6.80e+01 - 1.00e+00 1.00e+00h 1\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 40 5.0764162e-04 2.54e+00 1.76e-05 -5.7 6.80e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 41 5.0740672e-04 2.55e+00 1.88e-05 -5.7 6.80e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 42 5.0782847e-04 1.43e-01 1.83e-05 -5.7 6.80e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 43 5.0751252e-04 1.58e-02 1.93e-05 -5.7 6.88e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 44 5.0783218e-04 4.79e-03 1.85e-05 -5.7 6.92e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 45 5.0751252e-04 1.60e-02 1.93e-05 -5.7 6.89e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 46 5.0783222e-04 1.23e-04 1.85e-05 -5.7 6.92e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 47 5.0751252e-04 1.60e-02 1.93e-05 -5.7 6.89e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 48 5.0783216e-04 1.24e-04 1.85e-05 -5.7 6.92e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 49 5.0751765e-04 3.20e-03 1.93e-05 -5.7 6.89e+01 - 1.00e+00 1.00e+00H 1\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 50 5.0764151e-04 2.56e+00 1.77e-05 -5.7 6.93e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 51 5.0740671e-04 2.55e+00 1.88e-05 -5.7 6.81e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 52 5.0764162e-04 2.54e+00 1.76e-05 -5.7 6.80e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 53 5.0740672e-04 2.55e+00 1.88e-05 -5.7 6.80e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 54 5.0764162e-04 2.54e+00 1.76e-05 -5.7 6.80e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 55 5.0748886e-04 1.91e+00 8.64e-06 -5.7 6.80e+01 - 1.00e+00 5.00e-01h 2\n",
+ " 56 5.0744550e-04 3.37e-01 1.64e-05 -5.7 2.54e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 57 5.0763613e-04 1.82e+00 1.43e-05 -5.7 5.79e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 58 5.0751252e-04 2.25e-02 1.93e-05 -5.7 6.65e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 59 5.0783220e-04 1.23e-04 1.85e-05 -5.7 6.92e+01 - 1.00e+00 1.00e+00H 1\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 60 5.0751252e-04 1.60e-02 1.93e-05 -5.7 6.89e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 61 5.0783207e-04 3.26e-04 1.85e-05 -5.7 6.92e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 62 5.0751786e-04 7.95e-05 1.93e-05 -5.7 6.89e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 63 5.0754291e-04 6.40e-01 8.69e-06 -5.7 6.93e+01 - 1.00e+00 5.00e-01h 2\n",
+ " 64 5.0745167e-04 3.00e-01 1.61e-05 -5.7 2.35e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 65 5.0763437e-04 1.71e+00 1.33e-05 -5.7 5.61e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 66 5.0751762e-04 2.91e-03 1.93e-05 -5.7 6.60e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 67 5.0752104e-04 1.62e-01 1.43e-05 -5.7 6.92e+01 - 1.00e+00 2.50e-01h 3\n",
+ " 68 5.0761295e-04 1.03e+00 2.18e-05 -5.7 4.35e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 69 5.0751251e-04 2.38e-02 1.92e-05 -5.7 5.95e+01 - 1.00e+00 1.00e+00H 1\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 70 5.0783210e-04 3.29e-06 1.85e-05 -5.7 6.90e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 71 5.0751786e-04 7.94e-05 1.93e-05 -5.7 6.89e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 72 5.0754292e-04 6.40e-01 8.69e-06 -5.7 6.93e+01 - 1.00e+00 5.00e-01h 2\n",
+ " 73 5.0749299e-04 3.95e-01 1.21e-05 -5.7 2.35e+01 - 1.00e+00 5.00e-01h 2\n",
+ " 74 5.0755524e-04 1.36e-01 3.09e-05 -5.7 1.57e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 75 5.0751308e-04 1.96e-02 1.80e-05 -5.7 3.30e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 76 5.0754492e-04 5.62e-01 8.19e-06 -5.7 6.42e+01 - 1.00e+00 5.00e-01h 2\n",
+ " 77 5.0748301e-04 3.98e-01 1.25e-05 -5.7 2.93e+01 - 1.00e+00 5.00e-01h 2\n",
+ " 78 5.0756455e-04 2.42e-01 3.07e-05 -5.7 2.09e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 79 5.0751710e-04 1.38e-03 1.87e-05 -5.7 3.98e+01 - 1.00e+00 1.00e+00H 1\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 80 5.0783077e-04 3.26e-06 1.84e-05 -5.7 6.70e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 81 5.0726420e-04 1.24e+01 1.85e-05 -8.6 1.34e+02 - 9.93e-01 1.00e+00h 1\n",
+ " 82 5.0749897e-04 2.75e+00 2.53e-06 -8.6 6.93e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 83 5.0749686e-04 3.64e-04 6.40e-10 -8.6 4.69e-02 - 1.00e+00 1.00e+00h 1\n",
+ " 84 5.0749686e-04 7.28e-11 2.51e-14 -8.6 6.86e-05 - 1.00e+00 1.00e+00h 1\n",
+ "\n",
+ "Number of Iterations....: 84\n",
+ "\n",
+ " (scaled) (unscaled)\n",
+ "Objective...............: 5.0749685809243843e-04 5.0749685809243843e-04\n",
+ "Dual infeasibility......: 2.5059195074646584e-14 2.5059195074646584e-14\n",
+ "Constraint violation....: 1.4104644499482425e-11 7.2759576141834259e-11\n",
+ "Complementarity.........: 2.5059035596800647e-09 2.5059035596800647e-09\n",
+ "Overall NLP error.......: 2.5059035596800647e-09 2.5059035596800647e-09\n",
+ "\n",
+ "\n",
+ "Number of objective function evaluations = 260\n",
+ "Number of objective gradient evaluations = 85\n",
+ "Number of equality constraint evaluations = 260\n",
+ "Number of inequality constraint evaluations = 0\n",
+ "Number of equality constraint Jacobian evaluations = 85\n",
+ "Number of inequality constraint Jacobian evaluations = 0\n",
+ "Number of Lagrangian Hessian evaluations = 84\n",
+ "Total CPU secs in IPOPT (w/o function evaluations) = 0.338\n",
+ "Total CPU secs in NLP function evaluations = 0.092\n",
+ "\n",
+ "EXIT: Optimal Solution Found.\n"
+ ]
+ }
+ ],
"source": [
- "# Initialize a parameter estimation object\n",
- "pest = parmest.Estimator(NRTL_model, data, variable_name, SSE, tee=True)\n",
+ "import logging\n",
+ "\n",
+ "idaeslog.getIdaesLogger(\"core.property_meta\").setLevel(logging.ERROR)\n",
"\n",
- "# Run parameter estimation using all data\n",
+ "pest = parmest.Estimator(exp_list, obj_function=\"SSE\", tee=True)\n",
"obj_value, parameters = pest.theta_est()"
]
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 13,
"metadata": {
"tags": [
"testing"
@@ -391,7 +975,7 @@
"outputs": [],
"source": [
"# Check for values of the parameter estimation problem\n",
- "assert obj_value == pytest.approx(5.07496, abs=1e-1)\n",
+ "assert obj_value == pytest.approx(5.07496e-4, abs=1e-1)\n",
"assert parameters[\"fs.properties.tau[benzene,toluene]\"] == pytest.approx(-0.89876, 1e-3)\n",
"assert parameters[\"fs.properties.tau[toluene,benzene]\"] == pytest.approx(1.410486, 1e-3)"
]
@@ -407,11 +991,23 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 14,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "The SSE at the optimal solution is 0.000507\n",
+ "\n",
+ "The values for the parameters are as follows:\n",
+ "fs.properties.tau[benzene,toluene] = -0.8987454466579063\n",
+ "fs.properties.tau[toluene,benzene] = 1.410449514796474\n"
+ ]
+ }
+ ],
"source": [
- "print(\"The SSE at the optimal solution is %0.6f\" % (obj_value * 1e-4))\n",
+ "print(\"The SSE at the optimal solution is %0.6f\" % (obj_value))\n",
"print()\n",
"print(\"The values for the parameters are as follows:\")\n",
"for k, v in parameters.items():\n",
@@ -437,7 +1033,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
- "Pyomo's `parmest` tool allows for bootstrapping where the parameter estimation is repeated over `n` samples with resampling from the original data set. Parameter estimation with bootstrap resampling can be used to identify confidence regions around each parameter estimate. This analysis can be slow given the increased number of model instances that need to be solved. Please refer to https://pyomo.readthedocs.io/en/stable/contributed_packages/parmest/driver.html for more details. \n",
+ "Pyomo's `parmest` tool allows for bootstrapping where the parameter estimation is repeated over `n` samples with resampling from the original data set. Parameter estimation with bootstrap resampling can be used to identify confidence regions around each parameter estimate. This analysis can be slow given the increased number of model instances that need to be solved. Please refer to https://pyomo.readthedocs.io/en/stable/explanation/analysis/parmest/covariance.html#bootstrapping for more details. \n",
"\n",
"For the example above, the bootstrapping can be run by uncommenting the code in the following cell:"
]
@@ -448,12 +1044,8 @@
"metadata": {},
"outputs": [],
"source": [
- "# Run parameter estimation using bootstrap resample of the data (10 samples),\n",
- "# plot results along with confidence regions\n",
- "\n",
"# Uncomment the following lines\n",
- "\n",
- "# bootstrap_theta = pest.theta_est_bootstrap(4)\n",
+ "# bootstrap_theta = pest.theta_est_bootstrap(4, seed=542)\n",
"# display(bootstrap_theta)"
]
}
@@ -461,7 +1053,7 @@
"metadata": {
"celltoolbar": "Tags",
"kernelspec": {
- "display_name": "Python 3 (ipykernel)",
+ "display_name": "idaes-pse-and-examples-dev-py313-macmini",
"language": "python",
"name": "python3"
},
@@ -475,9 +1067,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.9.12"
+ "version": "3.13.13"
}
},
"nbformat": 4,
"nbformat_minor": 3
-}
+}
\ No newline at end of file
diff --git a/idaes_examples/notebooks/docs/param_est/parameter_estimation_nrtl_using_unit_model_usr.ipynb b/idaes_examples/notebooks/docs/param_est/parameter_estimation_nrtl_using_unit_model_usr.ipynb
index d70ff27d..ad88977a 100644
--- a/idaes_examples/notebooks/docs/param_est/parameter_estimation_nrtl_using_unit_model_usr.ipynb
+++ b/idaes_examples/notebooks/docs/param_est/parameter_estimation_nrtl_using_unit_model_usr.ipynb
@@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 1,
"metadata": {
"tags": [
"header",
@@ -16,7 +16,7 @@
"# Framework (IDAES IP) was produced under the DOE Institute for the\n",
"# Design of Advanced Energy Systems (IDAES).\n",
"#\n",
- "# Copyright (c) 2018-2023 by the software owners: The Regents of the\n",
+ "# Copyright (c) 2018-2026 by the software owners: The Regents of the\n",
"# University of California, through Lawrence Berkeley National Laboratory,\n",
"# National Technology & Engineering Solutions of Sandia, LLC, Carnegie Mellon\n",
"# University, West Virginia University Research Corporation, et al.\n",
@@ -32,8 +32,8 @@
"# Parameter Estimation Using Flash Unit Model\n",
"\n",
"Author: Jaffer Ghouse \n",
- "Maintainer: Andrew Lee \n",
- "Updated: 2023-06-01 \n",
+ "Maintainer: Stephen Cini \n",
+ "Updated: 2026-06-11 \n",
"\n",
"In this module, we will be using Pyomo's `parmest` tool in conjunction with IDAES models for parameter estimation. We demonstrate these tools by estimating the parameters associated with the NRTL property model for a benzene-toluene mixture. The NRTL model has 2 sets of parameters: the non-randomness parameter (`alpha_ij`) and the binary interaction parameter (`tau_ij`), where `i` and `j` is the pure component species. In this example, we will be only estimate the binary interaction parameter (`tau_ij`) for a given dataset. When estimating parameters associated with the property package, IDAES provides the flexibility of doing the parameter estimation by just using the state block or by using a unit model with a specified property package. This module will demonstrate parameter estimation by using the flash unit model with the NRTL property package. \n",
"\n",
@@ -45,7 +45,7 @@
"\n",
"## Key links to documentation:\n",
"* NRTL Model - https://idaes-pse.readthedocs.io/en/stable/reference_guides/model_libraries/generic/property_models/activity_coefficient.html\n",
- "* parmest - https://pyomo.readthedocs.io/en/stable/contributed_packages/parmest/index.html\n"
+ "* parmest - https://pyomo.readthedocs.io/en/stable/explanation/analysis/parmest/index.html"
]
},
{
@@ -54,13 +54,13 @@
"source": [
"\n",
"Inline Exercise:\n",
- "import `ConcreteModel` from Pyomo, `FlowsheetBlock` and `Flash` from IDAES. \n",
+ "import `ConcreteModel`, `value`, and `Suffix` from Pyomo, `FlowsheetBlock` and `Flash` from IDAES. \n",
"
"
]
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 2,
"metadata": {
"tags": [
"exercise"
@@ -68,7 +68,7 @@
},
"outputs": [],
"source": [
- "# Todo: import ConcreteModel from pyomo.environ\n",
+ "# Todo: import ConcreteModel, value, and Suffix from pyomo.environ\n",
"\n",
"# Todo: import FlowsheetBlock from idaes.core\n",
"\n",
@@ -77,7 +77,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 3,
"metadata": {
"tags": [
"solution"
@@ -85,8 +85,8 @@
},
"outputs": [],
"source": [
- "# Todo: import ConcreteModel from pyomo.environ\n",
- "from pyomo.environ import ConcreteModel, value\n",
+ "# Todo: import ConcreteModel, value, and Suffix from pyomo.environ\n",
+ "from pyomo.environ import ConcreteModel, value, Suffix\n",
"\n",
"# Todo: import FlowsheetBlock from idaes.core\n",
"from idaes.core import FlowsheetBlock\n",
@@ -104,7 +104,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
@@ -123,7 +123,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
@@ -152,7 +152,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 6,
"metadata": {
"tags": [
"exercise"
@@ -200,7 +200,12 @@
" m.fs.flash.initialize(outlvl=idaeslog.INFO_LOW)\n",
"\n",
" # Fix at actual temperature\n",
- " m.fs.flash.inlet.temperature.fix(float(data[\"temperature\"]))\n",
+ " if isinstance(data, dict) or isinstance(data, pd.Series):\n",
+ " m.fs.state_block.temperature.fix(float(data[\"temperature\"]))\n",
+ " elif isinstance(data, pd.DataFrame):\n",
+ " m.fs.state_block.temperature.fix(float(data.iloc[0][\"temperature\"]))\n",
+ " else:\n",
+ " raise ValueError(\"Unrecognized data type.\")\n",
"\n",
" # Set bounds on variables to be estimated\n",
" m.fs.properties.tau[\"benzene\", \"toluene\"].setlb(-5)\n",
@@ -215,7 +220,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 7,
"metadata": {
"tags": [
"solution"
@@ -267,7 +272,12 @@
" m.fs.flash.initialize(outlvl=idaeslog.INFO_LOW)\n",
"\n",
" # Fix at actual temperature\n",
- " m.fs.flash.inlet.temperature.fix(float(data[\"temperature\"]))\n",
+ " if isinstance(data, dict) or isinstance(data, pd.Series):\n",
+ " m.fs.flash.inlet.temperature.fix(float(data[\"temperature\"]))\n",
+ " elif isinstance(data, pd.DataFrame):\n",
+ " m.fs.flash.inlet.temperature.fix(float(data.iloc[0][\"temperature\"]))\n",
+ " else:\n",
+ " raise ValueError(\"Unrecognized data type.\")\n",
"\n",
" # Set bounds on variables to be estimated\n",
" m.fs.properties.tau[\"benzene\", \"toluene\"].setlb(-5)\n",
@@ -293,55 +303,98 @@
"source": [
"In addition to providing a method to return an initialized model, the `parmest` tool needs the following:\n",
"\n",
- "* List of variable names to be estimated\n",
- "* Dataset with multiple scenarios\n",
- "* Expression to compute the sum of squared errors\n",
- "\n"
+ "* Experiment class to set up and label model with suffixes\n",
+ "* Dataset with multiple scenarios - organized into an experiment list"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
+ "Here we build an experiment class to label our model problem for parameter estimation. The labels are defined as a `Suffix`, and the main labels for our model are `experiment_outputs`, `unknown_parameters`, and `measurement_error`.\n",
+ "\n",
+ "For this problem, the error will be computed for the mole fraction of benzene in the vapor and liquid phase between the model prediction and data. The `experimental_outputs` will therefore be the mole fraction of benzene in the two phases.\n",
+ "\n",
"In this example, we only estimate the binary interaction parameter (`tau_ij`). Given that this variable is usually indexed as `tau_ij = Var(component_list, component_list)`, there are 2*2=4 degrees of freedom. However, when i=j, the binary interaction parameter is 0. Therefore, in this problem, we estimate the binary interaction parameter for the following variables only:\n",
"\n",
"* fs.properties.tau['benzene', 'toluene']\n",
"* fs.properties.tau['toluene', 'benzene']\n",
"\n",
- "\n",
- "Inline Exercise:\n",
- "Create a list called `variable_name` with the above-mentioned variables declared as strings.\n",
- "
"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {
- "tags": [
- "exercise"
- ]
- },
- "outputs": [],
- "source": [
- "# Todo: Create a list of vars to estimate"
+ "As shown below, these model components are used as our `unknown_parameters`.\n",
+ "\n",
+ "We define `measurement_error` as none so parmest calculates the value internally based on the experimental outputs. Refer to https://pyomo.readthedocs.io/en/stable/explanation/analysis/parmest/driver.html for more information. "
]
},
{
"cell_type": "code",
- "execution_count": null,
- "metadata": {
- "tags": [
- "solution"
- ]
- },
+ "execution_count": 9,
+ "metadata": {},
"outputs": [],
"source": [
- "# Todo: Create a list of vars to estimate\n",
- "variable_name = [\n",
- " \"fs.properties.tau['benzene', 'toluene']\",\n",
- " \"fs.properties.tau['toluene', 'benzene']\",\n",
- "]"
+ "# Build an experiment class to take advantage of new parmest interface\n",
+ "from pyomo.contrib.parmest.experiment import Experiment\n",
+ "\n",
+ "\n",
+ "class NRTLExperiment(Experiment):\n",
+ " \"\"\"Experiment class for parameter estimation of NRTL model using parmest\"\"\"\n",
+ "\n",
+ " def __init__(self, data, meas_error=None):\n",
+ " \"\"\"Initialize the NRTLExperiment class\n",
+ "\n",
+ " Args:\n",
+ " data: DataFrame containing the experimental data\n",
+ " meas_error: Measurement error for the data (optional)\n",
+ " \"\"\"\n",
+ " self.model = None\n",
+ " self.data = data\n",
+ " self.meas_error = meas_error\n",
+ "\n",
+ " def create_model(self):\n",
+ " \"\"\"Create the Pyomo model for the NRTL parameter estimation problem\"\"\"\n",
+ " self.model = NRTL_model(self.data)\n",
+ "\n",
+ " def label_model(self):\n",
+ " m = self.model\n",
+ "\n",
+ " # Add experiment outputs to the model for easier access\n",
+ " m.experiment_outputs = Suffix(direction=Suffix.LOCAL)\n",
+ " m.experiment_outputs.update(\n",
+ " [\n",
+ " (\n",
+ " m.fs.flash.liq_outlet.mole_frac_comp[0, \"benzene\"],\n",
+ " self.data[\"liq_benzene\"],\n",
+ " ),\n",
+ " (\n",
+ " m.fs.flash.vap_outlet.mole_frac_comp[0, \"benzene\"],\n",
+ " self.data[\"vap_benzene\"],\n",
+ " ),\n",
+ " ]\n",
+ " )\n",
+ "\n",
+ " m.measurement_error = Suffix(direction=Suffix.LOCAL)\n",
+ " m.measurement_error.update(\n",
+ " [\n",
+ " (m.fs.flash.liq_outlet.mole_frac_comp[0, \"benzene\"], self.meas_error),\n",
+ " (m.fs.flash.vap_outlet.mole_frac_comp[0, \"benzene\"], self.meas_error),\n",
+ " ]\n",
+ " )\n",
+ "\n",
+ " # Add unknown parameters to the model for easier access\n",
+ " m.unknown_parameters = Suffix(direction=Suffix.LOCAL)\n",
+ " m.unknown_parameters.update(\n",
+ " (k, value(k))\n",
+ " for k in [\n",
+ " m.fs.properties.tau[\"benzene\", \"toluene\"],\n",
+ " m.fs.properties.tau[\"toluene\", \"benzene\"],\n",
+ " ]\n",
+ " )\n",
+ "\n",
+ " def get_labeled_model(self):\n",
+ " \"\"\"Return the labeled model\"\"\"\n",
+ " if self.model is None:\n",
+ " self.create_model()\n",
+ " self.label_model()\n",
+ " return self.model"
]
},
{
@@ -360,9 +413,398 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 10,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " temperature | \n",
+ " liq_benzene | \n",
+ " vap_benzene | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 0 | \n",
+ " 365.500000 | \n",
+ " 0.480953 | \n",
+ " 0.692110 | \n",
+ "
\n",
+ " \n",
+ " | 1 | \n",
+ " 365.617647 | \n",
+ " 0.462444 | \n",
+ " 0.667699 | \n",
+ "
\n",
+ " \n",
+ " | 2 | \n",
+ " 365.735294 | \n",
+ " 0.477984 | \n",
+ " 0.692441 | \n",
+ "
\n",
+ " \n",
+ " | 3 | \n",
+ " 365.852941 | \n",
+ " 0.440547 | \n",
+ " 0.640336 | \n",
+ "
\n",
+ " \n",
+ " | 4 | \n",
+ " 365.970588 | \n",
+ " 0.427421 | \n",
+ " 0.623328 | \n",
+ "
\n",
+ " \n",
+ " | 5 | \n",
+ " 366.088235 | \n",
+ " 0.442725 | \n",
+ " 0.647796 | \n",
+ "
\n",
+ " \n",
+ " | 6 | \n",
+ " 366.205882 | \n",
+ " 0.434374 | \n",
+ " 0.637691 | \n",
+ "
\n",
+ " \n",
+ " | 7 | \n",
+ " 366.323529 | \n",
+ " 0.444642 | \n",
+ " 0.654933 | \n",
+ "
\n",
+ " \n",
+ " | 8 | \n",
+ " 366.441176 | \n",
+ " 0.427132 | \n",
+ " 0.631229 | \n",
+ "
\n",
+ " \n",
+ " | 9 | \n",
+ " 366.558824 | \n",
+ " 0.446301 | \n",
+ " 0.661743 | \n",
+ "
\n",
+ " \n",
+ " | 10 | \n",
+ " 366.676471 | \n",
+ " 0.438004 | \n",
+ " 0.651591 | \n",
+ "
\n",
+ " \n",
+ " | 11 | \n",
+ " 366.794118 | \n",
+ " 0.425320 | \n",
+ " 0.634814 | \n",
+ "
\n",
+ " \n",
+ " | 12 | \n",
+ " 366.911765 | \n",
+ " 0.439435 | \n",
+ " 0.658047 | \n",
+ "
\n",
+ " \n",
+ " | 13 | \n",
+ " 367.029412 | \n",
+ " 0.435655 | \n",
+ " 0.654539 | \n",
+ "
\n",
+ " \n",
+ " | 14 | \n",
+ " 367.147059 | \n",
+ " 0.401350 | \n",
+ " 0.604987 | \n",
+ "
\n",
+ " \n",
+ " | 15 | \n",
+ " 367.264706 | \n",
+ " 0.397862 | \n",
+ " 0.601703 | \n",
+ "
\n",
+ " \n",
+ " | 16 | \n",
+ " 367.382353 | \n",
+ " 0.415821 | \n",
+ " 0.630930 | \n",
+ "
\n",
+ " \n",
+ " | 17 | \n",
+ " 367.500000 | \n",
+ " 0.420667 | \n",
+ " 0.640380 | \n",
+ "
\n",
+ " \n",
+ " | 18 | \n",
+ " 367.617647 | \n",
+ " 0.391683 | \n",
+ " 0.598214 | \n",
+ "
\n",
+ " \n",
+ " | 19 | \n",
+ " 367.735294 | \n",
+ " 0.404903 | \n",
+ " 0.620432 | \n",
+ "
\n",
+ " \n",
+ " | 20 | \n",
+ " 367.852941 | \n",
+ " 0.409563 | \n",
+ " 0.629626 | \n",
+ "
\n",
+ " \n",
+ " | 21 | \n",
+ " 367.970588 | \n",
+ " 0.389488 | \n",
+ " 0.600722 | \n",
+ "
\n",
+ " \n",
+ " | 22 | \n",
+ " 368.000000 | \n",
+ " 0.396789 | \n",
+ " 0.612483 | \n",
+ "
\n",
+ " \n",
+ " | 23 | \n",
+ " 368.088235 | \n",
+ " 0.398162 | \n",
+ " 0.616106 | \n",
+ "
\n",
+ " \n",
+ " | 24 | \n",
+ " 368.205882 | \n",
+ " 0.362340 | \n",
+ " 0.562505 | \n",
+ "
\n",
+ " \n",
+ " | 25 | \n",
+ " 368.323529 | \n",
+ " 0.386958 | \n",
+ " 0.602680 | \n",
+ "
\n",
+ " \n",
+ " | 26 | \n",
+ " 368.441176 | \n",
+ " 0.363643 | \n",
+ " 0.568210 | \n",
+ "
\n",
+ " \n",
+ " | 27 | \n",
+ " 368.558824 | \n",
+ " 0.368118 | \n",
+ " 0.577072 | \n",
+ "
\n",
+ " \n",
+ " | 28 | \n",
+ " 368.676471 | \n",
+ " 0.384098 | \n",
+ " 0.604078 | \n",
+ "
\n",
+ " \n",
+ " | 29 | \n",
+ " 368.794118 | \n",
+ " 0.353605 | \n",
+ " 0.557925 | \n",
+ "
\n",
+ " \n",
+ " | 30 | \n",
+ " 368.911765 | \n",
+ " 0.346474 | \n",
+ " 0.548445 | \n",
+ "
\n",
+ " \n",
+ " | 31 | \n",
+ " 369.029412 | \n",
+ " 0.350741 | \n",
+ " 0.556996 | \n",
+ "
\n",
+ " \n",
+ " | 32 | \n",
+ " 369.147059 | \n",
+ " 0.362347 | \n",
+ " 0.577286 | \n",
+ "
\n",
+ " \n",
+ " | 33 | \n",
+ " 369.264706 | \n",
+ " 0.362578 | \n",
+ " 0.579519 | \n",
+ "
\n",
+ " \n",
+ " | 34 | \n",
+ " 369.382353 | \n",
+ " 0.340765 | \n",
+ " 0.546411 | \n",
+ "
\n",
+ " \n",
+ " | 35 | \n",
+ " 369.500000 | \n",
+ " 0.337462 | \n",
+ " 0.542857 | \n",
+ "
\n",
+ " \n",
+ " | 36 | \n",
+ " 369.617647 | \n",
+ " 0.355729 | \n",
+ " 0.574083 | \n",
+ "
\n",
+ " \n",
+ " | 37 | \n",
+ " 369.735294 | \n",
+ " 0.348679 | \n",
+ " 0.564513 | \n",
+ "
\n",
+ " \n",
+ " | 38 | \n",
+ " 369.852941 | \n",
+ " 0.338187 | \n",
+ " 0.549284 | \n",
+ "
\n",
+ " \n",
+ " | 39 | \n",
+ " 369.970588 | \n",
+ " 0.324360 | \n",
+ " 0.528514 | \n",
+ "
\n",
+ " \n",
+ " | 40 | \n",
+ " 370.088235 | \n",
+ " 0.310753 | \n",
+ " 0.507964 | \n",
+ "
\n",
+ " \n",
+ " | 41 | \n",
+ " 370.205882 | \n",
+ " 0.311037 | \n",
+ " 0.510055 | \n",
+ "
\n",
+ " \n",
+ " | 42 | \n",
+ " 370.323529 | \n",
+ " 0.311263 | \n",
+ " 0.512055 | \n",
+ "
\n",
+ " \n",
+ " | 43 | \n",
+ " 370.441176 | \n",
+ " 0.308081 | \n",
+ " 0.508437 | \n",
+ "
\n",
+ " \n",
+ " | 44 | \n",
+ " 370.558824 | \n",
+ " 0.308224 | \n",
+ " 0.510293 | \n",
+ "
\n",
+ " \n",
+ " | 45 | \n",
+ " 370.676471 | \n",
+ " 0.318148 | \n",
+ " 0.528399 | \n",
+ "
\n",
+ " \n",
+ " | 46 | \n",
+ " 370.794118 | \n",
+ " 0.308334 | \n",
+ " 0.513728 | \n",
+ "
\n",
+ " \n",
+ " | 47 | \n",
+ " 370.911765 | \n",
+ " 0.317937 | \n",
+ " 0.531410 | \n",
+ "
\n",
+ " \n",
+ " | 48 | \n",
+ " 371.029412 | \n",
+ " 0.289149 | \n",
+ " 0.484824 | \n",
+ "
\n",
+ " \n",
+ " | 49 | \n",
+ " 371.147059 | \n",
+ " 0.298637 | \n",
+ " 0.502318 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " temperature liq_benzene vap_benzene\n",
+ "0 365.500000 0.480953 0.692110\n",
+ "1 365.617647 0.462444 0.667699\n",
+ "2 365.735294 0.477984 0.692441\n",
+ "3 365.852941 0.440547 0.640336\n",
+ "4 365.970588 0.427421 0.623328\n",
+ "5 366.088235 0.442725 0.647796\n",
+ "6 366.205882 0.434374 0.637691\n",
+ "7 366.323529 0.444642 0.654933\n",
+ "8 366.441176 0.427132 0.631229\n",
+ "9 366.558824 0.446301 0.661743\n",
+ "10 366.676471 0.438004 0.651591\n",
+ "11 366.794118 0.425320 0.634814\n",
+ "12 366.911765 0.439435 0.658047\n",
+ "13 367.029412 0.435655 0.654539\n",
+ "14 367.147059 0.401350 0.604987\n",
+ "15 367.264706 0.397862 0.601703\n",
+ "16 367.382353 0.415821 0.630930\n",
+ "17 367.500000 0.420667 0.640380\n",
+ "18 367.617647 0.391683 0.598214\n",
+ "19 367.735294 0.404903 0.620432\n",
+ "20 367.852941 0.409563 0.629626\n",
+ "21 367.970588 0.389488 0.600722\n",
+ "22 368.000000 0.396789 0.612483\n",
+ "23 368.088235 0.398162 0.616106\n",
+ "24 368.205882 0.362340 0.562505\n",
+ "25 368.323529 0.386958 0.602680\n",
+ "26 368.441176 0.363643 0.568210\n",
+ "27 368.558824 0.368118 0.577072\n",
+ "28 368.676471 0.384098 0.604078\n",
+ "29 368.794118 0.353605 0.557925\n",
+ "30 368.911765 0.346474 0.548445\n",
+ "31 369.029412 0.350741 0.556996\n",
+ "32 369.147059 0.362347 0.577286\n",
+ "33 369.264706 0.362578 0.579519\n",
+ "34 369.382353 0.340765 0.546411\n",
+ "35 369.500000 0.337462 0.542857\n",
+ "36 369.617647 0.355729 0.574083\n",
+ "37 369.735294 0.348679 0.564513\n",
+ "38 369.852941 0.338187 0.549284\n",
+ "39 369.970588 0.324360 0.528514\n",
+ "40 370.088235 0.310753 0.507964\n",
+ "41 370.205882 0.311037 0.510055\n",
+ "42 370.323529 0.311263 0.512055\n",
+ "43 370.441176 0.308081 0.508437\n",
+ "44 370.558824 0.308224 0.510293\n",
+ "45 370.676471 0.318148 0.528399\n",
+ "46 370.794118 0.308334 0.513728\n",
+ "47 370.911765 0.317937 0.531410\n",
+ "48 371.029412 0.289149 0.484824\n",
+ "49 371.147059 0.298637 0.502318"
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ }
+ ],
"source": [
"# Load data from csv\n",
"data = pd.read_csv(\"BT_NRTL_dataset.csv\")\n",
@@ -375,83 +817,198 @@
"cell_type": "markdown",
"metadata": {},
"source": [
- "We need to provide a method to return an expression to compute the sum of squared errors that will be used as the objective in solving the parameter estimation problem. For this problem, the error will be computed for the mole fraction of benzene in the vapor and liquid phase between the model prediction and data. \n",
- "\n",
- "\n",
- "Inline Exercise:\n",
- "Complete the following cell by adding an expression to compute the sum of square errors. \n",
- "
"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {
- "tags": [
- "exercise"
- ]
- },
- "outputs": [],
- "source": [
- "# Create method to return an expression that computes the sum of squared error\n",
- "def SSE(m, data):\n",
- " # Todo: Add expression for computing the sum of squared errors in mole fraction of benzene in the liquid\n",
- " # and vapor phase. For example, the squared error for the vapor phase is:\n",
- " # (float(data[\"vap_benzene\"]) - m.fs.flash.vap_outlet.mole_frac_comp[0, \"benzene\"])**2\n",
- "\n",
- " return expr * 1e4"
+ "We define the `exp_list` by splitting the data into individual experiments, or data points."
]
},
{
"cell_type": "code",
- "execution_count": null,
- "metadata": {
- "tags": [
- "solution"
- ]
- },
- "outputs": [],
- "source": [
- "# Create method to return an expression that computes the sum of squared error\n",
- "def SSE(m, data):\n",
- " # Todo: Add expression for computing the sum of squared errors in mole fraction of benzene in the liquid\n",
- " # and vapor phase. For example, the squared error for the vapor phase is:\n",
- " # (float(data[\"vap_benzene\"]) - m.fs.flash.vap_outlet.mole_frac_comp[0, \"benzene\"])**2\n",
- " expr = (\n",
- " float(data[\"vap_benzene\"]) - m.fs.flash.vap_outlet.mole_frac_comp[0, \"benzene\"]\n",
- " ) ** 2 + (\n",
- " float(data[\"liq_benzene\"]) - m.fs.flash.liq_outlet.mole_frac_comp[0, \"benzene\"]\n",
- " ) ** 2\n",
- " return expr * 1e4"
- ]
- },
- {
- "cell_type": "markdown",
+ "execution_count": 11,
"metadata": {},
+ "outputs": [],
"source": [
- "\n",
- "Note:\n",
- "Notice that we have scaled the expression up by a factor of 10000 as the SSE computed here will be an extremely small number given that we are using the difference in mole fraction in our expression. A well-scaled objective will help improve solve robustness when using IPOPT. \n",
- "
\n"
+ "# Loop through the dataset and create an experiment for each row of data\n",
+ "exp_list = []\n",
+ "for i in range(data.shape[0]):\n",
+ " exp_list.append(NRTLExperiment(data.iloc[i]))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
- "We are now ready to set up the parameter estimation problem. We will create a parameter estimation object called `pest`. As shown below, we pass the method that returns an initialized model, dataset, list of variable names to estimate, and the SSE expression to the Estimator object. `tee=True` will print the solver output after solving the parameter estimation problem."
+ "We are now ready to set up the parameter estimation problem. We will create a parameter estimation object called pest. As shown below, we pass the experiment list, and an objective function to the Estimator method. tee=True will print the solver output after solving the parameter estimation problem."
]
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 12,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Ipopt 3.13.2: \n",
+ "\n",
+ "******************************************************************************\n",
+ "This program contains Ipopt, a library for large-scale nonlinear optimization.\n",
+ " Ipopt is released as open source code under the Eclipse Public License (EPL).\n",
+ " For more information visit http://projects.coin-or.org/Ipopt\n",
+ "\n",
+ "This version of Ipopt was compiled from source code available at\n",
+ " https://github.com/IDAES/Ipopt as part of the Institute for the Design of\n",
+ " Advanced Energy Systems Process Systems Engineering Framework (IDAES PSE\n",
+ " Framework) Copyright (c) 2018-2019. See https://github.com/IDAES/idaes-pse.\n",
+ "\n",
+ "This version of Ipopt was compiled using HSL, a collection of Fortran codes\n",
+ " for large-scale scientific computation. All technical papers, sales and\n",
+ " publicity material resulting from use of the HSL codes within IPOPT must\n",
+ " contain the following acknowledgement:\n",
+ " HSL, a collection of Fortran codes for large-scale scientific\n",
+ " computation. See http://www.hsl.rl.ac.uk.\n",
+ "******************************************************************************\n",
+ "\n",
+ "This is Ipopt version 3.13.2, running with linear solver ma27.\n",
+ "\n",
+ "Number of nonzeros in equality constraint Jacobian...: 10950\n",
+ "Number of nonzeros in inequality constraint Jacobian.: 0\n",
+ "Number of nonzeros in Lagrangian Hessian.............: 6600\n",
+ "\n",
+ "Total number of variables............................: 2952\n",
+ " variables with only lower bounds: 150\n",
+ " variables with lower and upper bounds: 600\n",
+ " variables with only upper bounds: 0\n",
+ "Total number of equality constraints.................: 2950\n",
+ "Total number of inequality constraints...............: 0\n",
+ " inequality constraints with only lower bounds: 0\n",
+ " inequality constraints with lower and upper bounds: 0\n",
+ " inequality constraints with only upper bounds: 0\n",
+ "\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 0 6.0671019e-03 5.63e+02 1.20e-08 -1.0 0.00e+00 - 0.00e+00 0.00e+00 0\n",
+ " 1 9.0714942e-04 1.37e+03 1.61e+01 -1.0 1.37e+04 - 9.82e-01 1.00e+00h 1\n",
+ " 2 1.3219937e-03 1.17e+04 1.62e+01 -1.0 5.23e+03 - 3.41e-01 1.65e-01h 3\n",
+ " 3 1.3161671e-03 1.11e+04 4.02e+01 -1.0 3.96e+02 -4.0 8.19e-01 1.25e-01h 4\n",
+ " 4 1.3154170e-03 1.11e+04 4.32e+01 -1.0 3.47e+02 -4.5 9.90e-01 4.43e-02h 5\n",
+ " 5 9.4424343e-04 1.04e+04 4.05e+01 -1.0 1.16e+04 - 9.33e-01 5.61e-02h 5\n",
+ " 6 9.4571258e-04 1.11e+04 4.85e+01 -1.0 3.13e+02 -5.0 8.74e-01 1.25e-01h 4\n",
+ " 7 9.4862862e-04 1.11e+04 4.84e+01 -1.0 2.41e+03 -5.4 1.72e-01 1.50e-03h 8\n",
+ " 8 9.5448936e-04 1.10e+04 4.81e+01 -1.0 4.11e+02 -5.0 1.00e+00 1.97e-02h 6\n",
+ " 9 9.5650047e-04 1.10e+04 4.81e+01 -1.0 5.14e+02 -4.6 3.46e-01 5.24e-03h 7\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 10 9.5730419e-04 1.10e+04 4.81e+01 -1.0 9.78e+02 -4.2 4.40e-01 1.08e-03h 8\n",
+ " 11 9.5774182e-04 1.10e+04 4.84e+01 -1.0 2.76e+02 -3.7 2.91e-01 2.99e-03h 7\n",
+ " 12 9.4292855e-04 7.77e+04 4.09e+04 -1.0 5.38e+02 -2.4 5.48e-02 6.44e-02w 1\n",
+ " 13 2.4318219e-01 2.38e+07 4.22e+14 -1.0 1.28e+06 - 2.55e-02 3.49e-02w 1\n",
+ " 14 2.8902019e-01 1.64e+07 2.92e+14 -1.0 1.11e+05 -2.9 9.54e-01 3.01e-01w 1\n",
+ " 15 9.5768293e-04 1.10e+04 4.85e+01 -1.0 2.80e+05 -3.4 5.48e-02 2.52e-04h 8\n",
+ " 16 9.5769345e-04 1.10e+04 4.85e+01 -1.0 4.33e+02 -2.9 7.95e-02 1.91e-04h 9\n",
+ " 17 9.5763809e-04 1.10e+04 4.85e+01 -1.0 6.35e+02 -2.5 4.94e-02 2.08e-04h 9\n",
+ " 18 9.5734836e-04 1.10e+04 4.87e+01 -1.0 3.22e+02 -3.0 1.00e+00 1.22e-03h 8\n",
+ " 19 9.3628114e-04 1.09e+04 4.62e+01 -1.0 4.22e+02 -3.5 5.16e-01 5.87e-02h 5\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 20 7.1894543e-04 4.02e+03 4.95e+02 -1.0 3.49e+02 -3.9 1.00e+00 1.00e+00h 1\n",
+ " 21 6.7062834e-04 1.58e+02 2.21e+02 -1.0 1.78e+02 -4.4 1.00e+00 1.00e+00h 1\n",
+ " 22 6.6635123e-04 4.17e+01 1.12e+01 -1.0 2.44e+02 -4.9 1.00e+00 1.00e+00h 1\n",
+ " 23 6.6729070e-04 1.43e+00 9.69e-01 -1.0 1.08e+01 -5.4 1.00e+00 1.00e+00h 1\n",
+ " 24 6.6785681e-04 3.58e-01 5.25e-03 -1.7 6.65e+00 -5.8 1.00e+00 1.00e+00h 1\n",
+ " 25 6.2552355e-04 9.80e+02 6.48e-02 -3.8 7.92e+02 - 9.22e-01 1.00e+00h 1\n",
+ " 26 5.9105707e-04 8.13e+00 6.13e-04 -3.8 5.66e+02 - 1.00e+00 1.00e+00h 1\n",
+ " 27 6.1313801e-04 6.24e+01 8.08e-06 -3.8 1.70e+02 - 1.00e+00 1.00e+00h 1\n",
+ " 28 6.1208051e-04 3.58e-01 1.18e-08 -3.8 1.88e+00 - 1.00e+00 1.00e+00h 1\n",
+ " 29 5.9010560e-04 1.58e+01 1.00e-05 -5.7 1.08e+02 - 1.00e+00 1.00e+00h 1\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 30 5.9008319e-04 2.74e-02 7.90e-07 -5.7 7.54e-02 -6.3 1.00e+00 1.00e+00h 1\n",
+ " 31 5.3570104e-04 1.48e+04 8.70e-04 -5.7 1.81e+02 - 1.00e+00 1.00e+00h 1\n",
+ " 32 5.1618763e-04 6.29e+02 8.06e-05 -5.7 2.55e+02 - 1.00e+00 1.00e+00h 1\n",
+ " 33 5.5250565e-04 2.88e+01 2.58e-04 -5.7 1.81e+04 - 6.26e-01 6.25e-02h 5\n",
+ " 34 5.2209909e-04 2.88e+02 2.02e-04 -5.7 1.89e+03 - 1.00e+00 1.00e+00h 1\n",
+ " 35 5.0707798e-04 5.60e+01 2.02e-04 -5.7 2.93e+03 - 1.00e+00 1.00e+00h 1\n",
+ " 36 5.0765648e-04 7.87e+00 1.91e-05 -5.7 1.02e+02 - 1.00e+00 1.00e+00h 1\n",
+ " 37 5.0740606e-04 2.57e+00 1.88e-05 -5.7 6.96e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 38 5.0764164e-04 2.55e+00 1.76e-05 -5.7 6.81e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 39 5.0740672e-04 2.55e+00 1.88e-05 -5.7 6.80e+01 - 1.00e+00 1.00e+00h 1\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 40 5.0764162e-04 2.54e+00 1.76e-05 -5.7 6.80e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 41 5.0740672e-04 2.55e+00 1.88e-05 -5.7 6.80e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 42 5.0782847e-04 1.43e-01 1.83e-05 -5.7 6.80e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 43 5.0751252e-04 1.58e-02 1.93e-05 -5.7 6.88e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 44 5.0783218e-04 4.79e-03 1.85e-05 -5.7 6.92e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 45 5.0751252e-04 1.60e-02 1.93e-05 -5.7 6.89e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 46 5.0783222e-04 1.23e-04 1.85e-05 -5.7 6.92e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 47 5.0751252e-04 1.60e-02 1.93e-05 -5.7 6.89e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 48 5.0783216e-04 1.24e-04 1.85e-05 -5.7 6.92e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 49 5.0751765e-04 3.20e-03 1.93e-05 -5.7 6.89e+01 - 1.00e+00 1.00e+00H 1\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 50 5.0764151e-04 2.56e+00 1.77e-05 -5.7 6.93e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 51 5.0740671e-04 2.55e+00 1.88e-05 -5.7 6.81e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 52 5.0764162e-04 2.54e+00 1.76e-05 -5.7 6.80e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 53 5.0740672e-04 2.55e+00 1.88e-05 -5.7 6.80e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 54 5.0764162e-04 2.54e+00 1.76e-05 -5.7 6.80e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 55 5.0748886e-04 1.91e+00 8.64e-06 -5.7 6.80e+01 - 1.00e+00 5.00e-01h 2\n",
+ " 56 5.0744550e-04 3.37e-01 1.64e-05 -5.7 2.54e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 57 5.0763613e-04 1.82e+00 1.43e-05 -5.7 5.79e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 58 5.0751252e-04 2.25e-02 1.93e-05 -5.7 6.65e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 59 5.0783220e-04 1.23e-04 1.85e-05 -5.7 6.92e+01 - 1.00e+00 1.00e+00H 1\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 60 5.0751252e-04 1.60e-02 1.93e-05 -5.7 6.89e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 61 5.0783207e-04 3.26e-04 1.85e-05 -5.7 6.92e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 62 5.0751786e-04 7.95e-05 1.93e-05 -5.7 6.89e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 63 5.0754291e-04 6.40e-01 8.69e-06 -5.7 6.93e+01 - 1.00e+00 5.00e-01h 2\n",
+ " 64 5.0745167e-04 3.00e-01 1.61e-05 -5.7 2.35e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 65 5.0763437e-04 1.71e+00 1.33e-05 -5.7 5.61e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 66 5.0751762e-04 2.91e-03 1.93e-05 -5.7 6.60e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 67 5.0752104e-04 1.62e-01 1.43e-05 -5.7 6.92e+01 - 1.00e+00 2.50e-01h 3\n",
+ " 68 5.0761295e-04 1.03e+00 2.18e-05 -5.7 4.35e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 69 5.0751251e-04 2.38e-02 1.92e-05 -5.7 5.95e+01 - 1.00e+00 1.00e+00H 1\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 70 5.0783210e-04 3.29e-06 1.85e-05 -5.7 6.90e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 71 5.0751786e-04 7.94e-05 1.93e-05 -5.7 6.89e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 72 5.0754292e-04 6.40e-01 8.69e-06 -5.7 6.93e+01 - 1.00e+00 5.00e-01h 2\n",
+ " 73 5.0749299e-04 3.95e-01 1.21e-05 -5.7 2.35e+01 - 1.00e+00 5.00e-01h 2\n",
+ " 74 5.0755524e-04 1.36e-01 3.09e-05 -5.7 1.57e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 75 5.0751308e-04 1.96e-02 1.80e-05 -5.7 3.30e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 76 5.0754492e-04 5.62e-01 8.19e-06 -5.7 6.42e+01 - 1.00e+00 5.00e-01h 2\n",
+ " 77 5.0748301e-04 3.98e-01 1.25e-05 -5.7 2.93e+01 - 1.00e+00 5.00e-01h 2\n",
+ " 78 5.0756455e-04 2.42e-01 3.07e-05 -5.7 2.09e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 79 5.0751710e-04 1.38e-03 1.87e-05 -5.7 3.98e+01 - 1.00e+00 1.00e+00H 1\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 80 5.0783077e-04 3.26e-06 1.84e-05 -5.7 6.70e+01 - 1.00e+00 1.00e+00H 1\n",
+ " 81 5.0726420e-04 1.24e+01 1.85e-05 -8.6 1.34e+02 - 9.93e-01 1.00e+00h 1\n",
+ " 82 5.0749897e-04 2.75e+00 2.53e-06 -8.6 6.93e+01 - 1.00e+00 1.00e+00h 1\n",
+ " 83 5.0749686e-04 3.64e-04 6.40e-10 -8.6 4.69e-02 - 1.00e+00 1.00e+00h 1\n",
+ " 84 5.0749686e-04 7.28e-11 2.51e-14 -8.6 6.86e-05 - 1.00e+00 1.00e+00h 1\n",
+ "\n",
+ "Number of Iterations....: 84\n",
+ "\n",
+ " (scaled) (unscaled)\n",
+ "Objective...............: 5.0749685809243843e-04 5.0749685809243843e-04\n",
+ "Dual infeasibility......: 2.5059195074646584e-14 2.5059195074646584e-14\n",
+ "Constraint violation....: 1.4104644499482425e-11 7.2759576141834259e-11\n",
+ "Complementarity.........: 2.5059035596800647e-09 2.5059035596800647e-09\n",
+ "Overall NLP error.......: 2.5059035596800647e-09 2.5059035596800647e-09\n",
+ "\n",
+ "\n",
+ "Number of objective function evaluations = 260\n",
+ "Number of objective gradient evaluations = 85\n",
+ "Number of equality constraint evaluations = 260\n",
+ "Number of inequality constraint evaluations = 0\n",
+ "Number of equality constraint Jacobian evaluations = 85\n",
+ "Number of inequality constraint Jacobian evaluations = 0\n",
+ "Number of Lagrangian Hessian evaluations = 84\n",
+ "Total CPU secs in IPOPT (w/o function evaluations) = 0.338\n",
+ "Total CPU secs in NLP function evaluations = 0.092\n",
+ "\n",
+ "EXIT: Optimal Solution Found.\n"
+ ]
+ }
+ ],
"source": [
- "# Initialize a parameter estimation object\n",
- "pest = parmest.Estimator(NRTL_model, data, variable_name, SSE, tee=True)\n",
+ "import logging\n",
"\n",
- "# Run parameter estimation using all data\n",
+ "idaeslog.getIdaesLogger(\"core.property_meta\").setLevel(logging.ERROR)\n",
+ "\n",
+ "pest = parmest.Estimator(exp_list, obj_function=\"SSE\", tee=True)\n",
"obj_value, parameters = pest.theta_est()"
]
},
@@ -466,11 +1023,23 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 14,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "The SSE at the optimal solution is 0.000507\n",
+ "\n",
+ "The values for the parameters are as follows:\n",
+ "fs.properties.tau[benzene,toluene] = -0.8987454466579063\n",
+ "fs.properties.tau[toluene,benzene] = 1.410449514796474\n"
+ ]
+ }
+ ],
"source": [
- "print(\"The SSE at the optimal solution is %0.6f\" % (obj_value * 1e-4))\n",
+ "print(\"The SSE at the optimal solution is %0.6f\" % (obj_value))\n",
"print()\n",
"print(\"The values for the parameters are as follows:\")\n",
"for k, v in parameters.items():\n",
@@ -496,7 +1065,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
- "Pyomo's `parmest` tool allows for bootstrapping where the parameter estimation is repeated over `n` samples with resampling from the original data set. Parameter estimation with bootstrap resampling can be used to identify confidence regions around each parameter estimate. This analysis can be slow given the increased number of model instances that need to be solved. Please refer to https://pyomo.readthedocs.io/en/stable/contributed_packages/parmest/driver.html for more details. \n",
+ "Pyomo's `parmest` tool allows for bootstrapping where the parameter estimation is repeated over `n` samples with resampling from the original data set. Parameter estimation with bootstrap resampling can be used to identify confidence regions around each parameter estimate. This analysis can be slow given the increased number of model instances that need to be solved. Please refer to https://pyomo.readthedocs.io/en/stable/explanation/analysis/parmest/covariance.html#bootstrapping for more details. \n",
"\n",
"For the example above, the bootstrapping can be run by uncommenting the code in the following cell:"
]
@@ -507,12 +1076,8 @@
"metadata": {},
"outputs": [],
"source": [
- "# Run parameter estimation using bootstrap resample of the data (10 samples),\n",
- "# plot results along with confidence regions\n",
- "\n",
"# Uncomment the following lines\n",
- "\n",
- "# bootstrap_theta = pest.theta_est_bootstrap(4)\n",
+ "# bootstrap_theta = pest.theta_est_bootstrap(4, seed=542)\n",
"# display(bootstrap_theta)"
]
}
@@ -520,7 +1085,7 @@
"metadata": {
"celltoolbar": "Tags",
"kernelspec": {
- "display_name": "Python 3 (ipykernel)",
+ "display_name": "idaes-pse-and-examples-dev-py313-macmini",
"language": "python",
"name": "python3"
},
@@ -534,9 +1099,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.9.12"
+ "version": "3.13.13"
}
},
"nbformat": 4,
"nbformat_minor": 3
-}
+}
\ No newline at end of file
diff --git a/idaes_examples/notebooks/docs/properties/parameter_estimation_pr.ipynb b/idaes_examples/notebooks/docs/properties/parameter_estimation_pr.ipynb
index 1d0fcf3e..1d59634c 100644
--- a/idaes_examples/notebooks/docs/properties/parameter_estimation_pr.ipynb
+++ b/idaes_examples/notebooks/docs/properties/parameter_estimation_pr.ipynb
@@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 1,
"metadata": {
"tags": [
"header",
@@ -16,7 +16,7 @@
"# Framework (IDAES IP) was produced under the DOE Institute for the\n",
"# Design of Advanced Energy Systems (IDAES).\n",
"#\n",
- "# Copyright (c) 2018-2023 by the software owners: The Regents of the\n",
+ "# Copyright (c) 2018-2026 by the software owners: The Regents of the\n",
"# University of California, through Lawrence Berkeley National Laboratory,\n",
"# National Technology & Engineering Solutions of Sandia, LLC, Carnegie Mellon\n",
"# University, West Virginia University Research Corporation, et al.\n",
@@ -31,8 +31,8 @@
"source": [
"# Using Parameter Estimation with Modular Property Packages\n",
"Author: Alejandro Garciadego \n",
- "Maintainer: Andrew Lee \n",
- "Updated: 2023-06-01 \n",
+ "Maintainer: Stephen Cini \n",
+ "Updated: 2026-06-11 \n",
"## 1. Introduction\n",
"\n",
"This Jupyter Notebook estimates binary interaction parameters for a CO$_2$-Ionic liquid property package. A property package has been created for CO$_2$-[bmim][PF6]. We will utilize Pyomo's `parmest` tool in conjunction with IDAES models for parameter estimation. We demonstrate these tools by estimating the parameters associated with the Peng-Robinson property model for a benzene-toluene mixture. The Peng-Robinson EOS the binary interaction parameter (kappa_ij). When estimating parameters associated with the property package, IDAES provides the flexibility of doing the parameter estimation by just using the state block or by using a unit model with a specified property package. This module will demonstrate parameter estimation by using the flash unit model with a Modular Property Package.\n",
@@ -57,12 +57,12 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"# Import objects from pyomo package\n",
- "from pyomo.environ import ConcreteModel, SolverFactory, units as pyunits\n",
+ "from pyomo.environ import ConcreteModel, SolverFactory, value, Suffix\n",
"\n",
"# Import the main FlowsheetBlock from IDAES. The flowsheet block will contain the unit model\n",
"from idaes.core import FlowsheetBlock\n",
@@ -83,7 +83,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
@@ -99,7 +99,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
@@ -121,7 +121,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
@@ -146,7 +146,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
@@ -229,9 +229,147 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 7,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "2026-06-11 12:42:22 [INFO] idaes.init.fs.state_block: Starting initialization\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: Bubble, dew, and critical point initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n",
+ "Ipopt 3.13.2: \n",
+ "\n",
+ "******************************************************************************\n",
+ "This program contains Ipopt, a library for large-scale nonlinear optimization.\n",
+ " Ipopt is released as open source code under the Eclipse Public License (EPL).\n",
+ " For more information visit http://projects.coin-or.org/Ipopt\n",
+ "\n",
+ "This version of Ipopt was compiled from source code available at\n",
+ " https://github.com/IDAES/Ipopt as part of the Institute for the Design of\n",
+ " Advanced Energy Systems Process Systems Engineering Framework (IDAES PSE\n",
+ " Framework) Copyright (c) 2018-2019. See https://github.com/IDAES/idaes-pse.\n",
+ "\n",
+ "This version of Ipopt was compiled using HSL, a collection of Fortran codes\n",
+ " for large-scale scientific computation. All technical papers, sales and\n",
+ " publicity material resulting from use of the HSL codes within IPOPT must\n",
+ " contain the following acknowledgement:\n",
+ " HSL, a collection of Fortran codes for large-scale scientific\n",
+ " computation. See http://www.hsl.rl.ac.uk.\n",
+ "******************************************************************************\n",
+ "\n",
+ "This is Ipopt version 3.13.2, running with linear solver ma27.\n",
+ "\n",
+ "Number of nonzeros in equality constraint Jacobian...: 39\n",
+ "Number of nonzeros in inequality constraint Jacobian.: 0\n",
+ "Number of nonzeros in Lagrangian Hessian.............: 25\n",
+ "\n",
+ "Total number of variables............................: 18\n",
+ " variables with only lower bounds: 4\n",
+ " variables with lower and upper bounds: 13\n",
+ " variables with only upper bounds: 1\n",
+ "Total number of equality constraints.................: 18\n",
+ "Total number of inequality constraints...............: 0\n",
+ " inequality constraints with only lower bounds: 0\n",
+ " inequality constraints with lower and upper bounds: 0\n",
+ " inequality constraints with only upper bounds: 0\n",
+ "\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 0 0.0000000e+00 5.00e-01 1.00e+00 -1.0 0.00e+00 - 0.00e+00 0.00e+00 0\n",
+ " 1 0.0000000e+00 1.76e-01 6.65e+03 -1.0 7.51e+04 - 2.67e-01 9.90e-01H 1\n",
+ " 2 0.0000000e+00 4.81e-02 1.40e+02 -1.0 6.76e+02 - 9.46e-01 9.90e-01h 1\n",
+ " 3 0.0000000e+00 8.65e-03 1.76e+01 -1.0 9.79e+00 - 9.90e-01 9.90e-01h 1\n",
+ " 4 0.0000000e+00 1.81e-03 4.99e+04 -1.0 1.20e+00 - 9.90e-01 1.00e+00h 1\n",
+ " 5 0.0000000e+00 3.48e-03 9.81e+04 -1.0 5.29e+01 - 9.90e-01 1.00e+00h 1\n",
+ " 6 0.0000000e+00 1.57e-03 8.00e+02 -1.0 1.54e+02 - 9.92e-01 1.00e+00h 1\n",
+ " 7 0.0000000e+00 7.66e-04 2.93e-04 -2.5 2.52e+02 - 1.00e+00 1.00e+00h 1\n",
+ " 8 0.0000000e+00 3.81e-04 1.61e-04 -5.7 4.82e+02 - 1.00e+00 1.00e+00h 1\n",
+ " 9 0.0000000e+00 1.90e-04 6.49e-05 -5.7 9.53e+02 - 1.00e+00 1.00e+00h 1\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 10 0.0000000e+00 9.50e-05 8.68e-05 -5.7 1.90e+03 - 1.00e+00 1.00e+00h 1\n",
+ " 11 0.0000000e+00 4.75e-05 3.47e-04 -5.7 3.81e+03 - 1.00e+00 1.00e+00h 1\n",
+ " 12 0.0000000e+00 2.72e-05 1.39e-03 -5.7 7.64e+03 - 1.00e+00 1.00e+00h 1\n",
+ " 13 0.0000000e+00 1.07e-04 5.57e-03 -5.7 1.54e+04 - 1.00e+00 1.00e+00h 1\n",
+ " 14 0.0000000e+00 4.09e-04 2.23e-02 -5.7 3.11e+04 - 1.00e+00 1.00e+00h 1\n",
+ " 15 0.0000000e+00 1.51e-03 8.91e-02 -5.7 6.38e+04 - 1.00e+00 1.00e+00h 1\n",
+ " 16 0.0000000e+00 5.12e-03 3.53e-01 -5.7 1.33e+05 - 1.00e+00 1.00e+00h 1\n",
+ " 17 0.0000000e+00 1.49e-02 1.34e+00 -5.7 2.89e+05 - 1.00e+00 1.00e+00h 1\n",
+ " 18 0.0000000e+00 3.14e-02 4.58e+00 -5.7 6.55e+05 - 1.00e+00 1.00e+00h 1\n",
+ " 19 0.0000000e+00 2.86e-02 4.32e+00 -5.7 1.51e+06 - 1.00e+00 1.25e-01h 4\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 20 0.0000000e+00 2.82e-02 4.26e+00 -5.7 1.73e+06 - 1.00e+00 1.56e-02h 7\n",
+ " 21 0.0000000e+00 2.79e-02 4.23e+00 -5.7 1.76e+06 - 1.00e+00 7.81e-03h 8\n",
+ " 22 0.0000000e+00 2.79e-02 4.22e+00 -5.7 1.77e+06 - 1.00e+00 4.88e-04h 12\n",
+ " 23 0.0000000e+00 2.79e-02 4.22e+00 -5.7 1.77e+06 - 1.00e+00 1.22e-04h 14\n",
+ " 24 0.0000000e+00 7.05e-03 1.51e+01 -5.7 1.77e+06 - 1.00e+00 1.00e+00h 1\n",
+ " 25 0.0000000e+00 9.63e-04 4.01e+00 -5.7 3.18e+06 - 1.00e+00 1.50e-01h 2\n",
+ " 26 0.0000000e+00 5.53e-04 8.54e+01 -5.7 3.24e+06 - 1.00e+00 6.53e-02h 2\n",
+ " 27 0.0000000e+00 5.53e-04 8.57e+01 -5.7 3.20e+06 - 1.00e+00 9.58e-04h 7\n",
+ " 28 0.0000000e+00 5.53e-04 9.27e+01 -5.7 3.19e+06 - 1.00e+00 9.42e-04h 7\n",
+ " 29 0.0000000e+00 5.53e-04 2.08e+02 -5.7 3.19e+06 - 1.00e+00 9.27e-04h 7\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 30 0.0000000e+00 5.52e-04 7.91e+03 -5.7 1.83e+06 - 1.00e+00 3.17e-03h 6\n",
+ " 31 0.0000000e+00 3.77e-05 2.11e+06 -5.7 2.63e+04 - 1.00e+00 1.00e+00h 1\n",
+ " 32 0.0000000e+00 3.77e-05 2.10e+06 -5.7 1.03e+06 - 1.00e+00 5.67e-04h 9\n",
+ " 33 0.0000000e+00 3.77e-05 2.10e+06 -5.7 1.03e+06 - 1.00e+00 5.65e-04h 9\n",
+ " 34 0.0000000e+00 3.77e-05 2.10e+06 -5.7 1.02e+06 - 1.00e+00 5.63e-04h 9\n",
+ " 35 0.0000000e+00 3.77e-05 2.12e+06 -5.7 9.14e+05 - 1.00e+00 6.29e-04h 9\n",
+ " 36 0.0000000e+00 3.77e-05 2.23e+06 -5.7 9.36e+05 - 1.00e+00 6.11e-04h 9\n",
+ " 37 0.0000000e+00 3.76e-05 4.98e+06 -5.7 4.23e+05 - 1.00e+00 2.69e-03h 8\n",
+ " 38 0.0000000e+00 3.76e-05 6.97e+06 -5.7 8.98e+05 - 1.00e+00 6.29e-04h 9\n",
+ " 39 0.0000000e+00 3.76e-05 5.17e+07 -5.7 6.09e+05 - 1.00e+00 1.85e-03h 8\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 40 0.0000000e+00 3.76e-05 6.29e+07 -5.7 1.03e+06 - 1.00e+00 5.42e-04h 9\n",
+ " 41 0.0000000e+00 3.76e-05 7.41e+07 -5.7 1.02e+06 - 1.00e+00 5.43e-04h 9\n",
+ " 42 0.0000000e+00 8.59e-04 7.30e+11 -5.7 1.02e+06 - 1.00e+00 1.39e-01w 1\n",
+ " 43 0.0000000e+00 8.58e-04 7.30e+11 -5.7 7.14e+03 - 1.00e+00 2.07e-05w 1\n",
+ "In iteration 43, 2 Slacks too small, adjusting variable bounds\n",
+ " 44 0.0000000e+00 7.90e-04 5.95e+14 -5.7 4.69e+03 - 1.00e+00 8.02e-02w 1\n",
+ " 45 0.0000000e+00 3.76e-05 8.53e+07 -5.7 4.31e+03 - 1.00e+00 5.41e-04h 8\n",
+ " 46 0.0000000e+00 3.75e-05 9.64e+07 -5.7 1.02e+06 - 1.00e+00 5.39e-04h 9\n",
+ " 47 0.0000000e+00 3.75e-05 1.08e+08 -5.7 1.02e+06 - 1.00e+00 5.37e-04h 9\n",
+ " 48 0.0000000e+00 3.75e-05 1.19e+08 -5.7 1.02e+06 - 1.00e+00 5.35e-04h 9\n",
+ " 49 0.0000000e+00 3.75e-05 1.30e+08 -5.7 1.02e+06 - 1.00e+00 5.33e-04h 9\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 50 0.0000000e+00 3.75e-05 1.41e+08 -5.7 1.02e+06 - 1.00e+00 5.31e-04h 9\n",
+ " 51 0.0000000e+00 3.75e-05 1.52e+08 -5.7 1.02e+06 - 1.00e+00 5.29e-04h 9\n",
+ " 52 0.0000000e+00 3.75e-05 1.64e+08 -5.7 1.02e+06 - 1.00e+00 5.27e-04h 9\n",
+ " 53 0.0000000e+00 3.75e-05 1.75e+08 -5.7 1.02e+06 - 1.00e+00 5.25e-04h 9\n",
+ " 54 0.0000000e+00 3.75e-05 1.86e+08 -5.7 1.02e+06 - 1.00e+00 5.23e-04h 9\n",
+ " 55 0.0000000e+00 7.97e-04 7.34e+11 -5.7 1.02e+06 - 1.00e+00 1.33e-01w 1\n",
+ " 56 0.0000000e+00 7.97e-04 6.89e+11 -5.7 6.89e-05 16.0 2.81e-04 5.39e-01w 1\n",
+ " 57 0.0000000e+00 4.04e-07 2.66e+15 -5.7 4.36e+03 - 2.29e-07 1.00e+00h 1\n",
+ "Cannot recompute multipliers for feasibility problem. Error in eq_mult_calculator\n",
+ "\n",
+ "Number of Iterations....: 57\n",
+ "\n",
+ " (scaled) (unscaled)\n",
+ "Objective...............: 0.0000000000000000e+00 0.0000000000000000e+00\n",
+ "Dual infeasibility......: 2.6563801083485440e+15 2.6563801083485440e+15\n",
+ "Constraint violation....: 4.0441652946975677e-07 4.0441652946975677e-07\n",
+ "Complementarity.........: 0.0000000000000000e+00 0.0000000000000000e+00\n",
+ "Overall NLP error.......: 4.0441652946975677e-07 2.6563801083485440e+15\n",
+ "\n",
+ "\n",
+ "Number of objective function evaluations = 337\n",
+ "Number of objective gradient evaluations = 59\n",
+ "Number of equality constraint evaluations = 337\n",
+ "Number of inequality constraint evaluations = 0\n",
+ "Number of equality constraint Jacobian evaluations = 59\n",
+ "Number of inequality constraint Jacobian evaluations = 0\n",
+ "Number of Lagrangian Hessian evaluations = 58\n",
+ "Total CPU secs in IPOPT (w/o function evaluations) = 0.005\n",
+ "Total CPU secs in NLP function evaluations = 0.008\n",
+ "\n",
+ "EXIT: Solved To Acceptable Level.\n"
+ ]
+ }
+ ],
"source": [
"from idaes.core.util.model_statistics import degrees_of_freedom\n",
"import pytest\n",
@@ -246,7 +384,11 @@
"m = PR_model(test_data)\n",
"\n",
"# Check that degrees of freedom is 0\n",
- "assert degrees_of_freedom(m) == 0"
+ "assert degrees_of_freedom(m) == 0\n",
+ "\n",
+ "# Solve the model with the default solver and display results\n",
+ "solver = SolverFactory(\"ipopt\")\n",
+ "results = solver.solve(m, tee=True)"
]
},
{
@@ -255,41 +397,87 @@
"source": [
"## 4.0 Parameter estimation using parmest \n",
"\n",
- "### 4.1 List of variable names to be estimated\n",
+ "### 4.1 Define the Experiment class\n",
"\n",
- "Create a list of vars to estimate"
+ "Define the Experiment class to label model for parameter estimation."
]
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
- "variable_name = [\n",
- " \"fs.properties.PR_kappa['bmimPF6', 'carbon_dioxide']\",\n",
- " \"fs.properties.PR_kappa['carbon_dioxide', 'bmimPF6']\",\n",
- "]"
+ "from pyomo.contrib.parmest.experiment import Experiment\n",
+ "\n",
+ "\n",
+ "# Create experiment class for parameter estimation\n",
+ "class PRExperiment(Experiment):\n",
+ "\n",
+ " def __init__(self, data, meas_error=None):\n",
+ " \"\"\"Initialize the PR Experiment class\n",
+ "\n",
+ " Args:\n",
+ " data: DataFrame containing the experimental data\n",
+ " meas_error: Measurement error for the data (optional)\n",
+ " \"\"\"\n",
+ " self.model = None\n",
+ " self.data = data\n",
+ " self.meas_error = meas_error\n",
+ "\n",
+ " def create_model(self):\n",
+ " \"\"\"Create the Pyomo model for the PR parameter estimation problem\"\"\"\n",
+ " self.model = PR_model(self.data)\n",
+ "\n",
+ " def label_model(self):\n",
+ " m = self.model\n",
+ "\n",
+ " # Add Suffixes to label the outputs, parameters, and measurement error in the model\n",
+ " m.experiment_outputs = Suffix(direction=Suffix.LOCAL)\n",
+ " m.experiment_outputs.update(\n",
+ " [(m.fs.state_block[1].pressure, self.data[\"pressure\"])]\n",
+ " )\n",
+ "\n",
+ " m.measurement_error = Suffix(direction=Suffix.LOCAL)\n",
+ " m.measurement_error.update([(m.fs.state_block[1].pressure, self.meas_error)])\n",
+ "\n",
+ " # Add unknown parameters to the model for easier access\n",
+ " m.unknown_parameters = Suffix(direction=Suffix.LOCAL)\n",
+ " m.unknown_parameters.update(\n",
+ " (k, value(k))\n",
+ " for k in [\n",
+ " m.fs.properties.PR_kappa[\"bmimPF6\", \"carbon_dioxide\"],\n",
+ " m.fs.properties.PR_kappa[\"carbon_dioxide\", \"bmimPF6\"],\n",
+ " ]\n",
+ " )\n",
+ "\n",
+ " def get_labeled_model(self):\n",
+ " \"\"\"Return the labeled model\"\"\"\n",
+ " if self.model is None:\n",
+ " self.create_model()\n",
+ " self.label_model()\n",
+ " return self.model"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
- "### 4.2 Create method to return an expression that computes the sum of squared error\n",
+ "### 4.2 Pre-process the data into individual experiments\n",
"\n",
- "We need to provide a method to return an expression to compute the sum of squared errors that will be used as the objective in solving the parameter estimation problem. For this problem, the error will be computed for the pressure."
+ "We now separate our data and assign a model for each individual experiments, creating an experiment list. "
]
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
- "def SSE(m, data):\n",
- " expr = (float(data.iloc[0][\"pressure\"]) - m.fs.state_block[1].pressure) ** 2\n",
- " return expr * 1e-7"
+ "# Update to new interface\n",
+ "exp_list = []\n",
+ "for i in range(data.shape[0]):\n",
+ " exp_list.append(PRExperiment(data.iloc[i]))"
]
},
{
@@ -298,17 +486,218 @@
"source": [
"### 4.3 Run the parameter estimation\n",
"\n",
- "We are now ready to set up the parameter estimation problem. We will create a parameter estimation object called pest. As shown below, we pass the method that returns an initialized model, data, variable_name, and the SSE expression to the Estimator method. tee=True will print the solver output after solving the parameter estimation problem."
+ "We are now ready to set up the parameter estimation problem. We will create a parameter estimation object called pest. As shown below, we pass the experiment list, and an objective function to the Estimator method. tee=True will print the solver output after solving the parameter estimation problem."
]
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 10,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: Starting initialization\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: Bubble, dew, and critical point initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: Starting initialization\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: Bubble, dew, and critical point initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: Starting initialization\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: Bubble, dew, and critical point initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Starting initialization\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Bubble, dew, and critical point initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Starting initialization\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Bubble, dew, and critical point initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Starting initialization\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Bubble, dew, and critical point initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Starting initialization\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Bubble, dew, and critical point initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Starting initialization\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Bubble, dew, and critical point initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Starting initialization\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Bubble, dew, and critical point initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Starting initialization\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Bubble, dew, and critical point initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Starting initialization\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Bubble, dew, and critical point initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Starting initialization\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Bubble, dew, and critical point initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Starting initialization\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Bubble, dew, and critical point initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Starting initialization\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Bubble, dew, and critical point initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Starting initialization\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Bubble, dew, and critical point initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Starting initialization\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Bubble, dew, and critical point initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Starting initialization\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Bubble, dew, and critical point initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Starting initialization\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Bubble, dew, and critical point initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n",
+ "Ipopt 3.13.2: \n",
+ "\n",
+ "******************************************************************************\n",
+ "This program contains Ipopt, a library for large-scale nonlinear optimization.\n",
+ " Ipopt is released as open source code under the Eclipse Public License (EPL).\n",
+ " For more information visit http://projects.coin-or.org/Ipopt\n",
+ "\n",
+ "This version of Ipopt was compiled from source code available at\n",
+ " https://github.com/IDAES/Ipopt as part of the Institute for the Design of\n",
+ " Advanced Energy Systems Process Systems Engineering Framework (IDAES PSE\n",
+ " Framework) Copyright (c) 2018-2019. See https://github.com/IDAES/idaes-pse.\n",
+ "\n",
+ "This version of Ipopt was compiled using HSL, a collection of Fortran codes\n",
+ " for large-scale scientific computation. All technical papers, sales and\n",
+ " publicity material resulting from use of the HSL codes within IPOPT must\n",
+ " contain the following acknowledgement:\n",
+ " HSL, a collection of Fortran codes for large-scale scientific\n",
+ " computation. See http://www.hsl.rl.ac.uk.\n",
+ "******************************************************************************\n",
+ "\n",
+ "This is Ipopt version 3.13.2, running with linear solver ma27.\n",
+ "\n",
+ "Number of nonzeros in equality constraint Jacobian...: 846\n",
+ "Number of nonzeros in inequality constraint Jacobian.: 0\n",
+ "Number of nonzeros in Lagrangian Hessian.............: 720\n",
+ "\n",
+ "Total number of variables............................: 362\n",
+ " variables with only lower bounds: 72\n",
+ " variables with lower and upper bounds: 270\n",
+ " variables with only upper bounds: 18\n",
+ "Total number of equality constraints.................: 360\n",
+ "Total number of inequality constraints...............: 0\n",
+ " inequality constraints with only lower bounds: 0\n",
+ " inequality constraints with lower and upper bounds: 0\n",
+ " inequality constraints with only upper bounds: 0\n",
+ "\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 0 0.0000000e+00 5.00e-01 2.44e-15 -1.0 0.00e+00 - 0.00e+00 0.00e+00 0\n",
+ " 1 6.9602464e+06 4.12e-01 1.82e+07 -1.0 2.99e+04 - 3.39e-01 1.72e-01h 3\n",
+ " 2 1.6667677e+08 2.58e-01 2.70e+08 -1.0 2.58e+04 - 6.19e-01 7.79e-01h 1\n",
+ " 3 2.8786912e+08 1.32e-01 4.98e+07 -1.0 8.26e+03 - 8.13e-01 9.90e-01h 1\n",
+ " 4 2.9277551e+08 1.44e-01 5.76e+05 -1.0 3.05e+02 - 9.77e-01 9.90e-01h 1\n",
+ " 5 2.9282842e+08 3.31e-02 5.28e+03 -1.0 3.24e+00 - 9.90e-01 9.91e-01h 1\n",
+ " 6 2.9282891e+08 4.65e-03 8.12e+04 -1.0 1.08e+00 - 9.90e-01 1.00e+00h 1\n",
+ " 7 2.9282891e+08 3.59e-05 2.33e+04 -2.5 9.23e-02 - 9.97e-01 1.00e+00h 1\n",
+ " 8 2.9282891e+08 3.17e-09 2.26e-05 -3.8 8.65e-04 - 1.00e+00 1.00e+00h 1\n",
+ " 9 2.9282891e+08 1.29e-12 2.38e-05 -8.6 6.67e-08 - 1.00e+00 1.00e+00f 1\n",
+ "\n",
+ "Number of Iterations....: 9\n",
+ "\n",
+ " (scaled) (unscaled)\n",
+ "Objective...............: 2.9282891309627521e+08 2.9282891309627521e+08\n",
+ "Dual infeasibility......: 2.3841853781623475e-05 2.3841853781623475e-05\n",
+ "Constraint violation....: 1.2910152591875072e-12 1.2910152591875072e-12\n",
+ "Complementarity.........: 2.5062901281861244e-09 2.5062901281861244e-09\n",
+ "Overall NLP error.......: 2.5062901281861244e-09 2.3841853781623475e-05\n",
+ "\n",
+ "\n",
+ "Number of objective function evaluations = 12\n",
+ "Number of objective gradient evaluations = 10\n",
+ "Number of equality constraint evaluations = 12\n",
+ "Number of inequality constraint evaluations = 0\n",
+ "Number of equality constraint Jacobian evaluations = 10\n",
+ "Number of inequality constraint Jacobian evaluations = 0\n",
+ "Number of Lagrangian Hessian evaluations = 9\n",
+ "Total CPU secs in IPOPT (w/o function evaluations) = 0.006\n",
+ "Total CPU secs in NLP function evaluations = 0.020\n",
+ "\n",
+ "EXIT: Optimal Solution Found.\n"
+ ]
+ }
+ ],
"source": [
- "pest = parmest.Estimator(PR_model, data, variable_name, SSE, tee=True)\n",
- "\n",
+ "pest = parmest.Estimator(exp_list, obj_function=\"SSE\", tee=True)\n",
"obj_value, parameters = pest.theta_est()"
]
},
@@ -323,15 +712,27 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 11,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "The SSE at the optimal solution is 29.282891\n",
+ "\n",
+ "The values for the parameters are as follows:\n",
+ "fs.properties.PR_kappa[bmimPF6,carbon_dioxide] = -0.40714284008565715\n",
+ "fs.properties.PR_kappa[carbon_dioxide,bmimPF6] = 0.02059368400143062\n"
+ ]
+ }
+ ],
"source": [
- "print(\"The SSE at the optimal solution is %0.6f\" % obj_value)\n",
+ "print(f\"The SSE at the optimal solution is {obj_value*1e-7:0.6f}\")\n",
"print()\n",
"print(\"The values for the parameters are as follows:\")\n",
"for k, v in parameters.items():\n",
- " print(k, \"=\", v)"
+ " print(f\"{k} = {v}\")"
]
},
{
@@ -351,7 +752,7 @@
],
"metadata": {
"kernelspec": {
- "display_name": "Python 3 (ipykernel)",
+ "display_name": "idaes-pse-and-examples-dev-py313-macmini",
"language": "python",
"name": "python3"
},
@@ -365,7 +766,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.8.19"
+ "version": "3.13.13"
}
},
"nbformat": 4,
diff --git a/idaes_examples/notebooks/docs/properties/parameter_estimation_pr_doc.ipynb b/idaes_examples/notebooks/docs/properties/parameter_estimation_pr_doc.ipynb
index ea87d247..e42c5b93 100644
--- a/idaes_examples/notebooks/docs/properties/parameter_estimation_pr_doc.ipynb
+++ b/idaes_examples/notebooks/docs/properties/parameter_estimation_pr_doc.ipynb
@@ -1,1597 +1,774 @@
{
- "cells": [
- {
- "cell_type": "code",
- "execution_count": 1,
- "metadata": {
- "tags": [
- "header",
- "hide-cell"
- ]
- },
- "outputs": [],
- "source": [
- "###############################################################################\n",
- "# The Institute for the Design of Advanced Energy Systems Integrated Platform\n",
- "# Framework (IDAES IP) was produced under the DOE Institute for the\n",
- "# Design of Advanced Energy Systems (IDAES).\n",
- "#\n",
- "# Copyright (c) 2018-2023 by the software owners: The Regents of the\n",
- "# University of California, through Lawrence Berkeley National Laboratory,\n",
- "# National Technology & Engineering Solutions of Sandia, LLC, Carnegie Mellon\n",
- "# University, West Virginia University Research Corporation, et al.\n",
- "# All rights reserved. Please see the files COPYRIGHT.md and LICENSE.md\n",
- "# for full copyright and license information.\n",
- "###############################################################################"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "# Using Parameter Estimation with Modular Property Packages\n",
- "Author: Alejandro Garciadego \n",
- "Maintainer: Andrew Lee \n",
- "Updated: 2023-06-01 \n",
- "## 1. Introduction\n",
- "\n",
- "This Jupyter Notebook estimates binary interaction parameters for a CO$_2$-Ionic liquid property package. A property package has been created for CO$_2$-[bmim][PF6]. We will utilize Pyomo's `parmest` tool in conjunction with IDAES models for parameter estimation. We demonstrate these tools by estimating the parameters associated with the Peng-Robinson property model for a benzene-toluene mixture. The Peng-Robinson EOS the binary interaction parameter (kappa_ij). When estimating parameters associated with the property package, IDAES provides the flexibility of doing the parameter estimation by just using the state block or by using a unit model with a specified property package. This module will demonstrate parameter estimation by using the flash unit model with a Modular Property Package.\n",
- "\n",
- "### 1.1 Tutorial objectives\n",
- "\n",
- "* Utilize the Modular Property Package framework, which provides a flexible platform for users to build property packages by calling upon libraries of modular sub-models to build up complex property calculations with the least effort possible.\n",
- "* Set up a method to return an initialized model\n",
- "* Set up the parameter estimation problem using `parmest`"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "## 2. Problem Statement\n",
- "\n",
- "### 2.1 Importing Pyomo and IDAES model and flowsheet components.\n",
- "\n",
- "In the next cell, we will be importing the necessary components from Pyomo and IDAES."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 2,
- "metadata": {},
- "outputs": [],
- "source": [
- "# Import objects from pyomo package\n",
- "from pyomo.environ import ConcreteModel, SolverFactory, units as pyunits\n",
- "\n",
- "# Import the main FlowsheetBlock from IDAES. The flowsheet block will contain the unit model\n",
- "from idaes.core import FlowsheetBlock\n",
- "\n",
- "# Import idaes logger to set output levels\n",
- "import idaes.logger as idaeslog\n",
- "\n",
- "# Import Flash unit model from idaes.models.unit_models\n",
- "from idaes.models.unit_models import Flash"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "### 2.2 Import parmest "
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 3,
- "metadata": {},
- "outputs": [],
- "source": [
- "import pyomo.contrib.parmest.parmest as parmest"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "### 2.3 Import the Modular Property framework"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 4,
- "metadata": {},
- "outputs": [],
- "source": [
- "from idaes.models.properties.modular_properties.examples.CO2_bmimPF6_PR import (\n",
- " configuration,\n",
- ")\n",
- "\n",
- "from idaes.models.properties.modular_properties import GenericParameterBlock"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "### 2.4 Import data\n",
- "\n",
- "In the next cell, we will be importing `pandas` and the `.csv` file with preassure and composition data. For this example, we load data from the csv file CO2_IL_298.csv. The dataset consists of ninteen data points which provide the mole fraction of [bmim][PF6] and carbon dioxide and the pressure at three different temperatures."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 5,
- "metadata": {},
- "outputs": [],
- "source": [
- "import pandas as pd\n",
- "\n",
- "# Load data from csv\n",
- "data = pd.read_csv(\"CO2_IL_298.csv\")"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "## 3.0 Setting up an initialized model\n",
- "\n",
- "We need to provide a method that returns an initialized model to the `parmest` tool in Pyomo.\n",
- "\n",
- "How we build the model will depend on the data we provided in the data dataframe from pir .csv file.\n",
- "\n",
- "In this case we have data on the liquid mixture, the temperature and the pressure. We will fix the temperature, mole franction in the liquid phase, and the mole fraction of the inlet. "
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 6,
- "metadata": {},
- "outputs": [],
- "source": [
- "def PR_model(data):\n",
- "\n",
- " m = ConcreteModel()\n",
- "\n",
- " m.fs = FlowsheetBlock(dynamic=False)\n",
- "\n",
- " m.fs.properties = GenericParameterBlock(**configuration)\n",
- "\n",
- " m.fs.state_block = m.fs.properties.build_state_block([1], defined_state=True)\n",
- "\n",
- " m.fs.state_block[1].flow_mol.fix(1)\n",
- " x = float(data[\"x_carbon_dioxide\"]) + 0.5\n",
- " m.fs.state_block[1].temperature.fix(float(data[\"temperature\"]))\n",
- " m.fs.state_block[1].pressure.fix(float(data[\"pressure\"]))\n",
- " m.fs.state_block[1].mole_frac_comp[\"bmimPF6\"].fix(1 - x)\n",
- " m.fs.state_block[1].mole_frac_comp[\"carbon_dioxide\"].fix(x)\n",
- "\n",
- " # parameter - kappa_ij (set at 0.3, 0 if i=j)\n",
- " m.fs.properties.PR_kappa[\"bmimPF6\", \"bmimPF6\"].fix(0)\n",
- " m.fs.properties.PR_kappa[\"bmimPF6\", \"carbon_dioxide\"].fix(-0.047)\n",
- " m.fs.properties.PR_kappa[\"carbon_dioxide\", \"carbon_dioxide\"].fix(0)\n",
- " m.fs.properties.PR_kappa[\"carbon_dioxide\", \"bmimPF6\"].fix(0.002)\n",
- "\n",
- " # Initialize the flash unit\n",
- " m.fs.state_block.initialize(outlvl=idaeslog.INFO)\n",
- "\n",
- " # Fix the state variables on the state block\n",
- " m.fs.state_block[1].pressure.unfix()\n",
- " m.fs.state_block[1].temperature.fix(float(data[\"temperature\"]))\n",
- " m.fs.state_block[1].mole_frac_phase_comp[\"Liq\", \"bmimPF6\"].fix(\n",
- " float(data[\"x_bmimPF6\"])\n",
- " )\n",
- " m.fs.state_block[1].mole_frac_phase_comp[\"Liq\", \"carbon_dioxide\"].fix(\n",
- " float(data[\"x_carbon_dioxide\"])\n",
- " )\n",
- " m.fs.state_block[1].mole_frac_comp[\"bmimPF6\"].fix(float(data[\"x_bmimPF6\"]))\n",
- " m.fs.state_block[1].mole_frac_comp[\"carbon_dioxide\"].unfix()\n",
- " # Set bounds on variables to be estimated\n",
- " m.fs.properties.PR_kappa[\"bmimPF6\", \"carbon_dioxide\"].setlb(-5)\n",
- " m.fs.properties.PR_kappa[\"bmimPF6\", \"carbon_dioxide\"].setub(5)\n",
- "\n",
- " m.fs.properties.PR_kappa[\"carbon_dioxide\", \"bmimPF6\"].setlb(-5)\n",
- " m.fs.properties.PR_kappa[\"carbon_dioxide\", \"bmimPF6\"].setub(5)\n",
- "\n",
- " # Return initialized flash model\n",
- " return m"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "### 3.1 Solving square problem"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 7,
- "metadata": {
- "scrolled": false
- },
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:29:59 [INFO] idaes.init.fs.state_block: Starting initialization\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "WARNING (W1002): Setting Var\n",
- "'fs.state_block[1].log_mole_frac_tbub[Vap,Liq,carbon_dioxide]' to a numeric\n",
- "value `1.3789905650578088e-06` outside the bounds (None, 0).\n",
- " See also https://pyomo.readthedocs.io/en/stable/errors.html#w1002\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:29:59 [INFO] idaes.init.fs.state_block: Dew and bubble point initialization: optimal - Optimal Solution Found.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:29:59 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:29:59 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:00 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:00 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:00 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n"
- ]
+ "cells": [
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "metadata": {
+ "tags": [
+ "header",
+ "hide-cell"
+ ]
+ },
+ "outputs": [],
+ "source": [
+ "###############################################################################\n",
+ "# The Institute for the Design of Advanced Energy Systems Integrated Platform\n",
+ "# Framework (IDAES IP) was produced under the DOE Institute for the\n",
+ "# Design of Advanced Energy Systems (IDAES).\n",
+ "#\n",
+ "# Copyright (c) 2018-2026 by the software owners: The Regents of the\n",
+ "# University of California, through Lawrence Berkeley National Laboratory,\n",
+ "# National Technology & Engineering Solutions of Sandia, LLC, Carnegie Mellon\n",
+ "# University, West Virginia University Research Corporation, et al.\n",
+ "# All rights reserved. Please see the files COPYRIGHT.md and LICENSE.md\n",
+ "# for full copyright and license information.\n",
+ "###############################################################################"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Using Parameter Estimation with Modular Property Packages\n",
+ "Author: Alejandro Garciadego \n",
+ "Maintainer: Stephen Cini \n",
+ "Updated: 2026-06-11 \n",
+ "## 1. Introduction\n",
+ "\n",
+ "This Jupyter Notebook estimates binary interaction parameters for a CO$_2$-Ionic liquid property package. A property package has been created for CO$_2$-[bmim][PF6]. We will utilize Pyomo's `parmest` tool in conjunction with IDAES models for parameter estimation. We demonstrate these tools by estimating the parameters associated with the Peng-Robinson property model for a benzene-toluene mixture. The Peng-Robinson EOS the binary interaction parameter (kappa_ij). When estimating parameters associated with the property package, IDAES provides the flexibility of doing the parameter estimation by just using the state block or by using a unit model with a specified property package. This module will demonstrate parameter estimation by using the flash unit model with a Modular Property Package.\n",
+ "\n",
+ "### 1.1 Tutorial objectives\n",
+ "\n",
+ "* Utilize the Modular Property Package framework, which provides a flexible platform for users to build property packages by calling upon libraries of modular sub-models to build up complex property calculations with the least effort possible.\n",
+ "* Set up a method to return an initialized model\n",
+ "* Set up the parameter estimation problem using `parmest`"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## 2. Problem Statement\n",
+ "\n",
+ "### 2.1 Importing Pyomo and IDAES model and flowsheet components.\n",
+ "\n",
+ "In the next cell, we will be importing the necessary components from Pyomo and IDAES."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 2,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Import objects from pyomo package\n",
+ "from pyomo.environ import ConcreteModel, SolverFactory, value, Suffix\n",
+ "\n",
+ "# Import the main FlowsheetBlock from IDAES. The flowsheet block will contain the unit model\n",
+ "from idaes.core import FlowsheetBlock\n",
+ "\n",
+ "# Import idaes logger to set output levels\n",
+ "import idaes.logger as idaeslog\n",
+ "\n",
+ "# Import Flash unit model from idaes.models.unit_models\n",
+ "from idaes.models.unit_models import Flash"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "### 2.2 Import parmest "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 3,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "import pyomo.contrib.parmest.parmest as parmest"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "### 2.3 Import the Modular Property framework"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 4,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "from idaes.models.properties.modular_properties.examples.CO2_bmimPF6_PR import (\n",
+ " configuration,\n",
+ ")\n",
+ "\n",
+ "from idaes.models.properties.modular_properties import GenericParameterBlock"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "### 2.4 Import data\n",
+ "\n",
+ "In the next cell, we will be importing `pandas` and the `.csv` file with preassure and composition data. For this example, we load data from the csv file CO2_IL_298.csv. The dataset consists of ninteen data points which provide the mole fraction of [bmim][PF6] and carbon dioxide and the pressure at three different temperatures."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 5,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "import pandas as pd\n",
+ "\n",
+ "# Load data from csv\n",
+ "data = pd.read_csv(\"CO2_IL_298.csv\")"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## 3.0 Setting up an initialized model\n",
+ "\n",
+ "We need to provide a method that returns an initialized model to the `parmest` tool in Pyomo.\n",
+ "\n",
+ "How we build the model will depend on the data we provided in the data dataframe from pir .csv file.\n",
+ "\n",
+ "In this case we have data on the liquid mixture, the temperature and the pressure. We will fix the temperature, mole franction in the liquid phase, and the mole fraction of the inlet. "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 6,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "def PR_model(data):\n",
+ "\n",
+ " m = ConcreteModel()\n",
+ "\n",
+ " m.fs = FlowsheetBlock(dynamic=False)\n",
+ "\n",
+ " m.fs.properties = GenericParameterBlock(**configuration)\n",
+ "\n",
+ " m.fs.state_block = m.fs.properties.build_state_block([1], defined_state=True)\n",
+ "\n",
+ " m.fs.state_block[1].flow_mol.fix(1)\n",
+ " if isinstance(data, dict) or isinstance(data, pd.Series):\n",
+ " x = float(data[\"x_carbon_dioxide\"]) + 0.5\n",
+ " m.fs.state_block[1].temperature.fix(float(data[\"temperature\"]))\n",
+ " m.fs.state_block[1].pressure.fix(float(data[\"pressure\"]))\n",
+ " elif isinstance(data, pd.DataFrame):\n",
+ " x = float(data.iloc[0][\"x_carbon_dioxide\"]) + 0.5\n",
+ " m.fs.state_block[1].temperature.fix(float(data.iloc[0][\"temperature\"]))\n",
+ " m.fs.state_block[1].pressure.fix(float(data.iloc[0][\"pressure\"]))\n",
+ " else:\n",
+ " raise ValueError(\"Unrecognized data type.\")\n",
+ " m.fs.state_block[1].mole_frac_comp[\"bmimPF6\"].fix(1 - x)\n",
+ " m.fs.state_block[1].mole_frac_comp[\"carbon_dioxide\"].fix(x)\n",
+ "\n",
+ " # parameter - kappa_ij (set at 0.3, 0 if i=j)\n",
+ " m.fs.properties.PR_kappa[\"bmimPF6\", \"bmimPF6\"].fix(0)\n",
+ " m.fs.properties.PR_kappa[\"bmimPF6\", \"carbon_dioxide\"].fix(-0.047)\n",
+ " m.fs.properties.PR_kappa[\"carbon_dioxide\", \"carbon_dioxide\"].fix(0)\n",
+ " m.fs.properties.PR_kappa[\"carbon_dioxide\", \"bmimPF6\"].fix(0.002)\n",
+ "\n",
+ " # Initialize the flash unit\n",
+ " m.fs.state_block.initialize(outlvl=idaeslog.INFO)\n",
+ "\n",
+ " # Fix the state variables on the state block\n",
+ " if isinstance(data, dict) or isinstance(data, pd.Series):\n",
+ " m.fs.state_block[1].temperature.fix(float(data[\"temperature\"]))\n",
+ " m.fs.state_block[1].mole_frac_phase_comp[\"Liq\", \"bmimPF6\"].fix(\n",
+ " float(data[\"x_bmimPF6\"])\n",
+ " )\n",
+ " m.fs.state_block[1].mole_frac_phase_comp[\"Liq\", \"carbon_dioxide\"].fix(\n",
+ " float(data[\"x_carbon_dioxide\"])\n",
+ " )\n",
+ " m.fs.state_block[1].mole_frac_comp[\"bmimPF6\"].fix(float(data[\"x_bmimPF6\"]))\n",
+ " elif isinstance(data, pd.DataFrame):\n",
+ " m.fs.state_block[1].temperature.fix(float(data.iloc[0][\"temperature\"]))\n",
+ " m.fs.state_block[1].mole_frac_phase_comp[\"Liq\", \"bmimPF6\"].fix(\n",
+ " float(data.iloc[0][\"x_bmimPF6\"])\n",
+ " )\n",
+ " m.fs.state_block[1].mole_frac_phase_comp[\"Liq\", \"carbon_dioxide\"].fix(\n",
+ " float(data.iloc[0][\"x_carbon_dioxide\"])\n",
+ " )\n",
+ " m.fs.state_block[1].mole_frac_comp[\"bmimPF6\"].fix(\n",
+ " float(data.iloc[0][\"x_bmimPF6\"])\n",
+ " )\n",
+ " else:\n",
+ " raise ValueError(\"Unrecognized data type.\")\n",
+ "\n",
+ " m.fs.state_block[1].pressure.unfix()\n",
+ " m.fs.state_block[1].mole_frac_comp[\"carbon_dioxide\"].unfix()\n",
+ " # Set bounds on variables to be estimated\n",
+ " m.fs.properties.PR_kappa[\"bmimPF6\", \"carbon_dioxide\"].setlb(-5)\n",
+ " m.fs.properties.PR_kappa[\"bmimPF6\", \"carbon_dioxide\"].setub(5)\n",
+ "\n",
+ " m.fs.properties.PR_kappa[\"carbon_dioxide\", \"bmimPF6\"].setlb(-5)\n",
+ " m.fs.properties.PR_kappa[\"carbon_dioxide\", \"bmimPF6\"].setub(5)\n",
+ "\n",
+ " # Return initialized flash model\n",
+ " return m"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "### 3.1 Solving square problem"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 7,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "2026-06-11 12:42:22 [INFO] idaes.init.fs.state_block: Starting initialization\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: Bubble, dew, and critical point initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n",
+ "Ipopt 3.13.2: \n",
+ "\n",
+ "******************************************************************************\n",
+ "This program contains Ipopt, a library for large-scale nonlinear optimization.\n",
+ " Ipopt is released as open source code under the Eclipse Public License (EPL).\n",
+ " For more information visit http://projects.coin-or.org/Ipopt\n",
+ "\n",
+ "This version of Ipopt was compiled from source code available at\n",
+ " https://github.com/IDAES/Ipopt as part of the Institute for the Design of\n",
+ " Advanced Energy Systems Process Systems Engineering Framework (IDAES PSE\n",
+ " Framework) Copyright (c) 2018-2019. See https://github.com/IDAES/idaes-pse.\n",
+ "\n",
+ "This version of Ipopt was compiled using HSL, a collection of Fortran codes\n",
+ " for large-scale scientific computation. All technical papers, sales and\n",
+ " publicity material resulting from use of the HSL codes within IPOPT must\n",
+ " contain the following acknowledgement:\n",
+ " HSL, a collection of Fortran codes for large-scale scientific\n",
+ " computation. See http://www.hsl.rl.ac.uk.\n",
+ "******************************************************************************\n",
+ "\n",
+ "This is Ipopt version 3.13.2, running with linear solver ma27.\n",
+ "\n",
+ "Number of nonzeros in equality constraint Jacobian...: 39\n",
+ "Number of nonzeros in inequality constraint Jacobian.: 0\n",
+ "Number of nonzeros in Lagrangian Hessian.............: 25\n",
+ "\n",
+ "Total number of variables............................: 18\n",
+ " variables with only lower bounds: 4\n",
+ " variables with lower and upper bounds: 13\n",
+ " variables with only upper bounds: 1\n",
+ "Total number of equality constraints.................: 18\n",
+ "Total number of inequality constraints...............: 0\n",
+ " inequality constraints with only lower bounds: 0\n",
+ " inequality constraints with lower and upper bounds: 0\n",
+ " inequality constraints with only upper bounds: 0\n",
+ "\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 0 0.0000000e+00 5.00e-01 1.00e+00 -1.0 0.00e+00 - 0.00e+00 0.00e+00 0\n",
+ " 1 0.0000000e+00 1.76e-01 6.65e+03 -1.0 7.51e+04 - 2.67e-01 9.90e-01H 1\n",
+ " 2 0.0000000e+00 4.81e-02 1.40e+02 -1.0 6.76e+02 - 9.46e-01 9.90e-01h 1\n",
+ " 3 0.0000000e+00 8.65e-03 1.76e+01 -1.0 9.79e+00 - 9.90e-01 9.90e-01h 1\n",
+ " 4 0.0000000e+00 1.81e-03 4.99e+04 -1.0 1.20e+00 - 9.90e-01 1.00e+00h 1\n",
+ " 5 0.0000000e+00 3.48e-03 9.81e+04 -1.0 5.29e+01 - 9.90e-01 1.00e+00h 1\n",
+ " 6 0.0000000e+00 1.57e-03 8.00e+02 -1.0 1.54e+02 - 9.92e-01 1.00e+00h 1\n",
+ " 7 0.0000000e+00 7.66e-04 2.93e-04 -2.5 2.52e+02 - 1.00e+00 1.00e+00h 1\n",
+ " 8 0.0000000e+00 3.81e-04 1.61e-04 -5.7 4.82e+02 - 1.00e+00 1.00e+00h 1\n",
+ " 9 0.0000000e+00 1.90e-04 6.49e-05 -5.7 9.53e+02 - 1.00e+00 1.00e+00h 1\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 10 0.0000000e+00 9.50e-05 8.68e-05 -5.7 1.90e+03 - 1.00e+00 1.00e+00h 1\n",
+ " 11 0.0000000e+00 4.75e-05 3.47e-04 -5.7 3.81e+03 - 1.00e+00 1.00e+00h 1\n",
+ " 12 0.0000000e+00 2.72e-05 1.39e-03 -5.7 7.64e+03 - 1.00e+00 1.00e+00h 1\n",
+ " 13 0.0000000e+00 1.07e-04 5.57e-03 -5.7 1.54e+04 - 1.00e+00 1.00e+00h 1\n",
+ " 14 0.0000000e+00 4.09e-04 2.23e-02 -5.7 3.11e+04 - 1.00e+00 1.00e+00h 1\n",
+ " 15 0.0000000e+00 1.51e-03 8.91e-02 -5.7 6.38e+04 - 1.00e+00 1.00e+00h 1\n",
+ " 16 0.0000000e+00 5.12e-03 3.53e-01 -5.7 1.33e+05 - 1.00e+00 1.00e+00h 1\n",
+ " 17 0.0000000e+00 1.49e-02 1.34e+00 -5.7 2.89e+05 - 1.00e+00 1.00e+00h 1\n",
+ " 18 0.0000000e+00 3.14e-02 4.58e+00 -5.7 6.55e+05 - 1.00e+00 1.00e+00h 1\n",
+ " 19 0.0000000e+00 2.86e-02 4.32e+00 -5.7 1.51e+06 - 1.00e+00 1.25e-01h 4\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 20 0.0000000e+00 2.82e-02 4.26e+00 -5.7 1.73e+06 - 1.00e+00 1.56e-02h 7\n",
+ " 21 0.0000000e+00 2.79e-02 4.23e+00 -5.7 1.76e+06 - 1.00e+00 7.81e-03h 8\n",
+ " 22 0.0000000e+00 2.79e-02 4.22e+00 -5.7 1.77e+06 - 1.00e+00 4.88e-04h 12\n",
+ " 23 0.0000000e+00 2.79e-02 4.22e+00 -5.7 1.77e+06 - 1.00e+00 1.22e-04h 14\n",
+ " 24 0.0000000e+00 7.05e-03 1.51e+01 -5.7 1.77e+06 - 1.00e+00 1.00e+00h 1\n",
+ " 25 0.0000000e+00 9.63e-04 4.01e+00 -5.7 3.18e+06 - 1.00e+00 1.50e-01h 2\n",
+ " 26 0.0000000e+00 5.53e-04 8.54e+01 -5.7 3.24e+06 - 1.00e+00 6.53e-02h 2\n",
+ " 27 0.0000000e+00 5.53e-04 8.57e+01 -5.7 3.20e+06 - 1.00e+00 9.58e-04h 7\n",
+ " 28 0.0000000e+00 5.53e-04 9.27e+01 -5.7 3.19e+06 - 1.00e+00 9.42e-04h 7\n",
+ " 29 0.0000000e+00 5.53e-04 2.08e+02 -5.7 3.19e+06 - 1.00e+00 9.27e-04h 7\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 30 0.0000000e+00 5.52e-04 7.91e+03 -5.7 1.83e+06 - 1.00e+00 3.17e-03h 6\n",
+ " 31 0.0000000e+00 3.77e-05 2.11e+06 -5.7 2.63e+04 - 1.00e+00 1.00e+00h 1\n",
+ " 32 0.0000000e+00 3.77e-05 2.10e+06 -5.7 1.03e+06 - 1.00e+00 5.67e-04h 9\n",
+ " 33 0.0000000e+00 3.77e-05 2.10e+06 -5.7 1.03e+06 - 1.00e+00 5.65e-04h 9\n",
+ " 34 0.0000000e+00 3.77e-05 2.10e+06 -5.7 1.02e+06 - 1.00e+00 5.63e-04h 9\n",
+ " 35 0.0000000e+00 3.77e-05 2.12e+06 -5.7 9.14e+05 - 1.00e+00 6.29e-04h 9\n",
+ " 36 0.0000000e+00 3.77e-05 2.23e+06 -5.7 9.36e+05 - 1.00e+00 6.11e-04h 9\n",
+ " 37 0.0000000e+00 3.76e-05 4.98e+06 -5.7 4.23e+05 - 1.00e+00 2.69e-03h 8\n",
+ " 38 0.0000000e+00 3.76e-05 6.97e+06 -5.7 8.98e+05 - 1.00e+00 6.29e-04h 9\n",
+ " 39 0.0000000e+00 3.76e-05 5.17e+07 -5.7 6.09e+05 - 1.00e+00 1.85e-03h 8\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 40 0.0000000e+00 3.76e-05 6.29e+07 -5.7 1.03e+06 - 1.00e+00 5.42e-04h 9\n",
+ " 41 0.0000000e+00 3.76e-05 7.41e+07 -5.7 1.02e+06 - 1.00e+00 5.43e-04h 9\n",
+ " 42 0.0000000e+00 8.59e-04 7.30e+11 -5.7 1.02e+06 - 1.00e+00 1.39e-01w 1\n",
+ " 43 0.0000000e+00 8.58e-04 7.30e+11 -5.7 7.14e+03 - 1.00e+00 2.07e-05w 1\n",
+ "In iteration 43, 2 Slacks too small, adjusting variable bounds\n",
+ " 44 0.0000000e+00 7.90e-04 5.95e+14 -5.7 4.69e+03 - 1.00e+00 8.02e-02w 1\n",
+ " 45 0.0000000e+00 3.76e-05 8.53e+07 -5.7 4.31e+03 - 1.00e+00 5.41e-04h 8\n",
+ " 46 0.0000000e+00 3.75e-05 9.64e+07 -5.7 1.02e+06 - 1.00e+00 5.39e-04h 9\n",
+ " 47 0.0000000e+00 3.75e-05 1.08e+08 -5.7 1.02e+06 - 1.00e+00 5.37e-04h 9\n",
+ " 48 0.0000000e+00 3.75e-05 1.19e+08 -5.7 1.02e+06 - 1.00e+00 5.35e-04h 9\n",
+ " 49 0.0000000e+00 3.75e-05 1.30e+08 -5.7 1.02e+06 - 1.00e+00 5.33e-04h 9\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 50 0.0000000e+00 3.75e-05 1.41e+08 -5.7 1.02e+06 - 1.00e+00 5.31e-04h 9\n",
+ " 51 0.0000000e+00 3.75e-05 1.52e+08 -5.7 1.02e+06 - 1.00e+00 5.29e-04h 9\n",
+ " 52 0.0000000e+00 3.75e-05 1.64e+08 -5.7 1.02e+06 - 1.00e+00 5.27e-04h 9\n",
+ " 53 0.0000000e+00 3.75e-05 1.75e+08 -5.7 1.02e+06 - 1.00e+00 5.25e-04h 9\n",
+ " 54 0.0000000e+00 3.75e-05 1.86e+08 -5.7 1.02e+06 - 1.00e+00 5.23e-04h 9\n",
+ " 55 0.0000000e+00 7.97e-04 7.34e+11 -5.7 1.02e+06 - 1.00e+00 1.33e-01w 1\n",
+ " 56 0.0000000e+00 7.97e-04 6.89e+11 -5.7 6.89e-05 16.0 2.81e-04 5.39e-01w 1\n",
+ " 57 0.0000000e+00 4.04e-07 2.66e+15 -5.7 4.36e+03 - 2.29e-07 1.00e+00h 1\n",
+ "Cannot recompute multipliers for feasibility problem. Error in eq_mult_calculator\n",
+ "\n",
+ "Number of Iterations....: 57\n",
+ "\n",
+ " (scaled) (unscaled)\n",
+ "Objective...............: 0.0000000000000000e+00 0.0000000000000000e+00\n",
+ "Dual infeasibility......: 2.6563801083485440e+15 2.6563801083485440e+15\n",
+ "Constraint violation....: 4.0441652946975677e-07 4.0441652946975677e-07\n",
+ "Complementarity.........: 0.0000000000000000e+00 0.0000000000000000e+00\n",
+ "Overall NLP error.......: 4.0441652946975677e-07 2.6563801083485440e+15\n",
+ "\n",
+ "\n",
+ "Number of objective function evaluations = 337\n",
+ "Number of objective gradient evaluations = 59\n",
+ "Number of equality constraint evaluations = 337\n",
+ "Number of inequality constraint evaluations = 0\n",
+ "Number of equality constraint Jacobian evaluations = 59\n",
+ "Number of inequality constraint Jacobian evaluations = 0\n",
+ "Number of Lagrangian Hessian evaluations = 58\n",
+ "Total CPU secs in IPOPT (w/o function evaluations) = 0.005\n",
+ "Total CPU secs in NLP function evaluations = 0.008\n",
+ "\n",
+ "EXIT: Solved To Acceptable Level.\n"
+ ]
+ }
+ ],
+ "source": [
+ "from idaes.core.util.model_statistics import degrees_of_freedom\n",
+ "import pytest\n",
+ "\n",
+ "test_data = {\n",
+ " \"temperature\": 298,\n",
+ " \"pressure\": 812323,\n",
+ " \"x_bmimPF6\": 0.86,\n",
+ " \"x_carbon_dioxide\": 0.14,\n",
+ "}\n",
+ "\n",
+ "m = PR_model(test_data)\n",
+ "\n",
+ "# Check that degrees of freedom is 0\n",
+ "assert degrees_of_freedom(m) == 0\n",
+ "\n",
+ "# Solve the model with the default solver and display results\n",
+ "solver = SolverFactory(\"ipopt\")\n",
+ "results = solver.solve(m, tee=True)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## 4.0 Parameter estimation using parmest \n",
+ "\n",
+ "### 4.1 Define the Experiment class\n",
+ "\n",
+ "Define the Experiment class to label model for parameter estimation."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 8,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "from pyomo.contrib.parmest.experiment import Experiment\n",
+ "\n",
+ "\n",
+ "# Create experiment class for parameter estimation\n",
+ "class PRExperiment(Experiment):\n",
+ "\n",
+ " def __init__(self, data, meas_error=None):\n",
+ " \"\"\"Initialize the PR Experiment class\n",
+ "\n",
+ " Args:\n",
+ " data: DataFrame containing the experimental data\n",
+ " meas_error: Measurement error for the data (optional)\n",
+ " \"\"\"\n",
+ " self.model = None\n",
+ " self.data = data\n",
+ " self.meas_error = meas_error\n",
+ "\n",
+ " def create_model(self):\n",
+ " \"\"\"Create the Pyomo model for the PR parameter estimation problem\"\"\"\n",
+ " self.model = PR_model(self.data)\n",
+ "\n",
+ " def label_model(self):\n",
+ " m = self.model\n",
+ "\n",
+ " # Add Suffixes to label the outputs, parameters, and measurement error in the model\n",
+ " m.experiment_outputs = Suffix(direction=Suffix.LOCAL)\n",
+ " m.experiment_outputs.update(\n",
+ " [(m.fs.state_block[1].pressure, self.data[\"pressure\"])]\n",
+ " )\n",
+ "\n",
+ " m.measurement_error = Suffix(direction=Suffix.LOCAL)\n",
+ " m.measurement_error.update([(m.fs.state_block[1].pressure, self.meas_error)])\n",
+ "\n",
+ " # Add unknown parameters to the model for easier access\n",
+ " m.unknown_parameters = Suffix(direction=Suffix.LOCAL)\n",
+ " m.unknown_parameters.update(\n",
+ " (k, value(k))\n",
+ " for k in [\n",
+ " m.fs.properties.PR_kappa[\"bmimPF6\", \"carbon_dioxide\"],\n",
+ " m.fs.properties.PR_kappa[\"carbon_dioxide\", \"bmimPF6\"],\n",
+ " ]\n",
+ " )\n",
+ "\n",
+ " def get_labeled_model(self):\n",
+ " \"\"\"Return the labeled model\"\"\"\n",
+ " if self.model is None:\n",
+ " self.create_model()\n",
+ " self.label_model()\n",
+ " return self.model"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "### 4.2 Pre-process the data into individual experiments\n",
+ "\n",
+ "We now separate our data and assign a model for each individual experiments, creating an experiment list. "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 9,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Update to new interface\n",
+ "exp_list = []\n",
+ "for i in range(data.shape[0]):\n",
+ " exp_list.append(PRExperiment(data.iloc[i]))"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "### 4.3 Run the parameter estimation\n",
+ "\n",
+ "We are now ready to set up the parameter estimation problem. We will create a parameter estimation object called pest. As shown below, we pass the experiment list, and an objective function to the Estimator method. tee=True will print the solver output after solving the parameter estimation problem."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 10,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: Starting initialization\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: Bubble, dew, and critical point initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: Starting initialization\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: Bubble, dew, and critical point initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: Starting initialization\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: Bubble, dew, and critical point initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Starting initialization\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Bubble, dew, and critical point initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Starting initialization\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Bubble, dew, and critical point initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Starting initialization\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Bubble, dew, and critical point initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Starting initialization\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Bubble, dew, and critical point initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Starting initialization\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Bubble, dew, and critical point initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Starting initialization\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Bubble, dew, and critical point initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Starting initialization\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Bubble, dew, and critical point initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Starting initialization\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Bubble, dew, and critical point initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Starting initialization\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Bubble, dew, and critical point initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Starting initialization\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Bubble, dew, and critical point initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Starting initialization\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Bubble, dew, and critical point initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Starting initialization\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Bubble, dew, and critical point initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Starting initialization\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Bubble, dew, and critical point initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Starting initialization\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Bubble, dew, and critical point initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Starting initialization\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Bubble, dew, and critical point initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n",
+ "Ipopt 3.13.2: \n",
+ "\n",
+ "******************************************************************************\n",
+ "This program contains Ipopt, a library for large-scale nonlinear optimization.\n",
+ " Ipopt is released as open source code under the Eclipse Public License (EPL).\n",
+ " For more information visit http://projects.coin-or.org/Ipopt\n",
+ "\n",
+ "This version of Ipopt was compiled from source code available at\n",
+ " https://github.com/IDAES/Ipopt as part of the Institute for the Design of\n",
+ " Advanced Energy Systems Process Systems Engineering Framework (IDAES PSE\n",
+ " Framework) Copyright (c) 2018-2019. See https://github.com/IDAES/idaes-pse.\n",
+ "\n",
+ "This version of Ipopt was compiled using HSL, a collection of Fortran codes\n",
+ " for large-scale scientific computation. All technical papers, sales and\n",
+ " publicity material resulting from use of the HSL codes within IPOPT must\n",
+ " contain the following acknowledgement:\n",
+ " HSL, a collection of Fortran codes for large-scale scientific\n",
+ " computation. See http://www.hsl.rl.ac.uk.\n",
+ "******************************************************************************\n",
+ "\n",
+ "This is Ipopt version 3.13.2, running with linear solver ma27.\n",
+ "\n",
+ "Number of nonzeros in equality constraint Jacobian...: 846\n",
+ "Number of nonzeros in inequality constraint Jacobian.: 0\n",
+ "Number of nonzeros in Lagrangian Hessian.............: 720\n",
+ "\n",
+ "Total number of variables............................: 362\n",
+ " variables with only lower bounds: 72\n",
+ " variables with lower and upper bounds: 270\n",
+ " variables with only upper bounds: 18\n",
+ "Total number of equality constraints.................: 360\n",
+ "Total number of inequality constraints...............: 0\n",
+ " inequality constraints with only lower bounds: 0\n",
+ " inequality constraints with lower and upper bounds: 0\n",
+ " inequality constraints with only upper bounds: 0\n",
+ "\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 0 0.0000000e+00 5.00e-01 2.44e-15 -1.0 0.00e+00 - 0.00e+00 0.00e+00 0\n",
+ " 1 6.9602464e+06 4.12e-01 1.82e+07 -1.0 2.99e+04 - 3.39e-01 1.72e-01h 3\n",
+ " 2 1.6667677e+08 2.58e-01 2.70e+08 -1.0 2.58e+04 - 6.19e-01 7.79e-01h 1\n",
+ " 3 2.8786912e+08 1.32e-01 4.98e+07 -1.0 8.26e+03 - 8.13e-01 9.90e-01h 1\n",
+ " 4 2.9277551e+08 1.44e-01 5.76e+05 -1.0 3.05e+02 - 9.77e-01 9.90e-01h 1\n",
+ " 5 2.9282842e+08 3.31e-02 5.28e+03 -1.0 3.24e+00 - 9.90e-01 9.91e-01h 1\n",
+ " 6 2.9282891e+08 4.65e-03 8.12e+04 -1.0 1.08e+00 - 9.90e-01 1.00e+00h 1\n",
+ " 7 2.9282891e+08 3.59e-05 2.33e+04 -2.5 9.23e-02 - 9.97e-01 1.00e+00h 1\n",
+ " 8 2.9282891e+08 3.17e-09 2.26e-05 -3.8 8.65e-04 - 1.00e+00 1.00e+00h 1\n",
+ " 9 2.9282891e+08 1.29e-12 2.38e-05 -8.6 6.67e-08 - 1.00e+00 1.00e+00f 1\n",
+ "\n",
+ "Number of Iterations....: 9\n",
+ "\n",
+ " (scaled) (unscaled)\n",
+ "Objective...............: 2.9282891309627521e+08 2.9282891309627521e+08\n",
+ "Dual infeasibility......: 2.3841853781623475e-05 2.3841853781623475e-05\n",
+ "Constraint violation....: 1.2910152591875072e-12 1.2910152591875072e-12\n",
+ "Complementarity.........: 2.5062901281861244e-09 2.5062901281861244e-09\n",
+ "Overall NLP error.......: 2.5062901281861244e-09 2.3841853781623475e-05\n",
+ "\n",
+ "\n",
+ "Number of objective function evaluations = 12\n",
+ "Number of objective gradient evaluations = 10\n",
+ "Number of equality constraint evaluations = 12\n",
+ "Number of inequality constraint evaluations = 0\n",
+ "Number of equality constraint Jacobian evaluations = 10\n",
+ "Number of inequality constraint Jacobian evaluations = 0\n",
+ "Number of Lagrangian Hessian evaluations = 9\n",
+ "Total CPU secs in IPOPT (w/o function evaluations) = 0.006\n",
+ "Total CPU secs in NLP function evaluations = 0.020\n",
+ "\n",
+ "EXIT: Optimal Solution Found.\n"
+ ]
+ }
+ ],
+ "source": [
+ "pest = parmest.Estimator(exp_list, obj_function=\"SSE\", tee=True)\n",
+ "obj_value, parameters = pest.theta_est()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## 5.0 Display results\n",
+ "\n",
+ "Let us display the results by running the next cell."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 11,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "The SSE at the optimal solution is 29.282891\n",
+ "\n",
+ "The values for the parameters are as follows:\n",
+ "fs.properties.PR_kappa[bmimPF6,carbon_dioxide] = -0.40714284008565715\n",
+ "fs.properties.PR_kappa[carbon_dioxide,bmimPF6] = 0.02059368400143062\n"
+ ]
+ }
+ ],
+ "source": [
+ "print(f\"The SSE at the optimal solution is {obj_value*1e-7:0.6f}\")\n",
+ "print()\n",
+ "print(\"The values for the parameters are as follows:\")\n",
+ "for k, v in parameters.items():\n",
+ " print(f\"{k} = {v}\")"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Now we can use this parameters and include them in the configuration dictionary. We can also use `m.fs.properties = GenericParameterBlock(**configuration)` to solve unit models."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": []
}
- ],
- "source": [
- "from idaes.core.util.model_statistics import degrees_of_freedom\n",
- "import pytest\n",
- "\n",
- "test_data = {\n",
- " \"temperature\": 298,\n",
- " \"pressure\": 812323,\n",
- " \"x_bmimPF6\": 0.86,\n",
- " \"x_carbon_dioxide\": 0.14,\n",
- "}\n",
- "\n",
- "m = PR_model(test_data)\n",
- "\n",
- "# Check that degrees of freedom is 0\n",
- "assert degrees_of_freedom(m) == 0"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "## 4.0 Parameter estimation using parmest \n",
- "\n",
- "### 4.1 List of variable names to be estimated\n",
- "\n",
- "Create a list of vars to estimate"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 8,
- "metadata": {},
- "outputs": [],
- "source": [
- "variable_name = [\n",
- " \"fs.properties.PR_kappa['bmimPF6', 'carbon_dioxide']\",\n",
- " \"fs.properties.PR_kappa['carbon_dioxide', 'bmimPF6']\",\n",
- "]"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "### 4.2 Create method to return an expression that computes the sum of squared error\n",
- "\n",
- "We need to provide a method to return an expression to compute the sum of squared errors that will be used as the objective in solving the parameter estimation problem. For this problem, the error will be computed for the pressure."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 9,
- "metadata": {},
- "outputs": [],
- "source": [
- "def SSE(m, data):\n",
- " expr = (float(data[\"pressure\"]) - m.fs.state_block[1].pressure) ** 2\n",
- " return expr * 1e-7"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "### 4.3 Run the parameter estimation\n",
- "\n",
- "We are now ready to set up the parameter estimation problem. We will create a parameter estimation object called pest. As shown below, we pass the method that returns an initialized model, data, variable_name, and the SSE expression to the Estimator method. tee=True will print the solver output after solving the parameter estimation problem."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 10,
- "metadata": {
- "scrolled": false
- },
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:00 [INFO] idaes.init.fs.state_block: Starting initialization\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "WARNING (W1002): Setting Var\n",
- "'fs.state_block[1].log_mole_frac_tbub[Vap,Liq,carbon_dioxide]' to a numeric\n",
- "value `4.301303339264284e-06` outside the bounds (None, 0).\n",
- " See also https://pyomo.readthedocs.io/en/stable/errors.html#w1002\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:00 [INFO] idaes.init.fs.state_block: Dew and bubble point initialization: optimal - Optimal Solution Found.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:00 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:00 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:00 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n"
- ]
- },
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "C:\\Users\\dkgun\\AppData\\Local\\Temp\\ipykernel_28652\\3856510393.py:12: FutureWarning: Calling float on a single element Series is deprecated and will raise a TypeError in the future. Use float(ser.iloc[0]) instead\n",
- " x = float(data[\"x_carbon_dioxide\"]) + 0.5\n",
- "C:\\Users\\dkgun\\AppData\\Local\\Temp\\ipykernel_28652\\3856510393.py:13: FutureWarning: Calling float on a single element Series is deprecated and will raise a TypeError in the future. Use float(ser.iloc[0]) instead\n",
- " m.fs.state_block[1].temperature.fix(float(data[\"temperature\"]))\n",
- "C:\\Users\\dkgun\\AppData\\Local\\Temp\\ipykernel_28652\\3856510393.py:14: FutureWarning: Calling float on a single element Series is deprecated and will raise a TypeError in the future. Use float(ser.iloc[0]) instead\n",
- " m.fs.state_block[1].pressure.fix(float(data[\"pressure\"]))\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:00 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:00 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:00 [INFO] idaes.init.fs.state_block: Starting initialization\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "WARNING (W1002): Setting Var\n",
- "'fs.state_block[1].log_mole_frac_tbub[Vap,Liq,carbon_dioxide]' to a numeric\n",
- "value `4.814447495739171e-09` outside the bounds (None, 0).\n",
- " See also https://pyomo.readthedocs.io/en/stable/errors.html#w1002\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:00 [INFO] idaes.init.fs.state_block: Dew and bubble point initialization: optimal - Optimal Solution Found.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:00 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:00 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:00 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n"
- ]
- },
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "C:\\Users\\dkgun\\AppData\\Local\\Temp\\ipykernel_28652\\3856510393.py:29: FutureWarning: Calling float on a single element Series is deprecated and will raise a TypeError in the future. Use float(ser.iloc[0]) instead\n",
- " m.fs.state_block[1].temperature.fix(float(data[\"temperature\"]))\n",
- "C:\\Users\\dkgun\\AppData\\Local\\Temp\\ipykernel_28652\\3856510393.py:31: FutureWarning: Calling float on a single element Series is deprecated and will raise a TypeError in the future. Use float(ser.iloc[0]) instead\n",
- " float(data[\"x_bmimPF6\"])\n",
- "C:\\Users\\dkgun\\AppData\\Local\\Temp\\ipykernel_28652\\3856510393.py:34: FutureWarning: Calling float on a single element Series is deprecated and will raise a TypeError in the future. Use float(ser.iloc[0]) instead\n",
- " float(data[\"x_carbon_dioxide\"])\n",
- "C:\\Users\\dkgun\\AppData\\Local\\Temp\\ipykernel_28652\\3856510393.py:36: FutureWarning: Calling float on a single element Series is deprecated and will raise a TypeError in the future. Use float(ser.iloc[0]) instead\n",
- " m.fs.state_block[1].mole_frac_comp[\"bmimPF6\"].fix(float(data[\"x_bmimPF6\"]))\n",
- "C:\\Users\\dkgun\\AppData\\Local\\Temp\\ipykernel_28652\\1809745473.py:2: FutureWarning: Calling float on a single element Series is deprecated and will raise a TypeError in the future. Use float(ser.iloc[0]) instead\n",
- " expr = (float(data[\"pressure\"]) - m.fs.state_block[1].pressure) ** 2\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:00 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:00 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:00 [INFO] idaes.init.fs.state_block: Starting initialization\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "WARNING (W1002): Setting Var\n",
- "'fs.state_block[1].log_mole_frac_tbub[Vap,Liq,carbon_dioxide]' to a numeric\n",
- "value `6.357548229111755e-06` outside the bounds (None, 0).\n",
- " See also https://pyomo.readthedocs.io/en/stable/errors.html#w1002\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:00 [INFO] idaes.init.fs.state_block: Dew and bubble point initialization: optimal - Optimal Solution Found.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:00 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:00 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:00 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:01 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:01 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:01 [INFO] idaes.init.fs.state_block: Starting initialization\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "WARNING (W1002): Setting Var\n",
- "'fs.state_block[1].log_mole_frac_tbub[Vap,Liq,carbon_dioxide]' to a numeric\n",
- "value `6.169320987299437e-07` outside the bounds (None, 0).\n",
- " See also https://pyomo.readthedocs.io/en/stable/errors.html#w1002\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:01 [INFO] idaes.init.fs.state_block: Dew and bubble point initialization: optimal - Optimal Solution Found.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:01 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:01 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:01 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:01 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:01 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:01 [INFO] idaes.init.fs.state_block: Starting initialization\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "WARNING (W1002): Setting Var\n",
- "'fs.state_block[1].log_mole_frac_tbub[Vap,Liq,carbon_dioxide]' to a numeric\n",
- "value `7.629131479751715e-08` outside the bounds (None, 0).\n",
- " See also https://pyomo.readthedocs.io/en/stable/errors.html#w1002\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:01 [INFO] idaes.init.fs.state_block: Dew and bubble point initialization: optimal - Optimal Solution Found.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:01 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:01 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:01 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:01 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:01 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:01 [INFO] idaes.init.fs.state_block: Starting initialization\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "WARNING (W1002): Setting Var\n",
- "'fs.state_block[1].log_mole_frac_tbub[Vap,Liq,carbon_dioxide]' to a numeric\n",
- "value `1.3059472085065408e-08` outside the bounds (None, 0).\n",
- " See also https://pyomo.readthedocs.io/en/stable/errors.html#w1002\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:01 [INFO] idaes.init.fs.state_block: Dew and bubble point initialization: optimal - Optimal Solution Found.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:01 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:01 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:01 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:01 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:01 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:01 [INFO] idaes.init.fs.state_block: Starting initialization\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "WARNING (W1002): Setting Var\n",
- "'fs.state_block[1].log_mole_frac_tbub[Vap,Liq,carbon_dioxide]' to a numeric\n",
- "value `4.761445527533956e-06` outside the bounds (None, 0).\n",
- " See also https://pyomo.readthedocs.io/en/stable/errors.html#w1002\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:02 [INFO] idaes.init.fs.state_block: Dew and bubble point initialization: optimal - Optimal Solution Found.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:02 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:02 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:02 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:02 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:02 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:02 [INFO] idaes.init.fs.state_block: Starting initialization\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "WARNING (W1002): Setting Var\n",
- "'fs.state_block[1].log_mole_frac_tbub[Vap,Liq,carbon_dioxide]' to a numeric\n",
- "value `7.219204097329158e-09` outside the bounds (None, 0).\n",
- " See also https://pyomo.readthedocs.io/en/stable/errors.html#w1002\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:02 [INFO] idaes.init.fs.state_block: Dew and bubble point initialization: optimal - Optimal Solution Found.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:02 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:02 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:02 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:02 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:02 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:02 [INFO] idaes.init.fs.state_block: Starting initialization\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "WARNING (W1002): Setting Var\n",
- "'fs.state_block[1].log_mole_frac_tbub[Vap,Liq,carbon_dioxide]' to a numeric\n",
- "value `1.03769179356835e-05` outside the bounds (None, 0).\n",
- " See also https://pyomo.readthedocs.io/en/stable/errors.html#w1002\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:02 [INFO] idaes.init.fs.state_block: Dew and bubble point initialization: optimal - Optimal Solution Found.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:02 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:02 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:02 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:02 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:02 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:02 [INFO] idaes.init.fs.state_block: Starting initialization\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "WARNING (W1002): Setting Var\n",
- "'fs.state_block[1].log_mole_frac_tbub[Vap,Liq,carbon_dioxide]' to a numeric\n",
- "value `1.269889598521249e-06` outside the bounds (None, 0).\n",
- " See also https://pyomo.readthedocs.io/en/stable/errors.html#w1002\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:03 [INFO] idaes.init.fs.state_block: Dew and bubble point initialization: optimal - Optimal Solution Found.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:03 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:03 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:03 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:03 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:03 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:03 [INFO] idaes.init.fs.state_block: Starting initialization\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "WARNING (W1002): Setting Var\n",
- "'fs.state_block[1].log_mole_frac_tbub[Vap,Liq,carbon_dioxide]' to a numeric\n",
- "value `2.021447098567687e-07` outside the bounds (None, 0).\n",
- " See also https://pyomo.readthedocs.io/en/stable/errors.html#w1002\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:03 [INFO] idaes.init.fs.state_block: Dew and bubble point initialization: optimal - Optimal Solution Found.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:03 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:03 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:03 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:03 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:03 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:03 [INFO] idaes.init.fs.state_block: Starting initialization\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "WARNING (W1002): Setting Var\n",
- "'fs.state_block[1].log_mole_frac_tbub[Vap,Liq,carbon_dioxide]' to a numeric\n",
- "value `4.096574706592338e-08` outside the bounds (None, 0).\n",
- " See also https://pyomo.readthedocs.io/en/stable/errors.html#w1002\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:03 [INFO] idaes.init.fs.state_block: Dew and bubble point initialization: optimal - Optimal Solution Found.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:03 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:03 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:03 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:03 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:03 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:03 [INFO] idaes.init.fs.state_block: Starting initialization\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "WARNING (W1002): Setting Var\n",
- "'fs.state_block[1].log_mole_frac_tbub[Vap,Liq,carbon_dioxide]' to a numeric\n",
- "value `6.21086636630859e-06` outside the bounds (None, 0).\n",
- " See also https://pyomo.readthedocs.io/en/stable/errors.html#w1002\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:03 [INFO] idaes.init.fs.state_block: Dew and bubble point initialization: optimal - Optimal Solution Found.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:03 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:03 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:04 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:04 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:04 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:04 [INFO] idaes.init.fs.state_block: Starting initialization\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "WARNING (W1002): Setting Var\n",
- "'fs.state_block[1].log_mole_frac_tbub[Vap,Liq,carbon_dioxide]' to a numeric\n",
- "value `1.1919675619879674e-08` outside the bounds (None, 0).\n",
- " See also https://pyomo.readthedocs.io/en/stable/errors.html#w1002\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:04 [INFO] idaes.init.fs.state_block: Dew and bubble point initialization: optimal - Optimal Solution Found.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:04 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:04 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:04 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:04 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:04 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:04 [INFO] idaes.init.fs.state_block: Starting initialization\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "WARNING (W1002): Setting Var\n",
- "'fs.state_block[1].log_mole_frac_tbub[Vap,Liq,carbon_dioxide]' to a numeric\n",
- "value `1.0197309662820167e-10` outside the bounds (None, 0).\n",
- " See also https://pyomo.readthedocs.io/en/stable/errors.html#w1002\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:04 [INFO] idaes.init.fs.state_block: Dew and bubble point initialization: optimal - Optimal Solution Found.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:04 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:04 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:04 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:04 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:04 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:04 [INFO] idaes.init.fs.state_block: Starting initialization\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "WARNING (W1002): Setting Var\n",
- "'fs.state_block[1].log_mole_frac_tbub[Vap,Liq,carbon_dioxide]' to a numeric\n",
- "value `2.385494860297472e-06` outside the bounds (None, 0).\n",
- " See also https://pyomo.readthedocs.io/en/stable/errors.html#w1002\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:05 [INFO] idaes.init.fs.state_block: Dew and bubble point initialization: optimal - Optimal Solution Found.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:05 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:05 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:05 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:05 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:05 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:05 [INFO] idaes.init.fs.state_block: Starting initialization\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "WARNING (W1002): Setting Var\n",
- "'fs.state_block[1].log_mole_frac_tbub[Vap,Liq,carbon_dioxide]' to a numeric\n",
- "value `4.578395178499122e-07` outside the bounds (None, 0).\n",
- " See also https://pyomo.readthedocs.io/en/stable/errors.html#w1002\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:05 [INFO] idaes.init.fs.state_block: Dew and bubble point initialization: optimal - Optimal Solution Found.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:05 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:05 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:05 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:05 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:05 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:05 [INFO] idaes.init.fs.state_block: Starting initialization\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "WARNING (W1002): Setting Var\n",
- "'fs.state_block[1].log_mole_frac_tbub[Vap,Liq,carbon_dioxide]' to a numeric\n",
- "value `1.0835202436687703e-07` outside the bounds (None, 0).\n",
- " See also https://pyomo.readthedocs.io/en/stable/errors.html#w1002\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:05 [INFO] idaes.init.fs.state_block: Dew and bubble point initialization: optimal - Optimal Solution Found.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:05 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:05 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:05 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:05 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2023-11-02 10:30:05 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Ipopt 3.13.2: \n",
- "\n",
- "******************************************************************************\n",
- "This program contains Ipopt, a library for large-scale nonlinear optimization.\n",
- " Ipopt is released as open source code under the Eclipse Public License (EPL).\n",
- " For more information visit http://projects.coin-or.org/Ipopt\n",
- "\n",
- "This version of Ipopt was compiled from source code available at\n",
- " https://github.com/IDAES/Ipopt as part of the Institute for the Design of\n",
- " Advanced Energy Systems Process Systems Engineering Framework (IDAES PSE\n",
- " Framework) Copyright (c) 2018-2019. See https://github.com/IDAES/idaes-pse.\n",
- "\n",
- "This version of Ipopt was compiled using HSL, a collection of Fortran codes\n",
- " for large-scale scientific computation. All technical papers, sales and\n",
- " publicity material resulting from use of the HSL codes within IPOPT must\n",
- " contain the following acknowledgement:\n",
- " HSL, a collection of Fortran codes for large-scale scientific\n",
- " computation. See http://www.hsl.rl.ac.uk.\n",
- "******************************************************************************\n",
- "\n",
- "This is Ipopt version 3.13.2, running with linear solver ma27.\n",
- "\n",
- "Number of nonzeros in equality constraint Jacobian...: 842\n",
- "Number of nonzeros in inequality constraint Jacobian.: 0\n",
- "Number of nonzeros in Lagrangian Hessian.............: 720\n",
- "\n",
- "Total number of variables............................: 360\n",
- " variables with only lower bounds: 72\n",
- " variables with lower and upper bounds: 234\n",
- " variables with only upper bounds: 18\n",
- "Total number of equality constraints.................: 358\n",
- "Total number of inequality constraints...............: 0\n",
- " inequality constraints with only lower bounds: 0\n",
- " inequality constraints with lower and upper bounds: 0\n",
- " inequality constraints with only upper bounds: 0\n",
- "\n",
- "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
- " 0 0.0000000e+00 5.00e-01 6.99e-14 -1.0 0.00e+00 - 0.00e+00 0.00e+00 0\n",
- " 1 1.1422488e+01 2.60e-01 2.37e+03 -1.0 3.35e+04 - 3.39e-01 6.89e-01h 1\n",
- " 2 2.8748813e+01 1.27e-01 1.10e+03 -1.0 1.36e+04 - 8.22e-02 9.88e-01h 1\n",
- " 3 2.9813930e+01 1.87e-01 5.94e+02 -1.0 5.01e+02 - 8.73e-01 9.90e-01h 1\n",
- " 4 2.9709737e+01 4.27e-02 1.57e+03 -1.0 5.49e+02 - 9.85e-01 9.90e-01h 1\n",
- " 5 2.9285216e+01 8.02e-03 9.53e+04 -1.0 2.77e+03 - 9.87e-01 1.00e+00h 1\n",
- " 6 2.9283589e+01 1.44e-04 9.56e+04 -1.0 3.48e+02 - 9.90e-01 1.00e+00h 1\n",
- " 7 2.9283603e+01 7.59e-08 9.12e+02 -1.0 5.97e-01 - 9.90e-01 1.00e+00h 1\n",
- " 8 2.9282891e+01 3.35e-07 1.47e+04 -2.5 1.24e+02 - 9.98e-01 1.00e+00f 1\n",
- " 9 2.9282892e+01 2.21e-12 4.97e-08 -2.5 2.39e-01 - 1.00e+00 1.00e+00h 1\n",
- "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
- " 10 2.9282891e+01 2.85e-10 3.05e+00 -8.6 3.61e+00 - 1.00e+00 1.00e+00h 1\n",
- " 11 2.9282891e+01 2.72e-12 3.60e-12 -8.6 2.03e-04 - 1.00e+00 1.00e+00h 1\n",
- "\n",
- "Number of Iterations....: 11\n",
- "\n",
- " (scaled) (unscaled)\n",
- "Objective...............: 2.9282891309640156e+01 2.9282891309640156e+01\n",
- "Dual infeasibility......: 3.6021722623181066e-12 3.6021722623181066e-12\n",
- "Constraint violation....: 2.7191470654339899e-12 2.7191470654339899e-12\n",
- "Complementarity.........: 2.5059037693947522e-09 2.5059037693947522e-09\n",
- "Overall NLP error.......: 2.5059037693947522e-09 2.5059037693947522e-09\n",
- "\n",
- "\n",
- "Number of objective function evaluations = 12\n",
- "Number of objective gradient evaluations = 12\n",
- "Number of equality constraint evaluations = 12\n",
- "Number of inequality constraint evaluations = 0\n",
- "Number of equality constraint Jacobian evaluations = 12\n",
- "Number of inequality constraint Jacobian evaluations = 0\n",
- "Number of Lagrangian Hessian evaluations = 11\n",
- "Total CPU secs in IPOPT (w/o function evaluations) = 0.000\n",
- "Total CPU secs in NLP function evaluations = 0.048\n",
- "\n",
- "EXIT: Optimal Solution Found.\n",
- "\b\b\b\b\b\b\b\b\b\b\b\b\b\b"
- ]
- }
- ],
- "source": [
- "pest = parmest.Estimator(PR_model, data, variable_name, SSE, tee=True)\n",
- "\n",
- "obj_value, parameters = pest.theta_est()"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "## 5.0 Display results\n",
- "\n",
- "Let us display the results by running the next cell."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 11,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "The SSE at the optimal solution is 29.282891\n",
- "\n",
- "The values for the parameters are as follows:\n",
- "fs.properties.PR_kappa[bmimPF6,carbon_dioxide] = -0.4071428400296551\n",
- "fs.properties.PR_kappa[carbon_dioxide,bmimPF6] = 0.020593684002515204\n"
- ]
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "idaes-pse-and-examples-dev-py313-macmini",
+ "language": "python",
+ "name": "python3"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 3
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython3",
+ "version": "3.13.13"
}
- ],
- "source": [
- "print(\"The SSE at the optimal solution is %0.6f\" % obj_value)\n",
- "print()\n",
- "print(\"The values for the parameters are as follows:\")\n",
- "for k, v in parameters.items():\n",
- " print(k, \"=\", v)"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "Now we can use this parameters and include them in the configuration dictionary. We can also use `m.fs.properties = GenericParameterBlock(**configuration)` to solve unit models."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": []
- }
- ],
- "metadata": {
- "kernelspec": {
- "display_name": "Python 3 (ipykernel)",
- "language": "python",
- "name": "python3"
},
- "language_info": {
- "codemirror_mode": {
- "name": "ipython",
- "version": 3
- },
- "file_extension": ".py",
- "mimetype": "text/x-python",
- "name": "python",
- "nbconvert_exporter": "python",
- "pygments_lexer": "ipython3",
- "version": "3.11.5"
- }
- },
- "nbformat": 4,
- "nbformat_minor": 3
-}
+ "nbformat": 4,
+ "nbformat_minor": 3
+}
\ No newline at end of file
diff --git a/idaes_examples/notebooks/docs/properties/parameter_estimation_pr_test.ipynb b/idaes_examples/notebooks/docs/properties/parameter_estimation_pr_test.ipynb
index 4d620a5a..e42c5b93 100644
--- a/idaes_examples/notebooks/docs/properties/parameter_estimation_pr_test.ipynb
+++ b/idaes_examples/notebooks/docs/properties/parameter_estimation_pr_test.ipynb
@@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 1,
"metadata": {
"tags": [
"header",
@@ -16,7 +16,7 @@
"# Framework (IDAES IP) was produced under the DOE Institute for the\n",
"# Design of Advanced Energy Systems (IDAES).\n",
"#\n",
- "# Copyright (c) 2018-2023 by the software owners: The Regents of the\n",
+ "# Copyright (c) 2018-2026 by the software owners: The Regents of the\n",
"# University of California, through Lawrence Berkeley National Laboratory,\n",
"# National Technology & Engineering Solutions of Sandia, LLC, Carnegie Mellon\n",
"# University, West Virginia University Research Corporation, et al.\n",
@@ -31,8 +31,8 @@
"source": [
"# Using Parameter Estimation with Modular Property Packages\n",
"Author: Alejandro Garciadego \n",
- "Maintainer: Andrew Lee \n",
- "Updated: 2023-06-01 \n",
+ "Maintainer: Stephen Cini \n",
+ "Updated: 2026-06-11 \n",
"## 1. Introduction\n",
"\n",
"This Jupyter Notebook estimates binary interaction parameters for a CO$_2$-Ionic liquid property package. A property package has been created for CO$_2$-[bmim][PF6]. We will utilize Pyomo's `parmest` tool in conjunction with IDAES models for parameter estimation. We demonstrate these tools by estimating the parameters associated with the Peng-Robinson property model for a benzene-toluene mixture. The Peng-Robinson EOS the binary interaction parameter (kappa_ij). When estimating parameters associated with the property package, IDAES provides the flexibility of doing the parameter estimation by just using the state block or by using a unit model with a specified property package. This module will demonstrate parameter estimation by using the flash unit model with a Modular Property Package.\n",
@@ -57,12 +57,12 @@
},
{
"cell_type": "code",
- "execution_count": 1,
+ "execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"# Import objects from pyomo package\n",
- "from pyomo.environ import ConcreteModel, SolverFactory, units as pyunits\n",
+ "from pyomo.environ import ConcreteModel, SolverFactory, value, Suffix\n",
"\n",
"# Import the main FlowsheetBlock from IDAES. The flowsheet block will contain the unit model\n",
"from idaes.core import FlowsheetBlock\n",
@@ -83,7 +83,7 @@
},
{
"cell_type": "code",
- "execution_count": 2,
+ "execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
@@ -99,7 +99,7 @@
},
{
"cell_type": "code",
- "execution_count": 3,
+ "execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
@@ -121,7 +121,7 @@
},
{
"cell_type": "code",
- "execution_count": 4,
+ "execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
@@ -146,7 +146,7 @@
},
{
"cell_type": "code",
- "execution_count": 5,
+ "execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
@@ -161,9 +161,16 @@
" m.fs.state_block = m.fs.properties.build_state_block([1], defined_state=True)\n",
"\n",
" m.fs.state_block[1].flow_mol.fix(1)\n",
- " x = float(data[\"x_carbon_dioxide\"]) + 0.5\n",
- " m.fs.state_block[1].temperature.fix(float(data[\"temperature\"]))\n",
- " m.fs.state_block[1].pressure.fix(float(data[\"pressure\"]))\n",
+ " if isinstance(data, dict) or isinstance(data, pd.Series):\n",
+ " x = float(data[\"x_carbon_dioxide\"]) + 0.5\n",
+ " m.fs.state_block[1].temperature.fix(float(data[\"temperature\"]))\n",
+ " m.fs.state_block[1].pressure.fix(float(data[\"pressure\"]))\n",
+ " elif isinstance(data, pd.DataFrame):\n",
+ " x = float(data.iloc[0][\"x_carbon_dioxide\"]) + 0.5\n",
+ " m.fs.state_block[1].temperature.fix(float(data.iloc[0][\"temperature\"]))\n",
+ " m.fs.state_block[1].pressure.fix(float(data.iloc[0][\"pressure\"]))\n",
+ " else:\n",
+ " raise ValueError(\"Unrecognized data type.\")\n",
" m.fs.state_block[1].mole_frac_comp[\"bmimPF6\"].fix(1 - x)\n",
" m.fs.state_block[1].mole_frac_comp[\"carbon_dioxide\"].fix(x)\n",
"\n",
@@ -177,15 +184,30 @@
" m.fs.state_block.initialize(outlvl=idaeslog.INFO)\n",
"\n",
" # Fix the state variables on the state block\n",
+ " if isinstance(data, dict) or isinstance(data, pd.Series):\n",
+ " m.fs.state_block[1].temperature.fix(float(data[\"temperature\"]))\n",
+ " m.fs.state_block[1].mole_frac_phase_comp[\"Liq\", \"bmimPF6\"].fix(\n",
+ " float(data[\"x_bmimPF6\"])\n",
+ " )\n",
+ " m.fs.state_block[1].mole_frac_phase_comp[\"Liq\", \"carbon_dioxide\"].fix(\n",
+ " float(data[\"x_carbon_dioxide\"])\n",
+ " )\n",
+ " m.fs.state_block[1].mole_frac_comp[\"bmimPF6\"].fix(float(data[\"x_bmimPF6\"]))\n",
+ " elif isinstance(data, pd.DataFrame):\n",
+ " m.fs.state_block[1].temperature.fix(float(data.iloc[0][\"temperature\"]))\n",
+ " m.fs.state_block[1].mole_frac_phase_comp[\"Liq\", \"bmimPF6\"].fix(\n",
+ " float(data.iloc[0][\"x_bmimPF6\"])\n",
+ " )\n",
+ " m.fs.state_block[1].mole_frac_phase_comp[\"Liq\", \"carbon_dioxide\"].fix(\n",
+ " float(data.iloc[0][\"x_carbon_dioxide\"])\n",
+ " )\n",
+ " m.fs.state_block[1].mole_frac_comp[\"bmimPF6\"].fix(\n",
+ " float(data.iloc[0][\"x_bmimPF6\"])\n",
+ " )\n",
+ " else:\n",
+ " raise ValueError(\"Unrecognized data type.\")\n",
+ "\n",
" m.fs.state_block[1].pressure.unfix()\n",
- " m.fs.state_block[1].temperature.fix(float(data[\"temperature\"]))\n",
- " m.fs.state_block[1].mole_frac_phase_comp[\"Liq\", \"bmimPF6\"].fix(\n",
- " float(data[\"x_bmimPF6\"])\n",
- " )\n",
- " m.fs.state_block[1].mole_frac_phase_comp[\"Liq\", \"carbon_dioxide\"].fix(\n",
- " float(data[\"x_carbon_dioxide\"])\n",
- " )\n",
- " m.fs.state_block[1].mole_frac_comp[\"bmimPF6\"].fix(float(data[\"x_bmimPF6\"]))\n",
" m.fs.state_block[1].mole_frac_comp[\"carbon_dioxide\"].unfix()\n",
" # Set bounds on variables to be estimated\n",
" m.fs.properties.PR_kappa[\"bmimPF6\", \"carbon_dioxide\"].setlb(-5)\n",
@@ -207,11 +229,147 @@
},
{
"cell_type": "code",
- "execution_count": 6,
- "metadata": {
- "scrolled": false
- },
- "outputs": [],
+ "execution_count": 7,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "2026-06-11 12:42:22 [INFO] idaes.init.fs.state_block: Starting initialization\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: Bubble, dew, and critical point initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n",
+ "Ipopt 3.13.2: \n",
+ "\n",
+ "******************************************************************************\n",
+ "This program contains Ipopt, a library for large-scale nonlinear optimization.\n",
+ " Ipopt is released as open source code under the Eclipse Public License (EPL).\n",
+ " For more information visit http://projects.coin-or.org/Ipopt\n",
+ "\n",
+ "This version of Ipopt was compiled from source code available at\n",
+ " https://github.com/IDAES/Ipopt as part of the Institute for the Design of\n",
+ " Advanced Energy Systems Process Systems Engineering Framework (IDAES PSE\n",
+ " Framework) Copyright (c) 2018-2019. See https://github.com/IDAES/idaes-pse.\n",
+ "\n",
+ "This version of Ipopt was compiled using HSL, a collection of Fortran codes\n",
+ " for large-scale scientific computation. All technical papers, sales and\n",
+ " publicity material resulting from use of the HSL codes within IPOPT must\n",
+ " contain the following acknowledgement:\n",
+ " HSL, a collection of Fortran codes for large-scale scientific\n",
+ " computation. See http://www.hsl.rl.ac.uk.\n",
+ "******************************************************************************\n",
+ "\n",
+ "This is Ipopt version 3.13.2, running with linear solver ma27.\n",
+ "\n",
+ "Number of nonzeros in equality constraint Jacobian...: 39\n",
+ "Number of nonzeros in inequality constraint Jacobian.: 0\n",
+ "Number of nonzeros in Lagrangian Hessian.............: 25\n",
+ "\n",
+ "Total number of variables............................: 18\n",
+ " variables with only lower bounds: 4\n",
+ " variables with lower and upper bounds: 13\n",
+ " variables with only upper bounds: 1\n",
+ "Total number of equality constraints.................: 18\n",
+ "Total number of inequality constraints...............: 0\n",
+ " inequality constraints with only lower bounds: 0\n",
+ " inequality constraints with lower and upper bounds: 0\n",
+ " inequality constraints with only upper bounds: 0\n",
+ "\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 0 0.0000000e+00 5.00e-01 1.00e+00 -1.0 0.00e+00 - 0.00e+00 0.00e+00 0\n",
+ " 1 0.0000000e+00 1.76e-01 6.65e+03 -1.0 7.51e+04 - 2.67e-01 9.90e-01H 1\n",
+ " 2 0.0000000e+00 4.81e-02 1.40e+02 -1.0 6.76e+02 - 9.46e-01 9.90e-01h 1\n",
+ " 3 0.0000000e+00 8.65e-03 1.76e+01 -1.0 9.79e+00 - 9.90e-01 9.90e-01h 1\n",
+ " 4 0.0000000e+00 1.81e-03 4.99e+04 -1.0 1.20e+00 - 9.90e-01 1.00e+00h 1\n",
+ " 5 0.0000000e+00 3.48e-03 9.81e+04 -1.0 5.29e+01 - 9.90e-01 1.00e+00h 1\n",
+ " 6 0.0000000e+00 1.57e-03 8.00e+02 -1.0 1.54e+02 - 9.92e-01 1.00e+00h 1\n",
+ " 7 0.0000000e+00 7.66e-04 2.93e-04 -2.5 2.52e+02 - 1.00e+00 1.00e+00h 1\n",
+ " 8 0.0000000e+00 3.81e-04 1.61e-04 -5.7 4.82e+02 - 1.00e+00 1.00e+00h 1\n",
+ " 9 0.0000000e+00 1.90e-04 6.49e-05 -5.7 9.53e+02 - 1.00e+00 1.00e+00h 1\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 10 0.0000000e+00 9.50e-05 8.68e-05 -5.7 1.90e+03 - 1.00e+00 1.00e+00h 1\n",
+ " 11 0.0000000e+00 4.75e-05 3.47e-04 -5.7 3.81e+03 - 1.00e+00 1.00e+00h 1\n",
+ " 12 0.0000000e+00 2.72e-05 1.39e-03 -5.7 7.64e+03 - 1.00e+00 1.00e+00h 1\n",
+ " 13 0.0000000e+00 1.07e-04 5.57e-03 -5.7 1.54e+04 - 1.00e+00 1.00e+00h 1\n",
+ " 14 0.0000000e+00 4.09e-04 2.23e-02 -5.7 3.11e+04 - 1.00e+00 1.00e+00h 1\n",
+ " 15 0.0000000e+00 1.51e-03 8.91e-02 -5.7 6.38e+04 - 1.00e+00 1.00e+00h 1\n",
+ " 16 0.0000000e+00 5.12e-03 3.53e-01 -5.7 1.33e+05 - 1.00e+00 1.00e+00h 1\n",
+ " 17 0.0000000e+00 1.49e-02 1.34e+00 -5.7 2.89e+05 - 1.00e+00 1.00e+00h 1\n",
+ " 18 0.0000000e+00 3.14e-02 4.58e+00 -5.7 6.55e+05 - 1.00e+00 1.00e+00h 1\n",
+ " 19 0.0000000e+00 2.86e-02 4.32e+00 -5.7 1.51e+06 - 1.00e+00 1.25e-01h 4\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 20 0.0000000e+00 2.82e-02 4.26e+00 -5.7 1.73e+06 - 1.00e+00 1.56e-02h 7\n",
+ " 21 0.0000000e+00 2.79e-02 4.23e+00 -5.7 1.76e+06 - 1.00e+00 7.81e-03h 8\n",
+ " 22 0.0000000e+00 2.79e-02 4.22e+00 -5.7 1.77e+06 - 1.00e+00 4.88e-04h 12\n",
+ " 23 0.0000000e+00 2.79e-02 4.22e+00 -5.7 1.77e+06 - 1.00e+00 1.22e-04h 14\n",
+ " 24 0.0000000e+00 7.05e-03 1.51e+01 -5.7 1.77e+06 - 1.00e+00 1.00e+00h 1\n",
+ " 25 0.0000000e+00 9.63e-04 4.01e+00 -5.7 3.18e+06 - 1.00e+00 1.50e-01h 2\n",
+ " 26 0.0000000e+00 5.53e-04 8.54e+01 -5.7 3.24e+06 - 1.00e+00 6.53e-02h 2\n",
+ " 27 0.0000000e+00 5.53e-04 8.57e+01 -5.7 3.20e+06 - 1.00e+00 9.58e-04h 7\n",
+ " 28 0.0000000e+00 5.53e-04 9.27e+01 -5.7 3.19e+06 - 1.00e+00 9.42e-04h 7\n",
+ " 29 0.0000000e+00 5.53e-04 2.08e+02 -5.7 3.19e+06 - 1.00e+00 9.27e-04h 7\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 30 0.0000000e+00 5.52e-04 7.91e+03 -5.7 1.83e+06 - 1.00e+00 3.17e-03h 6\n",
+ " 31 0.0000000e+00 3.77e-05 2.11e+06 -5.7 2.63e+04 - 1.00e+00 1.00e+00h 1\n",
+ " 32 0.0000000e+00 3.77e-05 2.10e+06 -5.7 1.03e+06 - 1.00e+00 5.67e-04h 9\n",
+ " 33 0.0000000e+00 3.77e-05 2.10e+06 -5.7 1.03e+06 - 1.00e+00 5.65e-04h 9\n",
+ " 34 0.0000000e+00 3.77e-05 2.10e+06 -5.7 1.02e+06 - 1.00e+00 5.63e-04h 9\n",
+ " 35 0.0000000e+00 3.77e-05 2.12e+06 -5.7 9.14e+05 - 1.00e+00 6.29e-04h 9\n",
+ " 36 0.0000000e+00 3.77e-05 2.23e+06 -5.7 9.36e+05 - 1.00e+00 6.11e-04h 9\n",
+ " 37 0.0000000e+00 3.76e-05 4.98e+06 -5.7 4.23e+05 - 1.00e+00 2.69e-03h 8\n",
+ " 38 0.0000000e+00 3.76e-05 6.97e+06 -5.7 8.98e+05 - 1.00e+00 6.29e-04h 9\n",
+ " 39 0.0000000e+00 3.76e-05 5.17e+07 -5.7 6.09e+05 - 1.00e+00 1.85e-03h 8\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 40 0.0000000e+00 3.76e-05 6.29e+07 -5.7 1.03e+06 - 1.00e+00 5.42e-04h 9\n",
+ " 41 0.0000000e+00 3.76e-05 7.41e+07 -5.7 1.02e+06 - 1.00e+00 5.43e-04h 9\n",
+ " 42 0.0000000e+00 8.59e-04 7.30e+11 -5.7 1.02e+06 - 1.00e+00 1.39e-01w 1\n",
+ " 43 0.0000000e+00 8.58e-04 7.30e+11 -5.7 7.14e+03 - 1.00e+00 2.07e-05w 1\n",
+ "In iteration 43, 2 Slacks too small, adjusting variable bounds\n",
+ " 44 0.0000000e+00 7.90e-04 5.95e+14 -5.7 4.69e+03 - 1.00e+00 8.02e-02w 1\n",
+ " 45 0.0000000e+00 3.76e-05 8.53e+07 -5.7 4.31e+03 - 1.00e+00 5.41e-04h 8\n",
+ " 46 0.0000000e+00 3.75e-05 9.64e+07 -5.7 1.02e+06 - 1.00e+00 5.39e-04h 9\n",
+ " 47 0.0000000e+00 3.75e-05 1.08e+08 -5.7 1.02e+06 - 1.00e+00 5.37e-04h 9\n",
+ " 48 0.0000000e+00 3.75e-05 1.19e+08 -5.7 1.02e+06 - 1.00e+00 5.35e-04h 9\n",
+ " 49 0.0000000e+00 3.75e-05 1.30e+08 -5.7 1.02e+06 - 1.00e+00 5.33e-04h 9\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 50 0.0000000e+00 3.75e-05 1.41e+08 -5.7 1.02e+06 - 1.00e+00 5.31e-04h 9\n",
+ " 51 0.0000000e+00 3.75e-05 1.52e+08 -5.7 1.02e+06 - 1.00e+00 5.29e-04h 9\n",
+ " 52 0.0000000e+00 3.75e-05 1.64e+08 -5.7 1.02e+06 - 1.00e+00 5.27e-04h 9\n",
+ " 53 0.0000000e+00 3.75e-05 1.75e+08 -5.7 1.02e+06 - 1.00e+00 5.25e-04h 9\n",
+ " 54 0.0000000e+00 3.75e-05 1.86e+08 -5.7 1.02e+06 - 1.00e+00 5.23e-04h 9\n",
+ " 55 0.0000000e+00 7.97e-04 7.34e+11 -5.7 1.02e+06 - 1.00e+00 1.33e-01w 1\n",
+ " 56 0.0000000e+00 7.97e-04 6.89e+11 -5.7 6.89e-05 16.0 2.81e-04 5.39e-01w 1\n",
+ " 57 0.0000000e+00 4.04e-07 2.66e+15 -5.7 4.36e+03 - 2.29e-07 1.00e+00h 1\n",
+ "Cannot recompute multipliers for feasibility problem. Error in eq_mult_calculator\n",
+ "\n",
+ "Number of Iterations....: 57\n",
+ "\n",
+ " (scaled) (unscaled)\n",
+ "Objective...............: 0.0000000000000000e+00 0.0000000000000000e+00\n",
+ "Dual infeasibility......: 2.6563801083485440e+15 2.6563801083485440e+15\n",
+ "Constraint violation....: 4.0441652946975677e-07 4.0441652946975677e-07\n",
+ "Complementarity.........: 0.0000000000000000e+00 0.0000000000000000e+00\n",
+ "Overall NLP error.......: 4.0441652946975677e-07 2.6563801083485440e+15\n",
+ "\n",
+ "\n",
+ "Number of objective function evaluations = 337\n",
+ "Number of objective gradient evaluations = 59\n",
+ "Number of equality constraint evaluations = 337\n",
+ "Number of inequality constraint evaluations = 0\n",
+ "Number of equality constraint Jacobian evaluations = 59\n",
+ "Number of inequality constraint Jacobian evaluations = 0\n",
+ "Number of Lagrangian Hessian evaluations = 58\n",
+ "Total CPU secs in IPOPT (w/o function evaluations) = 0.005\n",
+ "Total CPU secs in NLP function evaluations = 0.008\n",
+ "\n",
+ "EXIT: Solved To Acceptable Level.\n"
+ ]
+ }
+ ],
"source": [
"from idaes.core.util.model_statistics import degrees_of_freedom\n",
"import pytest\n",
@@ -226,7 +384,11 @@
"m = PR_model(test_data)\n",
"\n",
"# Check that degrees of freedom is 0\n",
- "assert degrees_of_freedom(m) == 0"
+ "assert degrees_of_freedom(m) == 0\n",
+ "\n",
+ "# Solve the model with the default solver and display results\n",
+ "solver = SolverFactory(\"ipopt\")\n",
+ "results = solver.solve(m, tee=True)"
]
},
{
@@ -235,41 +397,87 @@
"source": [
"## 4.0 Parameter estimation using parmest \n",
"\n",
- "### 4.1 List of variable names to be estimated\n",
+ "### 4.1 Define the Experiment class\n",
"\n",
- "Create a list of vars to estimate"
+ "Define the Experiment class to label model for parameter estimation."
]
},
{
"cell_type": "code",
- "execution_count": 7,
+ "execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
- "variable_name = [\n",
- " \"fs.properties.PR_kappa['bmimPF6', 'carbon_dioxide']\",\n",
- " \"fs.properties.PR_kappa['carbon_dioxide', 'bmimPF6']\",\n",
- "]"
+ "from pyomo.contrib.parmest.experiment import Experiment\n",
+ "\n",
+ "\n",
+ "# Create experiment class for parameter estimation\n",
+ "class PRExperiment(Experiment):\n",
+ "\n",
+ " def __init__(self, data, meas_error=None):\n",
+ " \"\"\"Initialize the PR Experiment class\n",
+ "\n",
+ " Args:\n",
+ " data: DataFrame containing the experimental data\n",
+ " meas_error: Measurement error for the data (optional)\n",
+ " \"\"\"\n",
+ " self.model = None\n",
+ " self.data = data\n",
+ " self.meas_error = meas_error\n",
+ "\n",
+ " def create_model(self):\n",
+ " \"\"\"Create the Pyomo model for the PR parameter estimation problem\"\"\"\n",
+ " self.model = PR_model(self.data)\n",
+ "\n",
+ " def label_model(self):\n",
+ " m = self.model\n",
+ "\n",
+ " # Add Suffixes to label the outputs, parameters, and measurement error in the model\n",
+ " m.experiment_outputs = Suffix(direction=Suffix.LOCAL)\n",
+ " m.experiment_outputs.update(\n",
+ " [(m.fs.state_block[1].pressure, self.data[\"pressure\"])]\n",
+ " )\n",
+ "\n",
+ " m.measurement_error = Suffix(direction=Suffix.LOCAL)\n",
+ " m.measurement_error.update([(m.fs.state_block[1].pressure, self.meas_error)])\n",
+ "\n",
+ " # Add unknown parameters to the model for easier access\n",
+ " m.unknown_parameters = Suffix(direction=Suffix.LOCAL)\n",
+ " m.unknown_parameters.update(\n",
+ " (k, value(k))\n",
+ " for k in [\n",
+ " m.fs.properties.PR_kappa[\"bmimPF6\", \"carbon_dioxide\"],\n",
+ " m.fs.properties.PR_kappa[\"carbon_dioxide\", \"bmimPF6\"],\n",
+ " ]\n",
+ " )\n",
+ "\n",
+ " def get_labeled_model(self):\n",
+ " \"\"\"Return the labeled model\"\"\"\n",
+ " if self.model is None:\n",
+ " self.create_model()\n",
+ " self.label_model()\n",
+ " return self.model"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
- "### 4.2 Create method to return an expression that computes the sum of squared error\n",
+ "### 4.2 Pre-process the data into individual experiments\n",
"\n",
- "We need to provide a method to return an expression to compute the sum of squared errors that will be used as the objective in solving the parameter estimation problem. For this problem, the error will be computed for the pressure."
+ "We now separate our data and assign a model for each individual experiments, creating an experiment list. "
]
},
{
"cell_type": "code",
- "execution_count": 8,
+ "execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
- "def SSE(m, data):\n",
- " expr = (float(data[\"pressure\"]) - m.fs.state_block[1].pressure) ** 2\n",
- " return expr * 1e-7"
+ "# Update to new interface\n",
+ "exp_list = []\n",
+ "for i in range(data.shape[0]):\n",
+ " exp_list.append(PRExperiment(data.iloc[i]))"
]
},
{
@@ -278,19 +486,218 @@
"source": [
"### 4.3 Run the parameter estimation\n",
"\n",
- "We are now ready to set up the parameter estimation problem. We will create a parameter estimation object called pest. As shown below, we pass the method that returns an initialized model, data, variable_name, and the SSE expression to the Estimator method. tee=True will print the solver output after solving the parameter estimation problem."
+ "We are now ready to set up the parameter estimation problem. We will create a parameter estimation object called pest. As shown below, we pass the experiment list, and an objective function to the Estimator method. tee=True will print the solver output after solving the parameter estimation problem."
]
},
{
"cell_type": "code",
- "execution_count": 9,
- "metadata": {
- "scrolled": false
- },
- "outputs": [],
+ "execution_count": 10,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: Starting initialization\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: Bubble, dew, and critical point initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: Starting initialization\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: Bubble, dew, and critical point initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: Starting initialization\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: Bubble, dew, and critical point initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Starting initialization\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Bubble, dew, and critical point initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Starting initialization\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Bubble, dew, and critical point initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Starting initialization\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Bubble, dew, and critical point initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Starting initialization\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Bubble, dew, and critical point initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Starting initialization\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Bubble, dew, and critical point initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Starting initialization\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Bubble, dew, and critical point initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Starting initialization\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Bubble, dew, and critical point initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Starting initialization\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Bubble, dew, and critical point initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Starting initialization\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Bubble, dew, and critical point initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Starting initialization\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Bubble, dew, and critical point initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Starting initialization\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Bubble, dew, and critical point initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Starting initialization\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Bubble, dew, and critical point initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Starting initialization\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Bubble, dew, and critical point initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Starting initialization\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Bubble, dew, and critical point initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Starting initialization\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Bubble, dew, and critical point initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n",
+ "Ipopt 3.13.2: \n",
+ "\n",
+ "******************************************************************************\n",
+ "This program contains Ipopt, a library for large-scale nonlinear optimization.\n",
+ " Ipopt is released as open source code under the Eclipse Public License (EPL).\n",
+ " For more information visit http://projects.coin-or.org/Ipopt\n",
+ "\n",
+ "This version of Ipopt was compiled from source code available at\n",
+ " https://github.com/IDAES/Ipopt as part of the Institute for the Design of\n",
+ " Advanced Energy Systems Process Systems Engineering Framework (IDAES PSE\n",
+ " Framework) Copyright (c) 2018-2019. See https://github.com/IDAES/idaes-pse.\n",
+ "\n",
+ "This version of Ipopt was compiled using HSL, a collection of Fortran codes\n",
+ " for large-scale scientific computation. All technical papers, sales and\n",
+ " publicity material resulting from use of the HSL codes within IPOPT must\n",
+ " contain the following acknowledgement:\n",
+ " HSL, a collection of Fortran codes for large-scale scientific\n",
+ " computation. See http://www.hsl.rl.ac.uk.\n",
+ "******************************************************************************\n",
+ "\n",
+ "This is Ipopt version 3.13.2, running with linear solver ma27.\n",
+ "\n",
+ "Number of nonzeros in equality constraint Jacobian...: 846\n",
+ "Number of nonzeros in inequality constraint Jacobian.: 0\n",
+ "Number of nonzeros in Lagrangian Hessian.............: 720\n",
+ "\n",
+ "Total number of variables............................: 362\n",
+ " variables with only lower bounds: 72\n",
+ " variables with lower and upper bounds: 270\n",
+ " variables with only upper bounds: 18\n",
+ "Total number of equality constraints.................: 360\n",
+ "Total number of inequality constraints...............: 0\n",
+ " inequality constraints with only lower bounds: 0\n",
+ " inequality constraints with lower and upper bounds: 0\n",
+ " inequality constraints with only upper bounds: 0\n",
+ "\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 0 0.0000000e+00 5.00e-01 2.44e-15 -1.0 0.00e+00 - 0.00e+00 0.00e+00 0\n",
+ " 1 6.9602464e+06 4.12e-01 1.82e+07 -1.0 2.99e+04 - 3.39e-01 1.72e-01h 3\n",
+ " 2 1.6667677e+08 2.58e-01 2.70e+08 -1.0 2.58e+04 - 6.19e-01 7.79e-01h 1\n",
+ " 3 2.8786912e+08 1.32e-01 4.98e+07 -1.0 8.26e+03 - 8.13e-01 9.90e-01h 1\n",
+ " 4 2.9277551e+08 1.44e-01 5.76e+05 -1.0 3.05e+02 - 9.77e-01 9.90e-01h 1\n",
+ " 5 2.9282842e+08 3.31e-02 5.28e+03 -1.0 3.24e+00 - 9.90e-01 9.91e-01h 1\n",
+ " 6 2.9282891e+08 4.65e-03 8.12e+04 -1.0 1.08e+00 - 9.90e-01 1.00e+00h 1\n",
+ " 7 2.9282891e+08 3.59e-05 2.33e+04 -2.5 9.23e-02 - 9.97e-01 1.00e+00h 1\n",
+ " 8 2.9282891e+08 3.17e-09 2.26e-05 -3.8 8.65e-04 - 1.00e+00 1.00e+00h 1\n",
+ " 9 2.9282891e+08 1.29e-12 2.38e-05 -8.6 6.67e-08 - 1.00e+00 1.00e+00f 1\n",
+ "\n",
+ "Number of Iterations....: 9\n",
+ "\n",
+ " (scaled) (unscaled)\n",
+ "Objective...............: 2.9282891309627521e+08 2.9282891309627521e+08\n",
+ "Dual infeasibility......: 2.3841853781623475e-05 2.3841853781623475e-05\n",
+ "Constraint violation....: 1.2910152591875072e-12 1.2910152591875072e-12\n",
+ "Complementarity.........: 2.5062901281861244e-09 2.5062901281861244e-09\n",
+ "Overall NLP error.......: 2.5062901281861244e-09 2.3841853781623475e-05\n",
+ "\n",
+ "\n",
+ "Number of objective function evaluations = 12\n",
+ "Number of objective gradient evaluations = 10\n",
+ "Number of equality constraint evaluations = 12\n",
+ "Number of inequality constraint evaluations = 0\n",
+ "Number of equality constraint Jacobian evaluations = 10\n",
+ "Number of inequality constraint Jacobian evaluations = 0\n",
+ "Number of Lagrangian Hessian evaluations = 9\n",
+ "Total CPU secs in IPOPT (w/o function evaluations) = 0.006\n",
+ "Total CPU secs in NLP function evaluations = 0.020\n",
+ "\n",
+ "EXIT: Optimal Solution Found.\n"
+ ]
+ }
+ ],
"source": [
- "pest = parmest.Estimator(PR_model, data, variable_name, SSE, tee=True)\n",
- "\n",
+ "pest = parmest.Estimator(exp_list, obj_function=\"SSE\", tee=True)\n",
"obj_value, parameters = pest.theta_est()"
]
},
@@ -305,15 +712,27 @@
},
{
"cell_type": "code",
- "execution_count": 10,
+ "execution_count": 11,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "The SSE at the optimal solution is 29.282891\n",
+ "\n",
+ "The values for the parameters are as follows:\n",
+ "fs.properties.PR_kappa[bmimPF6,carbon_dioxide] = -0.40714284008565715\n",
+ "fs.properties.PR_kappa[carbon_dioxide,bmimPF6] = 0.02059368400143062\n"
+ ]
+ }
+ ],
"source": [
- "print(\"The SSE at the optimal solution is %0.6f\" % obj_value)\n",
+ "print(f\"The SSE at the optimal solution is {obj_value*1e-7:0.6f}\")\n",
"print()\n",
"print(\"The values for the parameters are as follows:\")\n",
"for k, v in parameters.items():\n",
- " print(k, \"=\", v)"
+ " print(f\"{k} = {v}\")"
]
},
{
@@ -333,7 +752,7 @@
],
"metadata": {
"kernelspec": {
- "display_name": "Python 3 (ipykernel)",
+ "display_name": "idaes-pse-and-examples-dev-py313-macmini",
"language": "python",
"name": "python3"
},
@@ -347,9 +766,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.9.12"
+ "version": "3.13.13"
}
},
"nbformat": 4,
"nbformat_minor": 3
-}
+}
\ No newline at end of file
diff --git a/idaes_examples/notebooks/docs/properties/parameter_estimation_pr_usr.ipynb b/idaes_examples/notebooks/docs/properties/parameter_estimation_pr_usr.ipynb
index 4d620a5a..e42c5b93 100644
--- a/idaes_examples/notebooks/docs/properties/parameter_estimation_pr_usr.ipynb
+++ b/idaes_examples/notebooks/docs/properties/parameter_estimation_pr_usr.ipynb
@@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 1,
"metadata": {
"tags": [
"header",
@@ -16,7 +16,7 @@
"# Framework (IDAES IP) was produced under the DOE Institute for the\n",
"# Design of Advanced Energy Systems (IDAES).\n",
"#\n",
- "# Copyright (c) 2018-2023 by the software owners: The Regents of the\n",
+ "# Copyright (c) 2018-2026 by the software owners: The Regents of the\n",
"# University of California, through Lawrence Berkeley National Laboratory,\n",
"# National Technology & Engineering Solutions of Sandia, LLC, Carnegie Mellon\n",
"# University, West Virginia University Research Corporation, et al.\n",
@@ -31,8 +31,8 @@
"source": [
"# Using Parameter Estimation with Modular Property Packages\n",
"Author: Alejandro Garciadego \n",
- "Maintainer: Andrew Lee \n",
- "Updated: 2023-06-01 \n",
+ "Maintainer: Stephen Cini \n",
+ "Updated: 2026-06-11 \n",
"## 1. Introduction\n",
"\n",
"This Jupyter Notebook estimates binary interaction parameters for a CO$_2$-Ionic liquid property package. A property package has been created for CO$_2$-[bmim][PF6]. We will utilize Pyomo's `parmest` tool in conjunction with IDAES models for parameter estimation. We demonstrate these tools by estimating the parameters associated with the Peng-Robinson property model for a benzene-toluene mixture. The Peng-Robinson EOS the binary interaction parameter (kappa_ij). When estimating parameters associated with the property package, IDAES provides the flexibility of doing the parameter estimation by just using the state block or by using a unit model with a specified property package. This module will demonstrate parameter estimation by using the flash unit model with a Modular Property Package.\n",
@@ -57,12 +57,12 @@
},
{
"cell_type": "code",
- "execution_count": 1,
+ "execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"# Import objects from pyomo package\n",
- "from pyomo.environ import ConcreteModel, SolverFactory, units as pyunits\n",
+ "from pyomo.environ import ConcreteModel, SolverFactory, value, Suffix\n",
"\n",
"# Import the main FlowsheetBlock from IDAES. The flowsheet block will contain the unit model\n",
"from idaes.core import FlowsheetBlock\n",
@@ -83,7 +83,7 @@
},
{
"cell_type": "code",
- "execution_count": 2,
+ "execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
@@ -99,7 +99,7 @@
},
{
"cell_type": "code",
- "execution_count": 3,
+ "execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
@@ -121,7 +121,7 @@
},
{
"cell_type": "code",
- "execution_count": 4,
+ "execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
@@ -146,7 +146,7 @@
},
{
"cell_type": "code",
- "execution_count": 5,
+ "execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
@@ -161,9 +161,16 @@
" m.fs.state_block = m.fs.properties.build_state_block([1], defined_state=True)\n",
"\n",
" m.fs.state_block[1].flow_mol.fix(1)\n",
- " x = float(data[\"x_carbon_dioxide\"]) + 0.5\n",
- " m.fs.state_block[1].temperature.fix(float(data[\"temperature\"]))\n",
- " m.fs.state_block[1].pressure.fix(float(data[\"pressure\"]))\n",
+ " if isinstance(data, dict) or isinstance(data, pd.Series):\n",
+ " x = float(data[\"x_carbon_dioxide\"]) + 0.5\n",
+ " m.fs.state_block[1].temperature.fix(float(data[\"temperature\"]))\n",
+ " m.fs.state_block[1].pressure.fix(float(data[\"pressure\"]))\n",
+ " elif isinstance(data, pd.DataFrame):\n",
+ " x = float(data.iloc[0][\"x_carbon_dioxide\"]) + 0.5\n",
+ " m.fs.state_block[1].temperature.fix(float(data.iloc[0][\"temperature\"]))\n",
+ " m.fs.state_block[1].pressure.fix(float(data.iloc[0][\"pressure\"]))\n",
+ " else:\n",
+ " raise ValueError(\"Unrecognized data type.\")\n",
" m.fs.state_block[1].mole_frac_comp[\"bmimPF6\"].fix(1 - x)\n",
" m.fs.state_block[1].mole_frac_comp[\"carbon_dioxide\"].fix(x)\n",
"\n",
@@ -177,15 +184,30 @@
" m.fs.state_block.initialize(outlvl=idaeslog.INFO)\n",
"\n",
" # Fix the state variables on the state block\n",
+ " if isinstance(data, dict) or isinstance(data, pd.Series):\n",
+ " m.fs.state_block[1].temperature.fix(float(data[\"temperature\"]))\n",
+ " m.fs.state_block[1].mole_frac_phase_comp[\"Liq\", \"bmimPF6\"].fix(\n",
+ " float(data[\"x_bmimPF6\"])\n",
+ " )\n",
+ " m.fs.state_block[1].mole_frac_phase_comp[\"Liq\", \"carbon_dioxide\"].fix(\n",
+ " float(data[\"x_carbon_dioxide\"])\n",
+ " )\n",
+ " m.fs.state_block[1].mole_frac_comp[\"bmimPF6\"].fix(float(data[\"x_bmimPF6\"]))\n",
+ " elif isinstance(data, pd.DataFrame):\n",
+ " m.fs.state_block[1].temperature.fix(float(data.iloc[0][\"temperature\"]))\n",
+ " m.fs.state_block[1].mole_frac_phase_comp[\"Liq\", \"bmimPF6\"].fix(\n",
+ " float(data.iloc[0][\"x_bmimPF6\"])\n",
+ " )\n",
+ " m.fs.state_block[1].mole_frac_phase_comp[\"Liq\", \"carbon_dioxide\"].fix(\n",
+ " float(data.iloc[0][\"x_carbon_dioxide\"])\n",
+ " )\n",
+ " m.fs.state_block[1].mole_frac_comp[\"bmimPF6\"].fix(\n",
+ " float(data.iloc[0][\"x_bmimPF6\"])\n",
+ " )\n",
+ " else:\n",
+ " raise ValueError(\"Unrecognized data type.\")\n",
+ "\n",
" m.fs.state_block[1].pressure.unfix()\n",
- " m.fs.state_block[1].temperature.fix(float(data[\"temperature\"]))\n",
- " m.fs.state_block[1].mole_frac_phase_comp[\"Liq\", \"bmimPF6\"].fix(\n",
- " float(data[\"x_bmimPF6\"])\n",
- " )\n",
- " m.fs.state_block[1].mole_frac_phase_comp[\"Liq\", \"carbon_dioxide\"].fix(\n",
- " float(data[\"x_carbon_dioxide\"])\n",
- " )\n",
- " m.fs.state_block[1].mole_frac_comp[\"bmimPF6\"].fix(float(data[\"x_bmimPF6\"]))\n",
" m.fs.state_block[1].mole_frac_comp[\"carbon_dioxide\"].unfix()\n",
" # Set bounds on variables to be estimated\n",
" m.fs.properties.PR_kappa[\"bmimPF6\", \"carbon_dioxide\"].setlb(-5)\n",
@@ -207,11 +229,147 @@
},
{
"cell_type": "code",
- "execution_count": 6,
- "metadata": {
- "scrolled": false
- },
- "outputs": [],
+ "execution_count": 7,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "2026-06-11 12:42:22 [INFO] idaes.init.fs.state_block: Starting initialization\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: Bubble, dew, and critical point initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n",
+ "Ipopt 3.13.2: \n",
+ "\n",
+ "******************************************************************************\n",
+ "This program contains Ipopt, a library for large-scale nonlinear optimization.\n",
+ " Ipopt is released as open source code under the Eclipse Public License (EPL).\n",
+ " For more information visit http://projects.coin-or.org/Ipopt\n",
+ "\n",
+ "This version of Ipopt was compiled from source code available at\n",
+ " https://github.com/IDAES/Ipopt as part of the Institute for the Design of\n",
+ " Advanced Energy Systems Process Systems Engineering Framework (IDAES PSE\n",
+ " Framework) Copyright (c) 2018-2019. See https://github.com/IDAES/idaes-pse.\n",
+ "\n",
+ "This version of Ipopt was compiled using HSL, a collection of Fortran codes\n",
+ " for large-scale scientific computation. All technical papers, sales and\n",
+ " publicity material resulting from use of the HSL codes within IPOPT must\n",
+ " contain the following acknowledgement:\n",
+ " HSL, a collection of Fortran codes for large-scale scientific\n",
+ " computation. See http://www.hsl.rl.ac.uk.\n",
+ "******************************************************************************\n",
+ "\n",
+ "This is Ipopt version 3.13.2, running with linear solver ma27.\n",
+ "\n",
+ "Number of nonzeros in equality constraint Jacobian...: 39\n",
+ "Number of nonzeros in inequality constraint Jacobian.: 0\n",
+ "Number of nonzeros in Lagrangian Hessian.............: 25\n",
+ "\n",
+ "Total number of variables............................: 18\n",
+ " variables with only lower bounds: 4\n",
+ " variables with lower and upper bounds: 13\n",
+ " variables with only upper bounds: 1\n",
+ "Total number of equality constraints.................: 18\n",
+ "Total number of inequality constraints...............: 0\n",
+ " inequality constraints with only lower bounds: 0\n",
+ " inequality constraints with lower and upper bounds: 0\n",
+ " inequality constraints with only upper bounds: 0\n",
+ "\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 0 0.0000000e+00 5.00e-01 1.00e+00 -1.0 0.00e+00 - 0.00e+00 0.00e+00 0\n",
+ " 1 0.0000000e+00 1.76e-01 6.65e+03 -1.0 7.51e+04 - 2.67e-01 9.90e-01H 1\n",
+ " 2 0.0000000e+00 4.81e-02 1.40e+02 -1.0 6.76e+02 - 9.46e-01 9.90e-01h 1\n",
+ " 3 0.0000000e+00 8.65e-03 1.76e+01 -1.0 9.79e+00 - 9.90e-01 9.90e-01h 1\n",
+ " 4 0.0000000e+00 1.81e-03 4.99e+04 -1.0 1.20e+00 - 9.90e-01 1.00e+00h 1\n",
+ " 5 0.0000000e+00 3.48e-03 9.81e+04 -1.0 5.29e+01 - 9.90e-01 1.00e+00h 1\n",
+ " 6 0.0000000e+00 1.57e-03 8.00e+02 -1.0 1.54e+02 - 9.92e-01 1.00e+00h 1\n",
+ " 7 0.0000000e+00 7.66e-04 2.93e-04 -2.5 2.52e+02 - 1.00e+00 1.00e+00h 1\n",
+ " 8 0.0000000e+00 3.81e-04 1.61e-04 -5.7 4.82e+02 - 1.00e+00 1.00e+00h 1\n",
+ " 9 0.0000000e+00 1.90e-04 6.49e-05 -5.7 9.53e+02 - 1.00e+00 1.00e+00h 1\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 10 0.0000000e+00 9.50e-05 8.68e-05 -5.7 1.90e+03 - 1.00e+00 1.00e+00h 1\n",
+ " 11 0.0000000e+00 4.75e-05 3.47e-04 -5.7 3.81e+03 - 1.00e+00 1.00e+00h 1\n",
+ " 12 0.0000000e+00 2.72e-05 1.39e-03 -5.7 7.64e+03 - 1.00e+00 1.00e+00h 1\n",
+ " 13 0.0000000e+00 1.07e-04 5.57e-03 -5.7 1.54e+04 - 1.00e+00 1.00e+00h 1\n",
+ " 14 0.0000000e+00 4.09e-04 2.23e-02 -5.7 3.11e+04 - 1.00e+00 1.00e+00h 1\n",
+ " 15 0.0000000e+00 1.51e-03 8.91e-02 -5.7 6.38e+04 - 1.00e+00 1.00e+00h 1\n",
+ " 16 0.0000000e+00 5.12e-03 3.53e-01 -5.7 1.33e+05 - 1.00e+00 1.00e+00h 1\n",
+ " 17 0.0000000e+00 1.49e-02 1.34e+00 -5.7 2.89e+05 - 1.00e+00 1.00e+00h 1\n",
+ " 18 0.0000000e+00 3.14e-02 4.58e+00 -5.7 6.55e+05 - 1.00e+00 1.00e+00h 1\n",
+ " 19 0.0000000e+00 2.86e-02 4.32e+00 -5.7 1.51e+06 - 1.00e+00 1.25e-01h 4\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 20 0.0000000e+00 2.82e-02 4.26e+00 -5.7 1.73e+06 - 1.00e+00 1.56e-02h 7\n",
+ " 21 0.0000000e+00 2.79e-02 4.23e+00 -5.7 1.76e+06 - 1.00e+00 7.81e-03h 8\n",
+ " 22 0.0000000e+00 2.79e-02 4.22e+00 -5.7 1.77e+06 - 1.00e+00 4.88e-04h 12\n",
+ " 23 0.0000000e+00 2.79e-02 4.22e+00 -5.7 1.77e+06 - 1.00e+00 1.22e-04h 14\n",
+ " 24 0.0000000e+00 7.05e-03 1.51e+01 -5.7 1.77e+06 - 1.00e+00 1.00e+00h 1\n",
+ " 25 0.0000000e+00 9.63e-04 4.01e+00 -5.7 3.18e+06 - 1.00e+00 1.50e-01h 2\n",
+ " 26 0.0000000e+00 5.53e-04 8.54e+01 -5.7 3.24e+06 - 1.00e+00 6.53e-02h 2\n",
+ " 27 0.0000000e+00 5.53e-04 8.57e+01 -5.7 3.20e+06 - 1.00e+00 9.58e-04h 7\n",
+ " 28 0.0000000e+00 5.53e-04 9.27e+01 -5.7 3.19e+06 - 1.00e+00 9.42e-04h 7\n",
+ " 29 0.0000000e+00 5.53e-04 2.08e+02 -5.7 3.19e+06 - 1.00e+00 9.27e-04h 7\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 30 0.0000000e+00 5.52e-04 7.91e+03 -5.7 1.83e+06 - 1.00e+00 3.17e-03h 6\n",
+ " 31 0.0000000e+00 3.77e-05 2.11e+06 -5.7 2.63e+04 - 1.00e+00 1.00e+00h 1\n",
+ " 32 0.0000000e+00 3.77e-05 2.10e+06 -5.7 1.03e+06 - 1.00e+00 5.67e-04h 9\n",
+ " 33 0.0000000e+00 3.77e-05 2.10e+06 -5.7 1.03e+06 - 1.00e+00 5.65e-04h 9\n",
+ " 34 0.0000000e+00 3.77e-05 2.10e+06 -5.7 1.02e+06 - 1.00e+00 5.63e-04h 9\n",
+ " 35 0.0000000e+00 3.77e-05 2.12e+06 -5.7 9.14e+05 - 1.00e+00 6.29e-04h 9\n",
+ " 36 0.0000000e+00 3.77e-05 2.23e+06 -5.7 9.36e+05 - 1.00e+00 6.11e-04h 9\n",
+ " 37 0.0000000e+00 3.76e-05 4.98e+06 -5.7 4.23e+05 - 1.00e+00 2.69e-03h 8\n",
+ " 38 0.0000000e+00 3.76e-05 6.97e+06 -5.7 8.98e+05 - 1.00e+00 6.29e-04h 9\n",
+ " 39 0.0000000e+00 3.76e-05 5.17e+07 -5.7 6.09e+05 - 1.00e+00 1.85e-03h 8\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 40 0.0000000e+00 3.76e-05 6.29e+07 -5.7 1.03e+06 - 1.00e+00 5.42e-04h 9\n",
+ " 41 0.0000000e+00 3.76e-05 7.41e+07 -5.7 1.02e+06 - 1.00e+00 5.43e-04h 9\n",
+ " 42 0.0000000e+00 8.59e-04 7.30e+11 -5.7 1.02e+06 - 1.00e+00 1.39e-01w 1\n",
+ " 43 0.0000000e+00 8.58e-04 7.30e+11 -5.7 7.14e+03 - 1.00e+00 2.07e-05w 1\n",
+ "In iteration 43, 2 Slacks too small, adjusting variable bounds\n",
+ " 44 0.0000000e+00 7.90e-04 5.95e+14 -5.7 4.69e+03 - 1.00e+00 8.02e-02w 1\n",
+ " 45 0.0000000e+00 3.76e-05 8.53e+07 -5.7 4.31e+03 - 1.00e+00 5.41e-04h 8\n",
+ " 46 0.0000000e+00 3.75e-05 9.64e+07 -5.7 1.02e+06 - 1.00e+00 5.39e-04h 9\n",
+ " 47 0.0000000e+00 3.75e-05 1.08e+08 -5.7 1.02e+06 - 1.00e+00 5.37e-04h 9\n",
+ " 48 0.0000000e+00 3.75e-05 1.19e+08 -5.7 1.02e+06 - 1.00e+00 5.35e-04h 9\n",
+ " 49 0.0000000e+00 3.75e-05 1.30e+08 -5.7 1.02e+06 - 1.00e+00 5.33e-04h 9\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 50 0.0000000e+00 3.75e-05 1.41e+08 -5.7 1.02e+06 - 1.00e+00 5.31e-04h 9\n",
+ " 51 0.0000000e+00 3.75e-05 1.52e+08 -5.7 1.02e+06 - 1.00e+00 5.29e-04h 9\n",
+ " 52 0.0000000e+00 3.75e-05 1.64e+08 -5.7 1.02e+06 - 1.00e+00 5.27e-04h 9\n",
+ " 53 0.0000000e+00 3.75e-05 1.75e+08 -5.7 1.02e+06 - 1.00e+00 5.25e-04h 9\n",
+ " 54 0.0000000e+00 3.75e-05 1.86e+08 -5.7 1.02e+06 - 1.00e+00 5.23e-04h 9\n",
+ " 55 0.0000000e+00 7.97e-04 7.34e+11 -5.7 1.02e+06 - 1.00e+00 1.33e-01w 1\n",
+ " 56 0.0000000e+00 7.97e-04 6.89e+11 -5.7 6.89e-05 16.0 2.81e-04 5.39e-01w 1\n",
+ " 57 0.0000000e+00 4.04e-07 2.66e+15 -5.7 4.36e+03 - 2.29e-07 1.00e+00h 1\n",
+ "Cannot recompute multipliers for feasibility problem. Error in eq_mult_calculator\n",
+ "\n",
+ "Number of Iterations....: 57\n",
+ "\n",
+ " (scaled) (unscaled)\n",
+ "Objective...............: 0.0000000000000000e+00 0.0000000000000000e+00\n",
+ "Dual infeasibility......: 2.6563801083485440e+15 2.6563801083485440e+15\n",
+ "Constraint violation....: 4.0441652946975677e-07 4.0441652946975677e-07\n",
+ "Complementarity.........: 0.0000000000000000e+00 0.0000000000000000e+00\n",
+ "Overall NLP error.......: 4.0441652946975677e-07 2.6563801083485440e+15\n",
+ "\n",
+ "\n",
+ "Number of objective function evaluations = 337\n",
+ "Number of objective gradient evaluations = 59\n",
+ "Number of equality constraint evaluations = 337\n",
+ "Number of inequality constraint evaluations = 0\n",
+ "Number of equality constraint Jacobian evaluations = 59\n",
+ "Number of inequality constraint Jacobian evaluations = 0\n",
+ "Number of Lagrangian Hessian evaluations = 58\n",
+ "Total CPU secs in IPOPT (w/o function evaluations) = 0.005\n",
+ "Total CPU secs in NLP function evaluations = 0.008\n",
+ "\n",
+ "EXIT: Solved To Acceptable Level.\n"
+ ]
+ }
+ ],
"source": [
"from idaes.core.util.model_statistics import degrees_of_freedom\n",
"import pytest\n",
@@ -226,7 +384,11 @@
"m = PR_model(test_data)\n",
"\n",
"# Check that degrees of freedom is 0\n",
- "assert degrees_of_freedom(m) == 0"
+ "assert degrees_of_freedom(m) == 0\n",
+ "\n",
+ "# Solve the model with the default solver and display results\n",
+ "solver = SolverFactory(\"ipopt\")\n",
+ "results = solver.solve(m, tee=True)"
]
},
{
@@ -235,41 +397,87 @@
"source": [
"## 4.0 Parameter estimation using parmest \n",
"\n",
- "### 4.1 List of variable names to be estimated\n",
+ "### 4.1 Define the Experiment class\n",
"\n",
- "Create a list of vars to estimate"
+ "Define the Experiment class to label model for parameter estimation."
]
},
{
"cell_type": "code",
- "execution_count": 7,
+ "execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
- "variable_name = [\n",
- " \"fs.properties.PR_kappa['bmimPF6', 'carbon_dioxide']\",\n",
- " \"fs.properties.PR_kappa['carbon_dioxide', 'bmimPF6']\",\n",
- "]"
+ "from pyomo.contrib.parmest.experiment import Experiment\n",
+ "\n",
+ "\n",
+ "# Create experiment class for parameter estimation\n",
+ "class PRExperiment(Experiment):\n",
+ "\n",
+ " def __init__(self, data, meas_error=None):\n",
+ " \"\"\"Initialize the PR Experiment class\n",
+ "\n",
+ " Args:\n",
+ " data: DataFrame containing the experimental data\n",
+ " meas_error: Measurement error for the data (optional)\n",
+ " \"\"\"\n",
+ " self.model = None\n",
+ " self.data = data\n",
+ " self.meas_error = meas_error\n",
+ "\n",
+ " def create_model(self):\n",
+ " \"\"\"Create the Pyomo model for the PR parameter estimation problem\"\"\"\n",
+ " self.model = PR_model(self.data)\n",
+ "\n",
+ " def label_model(self):\n",
+ " m = self.model\n",
+ "\n",
+ " # Add Suffixes to label the outputs, parameters, and measurement error in the model\n",
+ " m.experiment_outputs = Suffix(direction=Suffix.LOCAL)\n",
+ " m.experiment_outputs.update(\n",
+ " [(m.fs.state_block[1].pressure, self.data[\"pressure\"])]\n",
+ " )\n",
+ "\n",
+ " m.measurement_error = Suffix(direction=Suffix.LOCAL)\n",
+ " m.measurement_error.update([(m.fs.state_block[1].pressure, self.meas_error)])\n",
+ "\n",
+ " # Add unknown parameters to the model for easier access\n",
+ " m.unknown_parameters = Suffix(direction=Suffix.LOCAL)\n",
+ " m.unknown_parameters.update(\n",
+ " (k, value(k))\n",
+ " for k in [\n",
+ " m.fs.properties.PR_kappa[\"bmimPF6\", \"carbon_dioxide\"],\n",
+ " m.fs.properties.PR_kappa[\"carbon_dioxide\", \"bmimPF6\"],\n",
+ " ]\n",
+ " )\n",
+ "\n",
+ " def get_labeled_model(self):\n",
+ " \"\"\"Return the labeled model\"\"\"\n",
+ " if self.model is None:\n",
+ " self.create_model()\n",
+ " self.label_model()\n",
+ " return self.model"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
- "### 4.2 Create method to return an expression that computes the sum of squared error\n",
+ "### 4.2 Pre-process the data into individual experiments\n",
"\n",
- "We need to provide a method to return an expression to compute the sum of squared errors that will be used as the objective in solving the parameter estimation problem. For this problem, the error will be computed for the pressure."
+ "We now separate our data and assign a model for each individual experiments, creating an experiment list. "
]
},
{
"cell_type": "code",
- "execution_count": 8,
+ "execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
- "def SSE(m, data):\n",
- " expr = (float(data[\"pressure\"]) - m.fs.state_block[1].pressure) ** 2\n",
- " return expr * 1e-7"
+ "# Update to new interface\n",
+ "exp_list = []\n",
+ "for i in range(data.shape[0]):\n",
+ " exp_list.append(PRExperiment(data.iloc[i]))"
]
},
{
@@ -278,19 +486,218 @@
"source": [
"### 4.3 Run the parameter estimation\n",
"\n",
- "We are now ready to set up the parameter estimation problem. We will create a parameter estimation object called pest. As shown below, we pass the method that returns an initialized model, data, variable_name, and the SSE expression to the Estimator method. tee=True will print the solver output after solving the parameter estimation problem."
+ "We are now ready to set up the parameter estimation problem. We will create a parameter estimation object called pest. As shown below, we pass the experiment list, and an objective function to the Estimator method. tee=True will print the solver output after solving the parameter estimation problem."
]
},
{
"cell_type": "code",
- "execution_count": 9,
- "metadata": {
- "scrolled": false
- },
- "outputs": [],
+ "execution_count": 10,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: Starting initialization\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: Bubble, dew, and critical point initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: Starting initialization\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: Bubble, dew, and critical point initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: Starting initialization\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: Bubble, dew, and critical point initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n",
+ "2026-06-11 12:42:23 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Starting initialization\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Bubble, dew, and critical point initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Starting initialization\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Bubble, dew, and critical point initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Starting initialization\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Bubble, dew, and critical point initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Starting initialization\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Bubble, dew, and critical point initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Starting initialization\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Bubble, dew, and critical point initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:24 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Starting initialization\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Bubble, dew, and critical point initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Starting initialization\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Bubble, dew, and critical point initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Starting initialization\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Bubble, dew, and critical point initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Starting initialization\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Bubble, dew, and critical point initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Starting initialization\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Bubble, dew, and critical point initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Starting initialization\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Bubble, dew, and critical point initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n",
+ "2026-06-11 12:42:25 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Starting initialization\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Bubble, dew, and critical point initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Starting initialization\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Bubble, dew, and critical point initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Starting initialization\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Bubble, dew, and critical point initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Starting initialization\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Bubble, dew, and critical point initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Equilibrium temperature initialization completed.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: State variable initialization completed.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Phase equilibrium initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Property initialization: optimal - Optimal Solution Found.\n",
+ "2026-06-11 12:42:26 [INFO] idaes.init.fs.state_block: Property package initialization: optimal - Optimal Solution Found.\n",
+ "Ipopt 3.13.2: \n",
+ "\n",
+ "******************************************************************************\n",
+ "This program contains Ipopt, a library for large-scale nonlinear optimization.\n",
+ " Ipopt is released as open source code under the Eclipse Public License (EPL).\n",
+ " For more information visit http://projects.coin-or.org/Ipopt\n",
+ "\n",
+ "This version of Ipopt was compiled from source code available at\n",
+ " https://github.com/IDAES/Ipopt as part of the Institute for the Design of\n",
+ " Advanced Energy Systems Process Systems Engineering Framework (IDAES PSE\n",
+ " Framework) Copyright (c) 2018-2019. See https://github.com/IDAES/idaes-pse.\n",
+ "\n",
+ "This version of Ipopt was compiled using HSL, a collection of Fortran codes\n",
+ " for large-scale scientific computation. All technical papers, sales and\n",
+ " publicity material resulting from use of the HSL codes within IPOPT must\n",
+ " contain the following acknowledgement:\n",
+ " HSL, a collection of Fortran codes for large-scale scientific\n",
+ " computation. See http://www.hsl.rl.ac.uk.\n",
+ "******************************************************************************\n",
+ "\n",
+ "This is Ipopt version 3.13.2, running with linear solver ma27.\n",
+ "\n",
+ "Number of nonzeros in equality constraint Jacobian...: 846\n",
+ "Number of nonzeros in inequality constraint Jacobian.: 0\n",
+ "Number of nonzeros in Lagrangian Hessian.............: 720\n",
+ "\n",
+ "Total number of variables............................: 362\n",
+ " variables with only lower bounds: 72\n",
+ " variables with lower and upper bounds: 270\n",
+ " variables with only upper bounds: 18\n",
+ "Total number of equality constraints.................: 360\n",
+ "Total number of inequality constraints...............: 0\n",
+ " inequality constraints with only lower bounds: 0\n",
+ " inequality constraints with lower and upper bounds: 0\n",
+ " inequality constraints with only upper bounds: 0\n",
+ "\n",
+ "iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
+ " 0 0.0000000e+00 5.00e-01 2.44e-15 -1.0 0.00e+00 - 0.00e+00 0.00e+00 0\n",
+ " 1 6.9602464e+06 4.12e-01 1.82e+07 -1.0 2.99e+04 - 3.39e-01 1.72e-01h 3\n",
+ " 2 1.6667677e+08 2.58e-01 2.70e+08 -1.0 2.58e+04 - 6.19e-01 7.79e-01h 1\n",
+ " 3 2.8786912e+08 1.32e-01 4.98e+07 -1.0 8.26e+03 - 8.13e-01 9.90e-01h 1\n",
+ " 4 2.9277551e+08 1.44e-01 5.76e+05 -1.0 3.05e+02 - 9.77e-01 9.90e-01h 1\n",
+ " 5 2.9282842e+08 3.31e-02 5.28e+03 -1.0 3.24e+00 - 9.90e-01 9.91e-01h 1\n",
+ " 6 2.9282891e+08 4.65e-03 8.12e+04 -1.0 1.08e+00 - 9.90e-01 1.00e+00h 1\n",
+ " 7 2.9282891e+08 3.59e-05 2.33e+04 -2.5 9.23e-02 - 9.97e-01 1.00e+00h 1\n",
+ " 8 2.9282891e+08 3.17e-09 2.26e-05 -3.8 8.65e-04 - 1.00e+00 1.00e+00h 1\n",
+ " 9 2.9282891e+08 1.29e-12 2.38e-05 -8.6 6.67e-08 - 1.00e+00 1.00e+00f 1\n",
+ "\n",
+ "Number of Iterations....: 9\n",
+ "\n",
+ " (scaled) (unscaled)\n",
+ "Objective...............: 2.9282891309627521e+08 2.9282891309627521e+08\n",
+ "Dual infeasibility......: 2.3841853781623475e-05 2.3841853781623475e-05\n",
+ "Constraint violation....: 1.2910152591875072e-12 1.2910152591875072e-12\n",
+ "Complementarity.........: 2.5062901281861244e-09 2.5062901281861244e-09\n",
+ "Overall NLP error.......: 2.5062901281861244e-09 2.3841853781623475e-05\n",
+ "\n",
+ "\n",
+ "Number of objective function evaluations = 12\n",
+ "Number of objective gradient evaluations = 10\n",
+ "Number of equality constraint evaluations = 12\n",
+ "Number of inequality constraint evaluations = 0\n",
+ "Number of equality constraint Jacobian evaluations = 10\n",
+ "Number of inequality constraint Jacobian evaluations = 0\n",
+ "Number of Lagrangian Hessian evaluations = 9\n",
+ "Total CPU secs in IPOPT (w/o function evaluations) = 0.006\n",
+ "Total CPU secs in NLP function evaluations = 0.020\n",
+ "\n",
+ "EXIT: Optimal Solution Found.\n"
+ ]
+ }
+ ],
"source": [
- "pest = parmest.Estimator(PR_model, data, variable_name, SSE, tee=True)\n",
- "\n",
+ "pest = parmest.Estimator(exp_list, obj_function=\"SSE\", tee=True)\n",
"obj_value, parameters = pest.theta_est()"
]
},
@@ -305,15 +712,27 @@
},
{
"cell_type": "code",
- "execution_count": 10,
+ "execution_count": 11,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "The SSE at the optimal solution is 29.282891\n",
+ "\n",
+ "The values for the parameters are as follows:\n",
+ "fs.properties.PR_kappa[bmimPF6,carbon_dioxide] = -0.40714284008565715\n",
+ "fs.properties.PR_kappa[carbon_dioxide,bmimPF6] = 0.02059368400143062\n"
+ ]
+ }
+ ],
"source": [
- "print(\"The SSE at the optimal solution is %0.6f\" % obj_value)\n",
+ "print(f\"The SSE at the optimal solution is {obj_value*1e-7:0.6f}\")\n",
"print()\n",
"print(\"The values for the parameters are as follows:\")\n",
"for k, v in parameters.items():\n",
- " print(k, \"=\", v)"
+ " print(f\"{k} = {v}\")"
]
},
{
@@ -333,7 +752,7 @@
],
"metadata": {
"kernelspec": {
- "display_name": "Python 3 (ipykernel)",
+ "display_name": "idaes-pse-and-examples-dev-py313-macmini",
"language": "python",
"name": "python3"
},
@@ -347,9 +766,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.9.12"
+ "version": "3.13.13"
}
},
"nbformat": 4,
"nbformat_minor": 3
-}
+}
\ No newline at end of file