|
| 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). |
0 commit comments