Skip to content

Commit

Permalink
added docs
Browse files Browse the repository at this point in the history
  • Loading branch information
varchasgopalaswamy committed Apr 3, 2024
1 parent 14d7676 commit 1eb1105
Show file tree
Hide file tree
Showing 11 changed files with 345 additions and 0 deletions.
20 changes: 20 additions & 0 deletions docs/Makefile
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)
56 changes: 56 additions & 0 deletions docs/basic_usage.rst
Original file line number Diff line number Diff line change
@@ -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 <https://docs.python.org/3/reference/datamodel.html#object.__repr__>`_ 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
102 changes: 102 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -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),
}
18 changes: 18 additions & 0 deletions docs/getting_started.rst
Original file line number Diff line number Diff line change
@@ -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]
23 changes: 23 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
@@ -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`
35 changes: 35 additions & 0 deletions docs/make.bat
Original file line number Diff line number Diff line change
@@ -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
33 changes: 33 additions & 0 deletions docs/numpy_integration.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
Numpy Integration
================

Using `Jax <https://jax.readthedocs.io/en/latest/>`_ 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
Empty file added docs/pandas_integration.rst
Empty file.
6 changes: 6 additions & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -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
45 changes: 45 additions & 0 deletions docs/source/auto_uncertainties.rst
Original file line number Diff line number Diff line change
@@ -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:
7 changes: 7 additions & 0 deletions docs/source/modules.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
auto_uncertainties
==================

.. toctree::
:maxdepth: 4

auto_uncertainties

0 comments on commit 1eb1105

Please sign in to comment.