Skip to content

Commit

Permalink
redoing the changes for deprecation
Browse files Browse the repository at this point in the history
  • Loading branch information
agarciadiego committed May 21, 2024
1 parent 8818ba7 commit f31443d
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 10,
"execution_count": null,
"metadata": {
"tags": [
"header",
Expand Down Expand Up @@ -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/contributed_packages/parmest/index.html\n"
]
},
{
Expand All @@ -61,7 +60,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": null,
"metadata": {
"tags": [
"exercise"
Expand All @@ -76,7 +75,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": null,
"metadata": {
"tags": [
"solution"
Expand All @@ -100,7 +99,7 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": null,
"metadata": {
"tags": []
},
Expand All @@ -121,7 +120,7 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": null,
"metadata": {
"tags": []
},
Expand Down Expand Up @@ -152,7 +151,7 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": null,
"metadata": {
"tags": [
"exercise"
Expand Down Expand Up @@ -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",
Expand All @@ -213,7 +217,7 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": null,
"metadata": {
"tags": [
"solution"
Expand Down Expand Up @@ -264,7 +268,13 @@
" 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",
" # 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",
Expand All @@ -279,7 +289,7 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": null,
"metadata": {
"tags": [
"testing"
Expand Down Expand Up @@ -349,7 +359,7 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": null,
"metadata": {
"tags": [
"exercise"
Expand All @@ -362,7 +372,7 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": null,
"metadata": {
"tags": [
"solution"
Expand Down Expand Up @@ -393,7 +403,7 @@
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": null,
"metadata": {
"tags": []
},
Expand Down Expand Up @@ -453,10 +463,10 @@
" # 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",
" float(data.iloc[0][\"vap_benzene\"])\n",
" - m.fs.state_block.mole_frac_phase_comp[\"Vap\", \"benzene\"]\n",
" ) ** 2 + (\n",
" float(data[\"liq_benzene\"])\n",
" float(data.iloc[0][\"liq_benzene\"])\n",
" - m.fs.state_block.mole_frac_phase_comp[\"Liq\", \"benzene\"]\n",
" ) ** 2\n",
" return expr * 1e4"
Expand Down Expand Up @@ -587,7 +597,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.9"
"version": "3.8.19"
}
},
"nbformat": 4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -434,7 +444,7 @@
"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",
" # (float(data.iloc[0][\"vap_benzene\"]) - m.fs.flash.vap_outlet.mole_frac_comp[0, \"benzene\"])**2\n",
"\n",
" return expr * 1e4"
]
Expand All @@ -455,9 +465,9 @@
" # 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",
" float(data.iloc[0][\"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",
" float(data.iloc[0][\"liq_benzene\"]) - m.fs.flash.liq_outlet.mole_frac_comp[0, \"benzene\"]\n",
" ) ** 2\n",
" return expr * 1e4"
]
Expand Down Expand Up @@ -587,9 +597,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.12"
"version": "3.8.19"
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -83,7 +83,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -99,7 +99,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -121,7 +121,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -146,7 +146,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -155,15 +155,22 @@
" m = ConcreteModel()\n",
"\n",
" m.fs = FlowsheetBlock(dynamic=False)\n",
"\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",
" \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",
Expand All @@ -177,15 +184,28 @@
" 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",
" 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",
" )\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",
" )\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(float(data.iloc[0][\"x_bmimPF6\"])) \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",
Expand All @@ -207,10 +227,8 @@
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"scrolled": false
},
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from idaes.core.util.model_statistics import degrees_of_freedom\n",
Expand Down Expand Up @@ -242,7 +260,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -263,12 +281,12 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def SSE(m, data):\n",
" expr = (float(data[\"pressure\"]) - m.fs.state_block[1].pressure) ** 2\n",
" expr = (float(data.iloc[0][\"pressure\"]) - m.fs.state_block[1].pressure) ** 2\n",
" return expr * 1e-7"
]
},
Expand All @@ -283,10 +301,8 @@
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"scrolled": false
},
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"pest = parmest.Estimator(PR_model, data, variable_name, SSE, tee=True)\n",
Expand All @@ -305,7 +321,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -347,7 +363,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.12"
"version": "3.8.19"
}
},
"nbformat": 4,
Expand Down

0 comments on commit f31443d

Please sign in to comment.