Skip to content

Commit 2b57f74

Browse files
Add example gallery to docs (#1150)
* Add example gallery * Add example gallery * Update rtd environment * Fix typo in `generate_gallery.py` * Add graph rewriting tutorial to examples * Add default gallery image * Fix default image path * Add default image * Add scan tutorial example * Add header links to github/colab/binder Add ablog with tags, authors, and categories Modify example notebooks * Update license and package name in footer Delete placeholder notebook * Delete docs for `sandbox` module * rename `pytensor.tensor.var._tensor_py_operators` -> `pytensor.tensor.variable._tensor_py_operators` * Fix underline lengths * Remove reference to depreciated functions * Add end of file newline * Remove references to sandbox * Try adding sitemap and robots.txt * pre-commit * Add cross-references and fix formatting * Fix cross-reference
1 parent 1fc678c commit 2b57f74

26 files changed

+2334
-90
lines changed

doc/.templates/nb-badges.html

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{% if pagename in ablog %}
2+
3+
<!-- Generate correct links and render github/binder/colab badges -->
4+
{% set gh_basepath = github_user + '/' + github_repo + '/blob/' + github_version + '/' %}
5+
{% set encoded_base = github_user + '%252F' + github_repo %}
6+
{% set gh_binder = github_user + '/' + github_repo + '/' + github_version %}
7+
{% set doc_path_aux = doc_path | trim('/') %}
8+
{% set file_path = doc_path_aux + '/' + pagename + ".ipynb" %}
9+
{% set encoded_path = file_path | replace("/", "%252F") %}
10+
11+
12+
<div class="sd-text-right">
13+
<p>
14+
<a href="{{ github_url + '/' + gh_basepath + file_path }}", role="button" target="_blank">
15+
<img src="{{ pathto('_static/github.svg', 1) }}" alt="View On GitHub"></a>
16+
17+
<a href="{{ 'https://mybinder.org/v2/gh/' + sandbox_repo + '?urlpath=git-pull%3Frepo%3Dhttps%253A%252F%252Fgithub.com%252F' + encoded_base + '%26urlpath%3Dtree%252F' + github_repo + '%252F' + encoded_path + '%26branch%3D' + github_version }}" target="_blank">
18+
<img src="{{ pathto('_static/binder.svg', 1) }}" alt="Open In Binder"></a>
19+
20+
<a href="{{ 'https://colab.research.google.com/github/' + gh_basepath + file_path }}" target="_blank">
21+
<img src="{{ pathto('_static/colab.svg', 1) }}" alt="Open In Colab"/></a>
22+
</p>
23+
</div>
24+
{% endif %}

doc/.templates/rendered_citation.html

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!-- continuation of examples/page_footer.md -->
2+
{% if pagename in ablog %}
3+
{% set post = ablog[pagename] %}
4+
{% for coll in post.author %}
5+
{% if coll|length %}
6+
{{ coll }}
7+
{% if loop.index < post.author | length %},{% endif %}
8+
{% else %}
9+
{{ coll }}
10+
{% if loop.index < post.author | length %},{% endif %}
11+
{% endif %}
12+
{% endfor %}. "{{ title.split(' — ')[0] }}". In: <i>Pytensor Examples</i>. Ed. by Pytensor Team. <!-- DOI: <a href={{ doi_url }}>{{ doi_code }}</a> -->
13+
{% endif %}

doc/blog.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
orphan: true
3+
---
4+
5+
# Recent updates
6+
7+
<!-- auto generated by ablog so it's empty -->

doc/conf.py

+97-34
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,13 @@
1-
# pytensor documentation build configuration file, created by
2-
# sphinx-quickstart on Tue Oct 7 16:34:06 2008.
3-
#
4-
# This file is execfile()d with the current directory set to its containing
5-
# directory.
6-
#
7-
# The contents of this file are pickled, so don't put values in the namespace
8-
# that aren't pickleable (module imports are okay, they're removed
9-
# automatically).
10-
#
11-
# All configuration values have a default value; values that are commented out
12-
# serve to show the default value.
13-
14-
# If your extensions are in another directory, add it here. If the directory
15-
# is relative to the documentation root, use Path.absolute to make it
16-
# absolute, like shown here.
17-
# sys.path.append(str(Path("some/directory").absolute()))
18-
191
import os
202
import inspect
213
import sys
224
import pytensor
5+
from pathlib import Path
6+
7+
sys.path.insert(0, str(Path("..").resolve() / "scripts"))
238

249
# General configuration
2510
# ---------------------
26-
27-
# Add any Sphinx extension module names here, as strings. They can be
28-
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
2911
extensions = [
3012
"sphinx.ext.autodoc",
3113
"sphinx.ext.todo",
@@ -34,9 +16,22 @@
3416
"sphinx.ext.linkcode",
3517
"sphinx.ext.mathjax",
3618
"sphinx_design",
37-
"sphinx.ext.intersphinx"
19+
"sphinx.ext.intersphinx",
20+
"sphinx.ext.autosummary",
21+
"sphinx.ext.autosectionlabel",
22+
"ablog",
23+
"myst_nb",
24+
"generate_gallery",
25+
"sphinx_sitemap",
3826
]
3927

28+
# Don't auto-generate summary for class members.
29+
numpydoc_show_class_members = False
30+
autosummary_generate = True
31+
autodoc_typehints = "none"
32+
remove_from_toctrees = ["**/classmethods/*"]
33+
34+
4035
intersphinx_mapping = {
4136
"jax": ("https://jax.readthedocs.io/en/latest", None),
4237
"numpy": ("https://numpy.org/doc/stable", None),
@@ -92,6 +87,7 @@
9287
# List of directories, relative to source directories, that shouldn't be
9388
# searched for source files.
9489
exclude_dirs = ["images", "scripts", "sandbox"]
90+
exclude_patterns = ['page_footer.md', '**/*.myst.md']
9591

9692
# The reST default role (used for this markup: `text`) to use for all
9793
# documents.
@@ -115,19 +111,15 @@
115111
# Options for HTML output
116112
# -----------------------
117113

118-
# The style sheet to use for HTML and HTML Help pages. A file of that name
119-
# must exist either in Sphinx' static/ path, or in one of the custom paths
120-
# given in html_static_path.
121-
# html_style = 'default.css'
122-
# html_theme = 'sphinxdoc'
114+
# The theme to use for HTML and HTML Help pages. See the documentation for
115+
# a list of builtin themes.
116+
html_theme = "pymc_sphinx_theme"
117+
html_logo = "images/PyTensor_RGB.svg"
118+
119+
html_baseurl = "https://pytensor.readthedocs.io"
120+
sitemap_url_scheme = f"{{lang}}{rtd_version}/{{link}}"
123121

124-
# html4_writer added to Fix colon & whitespace misalignment
125-
# https://github.com/readthedocs/sphinx_rtd_theme/issues/766#issuecomment-513852197
126-
# https://github.com/readthedocs/sphinx_rtd_theme/issues/766#issuecomment-629666319
127-
# html4_writer = False
128122

129-
html_logo = "images/PyTensor_RGB.svg"
130-
html_theme = "pymc_sphinx_theme"
131123
html_theme_options = {
132124
"use_search_override": False,
133125
"icon_links": [
@@ -156,15 +148,27 @@
156148
"type": "fontawesome",
157149
},
158150
],
151+
"secondary_sidebar_items": ["page-toc", "edit-this-page", "sourcelink", "donate"],
152+
"navbar_start": ["navbar-logo"],
153+
"article_header_end": ["nb-badges"],
154+
"article_footer_items": ["rendered_citation.html"],
159155
}
160156
html_context = {
157+
"github_url": "https://github.com",
161158
"github_user": "pymc-devs",
162159
"github_repo": "pytensor",
163-
"github_version": "main",
160+
"github_version": version if "." in rtd_version else "main",
161+
"sandbox_repo": f"pymc-devs/pymc-sandbox/{version}",
164162
"doc_path": "doc",
165163
"default_mode": "light",
166164
}
167165

166+
# Add any paths that contain custom static files (such as style sheets) here,
167+
# relative to this directory. They are copied after the builtin static files,
168+
# so a file named "default.css" will overwrite the builtin "default.css".
169+
# html_static_path = ["../_static"]
170+
html_extra_path = ["_thumbnails", 'images', "robots.txt"]
171+
templates_path = [".templates"]
168172

169173
# The name for this set of Sphinx documents. If None, it defaults to
170174
# "<project> v<release> documentation".
@@ -295,3 +299,62 @@ def find_source():
295299

296300
# If false, no module index is generated.
297301
# latex_use_modindex = True
302+
303+
304+
# -- MyST config -------------------------------------------------
305+
myst_enable_extensions = [
306+
"colon_fence",
307+
"deflist",
308+
"dollarmath",
309+
"amsmath",
310+
"substitution",
311+
]
312+
myst_dmath_double_inline = True
313+
314+
citation_code = f"""
315+
```bibtex
316+
@incollection{{citekey,
317+
author = "<notebook authors, see above>",
318+
title = "<notebook title>",
319+
editor = "Pytensor Team",
320+
booktitle = "Pytensor Examples",
321+
}}
322+
```
323+
"""
324+
325+
myst_substitutions = {
326+
"pip_dependencies": "{{ extra_dependencies }}",
327+
"conda_dependencies": "{{ extra_dependencies }}",
328+
"extra_install_notes": "",
329+
"citation_code": citation_code,
330+
}
331+
332+
nb_execution_mode = "off"
333+
nbsphinx_execute = "never"
334+
nbsphinx_allow_errors = True
335+
336+
rediraffe_redirects = {
337+
"index.md": "gallery.md",
338+
}
339+
340+
# -- Bibtex config -------------------------------------------------
341+
bibtex_bibfiles = ["references.bib"]
342+
bibtex_default_style = "unsrt"
343+
bibtex_reference_style = "author_year"
344+
345+
346+
# -- ablog config -------------------------------------------------
347+
blog_baseurl = "https://pytensor.readthedocs.io/en/latest/index.html"
348+
blog_title = "Pytensor Examples"
349+
blog_path = "blog"
350+
blog_authors = {
351+
"contributors": ("Pytensor Contributors", "https://pytensor.readthedocs.io"),
352+
}
353+
blog_default_author = "contributors"
354+
post_show_prev_next = False
355+
fontawesome_included = True
356+
# post_redirect_refresh = 1
357+
# post_auto_image = 1
358+
# post_auto_excerpt = 2
359+
360+
# notfound_urls_prefix = ""

doc/core_development_guide.rst

-8
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,4 @@ some of them might be outdated though:
2626

2727
* :ref:`unittest` -- Tutorial on how to use unittest in testing PyTensor.
2828

29-
* :ref:`sandbox_debugging_step_mode` -- How to step through the execution of
30-
an PyTensor function and print the inputs and outputs of each op.
31-
32-
* :ref:`sandbox_elemwise` -- Description of element wise operations.
33-
34-
* :ref:`sandbox_randnb` -- Description of how PyTensor deals with random
35-
numbers.
36-
3729
* :ref:`sparse` -- Description of the ``sparse`` type in PyTensor.

doc/environment.yml

+8
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ dependencies:
1414
- pillow
1515
- pymc-sphinx-theme
1616
- sphinx-design
17+
- pygments
18+
- pydot
19+
- ipython
20+
- myst-nb
21+
- matplotlib
22+
- watermark
23+
- ablog
1724
- pip
1825
- pip:
26+
- sphinx_sitemap
1927
- -e ..

doc/extending/creating_a_numba_jax_op.rst

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
Adding JAX, Numba and Pytorch support for `Op`\s
2-
=======================================
2+
================================================
33

44
PyTensor is able to convert its graphs into JAX, Numba and Pytorch compiled functions. In order to do
55
this, each :class:`Op` in an PyTensor graph must have an equivalent JAX/Numba/Pytorch implementation function.
66

77
This tutorial will explain how JAX, Numba and Pytorch implementations are created for an :class:`Op`.
88

99
Step 1: Identify the PyTensor :class:`Op` you'd like to implement
10-
------------------------------------------------------------------------
10+
-----------------------------------------------------------------
1111

1212
Find the source for the PyTensor :class:`Op` you'd like to be supported and
1313
identify the function signature and return values. These can be determined by
@@ -98,7 +98,7 @@ how the inputs and outputs are used to compute the outputs for an :class:`Op`
9898
in Python. This method is effectively what needs to be implemented.
9999

100100
Step 2: Find the relevant method in JAX/Numba/Pytorch (or something close)
101-
---------------------------------------------------------
101+
--------------------------------------------------------------------------
102102

103103
With a precise idea of what the PyTensor :class:`Op` does we need to figure out how
104104
to implement it in JAX, Numba or Pytorch. In the best case scenario, there is a similarly named
@@ -269,7 +269,7 @@ and :func:`torch.cumprod`
269269
z[0] = np.cumprod(x, axis=self.axis)
270270
271271
Step 3: Register the function with the respective dispatcher
272-
---------------------------------------------------------------
272+
------------------------------------------------------------
273273

274274
With the PyTensor `Op` replicated, we'll need to register the
275275
function with the backends `Linker`. This is done through the use of

doc/gallery/page_footer.md

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
## License notice
2+
All the notebooks in this example gallery are provided under a
3+
[3-Clause BSD License](https://github.com/pymc-devs/pytensor/blob/main/doc/LICENSE.txt)
4+
which allows modification, and redistribution for any
5+
use provided the copyright and license notices are preserved.
6+
7+
## Citing Pytensor Examples
8+
9+
To cite this notebook, please use the suggested citation below.
10+
11+
:::{important}
12+
Many notebooks are adapted from other sources: blogs, books... In such cases you should
13+
cite the original source as well.
14+
15+
Also remember to cite the relevant libraries used by your code.
16+
:::
17+
18+
Here is an example citation template in bibtex:
19+
20+
{{ citation_code }}
21+
22+
which once rendered could look like:
23+
24+
<!-- continues in _templates/page.html!!! -->
25+
<!-- I wanted to get some kind of automation to the process,
26+
and html templates have access to many variables that are not available
27+
from jinja-myst -->

0 commit comments

Comments
 (0)