-
Notifications
You must be signed in to change notification settings - Fork 235
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
Contributes script to install IDAES and COIN solvers on Google Colab #1237
Conversation
Contributes script to install IDAES and COIN solvers on Google Colab
@jsiirola is another good reviewer. I'd like feedback on:
|
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.
In addition to the specific comments below, there are several general changes that should be made:
- fix the identified spelling errors
- remove the logic for direct downloads from
ampl.com
- I would suggest replacing (all?) uses of
os.system
withsubprocess.run
scripts/colab_helper.py
Outdated
''' | ||
|
||
# Check if idaes is available. If not, install it | ||
if not package_available("idaes"): |
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 don't think that looking for the IDAES executable is the best way to see if the package has been installed. Rather, I would recommend:
try:
import idaes
print("IDAES found! No need to install.")
except ImportError:
print("Installing idaes via pip...")
subprocess.run([sys.executable, "-m", "pip", "install", "-q", "idaes_pse"], check=True)
print("idaes was successfully installed")
subprocess.run(["idaes", "--version'], check=True)
also note in the above:
- the use of
subprocess.run()
withcheck=True
- the use of an explicit argument list and not a single string
- the use of
sys.executable
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 the great suggestion. I implemented it.
scripts/colab_helper.py
Outdated
# Add symbolic link for idaes solvers | ||
# These are needed for Colab to find the solvers | ||
os.system("ln -s /root/.idaes/bin/ipopt ipopt") | ||
os.system("ln -s /root/.idaes/bin/k_aug k_aug") | ||
os.system("ln -s /root/.idaes/bin/couenne couenne") | ||
os.system("ln -s /root/.idaes/bin/bonmin bonmin") | ||
os.system("ln -s /root/.idaes/bin/cbc cbc") | ||
os.system("ln -s /root/.idaes/bin/clp clp") | ||
os.system("ln -s /root/.idaes/bin/ipopt_l1 ipopt_l1") | ||
os.system("ln -s /root/.idaes/bin/dot_sens dot_sens") |
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.
This is only needed for the command_with_output
below and if you don't import idaes
in your script. I generally don't think that it is a good idea to link / move installed files. Instead it would be better to either update where Pyomo looks for executables, or add /root/.idaes/bin
to the os.environ['PATH']
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 got the PATH alternative to work. Thanks for the great suggestion.
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.
Also, I want to make these solvers accessible without import idaes
for two reasons:
- Have the script print the solver versions, which is a good check and helpful for debugging.
- Reuse this script in workshops/classes/tutorials that introduce Pyomo. In my experience, skipping
import idaes
is easier with brand-new Pyomo users.
scripts/colab_helper.py
Outdated
# As a backup, try copying the executable from AMPL | ||
if on_colab(): | ||
print("Installing Ipopt via zip file...") | ||
os.system('wget -N -q "https://ampl.com/dl/open/ipopt/ipopt-linux64.zip"') |
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.
Note that direct (anonymous) wget
from ampl.com
no longer works: AMPL requires all downloads to first authenticate using a valid user account.
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 removed these.
…ATH is a better solution.
@jsiirola This is ready for you to review. @dangunter You might also find this helpful/interesting. I've been using a script like this to install Pyomo and IDAES in Google Colab for my graduate elective. |
@ksbeattie @lbianchi-lbl I have black on the most updated version of this one file on my computer; it said no changes. I also confirmed I do not have any uncommitted or unpushed changes. Yet the black test is still failing. For everyone: I tested this on Google Colab (hence several commits this morning.) I am not sure how to automate testing in Google Colab or if that is really even needed. |
@adowling2 |
@andrewlee94 Now that I have your attention, do you want to review this quickly? |
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.
This looks OK to me, but I am no expert on this sort of stuff.
Codecov ReportPatch coverage has no change and project coverage change:
Additional details and impacted files@@ Coverage Diff @@
## main #1237 +/- ##
==========================================
- Coverage 76.83% 76.83% -0.01%
==========================================
Files 390 390
Lines 61942 61942
Branches 11398 11398
==========================================
- Hits 47595 47592 -3
- Misses 11878 11882 +4
+ Partials 2469 2468 -1 ☔ View full report in Codecov by Sentry. |
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.
This is getting pretty close.
|
||
def _check_available(executable_name): | ||
"""Utility to check in an executable is available""" | ||
return shutil.which(executable_name) or os.path.isfile(executable_name) |
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.
(More of an FYI than an action) This is fine for collab (where we know it is Linux-based). However, a more portable approach would be to use something akin to Pyomo's pyomo.common.fileutils.Executable
(which is what Pyomo uses for locating executables)
["idaes", "--version"], check=True, capture_output=True, text=True | ||
) | ||
print(v.stdout) | ||
print(v.stderr) |
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.
If you are just going to print out the output anyway, why bother with capture=True
?
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 couldn't get the output to show up without using capture. I'm also new to using subprocess.
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.
My quick research (again, I know little about subprocess) suggests I'd need to use Popen to get access to STDOUT or STDERR.
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.
On the terminal, the output comes to the terminal if you don't specify capture_output
. I wonder if this is different for the collab environment? If that's the case, we want to at least be consistent and capture/print for all subprocess calls.
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 expected that behavior on Colab, but no luck when testing in a cell.
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.
@jsiirola, I like your suggestion. I added a verbose flag to display the captured pip, idaes get-extensions, etc. output
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 think having this script here can be valuable for users of IDAES on Google Colab in addition to and beyond the original audience. A few general thoughts:
- I don't think there's a way to test this automatically (without an unreasonable amount of effort)
- Since the script is tested and will continue to be used in the future, I think we can pragmatically rely on this "outside testing" to detect possible breaking changes
- However, since we're adding code to the repository that's not being tested by the CI, before merging, we should:
- Identify who the maintainer(s) of this script will be, e.g. by adding an entry to the
CODEOWNERS
file - Add some kind of simple versioning information to the script itself (since the script won't have access to either the Git history or the
idaes
version at runtime)
- Identify who the maintainer(s) of this script will be, e.g. by adding an entry to the
"https://raw.githubusercontent.com/adowling2/idaes-pse/colab-install-script/scripts/colab_helper.py" | ||
|
||
""" | ||
|
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'd recommend to add some versioning information, e.g. by adding a line here with __version__ = "0.23.8"
(or any other date-based versioning schema).
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.
Great suggestion
@jsiirola @lbianchi-lbl Thanks for the suggested changes. This should be ready. Changes:
|
@jsiirola @lbianchi-lbl This is ready for your re-review. |
Contributes script to install IDAES and COIN solvers on Google Colab
Fixes
Summary/Motivation:
Changes proposed in this PR:
Legal Acknowledgement
By contributing to this software project, I agree to the following terms and conditions for my contribution: