braintools documentation

braintools documentation#

braintools implements a modern toolbox for brain simulation and analysis.

Overview#

braintools is a lightweight, JAX-friendly collection of utilities used across computational neuroscience workflows:

  • Declarative, unit-aware synaptic connectivity builders (braintools.conn) for point neurons, multi-compartment morphologies, and convolution kernels, population networks built from populations and projections, memory-bounded generation for large networks, and export to brainevent sparse formats; parameter initializers and distance profiles are in braintools.init

  • Spike data utilities (braintools.spike): the SpikeTrains container (a padded, jit/vmap-friendly spike-time layout with dense/event conversions), spike encoders, and bitwise spike operations

  • Neural data analysis (braintools.analysis): spike-train statistics (ISI/CV/Fano, PSTHs, correlograms, spike-train distances, synchrony), spectral and LFP analysis (multitaper and wavelet spectra, filtering, phase synchrony, cross-frequency coupling, current source density), population analysis (PCA, decoding, Granger causality, avalanches, functional connectivity), structural graph measures, and resampling-based statistics

  • A composable cognitive task framework (braintools.cogtask) for constructing trial-structured tasks — decision making, working memory, reasoning, motor — with JIT/vmap-friendly batch sampling and a registry of pre-built paradigms

  • Numerical integration utilities for ODE/SDE/DDE/IMEX one-step steppers (braintools.quad) designed for PyTrees and functional APIs, with a trajectory driver (odeint) and a differentiable adaptive solver (solve_ivp)

  • Model fitting (braintools.fit): composable objectives, summary-statistic losses, vmapped multi-start fitting of functions or brainstate modules, parameter sweeps, and confidence intervals

  • Losses and metrics for model training (braintools.metric): classification, regression, ranking, and pairwise similarity

  • Visualization helpers (braintools.visualize), input generators (braintools.input), surrogate gradients (braintools.surrogate), and PyTree utilities (braintools.tree)

  • Optimizer wrappers (braintools.optim) including a multi-start minimizer, online readout learning (RLS, LMS, FORCE) and closed-form regressions, and a lightweight training loop (braintools.trainer)

  • Data files (braintools.file): checkpoints, MATLAB files, and optional HDF5, NWB, and NEO formats

The project favors a simple, well-typed functional style that works seamlessly with brainstate, brainunit, and just-in-time compilation (jit/vmap).

Installation#

pip install -U braintools[cpu]
pip install -U braintools[cuda12]
pip install -U braintools[cuda13]
pip install -U braintools[tpu]

Upgrading to 1.0#

Names that moved since 0.4 still work but emit a BraintoolsDeprecationWarning (a FutureWarning, shown by default); version 1.0 removes them. The migration guide lists every deprecated name with its replacement.


See also the ecosystem#

BrainTools is one part of our brain simulation ecosystem.