From 1eb1105da2cbc882755d1c1b0edf438afb468d45 Mon Sep 17 00:00:00 2001 From: Varchas Gopalaswamy Date: Wed, 3 Apr 2024 18:50:13 -0400 Subject: [PATCH] added docs --- docs/Makefile | 20 ++++++ docs/basic_usage.rst | 56 ++++++++++++++++ docs/conf.py | 102 +++++++++++++++++++++++++++++ docs/getting_started.rst | 18 +++++ docs/index.rst | 23 +++++++ docs/make.bat | 35 ++++++++++ docs/numpy_integration.rst | 33 ++++++++++ docs/pandas_integration.rst | 0 docs/requirements.txt | 6 ++ docs/source/auto_uncertainties.rst | 45 +++++++++++++ docs/source/modules.rst | 7 ++ 11 files changed, 345 insertions(+) create mode 100644 docs/Makefile create mode 100644 docs/basic_usage.rst create mode 100644 docs/conf.py create mode 100644 docs/getting_started.rst create mode 100644 docs/index.rst create mode 100644 docs/make.bat create mode 100644 docs/numpy_integration.rst create mode 100644 docs/pandas_integration.rst create mode 100644 docs/requirements.txt create mode 100644 docs/source/auto_uncertainties.rst create mode 100644 docs/source/modules.rst diff --git a/docs/Makefile b/docs/Makefile new file mode 100644 index 0000000..d4bb2cb --- /dev/null +++ b/docs/Makefile @@ -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) diff --git a/docs/basic_usage.rst b/docs/basic_usage.rst new file mode 100644 index 0000000..cfefb92 --- /dev/null +++ b/docs/basic_usage.rst @@ -0,0 +1,56 @@ +Basic Usage +================ + +The goal is to have minimal changes to your code in order to enable uncertainty propagation. + +Creating a scalar Uncertainty variable is relatively simple: + +.. code-block:: python + + >>> from auto_uncertainties import Uncertainty + >>> value = 1.0 + >>> error = 0.1 + >>> u = Uncertainty(value,error) + >>> u + 1.0 +/- 0.1 + + +Scalar uncertainties implement all mathematical and logical `dunder methods `_ explicitly using linear uncertainty propagation. + +.. code-block:: python + + >>> from auto_uncertainties import Uncertainty + >>> u = Uncertainty(10.0, 3.0) + >>> v = Uncertainty(20.0, 4.0) + >>> u + v + 30.0 +/- 5.0 + + +The central value, uncertainty and relative error are available as attributes + +.. code-block:: python + + >>> from auto_uncertainties import Uncertainty + >>> u = Uncertainty(10.0, 3.0) + >>> u.value + 10.0 + >>> u.error + 3.0 + >>> u.rel + 0.33333 + +To strip central values and uncertainty from arbitrary variables, accessor functions `nominal_values` and `std_devs` are provided + +.. code-block:: python + + >>> from auto_uncertainties import nominal_values, std_devs + >>> u = Uncertainty(10.0, 3.0) + >>> v = 5.0 + >>> nominal_values(u) + 10.0 + >>> std_devs(u) + 3.0 + >>> nominal_values(v) + 5.0 + >>> std_devs(v) + 0.0 diff --git a/docs/conf.py b/docs/conf.py new file mode 100644 index 0000000..4767af6 --- /dev/null +++ b/docs/conf.py @@ -0,0 +1,102 @@ +# -*- coding: utf-8 -*- +from __future__ import annotations + +import datetime +import importlib.metadata + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. +# +import os +import sys + +import sphinx_rtd_theme # noqa: F401 + +# -- Path setup -------------------------------------------------------------- + + +sys.path.insert(0, os.path.abspath("../../")) +# -- Project information ----------------------------------------------------- +# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information + +project = "auto_uncertainties" +version = importlib.metadata.version(project) +release = version +this_year = datetime.date.today() +copyright = f"2021-{this_year:%Y}, Varchas Gopalaswamy" +author = "Varchas Gopalaswamy" + +# -- General configuration --------------------------------------------------- +# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration + +extensions = [ + "sphinx.ext.autodoc", + "sphinx.ext.intersphinx", + "sphinx.ext.coverage", + "sphinx.ext.viewcode", + "sphinx.ext.mathjax", + "sphinx_rtd_theme", + "sphinx_autodoc_typehints", + "sphinx_copybutton", +] + + +templates_path = ["_templates"] +exclude_patterns = [ + "_build", + "Thumbs.db", + ".DS_Store", + "setup.rst", + "versioneer.rst", + "tests*", +] + + +# The name of the Pygments (syntax highlighting) style to use. +pygments_style = "sphinx" + +# The suffix of source filenames. +source_suffix = ".rst" + +# The master toctree document. +master_doc = "index" + +autodoc_default_options = {"class-doc-from": "__init__"} + +add_function_parentheses = False +# -- Options for extensions ---------------------------------------------------- +# napoleon + +typehints_defaults = "comma" +typehints_use_rtype = True +typehints_document_rtype = True +always_document_param_types = True +# -- Options for HTML output ------------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +# +html_theme = "sphinx_rtd_theme" + +html_title = f"{project} v{version} Manual" + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +html_static_path = ["_static"] + + +default_role = "py:obj" + + +# Example configuration for intersphinx: refer to the Python standard library. +intersphinx_mapping = { + "python": ("https://docs.python.org/3/", None), + "numpy": ("https://numpy.org/doc/stable", None), + "matplotlib": ("https://matplotlib.org/stable/", None), + "dask": ("https://docs.dask.org/en/latest", None), + "sparse": ("https://sparse.pydata.org/en/latest/", None), + "pint": ("https://pint.readthedocs.io/en/stable", None), + "pandas": ("https://pandas.pydata.org/docs/", None), +} diff --git a/docs/getting_started.rst b/docs/getting_started.rst new file mode 100644 index 0000000..7520199 --- /dev/null +++ b/docs/getting_started.rst @@ -0,0 +1,18 @@ + +Getting started +========================== + +:code:`auto_uncertainties` is easy to install via :code:`pip` + + +.. code:: bash + + pip install auto_uncertainties + + +The integration with pandas (still WIP) can be enabled by installing pandas, either separately or via + + +.. code:: bash + + pip install auto_uncertainties[pandas] diff --git a/docs/index.rst b/docs/index.rst new file mode 100644 index 0000000..730cdd2 --- /dev/null +++ b/docs/index.rst @@ -0,0 +1,23 @@ +.. AutoUncertainties documentation master file, created by + sphinx-quickstart on Wed Apr 3 18:26:30 2024. + You can adapt this file completely to your liking, but it should at least + contain the root `toctree` directive. + +Welcome to AutoUncertainties's documentation! +============================================= + +.. toctree:: + :maxdepth: 2 + :caption: Contents: + + getting_started + basic_usage + numpy_integration + pandas_integration + +Indices and tables +================== + +* :ref:`genindex` +* :ref:`modindex` +* :ref:`search` diff --git a/docs/make.bat b/docs/make.bat new file mode 100644 index 0000000..32bb245 --- /dev/null +++ b/docs/make.bat @@ -0,0 +1,35 @@ +@ECHO OFF + +pushd %~dp0 + +REM Command file for Sphinx documentation + +if "%SPHINXBUILD%" == "" ( + set SPHINXBUILD=sphinx-build +) +set SOURCEDIR=. +set BUILDDIR=_build + +%SPHINXBUILD% >NUL 2>NUL +if errorlevel 9009 ( + echo. + echo.The 'sphinx-build' command was not found. Make sure you have Sphinx + echo.installed, then set the SPHINXBUILD environment variable to point + echo.to the full path of the 'sphinx-build' executable. Alternatively you + echo.may add the Sphinx directory to PATH. + echo. + echo.If you don't have Sphinx installed, grab it from + echo.https://www.sphinx-doc.org/ + exit /b 1 +) + +if "%1" == "" goto help + +%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% +goto end + +:help +%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% + +:end +popd diff --git a/docs/numpy_integration.rst b/docs/numpy_integration.rst new file mode 100644 index 0000000..ff6a961 --- /dev/null +++ b/docs/numpy_integration.rst @@ -0,0 +1,33 @@ +Numpy Integration +================ + +Using `Jax `_ to provide auto-differentiation capabilities (either :code:`jax.grad` or :code:`jax.jacfwd`), linear uncertainty propagation is enabled for most numpy operations + +.. code-block:: python + + >>> from auto_uncertainties import Uncertainty + >>> import numpy as np + >>> value = np.linspace(start=0,stop=10,num=5) + >>> error = np.ones_like(value)*0.1 + >>> u = Uncertainty(value,error) + >>> u + [ 0. 2.5 5. 7.5 10. ] +/- [0.1 0.1 0.1 0.1 0.1] + + +.. code-block:: python + + >>> from auto_uncertainties import Uncertainty + >>> import numpy as np + >>> value = np.linspace(start=0,stop=10,num=5) + >>> error = np.ones_like(value)*0.1 + >>> u = Uncertainty(value,error) + >>> np.exp(u) + [1.00000000e+00 1.21824940e+01 1.48413159e+02 1.80804241e+03 + 2.20264658e+04] +/- [1.00000000e-01 1.21824940e+00 1.48413159e+01 1.80804241e+02 + 2.20264658e+03] + >>> np.sum(u) + 25.0 +/- 0.223606797749979 + >>> u.sum() + 25.0 +/- 0.223606797749979 + >>> np.sqrt(np.sum(error**2)) + 0.223606797749979 diff --git a/docs/pandas_integration.rst b/docs/pandas_integration.rst new file mode 100644 index 0000000..e69de29 diff --git a/docs/requirements.txt b/docs/requirements.txt new file mode 100644 index 0000000..5492c41 --- /dev/null +++ b/docs/requirements.txt @@ -0,0 +1,6 @@ +sphinx >= 4.1.2 +sphinx_rtd_theme >= 1.0.0 +sphinxcontrib-bibtex >= 2.3.1 +sphinxcontrib-napoleon >= 0.7 +sphinx_autodoc_typehints +sphinx-copybutton diff --git a/docs/source/auto_uncertainties.rst b/docs/source/auto_uncertainties.rst new file mode 100644 index 0000000..10a5a77 --- /dev/null +++ b/docs/source/auto_uncertainties.rst @@ -0,0 +1,45 @@ +auto\_uncertainties package +=========================== + +Submodules +---------- + +auto\_uncertainties.pandas\_compat module +----------------------------------------- + +.. automodule:: auto_uncertainties.pandas_compat + :members: + :undoc-members: + :show-inheritance: + +auto\_uncertainties.uncertainty module +-------------------------------------- + +.. automodule:: auto_uncertainties.uncertainty + :members: + :undoc-members: + :show-inheritance: + +auto\_uncertainties.util module +------------------------------- + +.. automodule:: auto_uncertainties.util + :members: + :undoc-members: + :show-inheritance: + +auto\_uncertainties.wrap\_numpy module +-------------------------------------- + +.. automodule:: auto_uncertainties.wrap_numpy + :members: + :undoc-members: + :show-inheritance: + +Module contents +--------------- + +.. automodule:: auto_uncertainties + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/source/modules.rst b/docs/source/modules.rst new file mode 100644 index 0000000..bd0e96b --- /dev/null +++ b/docs/source/modules.rst @@ -0,0 +1,7 @@ +auto_uncertainties +================== + +.. toctree:: + :maxdepth: 4 + + auto_uncertainties