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/

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

brainevent-0.2.0.tar.gz (768.0 kB view details)

Uploaded Source

Built Distribution

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

brainevent-0.2.0-py3-none-any.whl (907.1 kB view details)

Uploaded Python 3

File details

Details for the file brainevent-0.2.0.tar.gz.

File metadata

  • Download URL: brainevent-0.2.0.tar.gz
  • Upload date:
  • Size: 768.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for brainevent-0.2.0.tar.gz
Algorithm Hash digest
SHA256 a2963525ff49c85c7ea93af7b6e46ba7f2f3118d03aa2470af063964149ef40e
MD5 0ae1055bb53e5862938d7e021e3b3533
BLAKE2b-256 97f7f0de86af825be5cf815a3304ab30b6aa759926986a5479fdc7a4b0ee9357

See more details on using hashes here.

File details

Details for the file brainevent-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: brainevent-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 907.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for brainevent-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 91ea1c20cc2ca52e5e4626db17b176b2ac8d2519850cc27f420aaf42eb3963fa
MD5 c1fbe04caeb9fcc78d7676e02f0181c2
BLAKE2b-256 cf638ce4d2d98c2f013e78cc4e31232a68bb551853ea26327c2972dc2dba1027

See more details on using hashes here.

Release history Release notifications | RSS feed

0.2.1

2 files

This release

0.2.0 This release

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

0.0.7

2 files

0.0.6

2 files

0.0.5

2 files

0.0.4

1 file

0.0.3

1 file

0.0.2

1 file

0.0.1

1 file

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