brainunit

Attach physical units to numerical values and enforce dimensional safety in JAX-based neuroscience computations.

1|Updated Jul 23, 2026
One-click install
npx skills add https://github.com/chaobrain/BrainX-skill --skill brainunit-chaobrain
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: brainunit
Source: https://github.com/chaobrain/BrainX-skill/tree/main/brainx-display-cases/creative-experiment-verification/06-seizure-recruitment/run2/.agents/skills/brainunit
Command: npx skills add https://github.com/chaobrain/BrainX-skill --skill brainunit-chaobrain

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires brainunit, saiunit, jax, numpy, and includes references (resource) components.

What problem does it solve? Scientific code often loses track of physical units, causing silent errors like adding meters to seconds or misreading millivolts as volts. BrainUnit keeps physical meaning attached to every numerical value, catching dimensional mismatches automatically in BrainX brain-dynamics modeling. ## Core Features & Use Cases - Unit-Aware Quantities: Create Quantity objects combining mantissas with SI units, with automatic dimension tracking through arithmetic, conversion via in_unit() and to_decimal(), and predefined neuroscience units like u.mV, u.ms, and u.nA. - JAX Integration and Autodiff: Quantities work with jax.jit and jax.vmap, and u.autograd.grad returns derivatives with correct physical units (e.g., kg·m/s for dEnergy/dv). - Typing and Validation: Annotate functions with u.Quantity["length"] and enforce contracts at runtime using @u.typing.validate_units with optional strict exact-unit checking. - Use Case: When building a neuron model, define membrane voltage in mV, conductance in nS, and time in ms; BrainUnit raises a dimension error if you accidentally add current to voltage, and converts units automatically at external-library boundaries. ## Quick Start Ask the agent to write a BrainX simulation snippet that creates a 20 ms time quantity, converts it to seconds, and computes a unit-aware gradient with brainunit.

Frequently Asked Questions about brainunit

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I create a quantity with physical units in brainunit?

Multiply a number or array by a predefined unit, such as `jnp.array([1.0, 2.5]) * u.mV`, or use `u.Quantity(values, unit=u.nA)`. Import brainunit as `u` and use its predefined unit objects rather than bare scaling factors.

How do I convert between units like mV and volts in brainunit?

Use `q.in_unit(u.volt)` or `q.to(u.volt)` to rescale while keeping the Quantity wrapper, and `q.to_decimal(u.volt)` only when an external API requires raw numbers. Do not use `.mantissa` as a substitute for conversion.

Does brainunit work with JAX jit and vmap transformations?

Yes, BrainUnit quantities work with `jax.jit` and `jax.vmap`, with units tracked through compilation. For gradients, use `u.autograd.grad`, which returns derivatives with correct units, unlike raw `jax.grad`.

What happens when I add quantities with incompatible dimensions?

BrainUnit raises a dimension-mismatch error rather than silently reinterpreting values. Addition and subtraction require matching dimensions, while multiplication and division combine dimension exponents automatically.

How do I validate function arguments have the right physical units?

Annotate parameters with `u.Quantity["length"]` or `u.Quantity[u.meter]` and apply the `@u.typing.validate_units` decorator. By default it accepts dimensionally compatible scales; `strict=True` requires an exact unit match.

Why is brainunit.typing missing after installation?

Some released BrainUnit wheels lag the official site and lack `brainunit.typing`. Upgrade BrainUnit together with its exact SaiUnit dependency, and do not mix validators and Quantity types from different releases.