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 f6b10d38..13724a46 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": 10, + "execution_count": null, "metadata": { "tags": [ "header", @@ -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" ] }, { @@ -61,7 +60,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": null, "metadata": { "tags": [ "exercise" @@ -76,7 +75,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": null, "metadata": { "tags": [ "solution" @@ -100,7 +99,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": null, "metadata": { "tags": [] }, @@ -121,7 +120,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": null, "metadata": { "tags": [] }, @@ -152,7 +151,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": null, "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": null, "metadata": { "tags": [ "solution" @@ -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", @@ -279,7 +289,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": null, "metadata": { "tags": [ "testing" @@ -349,7 +359,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": null, "metadata": { "tags": [ "exercise" @@ -362,7 +372,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": null, "metadata": { "tags": [ "solution" @@ -393,7 +403,7 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": null, "metadata": { "tags": [] }, @@ -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" @@ -587,7 +597,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.9" + "version": "3.8.19" } }, "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 d1648edd..9397f6cc 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 @@ -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", @@ -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", @@ -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" ] @@ -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" ] @@ -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 } diff --git a/idaes_examples/notebooks/docs/properties/parameter_estimation_pr.ipynb b/idaes_examples/notebooks/docs/properties/parameter_estimation_pr.ipynb index 1546704a..8d91484d 100644 --- a/idaes_examples/notebooks/docs/properties/parameter_estimation_pr.ipynb +++ b/idaes_examples/notebooks/docs/properties/parameter_estimation_pr.ipynb @@ -57,7 +57,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -83,7 +83,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -99,7 +99,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -121,7 +121,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -146,7 +146,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -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", @@ -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", @@ -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", @@ -242,7 +260,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -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" ] }, @@ -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", @@ -305,7 +321,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -347,7 +363,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.12" + "version": "3.8.19" } }, "nbformat": 4,