Brian2 units and equations
Use this route when a task is about dimensional correctness, equation-string
syntax, stochastic symbols, numerical integration method selection, namespaces,
or unit-aware custom functions. Load only the reference needed for the current
question:
- Equation syntax for declarations, flags,
special symbols, parser limits, namespaces, and integrated-form conversion.
- Numerical methods for deterministic and
stochastic state-updater choices and restrictions.
- API reference for units,
Equations,
check_units, Function, and implementation boundaries.
- Troubleshooting for classified failures.
For a quick, read-only probe of unit declarations and unit-aware functions, run
python scripts/unit_equation_smoke.py --help, then --all in an environment
where the brian2 package imports successfully. The smoke script intentionally
checks both passing and failing dimensional cases; it is not a replacement for
model or device tests.
Operating procedure
- Write down the physical dimension of every state variable, parameter,
derivative, and external value. In a differential declaration, the unit
after
: is the variable's unit; the right-hand side must be that unit per
second.
- Use Brian's base unit names in declarations (
volt, second, amp,
metre, etc.), including compound dimensions. Use scaled units (mV,
ms, nA) for assigned values and external namespaces. Use mmolar/mM
for molar concentration in equations.
- Parse a minimal
Equations object first. Then instantiate the owning group
or call its unit check so unknown names, namespaces, flags, dependency cycles,
and dimensional errors are actually validated. Equations construction
alone does not perform all context-dependent checks.
- Resolve external names explicitly with a group
namespace or the
Network.run(..., namespace=...) argument when reproducibility matters.
Avoid relying on implicit locals/globals when a name could be shadowed.
- Select
method only after classifying the ODE (linear, conditionally linear,
deterministic nonlinear, additive noise, or multiplicative noise). If a
method rejects the equations, change the method or the equation form; do
not hide the rejection by disabling unit checks.
- For a custom function, declare argument and result units with
@check_units (or a complete Function). Add target implementations only
when the selected code-generation target needs them, and keep the
implementation decorator outside the unit decorator. Test the Python/NumPy
path separately from C++/Cython compiler integration.
The bundled smoke covers a valid and invalid dimensional operation, equation
flags and parser rejection, explicit namespaces, suffixed-noise rules, a
unit-checked Function, a NumPy implementation, exact versus Euler decay,
and finite additive noise. Treat --all as a bounded contract check, not as a
substitute for owner-specific synapse, linked-variable, or device tests.
Route high-level neuron/synapse construction to the modeling or
synapses-and-inputs routes. Route device, compiler, standalone build, and
backend installation problems to code-generation. Keep this route focused on
the contracts above.
1---2name: units-and-equations3description: "Use Brian2 physical units, equation declarations and flags,4 parser-supported expressions, stochastic terms, namespaces, state updaters,5 and unit-aware custom functions safely."6disable-model-invocation: true7metadata:8 source: https://skillmd.com/skills/vectorspacelab/units-and-equations9 disco-role: operating10license: NOASSERTION11---1213# Brian2 units and equations1415Use this route when a task is about dimensional correctness, equation-string16syntax, stochastic symbols, numerical integration method selection, namespaces,17or unit-aware custom functions. Load only the reference needed for the current18question:1920- [Equation syntax](references/equation-syntax.md) for declarations, flags,21 special symbols, parser limits, namespaces, and integrated-form conversion.22- [Numerical methods](references/numerical-methods.md) for deterministic and23 stochastic state-updater choices and restrictions.24- [API reference](references/api-reference.md) for units, `Equations`,25 `check_units`, `Function`, and `implementation` boundaries.26- [Troubleshooting](references/troubleshooting.md) for classified failures.2728For a quick, read-only probe of unit declarations and unit-aware functions, run29`python scripts/unit_equation_smoke.py --help`, then `--all` in an environment30where the `brian2` package imports successfully. The smoke script intentionally31checks both passing and failing dimensional cases; it is not a replacement for32model or device tests.3334## Operating procedure35361. Write down the physical dimension of every state variable, parameter,37 derivative, and external value. In a differential declaration, the unit38 after `:` is the variable's unit; the right-hand side must be that unit per39 second.402. Use Brian's base unit names in declarations (`volt`, `second`, `amp`,41 `metre`, etc.), including compound dimensions. Use scaled units (`mV`,42 `ms`, `nA`) for assigned values and external namespaces. Use `mmolar`/`mM`43 for molar concentration in equations.443. Parse a minimal `Equations` object first. Then instantiate the owning group45 or call its unit check so unknown names, namespaces, flags, dependency cycles,46 and dimensional errors are actually validated. `Equations` construction47 alone does not perform all context-dependent checks.484. Resolve external names explicitly with a group `namespace` or the49 `Network.run(..., namespace=...)` argument when reproducibility matters.50 Avoid relying on implicit locals/globals when a name could be shadowed.515. Select `method` only after classifying the ODE (linear, conditionally linear,52 deterministic nonlinear, additive noise, or multiplicative noise). If a53 method rejects the equations, change the method or the equation form; do54 not hide the rejection by disabling unit checks.556. For a custom function, declare argument and result units with56 `@check_units` (or a complete `Function`). Add target implementations only57 when the selected code-generation target needs them, and keep the58 `implementation` decorator outside the unit decorator. Test the Python/NumPy59 path separately from C++/Cython compiler integration.6061The bundled smoke covers a valid and invalid dimensional operation, equation62flags and parser rejection, explicit namespaces, suffixed-noise rules, a63unit-checked `Function`, a NumPy `implementation`, exact versus Euler decay,64and finite additive noise. Treat `--all` as a bounded contract check, not as a65substitute for owner-specific synapse, linked-variable, or device tests.6667Route high-level neuron/synapse construction to the modeling or68synapses-and-inputs routes. Route device, compiler, standalone build, and69backend installation problems to code-generation. Keep this route focused on70the contracts above.