Skip to content

Commit c157587

Browse files
authored
Merge pull request #3378 from jsiirola/doc-index
Autogenerate API documentation
2 parents f093e88 + c29de6b commit c157587

File tree

303 files changed

+4915
-2856
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

303 files changed

+4915
-2856
lines changed

doc/Archive/contributed_packages/parmest/driver.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Parameter Estimation
66
Parameter Estimation using parmest requires a Pyomo model, experimental
77
data which defines multiple scenarios, and parameters
88
(thetas) to estimate. parmest uses Pyomo [PyomoBookII]_ and (optionally)
9-
mpi-sppy [mpisppy]_ to solve a
9+
mpi-sppy [KMM+23]_ to solve a
1010
two-stage stochastic programming problem, where the experimental data is
1111
used to create a scenario tree. The objective function needs to be
1212
written with the Pyomo Expression for first stage cost

doc/OnlineDocs/Makefile

+4-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ SPHINXBUILD = sphinx-build
77
SPHINXPROJ = Pyomo
88
SOURCEDIR = .
99
BUILDDIR = _build
10+
APIDIR = api
1011

1112
# Put it first so that "make" without argument is like "make help".
1213
help:
@@ -23,9 +24,9 @@ clean:
2324
@$(SPHINXBUILD) -M clean "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
2425
@echo "Removing *.spy, *.out"
2526
@find . -name \*.spy -delete
27+
@for D in $(BUILDDIR) $(SOURCEDIR)/$(APIDIR); do \
28+
if test -d "$$D"; then echo "Removing $$D"; rm -r "$$D"; fi \
29+
done
2630

2731
rebuild:
2832
@$(MAKE) clean
29-
@for D in $(BUILDDIR) $(SOURCEDIR)/reference/API; do \
30-
if test -d "$$D"; then echo "Removing $$D"; rm -r "$$D"; fi \
31-
done

