Skip to content

Commit

Permalink
Documentation update (#68)
Browse files Browse the repository at this point in the history
* use new mandatory build.os env variable for RTD

* move examples to docs and make executable

* shorten sphinx config and add myst_nb to decode notebooks

* jupyter-book not needed for docs requirements

* Minor README update

* add NIR symbol pngs

* add myst-nb as docs requirement

* modify example titles

* update primitives in docs

* add sphinx autoapi

* minor text edits in document titles

* add sphinx-autoapi to docs requirements

* fix autoapi upstream bug by pinning astroid dep

* add html_title to docs

* Change logo in sidebar

* Corrected ruff github ci command

---------

Co-authored-by: Jens E. Pedersen <[email protected]>
  • Loading branch information
biphasic and Jegp authored Oct 17, 2023
1 parent 274748d commit 9aedb9b
Show file tree
Hide file tree
Showing 40 changed files with 597 additions and 472 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ jobs:
- name: Lint with ruff
run: |
# stop the build if there are Python syntax errors or undefined names
ruff --format=github --select=E9,F63,F7,F82 --target-version=py37 .
ruff --output-format=github --select=E9,F63,F7,F82 --target-version=py37 .
# default set of ruff rules with GitHub Annotations
ruff --format=github --target-version=py37 --exclude=docs/ .
ruff --output-format=github --target-version=py37 --exclude=docs/ .
- name: Test with pytest
run: |
pytest
pytest
23 changes: 2 additions & 21 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,16 @@
# Read the Docs configuration file
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details

# Required
version: 1
version: 2

# Set the OS, Python version and other tools you might need
build:
os: ubuntu-22.04
tools:
python: "3.10"
# You can also specify other tool versions:
# nodejs: "19"
# rust: "1.64"
# golang: "1.19"
# jobs:
# pre_build:
# # Generate on-the-fly Sphinx configuration from Jupyter Book's _config.yml
# - "jupyter-book config sphinx docs/"
python: "3.11"

# Build documentation in the "docs/" directory with Sphinx
sphinx:
configuration: docs/source/conf.py

# Optionally build your docs in additional formats such as PDF and ePub
formats:
- pdf
# - epub

# Optional but recommended, declare the Python requirements required
# to build your documentation
# See https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html
python:
install:
- requirements: docs/requirements.txt
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<img alt="NIR Logo" src="https://github.com/neuromorphs/NIR/raw/main/docs/logo_light.png">
</picture>

# NIR: Neuromorphic Intermediate Representation
# NIR - Neuromorphic Intermediate Representation

NIR provides a standard way to describe arbitrary **physical** networks.
**NIR is currently supported by 6 simulators and 4 hardware platforms**, allowing users to seamlessly move between any of these platforms.
Expand Down
5 changes: 3 additions & 2 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
sphinx==5.0.2
sphinx-book-theme
myst-parser
myst_nb
numpy
h5py
sphinx_external_toc
sphinxcontrib-mermaid
jupyter-book
astroid~=2.15 # https://github.com/readthedocs/sphinx-autoapi/issues/407
sphinx-autoapi
22 changes: 8 additions & 14 deletions docs/source/_toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,25 @@ parts:
- caption: Introduction
chapters:
- file: what
title: What is NIR?
title: What is it?
- file: about
title: About NIR
- caption: User guide
chapters:
- file: usage
- file: primitives
title: NIR primitives
- file: support
title: Platform support
- caption: Examples
chapters:
- file: examples/lava
- file: examples/nengo
- file: examples/norse
- file: examples/rockpool
- file: examples/sinabs
- file: examples/snntorch
- file: examples/spinnaker
- file: examples/lava/nir-conversion
- file: examples/nengo/nir-conversion
- file: examples/norse/nir-conversion
- file: examples/rockpool/nir-conversion
- file: examples/sinabs/nir-conversion
- file: examples/snntorch/nir-conversion
- file: examples/spinnaker2/import
- caption: Developer guide
chapters:
- file: api_design
- file: dev
title: Contributing
- caption: API
chapters:
- file: modindex
title: API reference
2 changes: 1 addition & 1 deletion docs/source/about.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# About NIR
# About

The Neuromorphic Intermediate Representation (NIR) is a joint effort between researchers and engineers working to spread the usage and accelerate the innnovation of neuromorphic technologies.
It is a product of many clever actors, thinking deeply about the interplay between computation and physics, and it would be incorrect to claim that NIR is owned by any single actor.
Expand Down
2 changes: 1 addition & 1 deletion docs/source/api_design.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# NIR API design
# API design

The reference implementation simply consists of a series of Python classes that *represent* [NIR structures](primitives).
In other words, they do not implement the functionality of the nodes, but simply represent the necessary parameters required to *eventually* evaluate the node.
Expand Down
49 changes: 24 additions & 25 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,46 +26,50 @@

# -- General configuration ---------------------------------------------------

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
"myst_parser",
"myst_nb",
"sphinx.ext.autodoc",
"sphinx.ext.mathjax",
"sphinx.ext.autosummary",
"sphinx_external_toc",
"sphinxcontrib.mermaid",
"autoapi.extension",
]

