Skip to main content

brainpy.state: stateful spiking neural network models in BrainPy

Project description

Header image of brainpy.state - brain dynamics programming in Python.

Supported Python Version LICENSE Documentation PyPI version Continuous Integration

brainpy.state provides comprehensive spiking neural network models built on JAX and brainstate. It is the point-neuron modeling layer of the BrainX ecosystem.

The library ships 167+ models organized in three tiers:

  • Base classes: Dynamics, Neuron, Synapse, the abstract foundation every model inherits from.
  • BrainPy-style models (45+): high-level, composable neurons (LIF, HH, Izhikevich, …), synapses (Expon, Alpha, AMPA, NMDA, …), projections, readouts, and input generators previously designed in BrainPy.
  • NEST-compatible models (119+): faithful JAX re-implementations of NEST simulator neuron, synapse, plasticity (STDP, STP), and device models.
  • All parameters carry physical units via brainunit, and every neuron supports surrogate-gradient-based training out of the box.

Compared to brainpy.dyn, brainpy.state has the following characteristics:

  • Ecosystem compatability: brainpy.state is built on brainstate and fully compatible with BrainX ecosystem.
  • Model scope: brainpy.state implements much more models including BrainPy-style models plus a large NEST-compatible model set.
  • Scientific ergonomics: brainpy.state uses physical units via brainunit by default and is designed for surrogate-gradient training.

Features

  • Comprehensive model library — 18 neuron families, 6 synapse types, 9 STDP rules, 17 generators, and more.
  • Physical units everywhere — parameters use brainunit quantities (mV, ms, nS, …), preventing unit errors.
  • Differentiable — surrogate gradients enable backpropagation through spiking networks for training with gradient descent.
  • NEST compatibility — benchmarked against NEST for numerical accuracy; uses NEST-compatible parameter names.
  • Hardware-accelerated — JAX backend with JIT compilation for CPU, GPU, and TPU.
  • Composable architecture — mix-and-match neurons, synapses, synaptic outputs (COBA/CUBA/MgBlock), and projections.

Quick Example

import brainpy
import brainstate
import brainunit as u

# Create neuron populations
E = brainpy.state.LIF(3200, V_rest=-60*u.mV, V_th=-50*u.mV, tau=20*u.ms)
I = brainpy.state.LIF(800,  V_rest=-60*u.mV, V_th=-50*u.mV, tau=20*u.ms)

Links

Installation

brainpy.state requires Python >= 3.10 and runs on Linux, macOS, and Windows.

pip install brainpy.state -U

For hardware-specific JAX backends:

pip install brainpy.state[cpu] -U     # CPU only
pip install brainpy.state[cuda12] -U  # CUDA 12.x
pip install brainpy.state[cuda13] -U  # CUDA 13.x
pip install brainpy.state[tpu] -U     # TPU

Or install the full BrainX ecosystem:

pip install BrainX -U

Ecosystem

brainpy.state is one part of the BrainX ecosystem:

Package Description
brainstate State management for JAX-based brain modeling
brainunit Physical units for neuroscience
brainevent Event-driven sparse operators
braintools Surrogate gradients, analysis, and utilities

Citing

If you use brainpy.state, please consider citing the following paper:

@article {10.7554/eLife.86365,
    article_type = {journal},
    title = {BrainPy, a flexible, integrative, efficient, and extensible framework for general-purpose brain dynamics programming},
    author = {Wang, Chaoming and Zhang, Tianqiu and Chen, Xiaoyu and He, Sichao and Li, Shangyang and Wu, Si},
    editor = {Stimberg, Marcel},
    volume = 12,
    year = 2023,
    month = {dec},
    pub_date = {2023-12-22},
    pages = {e86365},
    citation = {eLife 2023;12:e86365},
    doi = {10.7554/eLife.86365},
    url = {https://doi.org/10.7554/eLife.86365},
    abstract = {Elucidating the intricate neural mechanisms underlying brain functions requires integrative brain dynamics modeling. To facilitate this process, it is crucial to develop a general-purpose programming framework that allows users to freely define neural models across multiple scales, efficiently simulate, train, and analyze model dynamics, and conveniently incorporate new modeling approaches. In response to this need, we present BrainPy. BrainPy leverages the advanced just-in-time (JIT) compilation capabilities of JAX and XLA to provide a powerful infrastructure tailored for brain dynamics programming. It offers an integrated platform for building, simulating, training, and analyzing brain dynamics models. Models defined in BrainPy can be JIT compiled into binary instructions for various devices, including Central Processing Unit (CPU), Graphics Processing Unit (GPU), and Tensor Processing Unit (TPU), which ensures high running performance comparable to native C or CUDA. Additionally, BrainPy features an extensible architecture that allows for easy expansion of new infrastructure, utilities, and machine-learning approaches. This flexibility enables researchers to incorporate cutting-edge techniques and adapt the framework to their specific needs},
    journal = {eLife},
    issn = {2050-084X},
    publisher = {eLife Sciences Publications, Ltd},
}

@inproceedings{wang2024a,
    title={A differentiable brain simulator bridging brain simulation and brain-inspired computing},
    author={Chaoming Wang and Tianqiu Zhang and Sichao He and Hongyaoxing Gu and Shangyang Li and Si Wu},
    booktitle={The Twelfth International Conference on Learning Representations},
    year={2024},
    url={https://openreview.net/forum?id=AU2gS9ut61}
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

brainpy_state-0.0.4.tar.gz (1.5 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

brainpy_state-0.0.4-py3-none-any.whl (1.7 MB view details)

Uploaded Python 3

File details

Details for the file brainpy_state-0.0.4.tar.gz.

File metadata

  • Download URL: brainpy_state-0.0.4.tar.gz
  • Upload date:
  • Size: 1.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for brainpy_state-0.0.4.tar.gz
Algorithm Hash digest
SHA256 becb1af7bdc3303168c6cfaec9bdc080a3628d17164c17af23de2bfd0bf688fb
MD5 3b36bab0deef954277b5c3b4b7b9d943
BLAKE2b-256 478e775f1f2ef34b408f3f8c7093c96ae8cc50dfb076d6d23bf2a4f8f2c7884e

See more details on using hashes here.

File details

Details for the file brainpy_state-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: brainpy_state-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 1.7 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for brainpy_state-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 d8d68053f99461d20ef9d6df84998c0ed4a0217022b1cd7bb21a1122f3da3821
MD5 572ddb58beb1c71bc7ed93516aaa52a6
BLAKE2b-256 995d4f7f864b7695d371da54046694a16faee82eb327674d507a4b9f5d75397a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page