-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Sphinx docs and enable ReadTheDocs build (#13)
* Remove WaterTAP-specific how-to pages * Move existing files * Add core files for Sphinx docs * Add minimal installation instructions * Add ReadTheDocs config file * Reformat with Black * Add basic GHA check for docs build * Try resolving failures for Python 3.8 * Try fixing Codecov upload error * Try fixing workflow syntax error * Try with space * Try downgrading Codecov CLI due to codecov/codecov-action#1487
- Loading branch information
1 parent
4bf6514
commit cf93acc
Showing
15 changed files
with
279 additions
and
612 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# .readthedocs.yaml | ||
# Read the Docs configuration file | ||
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details | ||
|
||
# Required | ||
version: 2 | ||
|
||
# Build documentation in the docs/ directory with Sphinx | ||
sphinx: | ||
fail_on_warning: true | ||
|
||
build: | ||
os: ubuntu-22.04 | ||
tools: | ||
python: "3.10" | ||
|
||
python: | ||
install: | ||
- requirements: requirements-dev.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Minimal makefile for Sphinx documentation | ||
# | ||
|
||
# You can set these variables from the command line, and also | ||
# from the environment for the first two. | ||
SPHINXOPTS ?= | ||
SPHINXBUILD ?= sphinx-build | ||
SOURCEDIR = . | ||
BUILDDIR = _build | ||
|
||
# Put it first so that "make" without argument is like "make help". | ||
help: | ||
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) | ||
|
||
.PHONY: help Makefile | ||
|
||
# Catch-all target: route all unknown targets to Sphinx using the new | ||
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). | ||
%: Makefile | ||
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
from importlib import metadata | ||
|
||
# Configuration file for the Sphinx documentation builder. | ||
# | ||
# For the full list of built-in configuration values, see the documentation: | ||
# https://www.sphinx-doc.org/en/master/usage/configuration.html | ||
|
||
# -- Project information ----------------------------------------------------- | ||
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information | ||
|
||
project = "Parameter Sweep" | ||
copyright = "2024, WaterTAP" | ||
author = "WaterTAP" | ||
|
||
release = version = metadata.version("parameter-sweep") | ||
|
||
# -- General configuration --------------------------------------------------- | ||
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration | ||
|
||
extensions = [ | ||
"sphinx_rtd_theme", | ||
"sphinx.ext.doctest", | ||
"sphinx.ext.napoleon", | ||
"autoapi.extension", | ||
"sphinx.ext.intersphinx", | ||
] | ||
suppress_warnings = [] | ||
|
||
templates_path = ["_templates"] | ||
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"] | ||
|
||
# see https://sphinx-autoapi.readthedocs.io/en/latest/reference/config.html | ||
autoapi_dirs = ["../src"] | ||
autoapi_root = "technical_reference" | ||
autoapi_options = [ | ||
"members", | ||
"undoc-members", | ||
"show-module-summary", | ||
] | ||
# set to True to save the autogenerated | ||
autoapi_keep_files = False | ||
autoapi_ignore = [ | ||
"*conftest.py", | ||
"*test_*.py", | ||
"*tests/*.py", | ||
] | ||
# the warnings come from parameter_sweep._compat | ||
suppress_warnings += ["autoapi.python_import_resolution"] | ||
|
||
intersphinx_mapping = { | ||
"pyomo": ("https://pyomo.readthedocs.org/en/stable", None), | ||
"numpy": ("https://numpy.org/doc/1.26", None), | ||
} | ||
|
||
|
||
def _skip_tests(app, what: str, name: str, obj, skip, options): | ||
return skip | ||
|
||
|
||
def setup(sphinx): | ||
sphinx.connect("autoapi-skip-member", _skip_tests) | ||
|
||
|
||
# -- Options for HTML output ------------------------------------------------- | ||
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output | ||
|
||
html_theme = "sphinx_rtd_theme" | ||
html_static_path = ["_static"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Getting started | ||
=============== | ||
|
||
.. toctree:: | ||
:maxdepth: 1 | ||
|
||
installation | ||
parameter_sweep | ||
parallel_manager |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Installation | ||
------------ | ||
|
||
.. code-block:: bash | ||
pip install parameter-sweep |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
|
||
Parameter Sweep | ||
=============== | ||
|
||
.. currentmodule:: parameter_sweep.parameter_sweep | ||
|
||
Overview | ||
-------- | ||
|
||
The parameter sweep tool systematically fixes variables or modifies | ||
mutable parameters on a flowsheet (or Pyomo :class:`~pyomo.environ.ConcreteModel`), optimizes | ||
the flowsheet, and reports user-specified results. | ||
The parameter sweep tool can be operated in one of two ways: sweeping a | ||
fixed set of parameters, or allowing for random samples from a distribution. | ||
While different fixed or random sampling types can be combined, in a single | ||
parameter sweep the user must use either all fixed or all random sampling types. | ||
(This implementation detail may be relaxed in future releases.) | ||
|
||
For the "fixed" sampling type, :class:`LinearSample`, the parameter sweep tool will evaluate the | ||
cross product of all the specified parameters, whereas with the "random" sampling | ||
types :class:`UniformSample` and :class:`NormalSample` the parameter sweep tool will evaluate | ||
a fixed number of samples specified in :const:`num_samples`. With either sampling type, | ||
the values of the Pyomo objects (:class:`~pyomo.environ.Var` s, :class:`~pyomo.environ.NamedExpression` s, etc.), that the user specifies | ||
in `outputs`. | ||
|
||
For each item the user wants to change, they specify a `sweep_params` dictionary. | ||
The keys are "short" names, and the values are one of the included :class:`Sample` objects. | ||
In all cases the :class:`Sample` objects are instantiated with the Pyomo object to be changed, | ||
with additional arguements depending on the sampling type. For example, for the fixed | ||
:class:`LinearSample` the user would also specify a lower limit, an upper limit, and the number | ||
of elements to be sampled for this parameter between the lower limit and upper limit. | ||
Each item should be sampled at least twice to capture the upper and lower | ||
limit. The random :class:`UniformSample` requires a lower limit and upper limit, and the | ||
:class:`NormalSample` requires a mean and standard deviation. | ||
|
||
In addition to the parameters to sweep and the values to track for output, | ||
the user must provide an :const:`optimize_function`, which takes the :const:`model` as an | ||
attribute calls an optimization routine to solve it for the updated parameters. | ||
Should the call to :const:`optimize_function` fail, and a :const:`reinitialize_function` is not | ||
specified, the outputs will be reported as ``NaN`` for that parameter set. | ||
|
||
The user can optionally specify a :const:`reinitialize_function` in case any piece | ||
of the :const:`optimize_function` fails -- after the call to :const:`reinitialize_function` | ||
the model should be in a state ready to optimize again. If the :const:`reinitialize_function` | ||
or the second call to the :const:`optimize_function` fail for any reason, the outputs will | ||
be reported as ``NaN`` for that parameter set. | ||
|
||
The parameter sweep tool maintains the state of the flowsheet / Pyomo model between | ||
calls to :const:`optimize_function` to take advantage of initializations provided by | ||
earlier solutions. If this behavior is undesirable, the user should re-initialize | ||
their flowsheet as part of their :const:`optimize_function`. | ||
|
||
Finally, the user can specify a :const:`csv_results_file_name` and/or an :const:`h5_results_file_name`, | ||
which will write the outputs to disk in a CSV and/or H5 format, respectively. | ||
In the CSV results | ||
file, each column specifies a fixed parameter or the associated output, and each row | ||
is a single run with the specified parameters and resulting outputs. The H5 file | ||
contains the parameter sweep inputs and the outputs stored in a dictionary-like format. | ||
Additionally, when an H5 file is written, a companion text file is created with the name | ||
:const:`h5_results_file_name` + ``".txt"``. This text file contains the metadata of the H5 results | ||
file. | ||
|
||
Parallel Usage | ||
-------------- | ||
|
||
The parameter sweep tool can optionally utilize ``mpi4py`` to split the parameter | ||
sweep over multiple processors. If ``mpi4py`` is installed in the user's conda environment, | ||
a script utilizing the parameter sweep tool can be run in parallel, in this example | ||
using two threads. | ||
|
||
.. code:: bash | ||
mpiexec -n 2 python parameter_sweep_script.py | ||
For advanced users, the parameter sweep tool can optionally take a MPI communicator | ||
as an argument. |
Oops, something went wrong.