-
Notifications
You must be signed in to change notification settings - Fork 529
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
[PEP] Standardizing Pyomo Imports in examples as "import pyomo.environ as pyo" #1026
Comments
We should also propagate whatever import convention we choose to the workshop slides, examples, and exercises. I personally use |
I concur with @blnicho - and prefer to adopt "import pyomo.environ as pro" following our colleagues at NPS and elsewhere. |
Assuming you meant "pyo" instead of "pro", I agree as well. |
Whoops - yes. Stupid autocorrect. Or neurons. |
Bill above asked us to list comments against the use of an alias. The only one I can think about is that it adds some additional "pyo." to our code - that might not look as nice in examples. (maybe). This could be overcome with explicit imports (e.g., from pyomo.environ import ConcreteModel, Constraint, Objective, ...). But that list would get extensive, and I don't favor that approach over the pyo approach. |
We could ask everyone if they like "std::endl" or "endl" better - I bet the survey would predict who does and doesn't like aliases almost perfectly. For the record, I personally believe that "using namespace std" is evil. Sure, the alias makes short examples slightly longer. But the clarity has to outweigh the conciseness. |
I agree with standardizing to pyo; however, an interesting debate is based on the following: When Bill says "and provide more complete examples if we use an alias like 'pyo'" he seems to imply that every code snippet that uses pyo would , at a minimum, need to include There are many python packages that do that sort of thing, but our situation is a little different. Many of our code snippets rely on lots of things that are not rendered to the screen. These snippets are not intended to serve as a tutorial, but rather to let a user remember, or learn, a particular syntax. |
@DLWoodruff FWIW, I'm OK not adding the import alias in every example, but per a user suggestion we should include a simple example at the beginning of our documentation to establish this convention. |
I am going to do this when I get annoyed with solver refactor stuff. It's a good mindless-esque task. |
(Edited by @carldlaird)
This PEP advocates use of the "pyo" alias throughout the documentation, pyomo examples, and tutorials.
Motivation
Users find it confusing that we have not "standardized" on a particular approach for imports (some use
from pyomo.environ import *
, some useimport pyomo.environ as pe
, and some useimport pyomo.environ as pyo
). We also agree that it is generally bad practice to import *, and would prefer to use advocate the use of a named alias when importing pyomo.environ.Implementation
Standardize on "import pyomo.environ as pyo".
This will need to be done for:
@carldlaird has agreed to implement this PEP.
Original Introduction from @whart222 included below:
Currently, three conventions are used in the Pyomo online documentation for importing Pyomo:
"""
from pyomo.environ import *
"""
"""
import pyomo.environ as pyo
"""
"""
import pyomo.environ
from pyomo.opt import SolverFactory
"""
A brand new user recently noted how confusing this made the online documentation. The fact that 'pyo' was used was particularly confusing because that alias is not included in most examples.
We need to standardize documentation to avoid such confusion, and provide more complete examples if we use an alias like 'pyo'. I think this PEP should include a specific recommendation to either use 'pyo' or not. Let's include comments for/against.
The text was updated successfully, but these errors were encountered: