Skip to main content

Modeling tools for brain simulation

Header image of braintools.

Supported Python Version LICENSE PyPI version Continuous Integration Test Coverage DOI

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 to brainevent sparse formats
  • Initializers (braintools.init): parameter initializers (distributions, variance scaling, orthogonal, composites) and distance profiles shared with the connectivity builders
  • Spike data (braintools.spike): the SpikeTrains container (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 for jit/vmap, a fixed-step trajectory driver (odeint) and a differentiable adaptive solver (solve_ivp)
  • Model fitting (braintools.fit): fit any JAX or brainstate model 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 >> b runs b after a (sequential)
  • a * n repeats a n times
  • a | b runs a and b in parallel (multi-modal stimuli)
  • If, Switch, While add 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.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for braintools 0.5.0
File Size Uploaded Provenance Actions
braintools-0.5.0.tar.gz 1.4 MB Without provenance Details for braintools-0.5.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for braintools 0.5.0
File Interpreter ABI Platform Actions
braintools-0.5.0-py3-none-any.whl Python 3 none any Details for braintools-0.5.0-py3-none-any.whl

Total release size: 3.0 MB

Release files / braintools-0.5.0.tar.gz

Download URL braintools-0.5.0.tar.gz
Size 1.4 MB
Tags Source
SHA-256 checksum
How to use checksums
4104e68197e432e5667cb24244fcf877f31a83948c75aca9b506a35115595f6c
BLAKE2b-256 checksum
How to use checksums
13a18bf135bad153b085d4603da247a70c333832738be122737a218be65dc416
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / braintools-0.5.0-py3-none-any.whl

Download URL braintools-0.5.0-py3-none-any.whl
Size 1.7 MB
Tags Python 3
SHA-256 checksum
How to use checksums
dec6387b9cd442444527057b7382510d7adc3a9b8ceeada68fa6a0631db27adc
BLAKE2b-256 checksum
How to use checksums
26fc3dd84e105d93483cab649dca6feca1c1aa900995a63341f12d594f17e8cc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Security for braintools 0.5.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.

Release history Release notifications | RSS feed

This release

0.5.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page