external_toc_path = "_toc.yml"

myst_enable_extensions = [
"amsmath",
"dollarmath",
]

# Maps source configuration
source_suffix = {
".rst": "restructuredtext",
".txt": "markdown",
".md": "markdown",
}
autodoc_typehints = "both"
autoapi_type = "python"
autoapi_dirs = ["../../nir"]
autoapi_options = [
"members",
"undoc-members",
"show-inheritance",
"show-module-summary",
"special-members",
"imported-members",
]

# MyST settings
nb_execution_mode = "off" # this can be turned to 'auto' once the package is stable
nb_execution_timeout = 300
nb_execution_show_tb = True

# Add any paths that contain templates here, relative to this directory.
templates_path = ["_templates"]

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = []


# -- 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 = 'alabaster'
html_theme = "sphinx_book_theme"
html_title = "NIR documentation"
html_logo = "../logo_light.png"
html_show_sourcelink = True
html_sourcelink_suffix = ""

html_theme_options = {
"search_bar_text": "Search NIR docs...",
Expand All @@ -75,8 +79,3 @@
"use_edit_page_button": False,
"use_issues_button": True,
}

# 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"]
2 changes: 1 addition & 1 deletion docs/source/dev.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Contributing to NIR
# Contributing

## Developer guide: Getting started

Expand Down
3 changes: 0 additions & 3 deletions docs/source/examples/lava.md

This file was deleted.

26 changes: 26 additions & 0 deletions docs/source/examples/lava/nir-conversion.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Lava\n",
"\n",
"... coming soon"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": []
}
],
"metadata": {
"language_info": {
"name": "python"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}
3 changes: 0 additions & 3 deletions docs/source/examples/nengo.md

This file was deleted.

133 changes: 133 additions & 0 deletions docs/source/examples/nengo/nir-conversion.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Nengo\n",
"\n",
"[Nengo](nengo.ai) is a Python package for building, testing, and deploying neural networks.\n",
"The examples below shows how to import and export from Nengo to NIR and vice-versa.\n",
"\n",
"Examples:\n",
"* Lorentz oscillator: [nir-lorentz.py](https://github.com/neuromorphs/nir/tree/main/example/nengo/nir-lorentz.py)\n",
" * This script creates a Nengo model that simulates the Lorentz oscillator, maps it to NIR, and then back again into Nengo\n",
"* Leaky integrate-and-fire (LIF) tests [nir-test.py](https://github.com/neuromorphs/nir/tree/main/example/nengo/nir-test.py)\n",
" * Creates a NIR model for an Affine map and LIF population and map it into Nengo\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"vscode": {
"languageId": "plaintext"
}
},
"outputs": [],
"source": [
"import nengo\n",
"import numpy as np\n",
"\n",
"import nir\n",
"\n",
"n = nir.NIRGraph(\n",
" nodes=[\n",
" nir.Input(shape=np.array([3])),\n",
" nir.Affine(weight=np.array([[8, 2, 10], [14, 3, 14]]).T, bias=np.array([1, 2])),\n",
" nir.LIF(\n",
" tau=np.array([1] * 2),\n",
" r=np.array([1] * 2),\n",
" v_leak=np.array([0] * 2),\n",
" v_threshold=np.array([1] * 2),\n",
" ),\n",
" nir.Output(shape=np.array([3])),\n",
" ],\n",
" edges=[(0, 1), (1, 2), (2, 3)],\n",
")\n",
"\n",
"\n",
"def nir_to_nengo(n, swap_linear_order=False):\n",
" nengo_map = []\n",
"\n",
" model = nengo.Network()\n",
" with model:\n",
" filters = {}\n",
" for i, obj in enumerate(n.nodes):\n",
" if isinstance(obj, nir.Input):\n",
" node = nengo.Node(np.zeros(obj.shape), label=f\"Input {i} {obj.shape}\")\n",
" nengo_map.append(node)\n",
" elif isinstance(obj, nir.LIF):\n",
" N = obj.tau.flatten().shape[0]\n",
" ens = nengo.Ensemble(\n",
" n_neurons=N,\n",
" dimensions=1,\n",
" label=f\"LIF {i}\",\n",
" neuron_type=nengo.RegularSpiking(\n",
" nengo.LIFRate(tau_rc=obj.tau[0], tau_ref=0)\n",
" ),\n",
" # neuron_type=nengo.LIF(tau_rc=obj.tau[0], tau_ref=0),\n",
" gain=np.ones(N),\n",
" bias=np.zeros(N),\n",
" )\n",
" nengo_map.append(ens.neurons)\n",
" elif isinstance(obj, nir.LI):\n",
" filt = nengo.Node(\n",
" lambda t, x: x,\n",
" size_in=obj.tau.flatten().shape[0],\n",
" label=f\"LI {i} {obj.tau.shape}\",\n",
" )\n",
" filters[filt] = nengo.synapses.Lowpass(obj.tau[0])\n",
" nengo_map.append(filt)\n",
" elif isinstance(obj, nir.Affine):\n",
" weights = obj.weight\n",
" if swap_linear_order:\n",
" weights = weights.T\n",
" w = nengo.Node(\n",
" lambda t, x, obj=obj: weights @ x + obj.bias,\n",
" size_in=weights.shape[1],\n",
" size_out=weights.shape[0],\n",
" label=f\"({weights.shape[0]}x{weights.shape[1]})\",\n",
" )\n",
" nengo_map.append(w)\n",
" elif isinstance(obj, nir.Output):\n",
" nengo_map.append(\n",
" None\n",
" ) # because NIR spec doesn't tell me the size, I can't create this yet\n",
" else:\n",
" raise Exception(f\"Unknown NIR object: {obj}\")\n",
" for pre, post in n.edges:\n",
" if nengo_map[post] is None:\n",
" output = nengo.Node(\n",
" lambda t, x: x,\n",
" size_in=nengo_map[pre].size_out,\n",
" label=f\"Output {post}\",\n",
" )\n",
" nengo_map[post] = output\n",
" synapse = filters.get(nengo_map[post], None)\n",
"\n",
" if nengo_map[pre].size_out != nengo_map[post].size_in:\n",
" print(\"Error\")\n",
" print(\"pre\", nengo_map[pre])\n",
" print(\"post\", nengo_map[post])\n",
" 1 / 0\n",
"\n",
" else:\n",
" nengo.Connection(nengo_map[pre], nengo_map[post], synapse=synapse)\n",
"\n",
" return model\n",
"\n",
"\n",
"model = nir_to_nengo(n, swap_linear_order=True)\n"
]
}
],
"metadata": {
"language_info": {
"name": "python"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}
File renamed without changes.
Loading

0 comments on commit 9aedb9b

Please sign in to comment.