-
Notifications
You must be signed in to change notification settings - Fork 522
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
Updated Pyomo.DoE tutorial notebook. #2889
Conversation
"import sys\n", | ||
"# If running on Google Colab, install Ipopt via IDAES\n", | ||
"if \"google.colab\" in sys.modules:\n", | ||
" !wget \"https://raw.githubusercontent.com/ndcbe/CBE60499/main/notebooks/helper.py\"\n", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this the best place to distribute helper.py? Maybe it should be incorporated into the idaes-pse repo? @adowling2?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm considering updating the notebook to just give the helper code here.
Another option would be to have a separate package released by ideas, say colab-pyomo-helper. This would then make it !pip install colab-pyomo-helper.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just looked at the helper code, and it is sufficiently complex (and not directly tied to DoE) that I would not embed it here. I also think it is way too much overhead to have (yet another) package that has to be released. Plus, there is little / no value to being able to install previous versions of it.
It seems pretty simple to put it in idaes/scripts
and download it here. That has the side benefit that everyone can reference the same script, so as things evolve, we can keep just one script up-to-date.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hglynch Change code to as follows:
if "google.colab" in sys.modules:
!wget "https://raw.githubusercontent.com/adowling2/idaes-pse/tree/colab-install-script/scripts/colab_helper.py"
import colab_helper
colab_helper.install_idaes()
colab_helper.install_ipopt()
Does the IDAES and Ipopt install still work on Colab?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hglynch you should change the intro code to:
if "google.colab" in sys.modules:
!wget "https://raw.githubusercontent.com/idaes-pse/main/scripts"
import colab_helper
colab_helper.install_idaes()
colab_helper.install_ipopt()
I'll add it there. Thank you in advance for reviewing ;) |
@adowling2 completed updates for Pyomo.DoE tutorial, ready for review |
@hglynch @adowling2 the August Pyomo release is currently scheduled for August 23rd. Is this PR something you want included in the release? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hglynch Here are some minor edits. Once these are done, retag myself and John.
@hglynch , @adowling2 - Reminder that the target release for Pyomo is next week. If you'd like to get this in before the release, please make edits before this weekend, if possible. |
Another barrier is getting @jsiirola to review and approve this PR: IDAES/idaes-pse#1237 |
@hglynch here are the action items, which should be quick:
|
@adowling2 @jsiirola @blnicho @mrmundt This PR is ready for final review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great.
@hglynch One minor change:
Should become
Please also verify this notebook runs on Colab. |
@adowling2 I am receiving an error when I try running it in colab: "no module named colab_helper" |
@hglynch Did you successfully run this line first?
That downloads |
@adowling2 Yes I ran that first, here is the error: |
Ah, you can see the 404 error in the output. That means the script was not being downloaded correctly. Instead, try:
|
@adowling2 It works in colab now, I adjusted it in the jupyter notebook as well. |
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Key Takeaways\n", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the key takeaways. Can you maybe put them at the top and the bottom? That way I know what I am going to learn upfront and am reminded at the end what you taught me.
@hglynch - Please check out the Contributing guide for what tools we use for the automatic linting. |
@mrmundt I looked through this page and searched the documentation for "lint" and did not find anything. Can you provide a link to an example or give the commands to run for the automatic linting? |
See here: https://pyomo.readthedocs.io/en/stable/contribution_guide.html#coding-standards - |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for addressing it all! Looks great.
Codecov ReportPatch coverage has no change and project coverage change:
Additional details and impacted files@@ Coverage Diff @@
## main #2889 +/- ##
==========================================
- Coverage 87.84% 87.83% -0.01%
==========================================
Files 770 770
Lines 89665 89665
==========================================
- Hits 78764 78756 -8
- Misses 10901 10909 +8
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"metadata": { | ||
"tags": [] | ||
}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Successfully loaded idaes.\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"# Ipopt installer\n", | ||
"import sys\n", | ||
"\n", | ||
"# If running on Google Colab, install Ipopt via IDAES\n", | ||
"if \"google.colab\" in sys.modules:\n", | ||
" !wget \"https://raw.githubusercontent.com/IDAES/idaes-pse/main/scripts/colab_helper.py\"\n", | ||
" import colab_helper\n", | ||
"\n", | ||
" colab_helper.install_idaes()\n", | ||
" colab_helper.install_ipopt()\n", | ||
"\n", | ||
"# Otherwise, attempt to load IDAES which should include Ipopt and k_aug\n", | ||
"# See https://idaes-pse.readthedocs.io/en/stable/tutorials/getting_started/index.html\n", | ||
"# for instructions on running IDAES get-extensions\n", | ||
"else:\n", | ||
" try:\n", | ||
" import idaes\n", | ||
"\n", | ||
" # Provided IDAES extensions are installed, importing IDAES provides access to\n", | ||
" # Ipopt with HSL and k_aug which are needed for this example\n", | ||
" print(\"Successfully loaded IDAES.\")\n", | ||
" except:\n", | ||
" print(\n", | ||
" \"IDAES is not installed. Make sure you have independently installed Ipopt with HSL and k_aug.\"\n", | ||
" )" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"metadata": { | ||
"tags": [] | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"## check if ipopt available \n", | ||
"ipopt_available = pyo.SolverFactory('ipopt').available()\n", | ||
"# Check if Ipopt is available\n", | ||
"ipopt_available = pyo.SolverFactory(\"ipopt\").available()\n", | ||
"if not (ipopt_available):\n", | ||
" raise RuntimeError('This Pyomo.DoE example requires Ipopt.')" | ||
" raise RuntimeError(\"This Pyomo.DoE example requires Ipopt.\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": { | ||
"tags": [] | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"# Imports\n", | ||
"import numpy as np\n", | ||
"import pyomo.environ as pyo\n", | ||
"from pyomo.dae import ContinuousSet, DerivativeVar\n", | ||
"from pyomo.contrib.doe import (\n", | ||
" ModelOptionLib,\n", | ||
" DesignOfExperiments,\n", | ||
" MeasurementVariables,\n", | ||
" DesignVariables,\n", | ||
")" | ||
] | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These first three setup cells are out of order. The output captured in the notebook notes that they were executed in a different order than they appear in order to run successfully. In particular, the second cell checking solver availability uses the pyo
namespace which isn't imported until the third cell. Could you fix the ordering and rerun the notebook such that the cells are run in order?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
" 22 -1.4309111e+01 8.54e-12 2.66e-08 -8.6 2.66e-04 -4.0 1.00e+00 1.00e+00h 1\n", | ||
"Reallocating memory for MA57: lfact (450838)\n", | ||
"Reallocating memory for MA57: lfact (477335)\n", | ||
" 23 -1.4309111e+01 3.31e-12 5.52e-09 -8.6 1.66e-04 -4.5 1.00e+00 1.00e+00h 1\n", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you know why you're now getting regularization at the solution when the previous run of the notebook didn't?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added this to the todo list below. The initialization is also not as clear as I would prefer.
"text": [ | ||
"INFO: =======Iteration Number: 1 =====\n", | ||
"INFO: elapsed time: 5.7\n", | ||
"INFO: This is the 2 run out of 9 run.\n", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure where this info logging message is being generated but it looks like there is an off-by-one error in determining the current run number which leads to a confusing message at the end, "10 run out of 9". The grammar of this message could also be improved to "This is run 1 out of 9".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't look like your change to the log message was included when you reran the notebook. Are you running this with an installed version of Pyomo instead of the main branch?
" )\n", | ||
"\n", | ||
" # Gas constant\n", | ||
" mod.R = 8.31446261815324 # J / K / mole\n", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should get into the habit of actually using pyo.units
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree
" # Calculating C, Jacobian, FIM\n", | ||
" mod.k1_pert_rule = pyo.Constraint(mod.t, rule=cal_kp1)\n", | ||
" mod.k2_pert_rule = pyo.Constraint(mod.t, rule=cal_kp2)\n", | ||
" mod.dCdt_rule = pyo.Constraint(mod.C_set, mod.t, rule=dCdt_control)\n", | ||
"\n", | ||
" mod.alge_rule = pyo.Constraint(mod.t, rule=alge)\n", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Long term, I think this example would be a lot more powerful if we could separate the kinetic model from the DoE case study. One interesting (future) direction would be to use the examples/dae/ReactionKinetics.py
module to define the generic kinetic model.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have conflicting feelings about this. In at least one case, this notebook has helped attract a new Pyomo user, so having the model in the notebook is convenient. But it also duplicates code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hglynch a couple more minor comments and then I think we can merge this
"text": [ | ||
"INFO: =======Iteration Number: 1 =====\n", | ||
"INFO: elapsed time: 5.7\n", | ||
"INFO: This is the 2 run out of 9 run.\n", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't look like your change to the log message was included when you reran the notebook. Are you running this with an installed version of Pyomo instead of the main branch?
Enhancements for the next PR:
|
@hglynch: it looks like you may have forgotten to commit/push the changes to |
Should be working now, let me know if not! |
Fixes # .
Summary/Motivation:
Changes proposed in this PR:
Legal Acknowledgement
By contributing to this software project, I have read the contribution guide and agree to the following terms and conditions for my contribution: