Skip to content

Commit 7298915

Browse files
BLD: Replace sphinx-apidoc with sphinx-autosummary
The goal of this commit is to allow building a bit more sensible docs. Instead of a massive file with modules and submodules and classes all documented on the same page, this has one top-levelobject (module, class, or function) documented on each web page, akin to scikitlearn e.g. https://scikit-learn.org/stable/api/sklearn.multiclass.html There is one significant practical decision to make: we need to be clear about from where we expect an object to be imported. E.g. I've chosen to hide documentation of modules like sr3.py and instead document all optimizer classes under pysindy.optimizers. We can't do it in two places. This also means that pysindy/pysindy.py became pysindy/_core.py, so that SINDy is documented in the main pysindy package namespace. There's some other small flattening, but largely, I expect to hide more and more modules with an underscore as time goes on, so that helper functions don't end up as part of a backwards compatability contract. This isn't the final word in the page layouts. There's a lot more visual improvements that can be made. But this commit should solve the technical problems and allow us to tweak from here.
1 parent b6a7db1 commit 7298915

File tree

23 files changed

+192
-78
lines changed

23 files changed

+192
-78
lines changed

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ which correctly results in
7373
y' = 1.000 y
7474
7575
PySINDy provides numerous other features not shown here. We have a variety of tutorials and examples, starting with
76-
`feature overview <https://pysindy.readthedocs.io/en/latest/examples/1_feature_overview/example.html>`_.
76+
`generating data and fitting models <examples/tutorial_1/example.html>`_.
7777

7878

7979
Getting Help

docs/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
generated/

docs/api.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
:orphan:
2+
3+
pysindy package
4+
===============
5+
6+
.. autosummary::
7+
:toctree: generated/
8+
:template: module.rst
9+
:recursive:
10+
11+
pysindy

docs/conf.py

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,40 +14,32 @@
1414
from sphinx.util.docutils import SphinxDirective
1515

1616
author = "dynamicslab"
17-
project = "pysindy" # package name
18-
19-
20-
# no need to edit below this line
21-
17+
project = "pysindy"
2218
copyright = f"2020, {author}"
23-
2419
module = importlib.import_module(project)
2520
version = release = getattr(module, "__version__")
2621

2722
master_doc = "index"
2823

2924
extensions = [
30-
"nbsphinx",
31-
"sphinxcontrib.apidoc",
3225
"sphinx.ext.autodoc",
33-
"sphinx.ext.todo",
34-
"sphinx.ext.viewcode",
3526
"sphinx.ext.autosummary",
27+
"nbsphinx",
28+
"sphinx.ext.todo",
3629
"sphinx.ext.napoleon",
30+
"sphinx.ext.viewcode",
3731
"sphinx.ext.mathjax",
3832
"sphinx.ext.intersphinx",
3933
"IPython.sphinxext.ipython_console_highlighting",
4034
]
4135

4236
nb_execution_mode = "off"
4337

44-
apidoc_module_dir = f"../{project}"
45-
apidoc_excluded_paths = ["tests"]
46-
apidoc_toc_file = False
38+
templates_path = ["templates"]
39+
autosummary_generate = True
40+
autosummary_ignore_module_all = False
4741

48-
autodoc_default_options = {"members": True}
49-
autodoc_member_order = "bysource"
50-
autoclass_content = "init"
42+
autoclass_content = "both"
5143

5244
language = "en"
5345

@@ -69,10 +61,22 @@
6961
html_sourcelink_suffix = ""
7062

7163
intersphinx_mapping = {
72-
"derivative": ("https://derivative.readthedocs.io/en/latest/", None),
73-
"sklearn": ("https://scikit-learn.org/stable/", None),
64+
"derivative": ("https://derivative.readthedocs.io/en/latest", None),
65+
"sklearn": ("https://scikit-learn.org/stable", None),
66+
"numpy": ("https://numpy.org/doc/stable", None),
7467
}
7568

69+
show_warning_types = True
70+
suppress_warnings = [
71+
"ref.python",
72+
"ref.exc",
73+
"ref.class",
74+
"ref.obj",
75+
"ref.meth",
76+
"ref.any",
77+
"ref",
78+
]
79+
7680
# -- Extensions to the Napoleon GoogleDocstring class ---------------------
7781
# michaelgoerz.net/notes/extending-sphinx-napoleon-docstring-sections.html
7882
from sphinx.ext.napoleon.docstring import GoogleDocstring # noqa: E402

docs/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
Contributing <contributing>
1313
Using pysindy in academia <academic>
1414
Object Model <objects>
15-
API Documentation <api/pysindy>
15+
API Documentation <generated/pysindy>
1616

1717
.. toctree::
1818
:maxdepth: 1

