brainunit


Namebrainunit JSON
Version 0.0.7 PyPI version JSON
download
home_pagehttps://github.com/chaobrain/brainunit
SummaryPhysical Units and Unit-Aware Mathematical System for General-Purpose Brain Dynamics Modeling
upload_time2025-02-10 12:51:54
maintainerNone
docs_urlNone
authorBrainUnit Developers
requires_python>=3.9
licenseApache-2.0 license
keywords physical unit physical quantity brain modeling
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <h1 align='center'>BrainUnit</h1>
<h2 align='center'>Physical units and unit-aware math system for general-purpose brain dynamics modeling</h2>

<p align="center">
  	<img alt="Header image of brainunit." src="https://raw.githubusercontent.com/chaobrain/saiunit/main/docs/_static/brainunit.png" width=30%>
</p> 



<p align="center">
	<a href="https://pypi.org/project/brainunit/"><img alt="Supported Python Version" src="https://img.shields.io/pypi/pyversions/brainunit"></a>
	<a href="https://github.com/chaobrain/brainunit/blob/main/LICENSE"><img alt="LICENSE" src="https://img.shields.io/badge/License-Apache%202.0-blue.svg"></a>
    <a href='https://brainunit.readthedocs.io/en/latest/?badge=latest'>
        <img src='https://readthedocs.org/projects/brainunit/badge/?version=latest' alt='Documentation Status' />
    </a>  	
    <a href="https://badge.fury.io/py/brainunit"><img alt="PyPI version" src="https://badge.fury.io/py/brainunit.svg"></a>
    <a href="https://pepy.tech/projects/brainunit"><img src="https://static.pepy.tech/badge/brainunit" alt="PyPI Downloads"></a>
</p>