doc/OnlineDocs/README.md

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
Pyomo leverages ``make`` to generate documentation. The following two
2+
sections describe how to build and test the online documentation
3+
locally.
4+
5+
.. note::
6+
7+
All commands assume you are running from the `root Pyomo source directory`.
8+
9+
10+
Preview Changes Locally
11+
------------------------
12+
13+
1. Install documentation dependencies (e.g., Sphinx, etc):
14+
15+
```bash
16+
$ pip install -e .[docs]
17+
```
18+
19+
**NOTE**: You may get a warning about the `dot` command if you do not have
20+
`graphviz` installed.
21+
22+
2. Build the documentation. Sphinx (and Pyomo) support multiple
23+
documentation `targets`. These instructions describe building the
24+
`html` target, but the same process applies for other targets.
25+
26+
```bash
27+
$ make -C doc/OnlineDocs html
28+
```
29+
30+
3. View ``doc/OnlineDocs/_build/html/index.html`` in your browser
31+
32+
Test Changes Locally
33+
--------------------
34+
35+
```bash
36+
$ make -C doc/OnlineDocs doctest
37+
```
38+
39+
Rebuilding the documentation
40+
----------------------------
41+
42+
Sphinx caches significant amounts of work at the end of a documentation
43+
build. However, if you are in the process of editing the documentation,
44+
it may not correctly invalidate the cache. You can purge the entire
45+
cache with
46+
47+
```bash
48+
$ make -C doc/OnlineDocs clean
49+
```
50+
51+
Combining steps
52+
---------------
53+
54+
These steps can, of course, be combined into a single command:
55+
56+
```bash
57+
$ make -c doc/OnlineDocs clean html doctest
58+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{{ name | escape | underline}}
2+
3+
({{ objtype }} from :py:mod:`{{ module }}`)
4+
5+
.. testsetup:: *
6+
7+
# import everything from the module containing this class so that
8+
# doctests for the class docstrings see the correct environment
9+
from {{ module }} import *
10+
11+
.. currentmodule:: {{ module }}
12+
13+
.. auto{{ objtype }}:: {{ objname }}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{{ name | escape | underline}}
2+
3+
(class from :py:mod:`{{ module }}`)
4+
5+
.. testsetup:: *
6+
7+
# import everything from the module containing this class so that
8+
# doctests for the class docstrings see the correct environment
9+
from {{ module }} import *
10+
11+
.. currentmodule:: {{ module }}
12+
13+
{# Note that numpy.ndarray examples fail doctest; disable documentation
14+
of inherited members for classes derived from ndarray #}
15+
16+
.. autoclass:: {{ objname }}
17+
:members:
18+
:show-inheritance:
19+
{{ '' if (module + '.' + name) in (
20+
'pyomo.contrib.pynumero.sparse.block_vector.BlockVector',
21+
'pyomo.contrib.pynumero.sparse.mpi_block_vector.MPIBlockVector',
22+
'pyomo.core.expr.ndarray.NumericNDArray',
23+
) else ':inherited-members:' }}
24+
25+
{% block methods %}
26+
.. automethod:: __init__
27+
28+
{% if methods %}
29+
.. rubric:: {{ _('Methods') }}
30+
31+
.. autosummary::
32+
{% for item in methods %}
33+
~{{ name }}.{{ item }}
34+
{%- endfor %}
35+
{% endif %}
36+
{% endblock %}
37+
38+
{% block attributes %}
39+
{% if attributes %}
40+
.. rubric:: {{ _('Attributes') }}
41+
42+
.. autosummary::
43+
{% for item in attributes %}
44+
~{{ name }}.{{ item }}
45+
{%- endfor %}
46+
{% endif %}
47+
{% endblock %}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
{% if fullname == 'pyomo' %}
2+
Library Reference
3+
=================
4+
{% else %}
5+
{{ name | escape | underline}}
6+
{% endif %}
7+
8+
.. automodule:: {{ fullname }}
9+
:undoc-members:
10+
11+
{% block attributes %}
12+
{%- if attributes %}
13+
.. rubric:: {{ _('Module Attributes') }}
14+
15+
.. autosummary::
16+
:toctree:
17+
:template: recursive-base.rst
18+
{% for item in attributes %}
19+
{{ item }}
20+
{%- endfor %}
21+
{% endif %}
22+
{%- endblock %}
23+
24+
{%- block functions %}
25+
{%- if functions %}
26+
.. rubric:: {{ _('Functions') }}
27+
28+
.. autosummary::
29+
:toctree:
30+
:template: recursive-base.rst
31+
{% for item in functions %}
32+
{{ item }}
33+
{%- endfor %}
34+
{% endif %}
35+
{%- endblock %}
36+
37+
{%- block classes %}
38+
{%- if classes %}
39+
.. rubric:: {{ _('Classes') }}
40+
41+
.. autosummary::
42+
:toctree:
43+
:template: recursive-class.rst
44+
{% for item in classes %}
45+
{{ item }}
46+
{%- endfor %}
47+
{% endif %}
48+
{%- endblock %}
49+
50+
{%- block exceptions %}
51+
{%- if exceptions %}
52+
.. rubric:: {{ _('Exceptions') }}
53+
54+
.. autosummary::
55+
:toctree:
56+
:template: recursive-class.rst
57+
{% for item in exceptions %}
58+
{{ item }}
59+
{%- endfor %}
60+
{% endif %}
61+
{%- endblock %}
62+
63+
{%- block modules %}
64+
{%- if modules %}
65+
.. rubric:: Modules
66+
67+
.. autosummary::
68+
:toctree:
69+
:template: recursive-module.rst
70+
:recursive:
71+
{% for item in modules %}
72+
{# Need item != tests for Sphinx >= 8.0; !endswith(.tests) for < 8.0 #}
73+
{% if item != 'tests' and not item.endswith('.tests')
74+
and item != 'examples' and not item.endswith('.examples') %}
75+
{{ item }}
76+
{% endif %}
77+
{%- endfor %}
78+
{% endif %}
79+
{%- endblock %}

doc/OnlineDocs/code.rst

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
:orphan:
2+
3+
.. autosummary::
4+
:toctree: api
5+
:caption: Library Reference
6+
:template: recursive-module.rst
7+
:recursive:
8+
9+
pyomo

doc/OnlineDocs/conf.py

+40-11
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
'pandas': ('https://pandas.pydata.org/docs/', None),
5959
'scikit-learn': ('https://scikit-learn.org/stable/', None),
6060
'scipy': ('https://docs.scipy.org/doc/scipy/', None),
61-
'Sphinx': ('https://www.sphinx-doc.org/en/master/', None),
6261
}
6362

6463
# -- General configuration ------------------------------------------------
@@ -84,8 +83,6 @@
8483
'sphinx.ext.todo',
8584
'sphinx_copybutton',
8685
'enum_tools.autoenum',
87-
'sphinx.ext.autosectionlabel',
88-
#'sphinx.ext.githubpages',
8986
]
9087

9188
viewcode_follow_imported_members = True
@@ -108,7 +105,7 @@
108105

109106
# General information about the project.
110107
project = u'Pyomo'
111-
copyright = u'2008-2023, Sandia National Laboratories'
108+
copyright = u'2008-2024, Sandia National Laboratories'
112109
author = u'Pyomo Developers'
113110

114111
# The version info for the project you're documenting, acts as replacement for
@@ -132,7 +129,21 @@
132129
# List of patterns, relative to source directory, that match files and
133130
# directories to ignore when looking for source files.
134131
# This patterns also effect to html_static_path and html_extra_path
135-
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
132+
# Notes:
133+
# - _build : this is the Sphinx build (output) dir
134+
#
135+
# - api/*.tests.* : this matches autosummary RST files generated for
136+
# test modules. Note that the _templates/recursive-modules.rst
137+
# should prevent these file from being generated, so this is not
138+
# strictly necessary, but including it makes Sphinx throw warnings if
139+
# the filter in the template ever "breaks"
140+
#
141+
# - **/tests/** : this matches source files in any tests directory
142+
# [JDS: I *believe* this is necessary, but am not 100% certain]
143+
#
144+
# - 'Thumbs.db', '.DS_Store' : these have been included from the
145+
# beginning. Unclear if they are still necessary
146+
exclude_patterns = ['_build', 'api/*.tests.*', '**/tests/**', 'Thumbs.db', '.DS_Store']
136147

137148
# The name of the Pygments (syntax highlighting) style to use.
138149
pygments_style = 'sphinx'
@@ -168,7 +179,7 @@
168179
# further. For a list of options available for each theme, see the
169180
# documentation.
170181
#
171-
# html_theme_options = {}
182+
html_theme_options = {'navigation_depth': 6, 'titles_only': True}
172183

173184
# Add any paths that contain custom static files (such as style sheets) here,
174185
# relative to this directory. They are copied after the builtin static files,
@@ -235,6 +246,9 @@
235246
# autodoc_member_order = 'bysource'
236247
# autodoc_member_order = 'groupwise'
237248

249+
autosummary_generate = True
250+
autosummary_ignore_module_all = True
251+
238252
# -- Check which conditional dependencies are available ------------------
239253
# Used for skipping certain doctests
240254
from sphinx.ext.doctest import doctest
@@ -267,20 +281,25 @@ def check_output(self, want, got, optionflags):
267281
platform.python_implementation()
268282
)
269283
284+
# We need multiprocessing because some doctests must be skipped if the
285+
# start method is not "fork"
286+
import multiprocessing
287+
288+
# (register plugins, make environ available to tests)
289+
import pyomo.environ as pyo
290+
270291
from pyomo.common.dependencies import (
271292
attempt_import, numpy_available, scipy_available, pandas_available,
272293
yaml_available, networkx_available, matplotlib_available,
273-
pympler_available, dill_available,
294+
pympler_available, dill_available, pint_available,
295+
numpy as np,
274296
)
275-
pint_available = attempt_import('pint', defer_import=False)[1]
276297
from pyomo.contrib.parmest.parmest import parmest_available
277298
278-
import pyomo.environ as _pe # (trigger all plugin registrations)
279-
import pyomo.opt as _opt
280-
281299
# Not using SolverFactory to check solver availability because
282300
# as of June 2020 there is no way to suppress warnings when
283301
# solvers are not available
302+
import pyomo.opt as _opt
284303
ipopt_available = bool(_opt.check_available_solvers('ipopt'))
285304
sipopt_available = bool(_opt.check_available_solvers('ipopt_sens'))
286305
k_aug_available = bool(_opt.check_available_solvers('k_aug'))
@@ -291,6 +310,11 @@ def check_output(self, want, got, optionflags):
291310
292311
baron = _opt.SolverFactory('baron')
293312
313+
if numpy_available:
314+
# Recent changes on GHA seem to have dropped the default precision
315+
# from 8 to 4; restore the default.
316+
np.set_printoptions(precision=8)
317+
294318
if numpy_available and scipy_available:
295319
import pyomo.contrib.pynumero.asl as _asl
296320
asl_available = _asl.AmplInterface.available()
@@ -302,6 +326,11 @@ def check_output(self, want, got, optionflags):
302326
ma27_available = False
303327
mumps_available = False
304328
329+
# Mark that we are testing code (in this case, testing the documentation)
305330
from pyomo.common.flags import in_testing_environment
306331
in_testing_environment(True)
332+
333+
# Prevent any Pyomo logs from propagating up to the doctest logger
334+
import logging
335+
logging.getLogger('pyomo').propagate = False
307336
'''

doc/OnlineDocs/explanation/analysis/alternative_solutions.rst

+6
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,20 @@ Interface Documentation
9494
.. currentmodule:: pyomo.contrib.alternative_solutions
9595

9696
.. autofunction:: enumerate_binary_solutions
97+
:noindex:
9798

9899
.. autofunction:: enumerate_linear_solutions
100+
:noindex:
99101

100102
.. autofunction:: pyomo.contrib.alternative_solutions.lp_enum_solnpool.enumerate_linear_solutions_soln_pool
103+
:noindex:
101104

102105
.. autofunction:: gurobi_generate_solutions
106+
:noindex:
103107

104108
.. autofunction:: obbt_analysis_bounds_and_solutions
109+
:noindex:
105110

106111
.. autoclass:: Solution
112+
:noindex:
107113

0 commit comments

Comments
 (0)