docs/templates/class.rst

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{{ fullname | escape | underline}}
2+
3+
.. currentmodule:: {{ module }}
4+
5+
.. autoclass:: {{ objname }}
6+
:members:
7+
:special-members: __call__, __add__, __mul__
8+
9+
{% block methods %}
10+
{% if methods %}
11+
.. rubric:: {{ _('Methods') }}
12+
13+
.. autosummary::
14+
:nosignatures:
15+
{% for item in methods %}
16+
{%- if not item.startswith('_') and item not in inherited_members%}
17+
~{{ name }}.{{ item }}
18+
{%- endif -%}
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+
{%- if not item.startswith('_') and item not in inherited_members%}
30+
~{{ name }}.{{ item }}
31+
{%- endif -%}
32+
{%- endfor %}
33+
{% endif %}
34+
{% endblock %}

docs/templates/module.rst

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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+
:nosignatures:
24+
{% for item in functions %}
25+
{{ item }}
26+
{%- endfor %}
27+
{% endif %}
28+
{% endblock %}
29+
30+
{% block classes %}
31+
{% if classes %}
32+
.. rubric:: {{ _('Classes') }}
33+
34+
.. autosummary::
35+
:toctree:
36+
:template: class.rst
37+
:nosignatures:
38+
{% for item in classes %}
39+
{{ item }}
40+
{%- endfor %}
41+
{% endif %}
42+
{% endblock %}
43+
44+
{% block exceptions %}
45+
{% if exceptions %}
46+
.. rubric:: {{ _('Exceptions') }}
47+
48+
.. autosummary::
49+
:toctree:
50+
{% for item in exceptions %}
51+
{{ item }}
52+
{%- endfor %}
53+
{% endif %}
54+
{% endblock %}
55+
56+
{% block modules %}
57+
{% if modules %}
58+
.. autosummary::
59+
:toctree:
60+
:template: module.rst
61+
:recursive:
62+
{% for item in modules %}
63+
{{ item }}
64+
{%- endfor %}
65+
{% endif %}
66+
{% endblock %}

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ docs = [
5757
"pandoc",
5858
"requests",
5959
"sphinx-rtd-theme",
60-
"sphinx==7.4.7",
60+
"sphinx==8.2.3",
6161
"pyyaml",
6262
"sphinxcontrib-apidoc",
6363
]

pysindy/__init__.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
from . import optimizers
1212
from . import deeptime
1313
from . import utils
14-
from .pysindy import SINDy
15-
from .pysindy import AxesArray
14+
from ._core import SINDy
15+
from ._core import AxesArray
1616
from .differentiation import BaseDifferentiation
1717
from .differentiation import FiniteDifference
1818
from .differentiation import SpectralDerivative
@@ -63,9 +63,11 @@
6363
pass
6464

6565

66-
__all__ = ["SINDy", "AxesArray"]
67-
__all__.extend(differentiation.__all__)
68-
__all__.extend(feature_library.__all__)
69-
__all__.extend(optimizers.__all__)
70-
__all__.extend(["utils"])
71-
__all__.extend(["deeptime"])
66+
__all__ = [
67+
"SINDy",
68+
"differentiation",
69+
"feature_library",
70+
"optimizers",
71+
"deeptime",
72+
"utils",
73+
]

pysindy/pysindy.py renamed to pysindy/_core.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ class _BaseSINDy(BaseEstimator, ABC):
4848

4949
feature_library: BaseFeatureLibrary
5050
optimizer: _BaseOptimizer
51-
discrete_time: bool
5251
model: Pipeline
5352
# Hacks to remove later
5453
feature_names: Optional[list[str]]
@@ -178,31 +177,31 @@ class SINDy(_BaseSINDy):
178177
179178
Parameters
180179
----------
181-
optimizer : optimizer object, optional
180+
optimizer
182181
Optimization method used to fit the SINDy model. This must be a class
183182
extending :class:`pysindy.optimizers.BaseOptimizer`.
184-
The default is :class:`STLSQ`.
183+
The default is :class:`pysindy.optimizers.STLSQ`.
185184
186-
feature_library : feature library object, optional
185+
feature_library
187186
Feature library object used to specify candidate right-hand side features.
188187
This must be a class extending
189188
:class:`pysindy.feature_library.base.BaseFeatureLibrary`.
190-
The default option is :class:`PolynomialLibrary`.
189+
The default option is :class:`pysindy.feature_library.PolynomialLibrary`.
191190
192-
differentiation_method : differentiation object, optional
191+
differentiation_method
193192
Method for differentiating the data. This must be a class extending
194-
:class:`pysindy.differentiation_methods.base.BaseDifferentiation` class.
193+
:class:`pysindy.differentiation.base.BaseDifferentiation` class.
195194
The default option is centered difference.
196195
197-
discrete_time : boolean, optional (default False)
196+
discrete_time
198197
If True, dynamical system is treated as a map. Rather than predicting
199198
derivatives, the right hand side functions step the system forward by
200199
one time step. If False, dynamical system is assumed to be a flow
201200
(right-hand side functions predict continuous time derivatives).
202201
203202
Attributes
204203
----------
205-
model : ``sklearn.multioutput.MultiOutputRegressor`` object
204+
model : ``sklearn.multioutput.MultiOutputRegressor``
206205
The fitted SINDy model.
207206
208207
n_input_features_ : int

0 commit comments

Comments
 (0)