[BrainUnit](https://github.com/chaobrain/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](https://ecosystem-for-brain-dynamics.readthedocs.io/)). 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](https://github.com/chaobrain/saiunit) (the **Unit** system for **S**cientific **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 

```python
import brainunit as u
```

equals to 

```python
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](https://brainunit.readthedocs.io)



## Features

`brainunit` can be seamlessly integrated into every aspect of our [brain dynamics programming ecosystem](https://ecosystem-for-brain-dynamics.readthedocs.io/), such as, the checkpointing of [braintools](https://github.com/chaobrain/braintools), the event-driven operators in [brainevent](https://github.com/chaobrain/brainevent), the state-based JIT compilation in [brainstate](https://github.com/chaobrain/brainstate), online learning rules in [brainscale](https://github.com/chaobrain/brainscale), or event more. 

A quick example for this kind of integration:

```python

import braintools
import brainevent.nn
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=brainevent.nn.FixedProb(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=brainevent.nn.FixedProb(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:

```bash
pip install brainunit --upgrade
```



## See also the BDP ecosystem

We are building the [brain dynamics programming (BDP) ecosystem](https://ecosystem-for-brain-dynamics.readthedocs.io/). [brainunit](https://github.com/chaobrain/brainunit) has been deeply integrated into our BDP ecosystem.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/chaobrain/brainunit",
    "name": "brainunit",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "physical unit, physical quantity, brain modeling",
    "author": "BrainUnit Developers",
    "author_email": "BrainUnit Developers <chao.brain@qq.com>",
    "download_url": null,
    "platform": null,
    "description": "<h1 align='center'>BrainUnit</h1>\r\n<h2 align='center'>Physical units and unit-aware math system for general-purpose brain dynamics modeling</h2>\r\n\r\n<p align=\"center\">\r\n  \t<img alt=\"Header image of brainunit.\" src=\"https://raw.githubusercontent.com/chaobrain/saiunit/main/docs/_static/brainunit.png\" width=30%>\r\n</p> \r\n\r\n\r\n\r\n<p align=\"center\">\r\n\t<a href=\"https://pypi.org/project/brainunit/\"><img alt=\"Supported Python Version\" src=\"https://img.shields.io/pypi/pyversions/brainunit\"></a>\r\n\t<a href=\"https://github.com/chaobrain/brainunit/blob/main/LICENSE\"><img alt=\"LICENSE\" src=\"https://img.shields.io/badge/License-Apache%202.0-blue.svg\"></a>\r\n    <a href='https://brainunit.readthedocs.io/en/latest/?badge=latest'>\r\n        <img src='https://readthedocs.org/projects/brainunit/badge/?version=latest' alt='Documentation Status' />\r\n    </a>  \t\r\n    <a href=\"https://badge.fury.io/py/brainunit\"><img alt=\"PyPI version\" src=\"https://badge.fury.io/py/brainunit.svg\"></a>\r\n    <a href=\"https://pepy.tech/projects/brainunit\"><img src=\"https://static.pepy.tech/badge/brainunit\" alt=\"PyPI Downloads\"></a>\r\n</p>\r\n\r\n\r\n\r\n\r\n[BrainUnit](https://github.com/chaobrain/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. \r\n\r\nBrainUnit is initially designed to enable unit-aware computations in brain dynamics modeling (see our [BDP ecosystem](https://ecosystem-for-brain-dynamics.readthedocs.io/)). 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](https://github.com/chaobrain/saiunit) (the **Unit** system for **S**cientific **AI**). \r\n\r\nFunctionalities 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 \r\n\r\n```python\r\nimport brainunit as u\r\n```\r\n\r\nequals to \r\n\r\n```python\r\nimport saiunit as u\r\n```\r\n\r\nFor 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.\r\n\r\n\r\n\r\n## Documentation\r\n\r\nThe official documentation of BrainUnit is hosted on Read the Docs: [https://brainunit.readthedocs.io](https://brainunit.readthedocs.io)\r\n\r\n\r\n\r\n## Features\r\n\r\n`brainunit` can be seamlessly integrated into every aspect of our [brain dynamics programming ecosystem](https://ecosystem-for-brain-dynamics.readthedocs.io/), such as, the checkpointing of [braintools](https://github.com/chaobrain/braintools), the event-driven operators in [brainevent](https://github.com/chaobrain/brainevent), the state-based JIT compilation in [brainstate](https://github.com/chaobrain/brainstate), online learning rules in [brainscale](https://github.com/chaobrain/brainscale), or event more. \r\n\r\nA quick example for this kind of integration:\r\n\r\n```python\r\n\r\nimport braintools\r\nimport brainevent.nn\r\nimport brainstate\r\nimport brainunit as u\r\n\r\n\r\nclass EINet(brainstate.nn.Module):\r\n    def __init__(self):\r\n        super().__init__()\r\n        self.n_exc = 3200\r\n        self.n_inh = 800\r\n        self.num = self.n_exc + self.n_inh\r\n        self.N = brainstate.nn.LIFRef(\r\n            self.num, V_rest=-60. * u.mV, V_th=-50. * u.mV, V_reset=-60. * u.mV,\r\n            tau=20. * u.ms, tau_ref=5. * u.ms,\r\n            V_initializer=brainstate.init.Normal(-55., 2., unit=u.mV)\r\n        )\r\n        self.E = brainstate.nn.AlignPostProj(\r\n            comm=brainevent.nn.FixedProb(self.n_exc, self.num, 0.02, 0.6 * u.mS),\r\n            syn=brainstate.nn.Expon.desc(self.num, tau=5. * u.ms),\r\n            out=brainstate.nn.COBA.desc(E=0. * u.mV),\r\n            post=self.N\r\n        )\r\n        self.I = brainstate.nn.AlignPostProj(\r\n            comm=brainevent.nn.FixedProb(self.n_inh, self.num, 0.02, 6.7 * u.mS),\r\n            syn=brainstate.nn.Expon.desc(self.num, tau=10. * u.ms),\r\n            out=brainstate.nn.COBA.desc(E=-80. * u.mV),\r\n            post=self.N\r\n        )\r\n\r\n    def update(self, t, inp):\r\n        with brainstate.environ.context(t=t):\r\n            spk = self.N.get_spike() != 0.\r\n            self.E(spk[:self.n_exc])\r\n            self.I(spk[self.n_exc:])\r\n            self.N(inp)\r\n            return self.N.get_spike()\r\n    \r\n    def save_checkpoint(self):\r\n        braintools.file.msgpack_save('states.msgpack', self.states())\r\n    \r\n```\r\n\r\n\r\n\r\n## Installation\r\n\r\nYou can install ``brainunit`` via pip:\r\n\r\n```bash\r\npip install brainunit --upgrade\r\n```\r\n\r\n\r\n\r\n## See also the BDP ecosystem\r\n\r\nWe are building the [brain dynamics programming (BDP) ecosystem](https://ecosystem-for-brain-dynamics.readthedocs.io/). [brainunit](https://github.com/chaobrain/brainunit) has been deeply integrated into our BDP ecosystem.\r\n",
    "bugtrack_url": null,
    "license": "Apache-2.0 license",
    "summary": "Physical Units and Unit-Aware Mathematical System for General-Purpose Brain Dynamics Modeling",
    "version": "0.0.7",
    "project_urls": {
        "Homepage": "https://github.com/chaobrain/brainunit",
        "homepage": "http://github.com/chaobrain/brainunit",
        "repository": "http://github.com/chaobrain/brainunit"
    },
    "split_keywords": [
        "physical unit",
        " physical quantity",
        " brain modeling"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7d948aef023d850f4d8297f6ef6dc2b0f6a14b402ea29388427c4dee947d8a39",
                "md5": "d140c95f15b3c135f23217ef49c3a978",
                "sha256": "539e5b009ac4827c8419af592bb35b560240687c9413276da4a8f7ce881855e6"
            },
            "downloads": -1,
            "filename": "brainunit-0.0.7-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "d140c95f15b3c135f23217ef49c3a978",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": ">=3.9",
            "size": 31748,
            "upload_time": "2025-02-10T12:51:54",
            "upload_time_iso_8601": "2025-02-10T12:51:54.437688Z",
            "url": "https://files.pythonhosted.org/packages/7d/94/8aef023d850f4d8297f6ef6dc2b0f6a14b402ea29388427c4dee947d8a39/brainunit-0.0.7-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-02-10 12:51:54",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "chaobrain",
    "github_project": "brainunit",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "brainunit"
}
        
Elapsed time: 1.58080s