Whole-brain brain modeling for differentiable neural mass models.
Project description
BrainMass: whole-brain modeling with differentiable neural mass models
BrainMass is a Python library for whole-brain computational modeling using differentiable neural mass models. Built on JAX for high-performance computing, it provides tools for simulating brain dynamics, fitting neural signal data, and training cognitive tasks.
Installation
From PyPI (recommended)
pip install brainmass
From Source
git clone https://github.com/chaobrain/brainmass.git
cd brainmass
pip install -e .
GPU Support
For CUDA support:
pip install brainmass[cuda12]
pip install brainmass[cuda13]
For TPU support:
pip install brainmass[tpu]
Ecosystem
For whole brain modeling ecosystem:
pip install BrainX
# GPU support
pip install BrainX[cuda12]
pip install BrainX[cuda13]
# TPU support
pip install BrainX[tpu]
Quick Start
Simulate a single brain region with the Hopf oscillator model. The high-level
Simulator drives the compiled run loop and collects the monitored trajectories into a
unit-aware result dict -- no hand-written stepping required. The integration time step
dt is supplied to the Simulator:
import brainmass
import brainunit as u
# Create a single-region Hopf oscillator in the limit-cycle regime (a > 0)
node = brainmass.HopfStep(in_size=1, a=0.25, w=0.3)
# Run for 200 ms, dropping the first 20 ms transient, recording x and y
sim = brainmass.Simulator(node, dt=0.1 * u.ms)
res = sim.run(200 * u.ms, monitors=['x', 'y'], transient=20 * u.ms)
print(res['x'].shape) # (1800, 1)
# Plot the limit cycle (matplotlib via the optional [viz] extra)
brainmass.viz.plot_timeseries(res['x'], ts=res['ts'])
Wiring a whole-brain network and fitting a parameter are just as direct:
import brainmass
import brainunit as u
from brainstate.nn import Param
# A delay-coupled network from a bundled example connectome
conn = brainmass.datasets.load_dataset('example_connectome')
net = brainmass.Network(
brainmass.HopfStep(in_size=conn.weights.shape[0], a=0.1, w=0.3),
conn=conn.weights, distance=conn.distances, speed=10 * u.mm / u.ms,
coupling='diffusive', coupled_var='x', k=0.5,
)
# Fit a model parameter to data with gradients (or swap to Nevergrad / SciPy)
node = brainmass.HopfStep(in_size=1, a=Param(0.1, fit=True), w=0.3)
fitter = brainmass.Fitter(node, loss_fn=my_loss) # backend='grad' | 'nevergrad' | 'scipy'
result = fitter.fit(n_steps=50)
Documentation
The full documentation is organized for different goals:
- Getting Started — installation, a five-minute quickstart, key concepts, and persona learning paths.
- Tutorials — a sequential path from a first simulation to building networks, forward modeling, fitting, and training.
- How-To Guides — task-focused recipes (choose a model, work with units, accelerate, custom coupling/objective, sweeps, analysis).
- Concepts — the why: neural mass models, differentiable programming, architecture, coupling/delays, forward models.
- Data-Driven Modeling — the flagship guided path through the differentiable, data-driven workflow.
- Gallery — a runnable model zoo (one demo per model family) and end-to-end case studies.
- API Reference — every public symbol, organized by category.
- Developer Guide — contributing and the extension playbooks (custom models, couplings, objectives, workflows).
Citation
If you use BrainMass in your research, please cite:
@software{brainmass,
title={BrainMass: Whole-brain modeling with differentiable neural mass models},
author={BrainMass Developers},
url={https://github.com/chaobrain/brainmass},
version={0.1.0},
year={2026}
}
License
BrainMass is licensed under the Apache License 2.0. See LICENSE for details.
See also the ecosystem
BrainMass is one of our brain simulation ecosystem: https://brainx.chaobrain.com/
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file brainmass-0.1.0.tar.gz.
File metadata
- Download URL: brainmass-0.1.0.tar.gz
- Upload date:
- Size: 257.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3f1374a0e28d019b559aa620f234c583a4e46e87092fb48edc60219bede5fe49
|
|
| MD5 |
781b19c0b0b5871ea076d03428169f65
|
|
| BLAKE2b-256 |
2649be6cff6788816e7562f35948ca7e46b048b7f2a1c380506cdf14e6c6b5c0
|
File details
Details for the file brainmass-0.1.0-py3-none-any.whl.
File metadata
- Download URL: brainmass-0.1.0-py3-none-any.whl
- Upload date:
- Size: 317.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2f1c29569689dfdda8ed16cdc3c510fba7096eb0d82da4605f7583d06714be0d
|
|
| MD5 |
8cbb03424340b29475dd2fe3ffee3e83
|
|
| BLAKE2b-256 |
ccdf8a836be89b26e18fe49decd7478cd3c059e131b76c1b4c432752dbebc44f
|