Skip to content

Commit 2d97c97

Browse files
authored
Builds automatic documentation of the API (#103)
* Scaffolds automatic documentation of the API * Adds links to class implementations * Removes colons from attribute, raises, returns titles in docstrings * Fixes a colon in docstrings, to follow numpy standards * Adds documentation to the core module * Adds documentation to the objective factory module * Documents the objective script * Documents most functions inside the objective repository * Documents the remaining objective functions inside the repository * Adds several packages to the mock imports of autodoc * Removes the autogenerated rst files from git tracking
1 parent b0b165e commit 2d97c97

File tree

93 files changed

+1919
-472
lines changed

Some content is hidden

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

93 files changed

+1919
-472
lines changed

.github/workflows/python-tox-testing-including-conda.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
python -m pip install tox
2424
- name: Test linting with tox
2525
run: |
26-
tox -c tox.dev.ini -e lint
26+
tox -c tox.ini -e lint
2727
- name: Test poli-base with tox (ignoring RaSP)
2828
run: |
29-
tox -c tox.dev.ini -e poli-base-py39 -- --ignore=src/poli/tests/registry/proteins/test_rasp.py
29+
tox -c tox.ini -e poli-base-py39 -- --ignore=src/poli/tests/registry/proteins/test_rasp.py

.gitignore

+5-1
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,8 @@ wandb/
2020

2121
# Ignore temporary files
2222
tmp/
23-
src/poli/objective_repository/rasp/101m.pdb
23+
src/poli/objective_repository/rasp/101m.pdb
24+
25+
# Documentation
26+
docs/build/
27+
docs/source/generated/

README.MD

+21
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,24 @@ x = np.array([["[C]", "[C]", "[C]"]])
8585
print(f"f({x}) = {f(x)}")
8686

8787
```
88+
89+
## Where can I find the documentation?
90+
91+
92+
93+
### Building the documentation locally
94+
95+
If you install the `requirements-dev.txt` via
96+
97+
```bash
98+
pip install -r requirements-dev.txt
99+
```
100+
101+
then you will have access to `sphinx`. You should be able to build the documentation by going to the docs folder and building it:
102+
103+
```bash
104+
cd docs/
105+
make html
106+
```
107+
108+
Afterwards, you can enter the `build` folder and open `index.html`.

docs/Makefile

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Minimal makefile for Sphinx documentation
2+
#
3+
4+
# You can set these variables from the command line, and also
5+
# from the environment for the first two.
6+
SPHINXOPTS ?=
7+
SPHINXBUILD ?= sphinx-build
8+
SOURCEDIR = source
9+
BUILDDIR = build
10+
11+
# Put it first so that "make" without argument is like "make help".
12+
help:
13+
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
14+
15+
.PHONY: help Makefile
16+
17+
# Catch-all target: route all unknown targets to Sphinx using the new
18+
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
19+
%: Makefile
20+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

docs/make.bat

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
@ECHO OFF
2+
3+
pushd %~dp0
4+
5+
REM Command file for Sphinx documentation
6+
7+
if "%SPHINXBUILD%" == "" (
8+
set SPHINXBUILD=sphinx-build
9+
)
10+
set SOURCEDIR=source
11+
set BUILDDIR=build
12+
13+
%SPHINXBUILD% >NUL 2>NUL
14+
if errorlevel 9009 (
15+
echo.
16+
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
17+
echo.installed, then set the SPHINXBUILD environment variable to point
18+
echo.to the full path of the 'sphinx-build' executable. Alternatively you
19+
echo.may add the Sphinx directory to PATH.
20+
echo.
21+
echo.If you don't have Sphinx installed, grab it from
22+
echo.https://www.sphinx-doc.org/
23+
exit /b 1
24+
)
25+
26+
if "%1" == "" goto help
27+
28+
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
29+
goto end
30+
31+
:help
32+
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
33+
34+
:end
35+
popd
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{{ fullname | escape | underline}}
2+
3+
.. currentmodule:: {{ module }}
4+
5+
.. autoclass:: {{ objname }}
6+
:members:
7+
:show-inheritance:
8+
:inherited-members:
9+
10+
{% block methods %}
11+
.. automethod:: __init__
12+
13+
{% if methods %}
14+
.. rubric:: {{ _('Methods') }}
15+
16+
.. autosummary::
17+
{% for item in methods %}
18+
~{{ name }}.{{ item }}
19+
{%- endfor %}
20+
{% endif %}
21+
{% endblock %}
22+
23+
{% block attributes %}
24+
{% if attributes %}
25+
.. rubric:: {{ _('Attributes') }}
26+
27+
.. autosummary::
28+
{% for item in attributes %}
29+
~{{ name }}.{{ item }}
30+
{%- endfor %}
31+
{% endif %}
32+
{% endblock %}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
{{ fullname | escape | underline}}
2+
3+
.. automodule:: {{ fullname }}
4+
5+
{% block attributes %}
6+
{% if attributes %}
7+
.. rubric:: {{ _('Module Attributes') }}
8+
9+
.. autosummary::
10+
:toctree:
11+
{% for item in attributes %}
12+
{{ item }}
13+
{%- endfor %}
14+
{% endif %}
15+
{% endblock %}
16+
17+
{% block functions %}
18+
{% if functions %}
19+
.. rubric:: {{ _('Functions') }}
20+
21+
.. autosummary::
22+
:toctree:
23+
{% for item in functions %}
24+
{{ item }}
25+
{%- endfor %}
26+
{% endif %}
27+
{% endblock %}
28+
29+
{% block classes %}
30+
{% if classes %}
31+
.. rubric:: {{ _('Classes') }}
32+
33+
.. autosummary::
34+
:toctree:
35+
{% for item in classes %}
36+
{{ item }}
37+
{%- endfor %}
38+
{% endif %}
39+
{% endblock %}
40+
41+
{% block exceptions %}
42+
{% if exceptions %}
43+
.. rubric:: {{ _('Exceptions') }}
44+
45+
.. autosummary::
46+
:toctree:
47+
{% for item in exceptions %}
48+
{{ item }}
49+
{%- endfor %}
50+
{% endif %}
51+
{% endblock %}
52+
53+
{% block modules %}
54+
{% if modules %}
55+
.. rubric:: Modules
56+
57+
.. autosummary::
58+
:toctree:
59+
:template: custom-module-template.rst
60+
:recursive:
61+
{% for item in modules %}
62+
{{ item }}
63+
{%- endfor %}
64+
{% endif %}
65+
{% endblock %}

docs/source/conf.py

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# Configuration file for the Sphinx documentation builder.
2+
#
3+
# This file only contains a selection of the most common options. For a full
4+
# list see the documentation:
5+
# https://www.sphinx-doc.org/en/master/usage/configuration.html
6+
7+
# -- Path setup --------------------------------------------------------------
8+
9+
# If extensions (or modules to document with autodoc) are in another directory,
10+
# add these directories to sys.path here. If the directory is relative to the
11+
# documentation root, use os.path.abspath to make it absolute, like shown here.
12+
#
13+
import os
14+
15+
# import sys
16+
# sys.path.insert(0, os.path.abspath('.'))
17+
import pathlib
18+
import sys
19+
20+
path_to_poli = (pathlib.Path(__file__).parents[2].resolve() / "src").as_posix()
21+
sys.path.insert(0, path_to_poli)
22+
23+
for x in os.walk(path_to_poli):
24+
sys.path.insert(0, x[0])
25+
26+
27+
# -- Project information -----------------------------------------------------
28+
29+
project = "poli"
30+
copyright = "2023, MLLS"
31+
author = "MLLS"
32+
33+
# The full version, including alpha/beta/rc tags
34+
release = "0.0.1"
35+
36+
37+
# -- General configuration ---------------------------------------------------
38+
39+
# Add any Sphinx extension module names here, as strings. They can be
40+
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
41+
# ones.
42+
extensions = [
43+
"sphinx.ext.autodoc",
44+
"sphinx.ext.autosummary",
45+
"sphinx.ext.napoleon",
46+
]
47+
autosummary_generate = True # Turn on sphinx.ext.autosummary
48+
49+
autodoc_mock_imports = [
50+
"biopython",
51+
"Bio",
52+
"tdc",
53+
"pdbtools",
54+
"torch",
55+
"pandas",
56+
"rdkit",
57+
"lambo",
58+
"selfies",
59+
"github",
60+
"yaml",
61+
"pytz",
62+
"matplotlib",
63+
"scipy",
64+
"sklearn",
65+
"tensorflow",
66+
"hydra",
67+
"ptitprince",
68+
"seaborn",
69+
"pdbfixer",
70+
"openmm",
71+
"simtk",
72+
"dockstring",
73+
]
74+
75+
# Add any paths that contain templates here, relative to this directory.
76+
templates_path = ["_templates"]
77+
78+
# List of patterns, relative to source directory, that match files and
79+
# directories to ignore when looking for source files.
80+
# This pattern also affects html_static_path and html_extra_path.
81+
exclude_patterns = []
82+
83+
84+
# -- Options for HTML output -------------------------------------------------
85+
86+
# The theme to use for HTML and HTML Help pages. See the documentation for
87+
# a list of builtin themes.
88+
#
89+
html_theme = "furo"
90+
91+
# Add any paths that contain custom static files (such as style sheets) here,
92+
# relative to this directory. They are copied after the builtin static files,
93+
# so a file named "default.css" will overwrite the builtin "default.css".
94+
html_static_path = ["_static"]

docs/source/index.rst

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
.. poli documentation master file, created by
2+
sphinx-quickstart on Thu Dec 21 10:41:44 2023.
3+
You can adapt this file completely to your liking, but it should at least
4+
contain the root `toctree` directive.
5+
6+
Contents
7+
========
8+
9+
.. currentmodule:: poli
10+
11+
.. autosummary::
12+
:toctree: generated
13+
:template: custom-module-template.rst
14+
:recursive:
15+
16+
core
17+
objective_factory
18+
objective_repository
19+
20+
21+
22+
Indices and tables
23+
==================
24+
25+
* :ref:`genindex`
26+
* :ref:`modindex`
27+
* :ref:`search`

requirements-dev.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
black
22
tox
3-
setuptools
3+
setuptools
4+
sphinx
5+
furo

src/poli/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
"""poli, a library for black-box optimization of discrete sequences."""
12
__author__ = "Simon Bartels"

src/poli/core/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
"""Core classes and utilities inside poli
2+
"""

src/poli/core/abstract_black_box.py

+13
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ class AbstractBlackBox:
4646
-------
4747
set_observer(observer)
4848
Set the observer object for recording observations during evaluation.
49+
reset_evaluation_budget()
50+
Reset the evaluation budget by setting the number of evaluations made to 0.
4951
__call__(x, context=None)
5052
Evaluate the black box function for the given input.
5153
_black_box(x, context=None)
@@ -111,6 +113,7 @@ def set_observer(self, observer: AbstractObserver):
111113
self.observer = observer
112114

113115
def reset_evaluation_budget(self):
116+
"""Resets the evaluation budget by setting the number of evaluations made to 0."""
114117
self._num_evaluations = 0
115118

116119
def __call__(self, x: np.array, context=None):
@@ -283,6 +286,16 @@ def __neg__(self):
283286

284287

285288
class NegativeBlackBox(AbstractBlackBox):
289+
"""A wrapper for a black box that negates the objective function.
290+
291+
If you construct a black-box function f for maximizing, then -f is
292+
a black-box function for minimizing. This class is a wrapper for
293+
implementing the latter.
294+
295+
The only difference is that the __call__ method returns -f(x) instead
296+
of f(x). The _black_box method is the same as the original black box.
297+
"""
298+
286299
def __init__(self, f: AbstractBlackBox):
287300
self.f = f
288301
super().__init__(info=f.info, batch_size=f.batch_size)

0 commit comments

Comments
 (0)