-
Notifications
You must be signed in to change notification settings - Fork 562
Introduce formal principle documentation to support contrib changes #3768
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
base: main
Are you sure you want to change the base?
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3768 +/- ##
=======================================
Coverage 89.44% 89.45%
=======================================
Files 905 905
Lines 105485 105485
=======================================
+ Hits 94355 94362 +7
+ Misses 11130 11123 -7
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
blnicho
left a comment
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 a bunch of minor edit suggestions but overall I think this looks great!
michaelbynum
left a comment
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 only about halfway done, but here are a couple comments/questions.
michaelbynum
left a comment
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 some minor comments, but I think this looks great overall.
doc/OnlineDocs/principles.rst
Outdated
| change until the next major Pyomo release, which will coincide with a | ||
| new edition of the book. |
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.
While this is what we currently do, it is a strong statement/commitment. I'm fine with this, but I wanted to flag it for discussion.
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.
Yeah, I might be for hedging and just saying next major Pyomo release and failing to mention the promise of books?
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 talked about this in the dev call today (loosely). This is our "current" approach but nothing says we can't change it in the future, especially after the next book.
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 can always hedge our promise with something like will hopefully coincide
|
|
||
| Functionality that is part of the Pyomo source tree but not explicitly | ||
| included in the book is also expected to be stable if it resides outside | ||
| the ``contrib`` (or future ``addons`` / ``devel``) directories. This is |
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.
should this just say "devel" instead of "addons / devel"? I think the contribution guide stated that addons was supposed to be stable as well.
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 specifically looking under "Namespaces for Contributed and Experimental Code" in contribution_guide.rst.
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 call it "mostly stable". I don't want to promise that addons is for sure stable.
pyomo/addons/README.md
Outdated
| - Represent functionality that is **useful to the wider Pyomo community** but | ||
| not required for core operation. |
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 this bullet adds any value, and I think it could be misconstrued.
pyomo/addons/README.md
Outdated
| Examples include: | ||
| - `gdpopt` | ||
| - `incidence_analysis` | ||
| - `latex_printer` | ||
| - `trustregion` | ||
| - `viewer` |
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.
can't people just look to see what is in the addons directory? Why list it here?
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 an answer to this one! Because as of this PR, there will be nothing in the addons directory, so I wanted to list some actual examples while we go through the process of actually moving everything.
pyomo/addons/README.md
Outdated
| - (PREFERABLE) A **reference page** in the Pyomo online documentation. | ||
| - (MINIMUM) A **README.md** file summarizing: | ||
| - Functionality | ||
| - Example usage or link to docs |
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 "or link to docs" answers one of my earlier questions.
pyomo/addons/README.md
Outdated
| - Declared in `setup.py` under the appropriate category. | ||
| - Publicly available on PyPI and/or Anaconda and reasonably maintained. | ||
|
|
||
| ### Backward Compatibility |
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 section a duplicate of "Stability and Maintenance" above?
pyomo/devel/README.md
Outdated
| Examples include: | ||
| - `doe` | ||
| - `piecewise` | ||
| - `solver` | ||
| - `sensitivity_toolbox` |
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.
Again, I don't think this list is needed.
| *.egg-info/ | ||
|
|
||
| # Documentation builds | ||
| doc/OnlineDocs/api |
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 auto-generated stuff?
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.
Yup - when you run make -C doc/OnlineDocs html, this is all the automatic api docs that get generated. Which are great, we love them, but I have almost accidentally committed them way too many times.
emma58
left a comment
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 nice--I put a lot of ideas in the comments.
| Optional Dependencies | ||
| ~~~~~~~~~~~~~~~~~~~~~ | ||
|
|
||
| Extensions to Pyomo, and many of the contributions in ``pyomo.contrib``, |
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.
Should pyomo.contrib be updated to be pyomo.addons and pyomo.devel here?
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.
Not yet. We aren't moving anything out of contrib as of this particular PR. This file should be updated when we do actually move things.
doc/OnlineDocs/principles.rst
Outdated
| * **Print statements:** Avoid printing directly to ``stdout``. Pyomo is a | ||
| library, not an application, and copious output can interfere with downstream | ||
| tools and workflows. Use the appropriate logger instead. Print | ||
| information only when the user has enabled or requested it. |
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.
Maybe we should add one about logging below this: We have settled on usually naming the logger using __name__, and I think we like that?
| * **Pull Request naming:** Pull Request titles are added to the CHANGELOG | ||
| and the release notes. The Pyomo development team reserves the right to | ||
| alter titles as appropriate to ensure they fit the look and feel of | ||
| other titles in the CHANGELOG. |
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.
@blnicho, didn't you have more specific guidance for this at one point too? Character limit and starting with "package:" or something like that that we fail to do most of the time?
| # This software is distributed under the 3-clause BSD License. | ||
| # ___________________________________________________________________________ | ||
| Update the year range as appropriate when modifying files. |
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.
A few more in-the-weeds ideas we could add to this list (or defer for a more in-the-weeds thing later--I'm not super attached to any of these, just brainstorming):
- Loud failure is always better than silent failure: Write code to guard against cases you don't expect, even if you just raise
NotImplementedErrorsto start rather than handling them. The worst Pyomo bugs are the ones that silently do wrong or unexpected math. - Along this vein, if the behavior a user could reasonably expect is ambiguous, document assumptions well and fail loudly when they are violated.
- Some Pyomo components are
ActiveComponentsand others are not (perhaps most importantly, Vars are not)... We define models to be the set of active components accessible from the root Block. This means many things, but in common gotchas, thatm.component_data_objects(Var, ...)is almost always a bad idea: Usually you wantget_vars_from_componentswithConstraintor(Constraint, Objective)as thectypeargument. - Writers and their ilk should always complain about active Pyomo components they do not recognize. (This is because Pyomo supports extended modeling environments such as DAE and GDP so it is easy to accidentally send unexpected structures to solvers expecting algebraic model formulations). There is a utility for this in
pyomo.repn.utilcalledcategorize_valid_components. - We prefer not to use component names (or strings in general) to keep track of them in writers, algorithms, etc.
pyomo.common.collectionsincludes data structures where unhashable components (e.g., Vars) can be used as keys. - We prefer PEP8 naming conventions (descriptive names, snake case for functions, pascal case for classes, etc.) and also prefer functions be verb phrases and classes be noun-ish.
- We have a deadly allergy to repeated (and especially copy-pasted) code--we're always happy to talk about design if something seems to be headed that way
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.
Edit to the third bullet based on dev call discussion: If you want to gather all the variables on the model, it is recommended to use get_vars_from_components with (Constraint, Objective) as the ctype argument. This is as opposed to m.component_data_objects(Var, ...), which will get all the Vars declared on the model hierarchy, which is highly unlikely to be what is desired, as it has no mathematical meaning.
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 strongly agree with all of these.
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.
Me too.
| @TransformationFactory.register( | ||
| 'contrib.example.xfrm', | ||
| doc="An example of a transformation in a pyomo.contrib package", | ||
| 'devel.example.xfrm', doc="An example of a transformation in a pyomo.devel package" | ||
| ) | ||
| class Xfrm_PyomoTransformation(Transformation): | ||
| def __init__(self): |
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.
Perhaps while we're making this change, we should adjust naming here? I'd suggest devel.example.transform with a class name of just ExamplePyomoTransformation or something. I also think it would be good to not have a plugins directory in example and just flatten it out like we wish we had so many other places...
|
|
||
| As a result, Pyomo is transitioning to a more structured contribution | ||
| model with two clear namespaces: | ||
|
|
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.
| * ``pyomo`` core - These modules form the foundation of the Pyomo environment, | |
| including the base expression systems, modeling components, model compilers, | |
| and solver interfaces. The core development team has committed to | |
| maintaining these capabilities, adhering to the strictest policies for | |
| testing and backwards compatibility. |
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 with the words but not the placement here. I put them above so it doesn't confuse the message here, which is primarily focused on, "This is how we are splitting pyomo.contrib."
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.
| * **File headers:** Every ``.py`` file must begin with the standard Pyomo | ||
| copyright header: | ||
|
|
||
| .. code-block:: text |
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.
Can this be .. literalinclude::'ed from pyomo/__init__.py (that way the documentation is kept in sync with the codebase)?
| # This software is distributed under the 3-clause BSD License. | ||
| # ___________________________________________________________________________ | ||
| Update the year range as appropriate when modifying files. |
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.
Me too.
| from pyomo.contrib.example.foo import * | ||
| from pyomo.contrib.example import bar | ||
| from pyomo.devel.example.foo import a | ||
| from pyomo.devel.example import bar |
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 would like to propose removing contrib/example entirely and replacing it with a section in the Online Docs
| prototypes, or specialized modeling components. Functionality under | ||
| this namespace may change or be removed between releases without | ||
| deprecation warnings. | ||
|
|
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.
Reminder for myself to add in pyomo.unsupported as another new unique namespace.
Fixes None but starts to address #2460
Summary/Motivation:
Stage 1 of the changes inside
pyomo.contribis documenting a lot of different development principles that make the change a lot more reasonably understandable. This PR creates the new directories with their basic READMEs as well as creates documentation about our overarching development principles, including a teaser to the upcoming changes incontribas part of their contents.Changes proposed in this PR:
addonsanddevelprinciples.rstdocumentationdoc/OnlineDocs/apiin .gitignore because I have almost accidentally committed those files WAY too many timesLegal Acknowledgement
By contributing to this software project, I have read the contribution guide and agree to the following terms and conditions for my contribution: