Skip to content

Commit 4f5ec32

Browse files
committed
feat(docs): add documentation and examples for BrainPy 3.x
1 parent 6628c97 commit 4f5ec32

File tree

4 files changed

+365
-0
lines changed

4 files changed

+365
-0
lines changed

docs_version2/README.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# BrainPy Version 2 Documentation
2+
3+
This directory contains documentation for BrainPy 2.x, the previous major version of BrainPy.
4+
5+
## Overview
6+
7+
BrainPy 2.x is a highly flexible and extensible framework targeting general-purpose Brain Dynamics Programming (BDP). This documentation is maintained for users who are still using BrainPy 2.x.
8+
9+
## Important Note
10+
11+
**As of September 2025, BrainPy has been upgraded to version 3.x.** If you are using BrainPy 3.x, please refer to the main documentation.
12+
13+
To use BrainPy 2.x APIs within version 3.x installations, update your imports:
14+
15+
```python
16+
# Old version (v2.x standalone)
17+
import brainpy as bp
18+
import brainpy.math as bm
19+
20+
# Using v2.x API in BrainPy 3.x
21+
import brainpy.version2 as bp
22+
import brainpy.version2.math as bm
23+
```
24+
25+
## Documentation Contents
26+
27+
- **index.rst** - Main documentation entry point
28+
- **core_concepts.rst** - Fundamental concepts of Brain Dynamics Programming
29+
- **tutorials.rst** - Step-by-step tutorials
30+
- **advanced_tutorials.rst** - Advanced usage patterns
31+
- **toolboxes.rst** - Specialized toolboxes for different applications
32+
- **api.rst** - Complete API reference
33+
- **FAQ.rst** - Frequently asked questions
34+
- **brainpy-changelog.md** - Version history and changes
35+
- **brainpylib-changelog.md** - BrainPyLib backend changes
36+
37+
## Building Documentation
38+
39+
This documentation is written in reStructuredText (RST) format and can be built using Sphinx:
40+
41+
```bash
42+
cd docs_version2
43+
make html # or use the appropriate build script
44+
```
45+
46+
## Installation
47+
48+
For BrainPy 2.x compatibility:
49+
50+
```bash
51+
pip install -U brainpy[cpu]
52+
```
53+
54+
## Learn More
55+
56+
- [Core Concepts](core_concepts.rst) - Understand the fundamentals
57+
- [Tutorials](tutorials.rst) - Learn through examples
58+
- [API Documentation](api.rst) - Complete reference
59+
- [BrainPy Examples](https://brainpy-v2.readthedocs.io/projects/examples/) - Code examples
60+
- [BrainPy Ecosystem](https://brainmodeling.readthedocs.io) - Related projects
61+
62+
## Support
63+
64+
For questions and support, please visit the [BrainPy GitHub repository](https://github.com/brainpy/BrainPy).

docs_version3/README.md

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
# BrainPy Version 3 Documentation
2+
3+
This directory contains documentation for BrainPy 3.x, the latest major version of BrainPy.
4+
5+
## Overview
6+
7+
BrainPy 3.x is a flexible, efficient, and extensible framework for computational neuroscience and brain-inspired computation. It has been completely rewritten based on [brainstate](https://github.com/chaobrain/brainstate) (since August 2025) and provides powerful capabilities for building, simulating, and training spiking neural networks.
8+
9+
## Documentation Contents
10+
11+
This directory contains tutorial notebooks and API documentation:
12+
13+
### Tutorials (Bilingual: English & Chinese)
14+
15+
#### SNN Simulation
16+
- **snn_simulation-en.ipynb** - Building and simulating spiking neural networks (English)
17+
- **snn_simulation-zh.ipynb** - 构建和模拟脉冲神经网络 (Chinese)
18+
19+
#### SNN Training
20+
- **snn_training-en.ipynb** - Training spiking neural networks with surrogate gradients (English)
21+
- **snn_training-zh.ipynb** - 使用代理梯度训练脉冲神经网络 (Chinese)
22+
23+
#### Checkpointing
24+
- **checkpointing-en.ipynb** - Saving and loading model states (English)
25+
- **checkpointing-zh.ipynb** - 保存和加载模型状态 (Chinese)
26+
27+
### API Reference
28+
- **apis.rst** - Complete API documentation
29+
- **index.rst** - Main documentation entry point
30+
31+
## Key Features in Version 3.x
32+
33+
- Built on [brainstate](https://github.com/chaobrain/brainstate) for improved state management
34+
- Enhanced support for spiking neural networks
35+
- Streamlined API for building neural models
36+
- Improved performance and scalability
37+
- Better integration with JAX ecosystem
38+
- Support for GPU/TPU acceleration
39+
40+
## Installation
41+
42+
```bash
43+
# CPU version
44+
pip install -U brainpy[cpu]
45+
46+
# GPU version (CUDA 12)
47+
pip install -U brainpy[cuda12]
48+
49+
# GPU version (CUDA 13)
50+
pip install -U brainpy[cuda13]
51+
52+
# TPU version
53+
pip install -U brainpy[tpu]
54+
55+
# Full ecosystem
56+
pip install -U BrainX
57+
```
58+
59+
## Quick Start
60+
61+
```python
62+
import brainpy
63+
import brainstate
64+
import brainunit as u
65+
66+
# Define a simple LIF neuron
67+
neuron = brainpy.LIF(100, V_rest=-60.*u.mV, V_th=-50.*u.mV)
68+
69+
# Initialize and simulate
70+
brainstate.nn.init_all_states(neuron)
71+
spikes = neuron(1.*u.mA)
72+
```
73+
74+
## Migration from Version 2.x
75+
76+
If you're migrating from BrainPy 2.x, the API has changed significantly. See the migration guide in the main documentation for details.
77+
78+
To use legacy 2.x APIs in version 3.x:
79+
80+
```python
81+
import brainpy.version2 as bp
82+
import brainpy.version2.math as bm
83+
```
84+
85+
## Running Notebooks
86+
87+
The tutorial notebooks can be run using Jupyter:
88+
89+
```bash
90+
jupyter notebook snn_simulation-en.ipynb
91+
```
92+
93+
Or with JupyterLab:
94+
95+
```bash
96+
jupyter lab
97+
```
98+
99+
## Building Documentation
100+
101+
If you need to build the documentation locally, this directory is part of the larger documentation system. Please refer to the main documentation build instructions.
102+
103+
## Learn More
104+
105+
- [Main Documentation](https://brainpy.readthedocs.io)
106+
- [BrainPy GitHub](https://github.com/brainpy/BrainPy)
107+
- [BrainState GitHub](https://github.com/chaobrain/brainstate)
108+
- [BrainPy Ecosystem](https://brainmodeling.readthedocs.io)
109+
110+
## Contributing
111+
112+
Contributions to documentation are welcome! Please submit issues or pull requests to the [BrainPy repository](https://github.com/brainpy/BrainPy).

examples_version2/README.md

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# BrainPy Version 2 Examples
2+
3+
This directory contains example scripts demonstrating the capabilities of BrainPy 2.x for brain dynamics programming.
4+
5+
## Overview
6+
7+
These examples showcase BrainPy 2.x functionality including dynamics simulation, analysis, and training. BrainPy 2.x is maintained for backward compatibility, but new projects should consider using BrainPy 3.x.
8+
9+
## Important Note
10+
11+
**As of September 2025, BrainPy has been upgraded to version 3.x.** To use these examples with BrainPy 3.x, update your imports:
12+
13+
```python
14+
import brainpy.version2 as bp
15+
import brainpy.version2.math as bm
16+
```
17+
18+
## Example Categories
19+
20+
### Dynamics Simulation
21+
22+
Network simulation examples demonstrating various neural models and dynamics:
23+
24+
- **hh_model.py** - Hodgkin-Huxley neuron model
25+
- **ei_nets.py** - Excitatory-inhibitory networks
26+
- **COBA.py** - Conductance-based network model
27+
- **stdp.py** - Spike-timing-dependent plasticity
28+
- **decision_making_network.py** - Decision-making circuit
29+
- **whole_brain_simulation_with_fhn.py** - Whole-brain simulation with FitzHugh-Nagumo model
30+
- **whole_brain_simulation_with_sl_oscillator.py** - Whole-brain simulation with Stuart-Landau oscillator
31+
32+
### Dynamics Analysis
33+
34+
Phase plane and bifurcation analysis of neural models:
35+
36+
- **1d_qif.py** - 1D Quadratic Integrate-and-Fire model analysis
37+
- **2d_fitzhugh_nagumo_model.py** - 2D FitzHugh-Nagumo phase plane analysis
38+
- **2d_mean_field_QIF.py** - 2D mean-field QIF analysis
39+
- **3d_reduced_trn_model.py** - 3D reduced thalamic reticular nucleus model
40+
- **4d_HH_model.py** - 4D Hodgkin-Huxley model analysis
41+
- **highdim_RNN_Analysis.py** - High-dimensional RNN dynamics analysis
42+
43+
### Dynamics Training
44+
45+
Training examples for recurrent networks and reservoir computing:
46+
47+
- **echo_state_network.py** - Echo State Network (reservoir computing)
48+
- **integrator_rnn.py** - RNN for integration task
49+
- **reservoir-mnist.py** - MNIST classification with reservoir computing
50+
- **Sussillo_Abbott_2009_FORCE_Learning.py** - FORCE learning algorithm
51+
- **Song_2016_EI_RNN.py** - E/I RNN training
52+
- **integrate_brainpy_into_flax-lif.py** - Integration with Flax (LIF neurons)
53+
- **integrate_brainpy_into_flax-convlstm.py** - Integration with Flax (ConvLSTM)
54+
- **integrate_flax_into_brainpy.py** - Using Flax models in BrainPy
55+
56+
### Training ANN Models
57+
58+
Artificial neural network training examples:
59+
60+
- **mnist-cnn.py** - CNN for MNIST classification
61+
- **mnist_ResNet.py** - ResNet for MNIST classification
62+
63+
### Training SNN Models
64+
65+
Spiking neural network training examples:
66+
67+
- **spikebased_bp_for_cifar10.py** - Spike-based backpropagation for CIFAR-10
68+
- **readme.md** - Additional SNN training documentation
69+
70+
## Requirements
71+
72+
```bash
73+
pip install -U brainpy[cpu] # or brainpy[cuda12] for GPU
74+
```
75+
76+
For version 3.x with 2.x compatibility:
77+
78+
```bash
79+
pip install -U brainpy[cpu]
80+
# Then use: import brainpy.version2 as bp
81+
```
82+
83+
## Usage
84+
85+
Run any example directly:
86+
87+
```bash
88+
python dynamics_simulation/hh_model.py
89+
```
90+
91+
Or with version 3.x (examples may need import updates):
92+
93+
```bash
94+
# Modify imports in the script first, then run
95+
python dynamics_simulation/ei_nets.py
96+
```
97+
98+
## Key Concepts Demonstrated
99+
100+
- **Dynamics Simulation**: Simulating neural circuits and network dynamics
101+
- **Dynamics Analysis**: Phase plane analysis, bifurcation analysis, fixed points
102+
- **Reservoir Computing**: Echo State Networks and Liquid State Machines
103+
- **Network Training**: Gradient-based and FORCE learning for RNNs
104+
- **SNN Training**: Surrogate gradient methods for spiking networks
105+
- **Framework Integration**: Using BrainPy with other frameworks (Flax, JAX)
106+
107+
## Documentation
108+
109+
- [BrainPy 2.x Documentation](https://brainpy-v2.readthedocs.io)
110+
- [BrainPy 3.x Documentation](https://brainpy.readthedocs.io)
111+
- [BrainPy Ecosystem](https://brainmodeling.readthedocs.io)
112+
113+
## Migrating to Version 3.x
114+
115+
For new projects, we recommend using BrainPy 3.x which offers improved performance and a cleaner API. See the migration guide in the main documentation.
116+
117+
## Support
118+
119+
For questions and support, please visit the [BrainPy GitHub repository](https://github.com/brainpy/BrainPy).

examples_version3/README.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# BrainPy Version 3 Examples
2+
3+
This directory contains example scripts demonstrating the capabilities of BrainPy 3.x for simulating and training spiking neural networks.
4+
5+
## Overview
6+
7+
BrainPy 3.x is rewritten based on [brainstate](https://github.com/chaobrain/brainstate) and provides a powerful framework for computational neuroscience and brain-inspired computation.
8+
9+
## Example Categories
10+
11+
### Network Simulations (100-series)
12+
13+
Classic network models demonstrating recurrent dynamics and emergent behaviors:
14+
15+
- **102_EI_net_1996.py** - E/I balanced network from Brunel (1996) and Van Vreeswijk & Sompolinsky (1996)
16+
- **103_COBA_2005.py** - Conductance-based E/I network (COBA model)
17+
- **104_CUBA_2005.py** - Current-based E/I network (CUBA model)
18+
- **106_COBA_HH_2007.py** - COBA network with Hodgkin-Huxley neurons
19+
- **107_gamma_oscillation_1996.py** - Gamma oscillation generation
20+
- **108_synfire_chains_199.py** - Synfire chain propagation
21+
- **109_fast_global_oscillation.py** - Fast global oscillation dynamics
22+
23+
### Gamma Oscillation Models (110-series)
24+
25+
Implementations from Susin & Destexhe (2021) demonstrating different gamma oscillation mechanisms:
26+
27+
- **110_Susin_Destexhe_2021_gamma_oscillation_AI.py** - Asynchronous-Irregular (AI) regime
28+
- **111_Susin_Destexhe_2021_gamma_oscillation_CHING.py** - CHING mechanism
29+
- **112_Susin_Destexhe_2021_gamma_oscillation_ING.py** - Interneuron Gamma (ING)
30+
- **113_Susin_Destexhe_2021_gamma_oscillation_PING.py** - Pyramidal-Interneuron Gamma (PING)
31+
32+
### Spiking Neural Network Training (200-series)
33+
34+
Examples demonstrating training of SNNs using surrogate gradient methods:
35+
36+
- **200_surrogate_grad_lif.py** - Basic surrogate gradient learning with LIF neurons
37+
- **201_surrogate_grad_lif_fashion_mnist.py** - Fashion-MNIST classification with surrogate gradients
38+
- **202_mnist_lif_readout.py** - MNIST classification with LIF network and readout layer
39+
40+
## Requirements
41+
42+
```bash
43+
pip install -U brainpy[cpu] # or brainpy[cuda12] for GPU support
44+
```
45+
46+
## Usage
47+
48+
Run any example directly:
49+
50+
```bash
51+
python 102_EI_net_1996.py
52+
```
53+
54+
## Key Features Demonstrated
55+
56+
- Building recurrent spiking neural networks
57+
- Neuron models (LIF, Hodgkin-Huxley)
58+
- Synaptic models (exponential, conductance-based, current-based)
59+
- Network projection and connectivity
60+
- Surrogate gradient learning for SNNs
61+
- State management and initialization
62+
- Visualization of network activity
63+
64+
## References
65+
66+
These examples are based on influential papers in computational neuroscience. See individual script headers for specific citations.
67+
68+
## Documentation
69+
70+
For more information, visit the [BrainPy documentation](https://brainpy.readthedocs.io).

0 commit comments

Comments
 (0)