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/
Metadata
Release files for brainmass 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| brainmass-0.1.1.tar.gz | 257.2 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| brainmass-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 574.5 kB
Release files / brainmass-0.1.1.tar.gz
| Download URL | brainmass-0.1.1.tar.gz |
|---|---|
| Size | 257.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
995ed623e8426026a4d99d89ed6fbf6859f89d199b261417e956ad002449fd27
|
|
BLAKE2b-256 checksum How to use checksums |
84767eb3ac002cced21b3ae1d061ea4377c80bf9ec765625fd1c6e8f1d6f0ce1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Release files / brainmass-0.1.1-py3-none-any.whl
| Download URL | brainmass-0.1.1-py3-none-any.whl |
|---|---|
| Size | 317.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1fab73ed7900159e1a22d77a7aa9ba032be36e7f91233d6eb561e1b00b6e7e05
|
|
BLAKE2b-256 checksum How to use checksums |
4640bbb0e80441b45ac74c9cfdf4d6843a003c4db13c250d712541b4798b37e9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Security for brainmass 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.