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.3.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 brainevent 0.3.0
File Size Uploaded Provenance
brainevent-0.3.0.tar.gz 1.0 MB Without provenance Details

Built distribution (wheel)

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

Total release size: 2.2 MB

Release files / brainevent-0.3.0.tar.gz

Download URL brainevent-0.3.0.tar.gz
Size 1.0 MB
Tags Source
SHA-256 checksum
How to use checksums
35b18b7b44380268dba9ebceff7f002523ad80aeda1ff6cc5e4a253abc28a1a2
BLAKE2b-256 checksum
How to use checksums
8fd7a6422b1ccfa2558ce873257fe494648d934cfca24d6944ad2d14bb135cd2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

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

Download URL brainevent-0.3.0-py3-none-any.whl
Size 1.2 MB
Tags Python 3
SHA-256 checksum
How to use checksums
0479ef648b6e458dca760e3697f46c627bbd16556f130e2eb19367fd43c0f5b6
BLAKE2b-256 checksum
How to use checksums
d4e4615943aac2a7ddb99c9beab0a115c6d308af35fa8c125c9fec0d10a3372f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Security for brainevent 0.3.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.

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