Skip to main content

Physical Units and Unit-Aware Mathematical System for General-Purpose Brain Dynamics Modeling

Project description

BrainUnit

Physical units and unit-aware math system for general-purpose brain dynamics modeling

Header image of brainunit.

Supported Python Version LICENSE Documentation Status PyPI version PyPI Downloads

BrainUnit provides physical units and unit-aware mathematical system in JAX for brain dynamics modeling. It introduces rigoirous physical units into high-performance AI-driven abstract numerical computing.

BrainUnit is initially designed to enable unit-aware computations in brain dynamics modeling (see our BDP ecosystem). However, its features and capacities can be applied to general domains in scientific computing and AI4Science. Starting in 2025/02, BrainUnit has been fully integrated into SAIUnit (the Unit system for Scientific AI).

Functionalities are the same for both brainunit and saiunit, and their functions and data structures are interoperable, sharing the same set of APIs, and eliminating any potential conflicts. This meas that

import brainunit as u

equals to

import saiunit as u

For users primarily engaged in general scientific computing, saiunit is likely the preferred choice. However, for those focused on brain modeling, we recommend brainunit, as it is more closely aligned with our specialized brain dynamics programming ecosystem.

Documentation

The official documentation of BrainUnit is hosted on Read the Docs: https://brainunit.readthedocs.io

Features

brainunit can be seamlessly integrated into every aspect of our brain modeling ecosystem, such as, the checkpointing of braintools, the event-driven operators in brainevent, the state-based JIT compilation in brainstate, online learning rules in brainscale, or event more.

A quick example for this kind of integration:

import braintools
import brainevent
import brainstate
import brainunit as u


class EINet(brainstate.nn.Module):
    def __init__(self):
        super().__init__()
        self.n_exc = 3200
        self.n_inh = 800
        self.num = self.n_exc + self.n_inh
        self.N = brainstate.nn.LIFRef(
            self.num, V_rest=-60. * u.mV, V_th=-50. * u.mV, V_reset=-60. * u.mV,
            tau=20. * u.ms, tau_ref=5. * u.ms,
            V_initializer=brainstate.init.Normal(-55., 2., unit=u.mV)
        )
        self.E = brainstate.nn.AlignPostProj(
            comm=brainstate.nn.EventFixedProb(self.n_exc, self.num, 0.02, 0.6 * u.mS),
            syn=brainstate.nn.Expon.desc(self.num, tau=5. * u.ms),
            out=brainstate.nn.COBA.desc(E=0. * u.mV),
            post=self.N
        )
        self.I = brainstate.nn.AlignPostProj(
            comm=brainstate.nn.EventFixedProb(self.n_inh, self.num, 0.02, 6.7 * u.mS),
            syn=brainstate.nn.Expon.desc(self.num, tau=10. * u.ms),
            out=brainstate.nn.COBA.desc(E=-80. * u.mV),
            post=self.N
        )

    def update(self, t, inp):
        with brainstate.environ.context(t=t):
            spk = self.N.get_spike() != 0.
            self.E(spk[:self.n_exc])
            self.I(spk[self.n_exc:])
            self.N(inp)
            return self.N.get_spike()
    
    def save_checkpoint(self):
        braintools.file.msgpack_save('states.msgpack', self.states())
    

Installation

You can install brainunit via pip:

pip install brainunit --upgrade

Citation

If you use brainunit in your research, please consider citing the following paper:

@article{wang2025integrating,
  title={Integrating physical units into high-performance AI-driven scientific computing},
  author={Wang, Chaoming and He, Sichao and Luo, Shouwei and Huan, Yuxiang and Wu, Si},
  journal={Nature Communications},
  volume={16},
  number={1},
  pages={3609},
  year={2025},
  publisher={Nature Publishing Group UK London},
  url={https://doi.org/10.1038/s41467-025-58626-4}
}

See also the ecosystem

brainunit is one part of our brain modeling ecosystem.

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

brainunit-0.1.4.tar.gz (10.4 kB view details)

Uploaded Source

Built Distribution

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

brainunit-0.1.4-py3-none-any.whl (31.8 kB view details)

Uploaded Python 3

File details

Details for the file brainunit-0.1.4.tar.gz.

File metadata

  • Download URL: brainunit-0.1.4.tar.gz
  • Upload date:
  • Size: 10.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for brainunit-0.1.4.tar.gz
Algorithm Hash digest
SHA256 8045145d16a13b30fa36941f772bac740dabb60396cd89efc3e96e33e3191bcb
MD5 3397b1fcc878fdaa96613f6f7d469580
BLAKE2b-256 2d4f10001c3a7b600d9d4f4f891ad8769e0e5e3b759eeb1879758975008c91e6

See more details on using hashes here.

File details

Details for the file brainunit-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: brainunit-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 31.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for brainunit-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 69bef9d660f08c59d6eb9e2eac1f366d2a1f1b91f873e2e27fbda237a520c231
MD5 67e58accfd942722eff1499203cba23f
BLAKE2b-256 3f7f7a1517dbe23af8f8794efbf15f05195beef9434c2fccefb049ef1e79e1e6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page