Modeling tools for brain simulation
braintools is a lightweight, JAX-friendly toolbox with practical utilities for brain modeling.
Highlights
- Connectivity builders (
braintools.conn): declarative, unit-aware patterns for point neurons (random, fixed in-/out-degree, distance-dependent, small-world, modular, ...), multi-compartment morphologies, and convolution kernels; population networks assembled from populations and projections; vectorised, memory-bounded generation that scales to 1e5-neuron networks; export tobraineventsparse formats - Initializers (
braintools.init): parameter initializers (distributions, variance scaling, orthogonal, composites) and distance profiles shared with the connectivity builders - Spike data (
braintools.spike): theSpikeTrainscontainer (a padded,jit/vmap-friendly spike-time layout with dense/event conversions), spike encoders (latency, rate, Poisson, population, ...), 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 of connectivity, and resampling-based statistics - Cognitive task framework (
braintools.cogtask): phase-based, composable trial construction for training and analyzing networks on classic systems-neuroscience paradigms, plus a registry of pre-built tasks - Numerical integration (
braintools.quad): PyTree-aware ODE/SDE/DDE/IMEX one-step integrators ready forjit/vmap, a fixed-step trajectory driver (odeint) and a differentiable adaptive solver (solve_ivp) - Model fitting (
braintools.fit): fit any JAX orbrainstatemodel to data with composable objectives, summary-statistic losses, vmapped multi-start optimization, parameter sweeps, and confidence intervals - Losses and metrics (
braintools.metric): classification, regression, ranking, and pairwise-similarity losses for training - Inputs, surrogates, and visualization: input-current generators (
braintools.input), surrogate gradients (braintools.surrogate), and plotting helpers (braintools.visualize) - Training helpers: optimizer wrappers (
braintools.optim), a multi-start minimizer, online readout learning (RLS, LMS, FORCE), closed-form regressions, and a lightweight training loop (braintools.trainer) - Data files (
braintools.file): checkpoints, MATLAB files, and optional HDF5, NWB, and NEO formats
braintools integrates smoothly with the broader ecosystem (e.g., brainstate, brainunit) while keeping a simple, functional style.
Installation
pip install -U braintools
Optional extras select a JAX backend:
pip install -U braintools[cpu]
# CUDA 12.x / CUDA 13.x wheels
pip install -U braintools[cuda12]
pip install -U braintools[cuda13]
# TPU runtime
pip install -U braintools[tpu]
and enable optional features:
pip install -U braintools[viz] # interactive plotly figures in braintools.visualize
pip install -U braintools[progress] # tqdm / rich progress bars in braintools.trainer
pip install -U braintools[nevergrad] # gradient-free optimization in braintools.optim
Alternatively, install the curated BrainX bundle that ships with braintools and related projects:
pip install -U BrainX
Cognitive task framework (braintools.cogtask)
braintools.cogtask lets you build cognitive tasks from composable, named phases (fixation, stimulus, delay, response, ...) connected by simple operators:
a >> brunsbaftera(sequential)a * nrepeatsantimesa | brunsaandbin parallel (multi-modal stimuli)If,Switch,Whileadd trial-by-trial branching
Trials are generated lazily via task.sample(i) / task.batch_sample(B), both JIT- and vmap-friendly, with per-trial keys derived from seed so batches are fully reproducible.
import brainstate
import brainunit as u
from braintools.cogtask import PerceptualDecisionMaking
# Phase durations are expressed in units of the environment timestep, so a
# timestep must be set before a task is sampled.
brainstate.environ.set(dt=1.0 * u.ms)
task = PerceptualDecisionMaking(t_stimulus=1500 * u.ms, num_choices=2, seed=0)
X, Y = task.batch_sample(32) # X: (T, B, n_in), Y: (T, B) labels
The package also ships a registry of canonical tasks: PerceptualDecisionMaking, ContextDecisionMaking, DelayMatchSample, DelayComparison, GoNoGo, ReadySetGo, PostDecisionWager, Reaching1D, EvidenceAccumulation, HierarchicalReasoning, and more — see the API reference for the full list.
Documentation
The full documentation is available at https://brainx.chaobrain.com/braintools/
Upgrading to 1.0
Names that moved since 0.4 (for example the metric analysis functions, now in braintools.analysis, and the top-level spike encoders, now in braintools.spike) 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.
Ecosystem
braintools is one part of our brain simulation ecosystem: https://brainx.chaobrain.com/
Contributing
Contributions and issue reports are welcome! See CONTRIBUTING.md for guidelines.
License
Apache 2.0. See LICENSE for details.
Citation
If you use braintools in your work, please cite the Zenodo DOI: 10.5281/zenodo.17110064
Metadata
Release files for braintools 0.4.0
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 | Actions |
|---|---|---|---|---|
| braintools-0.4.0.tar.gz | 1.2 MB | Without provenance | Details for braintools-0.4.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| braintools-0.4.0-py3-none-any.whl | Python 3 | none | any | Details for braintools-0.4.0-py3-none-any.whl |
Total release size: 2.6 MB
Release files / braintools-0.4.0.tar.gz
| Download URL | braintools-0.4.0.tar.gz |
|---|---|
| Size | 1.2 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
00b5c367ec6d1cfcf8d1d03968b07ca43a7f353f6cade73de18318291d66d6aa
|
|
BLAKE2b-256 checksum How to use checksums |
4c1323dac6df100b885a2e4520a3377fc3f5fe73f16004f94f5ca0d2bacbf993
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / braintools-0.4.0-py3-none-any.whl
| Download URL | braintools-0.4.0-py3-none-any.whl |
|---|---|
| Size | 1.4 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
98e1e3aa49b9734e0c5d4f3f694ddec992002471971e998417d7c43cc3d9b6e0
|
|
BLAKE2b-256 checksum How to use checksums |
ed5e5a96c4cbde0e314afd5095bea11f801c2f96f7feb19c0d24ca0692262d0c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Security for braintools 0.4.0
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.
To learn more about protecting yourself from malicious actors, visit our package security documentation.