Skip to main content

Enabling Event-driven Computation in CPU/GPU/TPU

Header image of brainevent.

Supported Python Version LICENSE Documentation Status PyPI version Continuous Integration Daily CI Tests Code Coverage PyPI Downloads DOI

Brain is characterized by the discrete spiking events, which are the fundamental units of computation in the brain.

BrainEvent provides a set of data structures and algorithms for such event-driven computation on CPUs, GPUs, TPUs, and maybe more, which can be used to model the brain dynamics in an efficient and biologically plausible way.

Particularly, it provides the following classes to represent binary (spiking) events in the brain:

  • BinaryArray: an array wrapping a vector/matrix of binary events (spikes).
  • BitPackedBinary: a memory-efficient representation that packs binary events into bits (see also the bitpack helper).
  • CompactBinary: a compact representation that stores only the indices of the active (non-zero) events.

Furthermore, it implements the following commonly used data structures for event-driven computation of the above classes. Most structures come in row-oriented (R) and column-oriented (C) variants:

  • CSR / CSC: sparse matrices in CSR / CSC format for sparse and event-driven computation.
  • JITCScalarR / JITCScalarC: a just-in-time connectivity matrix with homogeneous (scalar) weight for sparse and event-driven computation.
  • JITCNormalR / JITCNormalC: a just-in-time connectivity matrix with normal-distribution weights for sparse and event-driven computation.
  • JITCUniformR / JITCUniformC: a just-in-time connectivity matrix with uniform-distribution weights for sparse and event-driven computation.
  • FixedNumConn / FixedNumPerPre / FixedNumPerPost: fixed-number connectivity matrices, where each neuron has a fixed number of synaptic connections.
  • ...

BrainEvent is fully compatible with physical units and unit-aware computations provided in BrainUnit.

Usage

If you want to take advantage of event-driven computations, you must warp your data with brainevent.BinaryArray:

import brainevent

# wrap your array with BinaryArray
event_array = brainevent.BinaryArray(your_array)

Then, the matrix multiplication with the following data structures, $\mathrm{event\ array} @ \mathrm{data}$, will take advantage of event-driven computations:

  • Sparse data structures provided by brainevent, like:
    • brainevent.CSR
    • brainevent.JITCScalarR
    • brainevent.FixedNumPerPre
    • ...
  • Dense data structures provided by JAX/NumPy, like:
    • jax.numpy.ndarray
    • numpy.ndarray
data = jax.random.rand(...)  # normal dense array
data = brainevent.CSR(...)  # CSR structure
data = brainevent.JITCScalarR(...)  # JIT connectivity
data = brainevent.FixedNumPerPre(...)  # fixed number of post-synaptic connections per pre-neuron

# event-driven matrix multiplication
r = event_array @ data
r = data @ event_array

Installation

You can install brainevent via pip:

pip install brainevent -U

Alternatively, you can install BrainX, which bundles brainevent with other compatible packages for a comprehensive brain modeling ecosystem:

pip install BrainX -U

GPU compile dependencies

The first time a kernel runs on a GPU, brainevent compiles its CUDA source on the fly. This needs three things:

  1. NVIDIA driver (provides libcuda and nvidia-smi) — a system-level requirement for any approach.
  2. jax[cuda12] or jax[cuda13] — installing it pulls in the nvidia-* pip packages, which already bundle nvcc/ptxas/CUDA runtime/headers. A separate system CUDA Toolkit is therefore not required.
  3. A host C++ compiler (g++/clang++) — pip does not provide one. Install it via conda install -c conda-forge gxx, sudo apt-get install g++, or sudo dnf install gcc-c++.

Optional configuration:

  • brainevent.config.prefer_system_nvcc() — prefer the system PATH nvcc instead of the pip-bundled one (pip is the default).
  • Environment variables: BRAINEVENT_NVCC_PREFER=pip|system, BRAINEVENT_NVCC_PATH, CUDA_HOME, CXX.
  • BRAINEVENT_ALLOW_UNSUPPORTED_COMPILER=1 — force compilation when the host gcc is newer than nvcc supports.
  • BRAINEVENT_COMPUTE_CAPABILITIES=8.6,8.0 — skip nvidia-smi auto-detection.
  • BRAINEVENT_TOOLCHAIN_DEBUG=1 — append a "toolchain snapshot" to every toolchain error for easier debugging.

Documentation

The official documentation is hosted on Read the Docs: https://brainx.chaobrain.com/brainevent/

See also the ecosystem

brainevent is one part of our brain modeling ecosystem: https://brainx.chaobrain.com/

Metadata

Release files for brainevent 0.2.1

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

Source distribution (sdist)

Source distribution for brainevent 0.2.1
File Size Uploaded
brainevent-0.2.1.tar.gz 771.4 kB Details

Built distribution (wheel)

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

Total release size: 1.7 MB

Release files / brainevent-0.2.1.tar.gz

Download URL brainevent-0.2.1.tar.gz
Size 771.4 kB
Tags Source
SHA-256 checksum
How to use checksums
102cee6cc13412a206f74f4ce8cd0c5b50aaf6556b22c5ea61a6d654c04dcfaa
BLAKE2b-256 checksum
How to use checksums
3d02123342dea045dd2abb2a3db8b2ed5e00981dad4060f44555adb11b41ccf1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / brainevent-0.2.1-py3-none-any.whl

Download URL brainevent-0.2.1-py3-none-any.whl
Size 914.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
28d352988363e6566c70ac9e8d90f55cd51e2358356fb4913dce94cd2e2f141e
BLAKE2b-256 checksum
How to use checksums
b6d1b76753c11253fbff6b33f842da271ff7af9d748dd669a53e08d50a52b36e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14
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