Skip to main content

Whole-brain brain modeling for differentiable neural mass models.

Project description

BrainMass: whole-brain modeling with differentiable neural mass models

Header image of braintrace.

License PyPI Version PyPI Downloads CI Python Docs

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

brainmass-0.1.1.tar.gz (257.2 kB view details)

Uploaded Source

Built Distribution

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

brainmass-0.1.1-py3-none-any.whl (317.3 kB view details)

Uploaded Python 3

File details

Details for the file brainmass-0.1.1.tar.gz.

File metadata

  • Download URL: brainmass-0.1.1.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

Hashes for brainmass-0.1.1.tar.gz
Algorithm Hash digest
SHA256 995ed623e8426026a4d99d89ed6fbf6859f89d199b261417e956ad002449fd27
MD5 fd4d4edd26ccb9af7f5d851506ccb851
BLAKE2b-256 84767eb3ac002cced21b3ae1d061ea4377c80bf9ec765625fd1c6e8f1d6f0ce1

See more details on using hashes here.

File details

Details for the file brainmass-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: brainmass-0.1.1-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

Hashes for brainmass-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1fab73ed7900159e1a22d77a7aa9ba032be36e7f91233d6eb561e1b00b6e7e05
MD5 73c4cf16a30b15bdb1ca83cc2a849145
BLAKE2b-256 4640bbb0e80441b45ac74c9cfdf4d6843a003c4db13c250d712541b4798b37e9

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