Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add notebook for scaling workshop #135

Merged
merged 14 commits into from
Nov 5, 2024
Prev Previous commit
Next Next commit
Adding tests for scaling workshop
Andrew Lee committed Oct 24, 2024
commit 60ae09f4b24df75cf2078b2c06cfd238814915c4
98 changes: 77 additions & 21 deletions idaes_examples/notebooks/docs/scaling/scaler_workshop.ipynb
Original file line number Diff line number Diff line change
@@ -175,6 +175,17 @@
"dt.report_structural_issues()"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "c7b4d6f9",
"metadata": {},
"outputs": [],
"source": [
"# Make sure base model is constructed propertly\n",
"dt.assert_no_structural_warnings()"
]
},
{
"cell_type": "markdown",
"id": "242909ef",
@@ -187,7 +198,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 4,
"id": "e00f12e5",
"metadata": {},
"outputs": [],
@@ -216,7 +227,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 5,
"id": "7db4db04",
"metadata": {},
"outputs": [
@@ -330,7 +341,7 @@
"Number of equality constraint Jacobian evaluations = 44\n",
"Number of inequality constraint Jacobian evaluations = 0\n",
"Number of Lagrangian Hessian evaluations = 42\n",
"Total CPU secs in IPOPT (w/o function evaluations) = 0.005\n",
"Total CPU secs in IPOPT (w/o function evaluations) = 0.007\n",
"Total CPU secs in NLP function evaluations = 0.000\n",
"\n",
"EXIT: Converged to a point of local infeasibility. Problem may be infeasible.\n"
@@ -369,7 +380,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 6,
"id": "72492bd6",
"metadata": {},
"outputs": [],
@@ -492,7 +503,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 7,
"id": "96ca1083",
"metadata": {},
"outputs": [
@@ -546,7 +557,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 8,
"id": "85175874",
"metadata": {},
"outputs": [
@@ -595,7 +606,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 9,
"id": "43fc4d67",
"metadata": {},
"outputs": [],
@@ -645,7 +656,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 10,
"id": "b0363a58",
"metadata": {},
"outputs": [
@@ -709,7 +720,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 11,
"id": "aa684f2e",
"metadata": {},
"outputs": [
@@ -763,7 +774,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 12,
"id": "f845d90e",
"metadata": {},
"outputs": [],
@@ -815,7 +826,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 13,
"id": "cbad67e9",
"metadata": {},
"outputs": [],
@@ -884,7 +895,7 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 14,
"id": "c67fa218",
"metadata": {},
"outputs": [],
@@ -928,7 +939,7 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 15,
"id": "781f06d0",
"metadata": {},
"outputs": [
@@ -1109,7 +1120,7 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 16,
"id": "a1ae2667",
"metadata": {},
"outputs": [],
@@ -1216,7 +1227,7 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 17,
"id": "5f8e0e6f",
"metadata": {},
"outputs": [
@@ -1356,7 +1367,7 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 18,
"id": "389332f0",
"metadata": {},
"outputs": [],
@@ -1477,7 +1488,7 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 19,
"id": "75d11627",
"metadata": {},
"outputs": [
@@ -1565,6 +1576,27 @@
"check_scaling()"
]
},
{
"cell_type": "code",
"execution_count": 20,
"id": "77fe3766",
"metadata": {},
"outputs": [],
"source": [
"# Build a new isntance of the model for testing\n",
"test_model = build_model()\n",
"scaler = EquilibriumReactorScaler()\n",
"scaler.scale_model(test_model.fs.equil)\n",
"\n",
"# Check that the number of scaling facotrs assgined matches expectations\n",
"# We will assume they were set correctly\n",
"assert len(test_model.fs.equil.scaling_factor) == 1\n",
"assert len(test_model.fs.equil.control_volume.scaling_factor) == 14\n",
"assert len(test_model.fs.equil.control_volume.properties_in[0].scaling_factor) == 8\n",
"assert len(test_model.fs.equil.control_volume.properties_out[0].scaling_factor) == 9\n",
"assert len(test_model.fs.equil.control_volume.reactions[0].scaling_factor) == 4"
]
},
{
"cell_type": "markdown",
"id": "35e8d1ad",
@@ -1586,7 +1618,7 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": 21,
"id": "80e47573",
"metadata": {},
"outputs": [
@@ -1650,6 +1682,17 @@
"dt.report_numerical_issues()"
]
},
{
"cell_type": "code",
"execution_count": 22,
"id": "dfec0c62",
"metadata": {},
"outputs": [],
"source": [
"# Test to ensure autoscaled model solved\n",
"assert check_optimal_termination(results)"
]
},
{
"cell_type": "markdown",
"id": "522076eb",
@@ -1679,7 +1722,7 @@
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": 23,
"id": "a5d82e55",
"metadata": {},
"outputs": [
@@ -1760,7 +1803,7 @@
"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 IPOPT (w/o function evaluations) = 0.002\n",
"Total CPU secs in NLP function evaluations = 0.000\n",
"\n",
"EXIT: Optimal Solution Found.\n"
@@ -1806,14 +1849,27 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 24,
"id": "c03a51d5",
"metadata": {},
"outputs": [],
"source": [
"# Test that scaled model re-solves\n",
"results = solver.solve(m)\n",
"assert check_optimal_termination(results)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "682a983a",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"celltoolbar": "Tags",
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
92 changes: 72 additions & 20 deletions idaes_examples/notebooks/docs/scaling/scaler_workshop_doc.ipynb
Original file line number Diff line number Diff line change
@@ -171,6 +171,16 @@
"dt.report_structural_issues()"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"# Make sure base model is constructed propertly\n",
"dt.assert_no_structural_warnings()"
]
},
{
"cell_type": "markdown",
"metadata": {},
@@ -182,7 +192,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
@@ -209,7 +219,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 5,
"metadata": {},
"outputs": [
{
@@ -322,7 +332,7 @@
"Number of equality constraint Jacobian evaluations = 44\n",
"Number of inequality constraint Jacobian evaluations = 0\n",
"Number of Lagrangian Hessian evaluations = 42\n",
"Total CPU secs in IPOPT (w/o function evaluations) = 0.005\n",
"Total CPU secs in IPOPT (w/o function evaluations) = 0.007\n",
"Total CPU secs in NLP function evaluations = 0.000\n",
"\n",
"EXIT: Converged to a point of local infeasibility. Problem may be infeasible.\n"
@@ -359,7 +369,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
@@ -480,7 +490,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 7,
"metadata": {},
"outputs": [
{
@@ -532,7 +542,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 8,
"metadata": {},
"outputs": [
{
@@ -579,7 +589,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
@@ -627,7 +637,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 10,
"metadata": {},
"outputs": [
{
@@ -689,7 +699,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 11,
"metadata": {},
"outputs": [
{
@@ -741,7 +751,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
@@ -791,7 +801,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
@@ -858,7 +868,7 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 14,
"metadata": {},
"outputs": [],
"source": [
@@ -900,7 +910,7 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 15,
"metadata": {},
"outputs": [
{
@@ -1078,7 +1088,7 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 16,
"metadata": {},
"outputs": [],
"source": [
@@ -1183,7 +1193,7 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 17,
"metadata": {},
"outputs": [
{
@@ -1321,7 +1331,7 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 18,
"metadata": {},
"outputs": [],
"source": [
@@ -1440,7 +1450,7 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 19,
"metadata": {},
"outputs": [
{
@@ -1527,6 +1537,26 @@
"check_scaling()"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [],
"source": [
"# Build a new isntance of the model for testing\n",
"test_model = build_model()\n",
"scaler = EquilibriumReactorScaler()\n",
"scaler.scale_model(test_model.fs.equil)\n",
"\n",
"# Check that the number of scaling facotrs assgined matches expectations\n",
"# We will assume they were set correctly\n",
"assert len(test_model.fs.equil.scaling_factor) == 1\n",
"assert len(test_model.fs.equil.control_volume.scaling_factor) == 14\n",
"assert len(test_model.fs.equil.control_volume.properties_in[0].scaling_factor) == 8\n",
"assert len(test_model.fs.equil.control_volume.properties_out[0].scaling_factor) == 9\n",
"assert len(test_model.fs.equil.control_volume.reactions[0].scaling_factor) == 4"
]
},
{
"cell_type": "markdown",
"metadata": {},
@@ -1547,7 +1577,7 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": 21,
"metadata": {},
"outputs": [
{
@@ -1610,6 +1640,16 @@
"dt.report_numerical_issues()"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [],
"source": [
"# Test to ensure autoscaled model solved\n",
"assert check_optimal_termination(results)"
]
},
{
"cell_type": "markdown",
"metadata": {},
@@ -1638,7 +1678,7 @@
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": 23,
"metadata": {},
"outputs": [
{
@@ -1718,7 +1758,7 @@
"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 IPOPT (w/o function evaluations) = 0.002\n",
"Total CPU secs in NLP function evaluations = 0.000\n",
"\n",
"EXIT: Optimal Solution Found.\n"
@@ -1761,6 +1801,17 @@
"With that, we have finished this workshop on developing ``Scaler`` classes. Hopefully you now know enough to begin writing ``Scalers`` for your own models, and have gained some insight into how to think about developing scaling routines and the tools available to help you."
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {},
"outputs": [],
"source": [
"# Test that scaled model re-solves\n",
"results = solver.solve(m)\n",
"assert check_optimal_termination(results)"
]
},
{
"cell_type": "code",
"execution_count": null,
@@ -1770,6 +1821,7 @@
}
],
"metadata": {
"celltoolbar": "Tags",
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
92 changes: 72 additions & 20 deletions idaes_examples/notebooks/docs/scaling/scaler_workshop_test.ipynb
Original file line number Diff line number Diff line change
@@ -171,6 +171,16 @@
"dt.report_structural_issues()"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"# Make sure base model is constructed propertly\n",

Check warning on line 180 in idaes_examples/notebooks/docs/scaling/scaler_workshop_test.ipynb

GitHub Actions / Check Spelling

"propertly" should be "property" or "properly".
"dt.assert_no_structural_warnings()"
]
},
{
"cell_type": "markdown",
"metadata": {},
@@ -182,7 +192,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
@@ -209,7 +219,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 5,
"metadata": {},
"outputs": [
{
@@ -322,7 +332,7 @@
"Number of equality constraint Jacobian evaluations = 44\n",
"Number of inequality constraint Jacobian evaluations = 0\n",
"Number of Lagrangian Hessian evaluations = 42\n",
"Total CPU secs in IPOPT (w/o function evaluations) = 0.005\n",
"Total CPU secs in IPOPT (w/o function evaluations) = 0.007\n",
"Total CPU secs in NLP function evaluations = 0.000\n",
"\n",
"EXIT: Converged to a point of local infeasibility. Problem may be infeasible.\n"
@@ -359,7 +369,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
@@ -480,7 +490,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 7,
"metadata": {},
"outputs": [
{
@@ -532,7 +542,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 8,
"metadata": {},
"outputs": [
{
@@ -579,7 +589,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
@@ -627,7 +637,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 10,
"metadata": {},
"outputs": [
{
@@ -689,7 +699,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 11,
"metadata": {},
"outputs": [
{
@@ -741,7 +751,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
@@ -791,7 +801,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
@@ -858,7 +868,7 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 14,
"metadata": {},
"outputs": [],
"source": [
@@ -867,7 +877,7 @@
"from idaes.core.scaling import report_scaling_factors\n",
"\n",
"def check_scaling(tee=False):\n",
" # Buld new instance of model\n",

Check warning on line 880 in idaes_examples/notebooks/docs/scaling/scaler_workshop_test.ipynb

GitHub Actions / Check Spelling

"Buld" should be "Build".
" m = build_model()\n",
"\n",
" # Apply scaler to model\n",
@@ -881,7 +891,7 @@
" else:\n",
" print(\"\\nModel Failed to Converge!\\n\")\n",
" \n",
" # Print reprot of scaling factors\n",

Check warning on line 894 in idaes_examples/notebooks/docs/scaling/scaler_workshop_test.ipynb

GitHub Actions / Check Spelling

"reprot" should be "report".
" report_scaling_factors(m.fs.equil, descend_into=True)\n",
"\n",
" # Show numerical issues report\n",
@@ -900,7 +910,7 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 15,
"metadata": {},
"outputs": [
{
@@ -1078,7 +1088,7 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 16,
"metadata": {},
"outputs": [],
"source": [
@@ -1183,7 +1193,7 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 17,
"metadata": {},
"outputs": [
{
@@ -1321,7 +1331,7 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 18,
"metadata": {},
"outputs": [],
"source": [
@@ -1440,7 +1450,7 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 19,
"metadata": {},
"outputs": [
{
@@ -1527,6 +1537,26 @@
"check_scaling()"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [],
"source": [
"# Build a new isntance of the model for testing\n",
"test_model = build_model()\n",
"scaler = EquilibriumReactorScaler()\n",
"scaler.scale_model(test_model.fs.equil)\n",
"\n",
"# Check that the number of scaling facotrs assgined matches expectations\n",
"# We will assume they were set correctly\n",
"assert len(test_model.fs.equil.scaling_factor) == 1\n",
"assert len(test_model.fs.equil.control_volume.scaling_factor) == 14\n",
"assert len(test_model.fs.equil.control_volume.properties_in[0].scaling_factor) == 8\n",
"assert len(test_model.fs.equil.control_volume.properties_out[0].scaling_factor) == 9\n",
"assert len(test_model.fs.equil.control_volume.reactions[0].scaling_factor) == 4"
]
},
{
"cell_type": "markdown",
"metadata": {},
@@ -1547,7 +1577,7 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": 21,
"metadata": {},
"outputs": [
{
@@ -1610,6 +1640,16 @@
"dt.report_numerical_issues()"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [],
"source": [
"# Test to ensure autoscaled model solved\n",
"assert check_optimal_termination(results)"
]
},
{
"cell_type": "markdown",
"metadata": {},
@@ -1638,7 +1678,7 @@
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": 23,
"metadata": {},
"outputs": [
{
@@ -1718,7 +1758,7 @@
"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 IPOPT (w/o function evaluations) = 0.002\n",
"Total CPU secs in NLP function evaluations = 0.000\n",
"\n",
"EXIT: Optimal Solution Found.\n"
@@ -1761,6 +1801,17 @@
"With that, we have finished this workshop on developing ``Scaler`` classes. Hopefully you now know enough to begin writing ``Scalers`` for your own models, and have gained some insight into how to think about developing scaling routines and the tools available to help you."
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {},
"outputs": [],
"source": [
"# Test that scaled model re-solves\n",
"results = solver.solve(m)\n",
"assert check_optimal_termination(results)"
]
},
{
"cell_type": "code",
"execution_count": null,
@@ -1770,6 +1821,7 @@
}
],
"metadata": {
"celltoolbar": "Tags",
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
92 changes: 72 additions & 20 deletions idaes_examples/notebooks/docs/scaling/scaler_workshop_usr.ipynb
Original file line number Diff line number Diff line change
@@ -171,6 +171,16 @@
"dt.report_structural_issues()"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"# Make sure base model is constructed propertly\n",

Check warning on line 180 in idaes_examples/notebooks/docs/scaling/scaler_workshop_usr.ipynb

GitHub Actions / Check Spelling

"propertly" should be "property" or "properly".
"dt.assert_no_structural_warnings()"
]
},
{
"cell_type": "markdown",
"metadata": {},
@@ -182,7 +192,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
@@ -209,7 +219,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 5,
"metadata": {},
"outputs": [
{
@@ -322,7 +332,7 @@
"Number of equality constraint Jacobian evaluations = 44\n",
"Number of inequality constraint Jacobian evaluations = 0\n",
"Number of Lagrangian Hessian evaluations = 42\n",
"Total CPU secs in IPOPT (w/o function evaluations) = 0.005\n",
"Total CPU secs in IPOPT (w/o function evaluations) = 0.007\n",
"Total CPU secs in NLP function evaluations = 0.000\n",
"\n",
"EXIT: Converged to a point of local infeasibility. Problem may be infeasible.\n"
@@ -359,7 +369,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
@@ -480,7 +490,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 7,
"metadata": {},
"outputs": [
{
@@ -532,7 +542,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 8,
"metadata": {},
"outputs": [
{
@@ -579,7 +589,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
@@ -627,7 +637,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 10,
"metadata": {},
"outputs": [
{
@@ -689,7 +699,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 11,
"metadata": {},
"outputs": [
{
@@ -741,7 +751,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
@@ -791,7 +801,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
@@ -858,7 +868,7 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 14,
"metadata": {},
"outputs": [],
"source": [
@@ -867,7 +877,7 @@
"from idaes.core.scaling import report_scaling_factors\n",
"\n",
"def check_scaling(tee=False):\n",
" # Buld new instance of model\n",

Check warning on line 880 in idaes_examples/notebooks/docs/scaling/scaler_workshop_usr.ipynb

GitHub Actions / Check Spelling

"Buld" should be "Build".
" m = build_model()\n",
"\n",
" # Apply scaler to model\n",
@@ -881,7 +891,7 @@
" else:\n",
" print(\"\\nModel Failed to Converge!\\n\")\n",
" \n",
" # Print reprot of scaling factors\n",

Check warning on line 894 in idaes_examples/notebooks/docs/scaling/scaler_workshop_usr.ipynb

GitHub Actions / Check Spelling

"reprot" should be "report".
" report_scaling_factors(m.fs.equil, descend_into=True)\n",
"\n",
" # Show numerical issues report\n",
@@ -900,7 +910,7 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 15,
"metadata": {},
"outputs": [
{
@@ -1078,7 +1088,7 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 16,
"metadata": {},
"outputs": [],
"source": [
@@ -1183,7 +1193,7 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 17,
"metadata": {},
"outputs": [
{
@@ -1321,7 +1331,7 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 18,
"metadata": {},
"outputs": [],
"source": [
@@ -1440,7 +1450,7 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 19,
"metadata": {},
"outputs": [
{
@@ -1527,6 +1537,26 @@
"check_scaling()"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [],
"source": [
"# Build a new isntance of the model for testing\n",

Check warning on line 1546 in idaes_examples/notebooks/docs/scaling/scaler_workshop_usr.ipynb

GitHub Actions / Check Spelling

"isntance" should be "instance".
"test_model = build_model()\n",
"scaler = EquilibriumReactorScaler()\n",
"scaler.scale_model(test_model.fs.equil)\n",
"\n",
"# Check that the number of scaling facotrs assgined matches expectations\n",

Check warning on line 1551 in idaes_examples/notebooks/docs/scaling/scaler_workshop_usr.ipynb

GitHub Actions / Check Spelling

"assgined" should be "assigned".
"# We will assume they were set correctly\n",
"assert len(test_model.fs.equil.scaling_factor) == 1\n",
"assert len(test_model.fs.equil.control_volume.scaling_factor) == 14\n",
"assert len(test_model.fs.equil.control_volume.properties_in[0].scaling_factor) == 8\n",
"assert len(test_model.fs.equil.control_volume.properties_out[0].scaling_factor) == 9\n",
"assert len(test_model.fs.equil.control_volume.reactions[0].scaling_factor) == 4"
]
},
{
"cell_type": "markdown",
"metadata": {},
@@ -1547,7 +1577,7 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": 21,
"metadata": {},
"outputs": [
{
@@ -1610,6 +1640,16 @@
"dt.report_numerical_issues()"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [],
"source": [
"# Test to ensure autoscaled model solved\n",
"assert check_optimal_termination(results)"
]
},
{
"cell_type": "markdown",
"metadata": {},
@@ -1638,7 +1678,7 @@
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": 23,
"metadata": {},
"outputs": [
{
@@ -1718,7 +1758,7 @@
"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 IPOPT (w/o function evaluations) = 0.002\n",
"Total CPU secs in NLP function evaluations = 0.000\n",
"\n",
"EXIT: Optimal Solution Found.\n"
@@ -1738,7 +1778,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"We can see that by applying our new ``EquilibriumReactorScaler`` we are now able to use IPOPT to solve for the perturbation, and that it reaches an optimal solution in 11 iterations. Looking at the solver logs we can see that the solver step lengths (``alpha_du`` and ``alpha_pr``) are rather small for the first iterations but the number of line searches (``ls``) is 1 for all iterations. This indicates that IPOPT is pushing up againt some bound or constraint and cannot mkae full steps, but in this case it is due to the fact that to achieve equilibrium for an irreversible reaction at least one concentration must be driven to zero (and is why an EquibriumReactor is probably not a good choice for this test case). However, the fact that our ``Scaler`` let us solve for this challenging test case is probably a good sign.\n",

Check warning on line 1781 in idaes_examples/notebooks/docs/scaling/scaler_workshop_usr.ipynb

GitHub Actions / Check Spelling

"againt" should be "against".

Check warning on line 1781 in idaes_examples/notebooks/docs/scaling/scaler_workshop_usr.ipynb

GitHub Actions / Check Spelling

"mkae" should be "make".
"\n",
"\n",
"## Step 8: Finishing Up\n",
@@ -1761,6 +1801,17 @@
"With that, we have finished this workshop on developing ``Scaler`` classes. Hopefully you now know enough to begin writing ``Scalers`` for your own models, and have gained some insight into how to think about developing scaling routines and the tools available to help you."
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {},
"outputs": [],
"source": [
"# Test that scaled model re-solves\n",
"results = solver.solve(m)\n",
"assert check_optimal_termination(results)"
]
},
{
"cell_type": "code",
"execution_count": null,
@@ -1770,6 +1821,7 @@
}
],
"metadata": {
"celltoolbar": "Tags",
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",