| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| """Configuration file for the Sphinx documentation builder.""" |
|
|
| |
| |
| |
|
|
| |
|
|
| |
| |
| |
|
|
| |
| |
| import inspect |
| import os |
| import sys |
|
|
|
|
| def _add_annotations_import(path): |
| """Appends a future annotations import to the file at the given path.""" |
| with open(path) as f: |
| contents = f.read() |
| if contents.startswith('from __future__ import annotations'): |
| |
| |
| return |
|
|
| assert contents.startswith('#'), (path, contents.split('\n')[0]) |
| with open(path, 'w') as f: |
| |
| |
| |
| |
| |
| f.write('from __future__ import annotations ') |
| f.write(contents) |
|
|
|
|
| def _recursive_add_annotations_import(): |
| for path, _, files in os.walk('../optax/'): |
| for file in files: |
| if file.endswith('.py'): |
| _add_annotations_import(os.path.abspath(os.path.join(path, file))) |
|
|
|
|
| if 'READTHEDOCS' in os.environ: |
| _recursive_add_annotations_import() |
|
|
| sys.path.insert(0, os.path.abspath('../')) |
| sys.path.append(os.path.abspath('ext')) |
|
|
| import optax |
| from sphinxcontrib import katex |
|
|
| |
|
|
| project = 'Optax' |
| copyright = '2021, DeepMind' |
| author = 'Optax Contributors' |
|
|
| |
|
|
| master_doc = 'index' |
|
|
| |
| |
| |
| extensions = [ |
| 'sphinx.ext.autodoc', |
| 'sphinx.ext.autosummary', |
| 'sphinx.ext.doctest', |
| 'sphinx.ext.inheritance_diagram', |
| 'sphinx.ext.intersphinx', |
| 'sphinx.ext.linkcode', |
| 'sphinx.ext.napoleon', |
| 'sphinxcontrib.katex', |
| 'coverage_check', |
| 'myst_nb', |
| 'sphinx_gallery.gen_gallery', |
| 'sphinxcontrib.collections', |
| 'sphinx_contributors' |
| ] |
|
|
| |
| doctest_global_setup = ''' |
| import optax |
| import jax |
| import jax.numpy as jnp |
| ''' |
|
|
| |
| templates_path = ['_templates'] |
|
|
| |
| |
| |
| exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store'] |
|
|
| |
|
|
| |
| autodoc_type_aliases = { |
| '~optax._src.base.GradientTransformation': 'optax.GradientTransformation', |
| '~optax._src.base.Params': 'Params', |
| '~optax._src.base.Updates': 'Updates', |
| '~optax._src.base.OptState': 'OptState', |
| '~optax._src.base.PyTree': 'optax.PyTree', |
| 'base.GradientTransformation': 'optax.GradientTransformation', |
| 'base.Params': 'optax.Params', |
| 'base.Updates': 'optax.Updates', |
| 'base.OptState': 'optax.OptState', |
| 'base.PyTree': 'optax.PyTree', |
| 'chex.ArrayTree': 'chex.ArrayTree', |
| 'chex.Array': 'chex.Array', |
| 'chex.Numeric': 'chex.Numeric' |
| } |
|
|
| autodoc_default_options = { |
| 'member-order': 'bysource', |
| 'special-members': True, |
| 'exclude-members': '__repr__, __str__, __weakref__', |
| } |
|
|
| |
|
|
| collections = { |
| 'examples': { |
| 'driver': 'copy_folder', |
| 'source': '../examples/', |
| 'ignore': 'BUILD' |
| } |
| } |
|
|
|
|
| |
|
|
| sphinx_gallery_conf = { |
| 'examples_dirs': '_collections/examples', |
| 'gallery_dirs': ( |
| '_collections/generated_examples/' |
| ), |
| 'ignore_pattern': r'_test\.py', |
| 'doc_module': 'optax', |
| 'backreferences_dir': os.path.join('modules', 'generated') |
| } |
|
|
|
|
| |
|
|
| |
| |
| html_theme = 'sphinx_book_theme' |
|
|
| html_theme_options = { |
| 'show_toc_level': 2, |
| 'repository_url': 'https://github.com/google-deepmind/optax', |
| 'use_repository_button': True, |
| 'navigation_with_keys': False, |
| } |
|
|
| html_logo = 'images/logo.svg' |
| html_favicon = 'images/favicon.svg' |
|
|
| |
| |
| |
|
|
| html_static_path = ['_static'] |
| html_css_files = [ |
| 'css/custom.css', |
| ] |
|
|
| |
| myst_enable_extensions = [ |
| 'amsmath', |
| 'dollarmath', |
| ] |
| nb_execution_mode = 'force' |
| nb_execution_allow_errors = False |
| nb_render_image_options = {} |
| nb_execution_excludepatterns = [ |
| |
| 'nanolm.ipynb', |
| 'cifar10_resnet.ipynb', |
| 'adversarial_training.ipynb', |
| 'reduce_on_plateau.ipynb', |
| 'differentially_private_sgd.ipynb' |
| ] |
|
|
| |
|
|
| |
| latex_macros = r""" |
| \def \d #1{\operatorname{#1}} |
| """ |
|
|
| |
| katex_macros = katex.latex_defs_to_katex_macros(latex_macros) |
| katex_options = ( |
| '{displayMode: true, fleqn: true, macros: {' + katex_macros + '}}' |
| ) |
|
|
| |
| latex_elements = {'preamble': latex_macros} |
|
|
| |
|
|
|
|
| def linkcode_resolve(domain, info): |
| """Resolve a GitHub URL corresponding to Python object.""" |
| if domain != 'py': |
| return None |
|
|
| try: |
| mod = sys.modules[info['module']] |
| except ImportError: |
| return None |
|
|
| obj = mod |
| try: |
| for attr in info['fullname'].split('.'): |
| obj = getattr(obj, attr) |
| except AttributeError: |
| return None |
| else: |
| obj = inspect.unwrap(obj) |
|
|
| try: |
| filename = inspect.getsourcefile(obj) |
| except TypeError: |
| return None |
|
|
| try: |
| source, lineno = inspect.getsourcelines(obj) |
| except OSError: |
| return None |
|
|
| |
| return ( |
| 'https://github.com/google-deepmind/optax/tree/main/optax/%s#L%d#L%d' |
| % ( |
| os.path.relpath(filename, start=os.path.dirname(optax.__file__)), |
| lineno, |
| lineno + len(source) - 1, |
| ) |
| ) |
|
|
|
|
| |
|
|
| intersphinx_mapping = { |
| 'jax': ('https://jax.readthedocs.io/en/latest/', None), |
| 'flax': ('https://flax.readthedocs.io/en/latest/', None), |
| 'chex': ('https://chex.readthedocs.io/en/latest/', None), |
| } |
|
|
| source_suffix = ['.rst', '.md', '.ipynb'] |
|
|