brainx-acceleration

Audits and refactors BrainX/BrainState simulation code into state-aware transform patterns for performance.

1|Updated Jul 23, 2026
One-click install
npx skills add https://github.com/chaobrain/BrainX-skill --skill brainx-acceleration-chaobrain
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: brainx-acceleration
Source: https://github.com/chaobrain/BrainX-skill/tree/main/skills/brainx-acceleration
Command: npx skills add https://github.com/chaobrain/BrainX-skill --skill brainx-acceleration-chaobrain

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? BrainX/BrainState simulation code written with NumPy loops, Python control flow, and per-neuron objects runs slowly and cannot be compiled or vectorized. This Skill systematically finds those inefficiencies and rewrites them into state-aware BrainState transform patterns such as jit, scan, vmap, and grad while preserving state, RNG, and gradient semantics. ## Core Features & Use Cases - Performance Auditing: Builds a hot-path inventory of loops, states, RNG usage, and host synchronization points, then classifies each inefficiency with labeled patterns like loop-T-python, np-in-transform, and rng-reuse. - Transform Rewrites: Converts Python time loops into scan/for_loop, batch and ensemble loops into vmap with explicit state axes, and finite-difference gradients into grad over ParamState. - Validation Gates: Enforces correctness checks covering outputs, final state, shape stability, RNG independence, gradients, warm timing, and memory before a rewrite is considered done. - Use Case: A researcher has a spiking neural network simulation that loops over 10,000 timesteps in Python and takes hours. Use this Skill to audit the code, rewrite the time loop as a jitted scan, vectorize trials with vmap, and verify numerical equivalence with the original. ## Quick Start Ask the agent to audit my BrainState simulation script for performance bottlenecks and rewrite the slow Python loops using BrainState transforms.

Frequently Asked Questions about brainx-acceleration

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

FAQPage Schema
How do I speed up a slow BrainState simulation loop?

Replace the Python time loop with brainstate.transform.scan or for_loop wrapped in jit, so the recurrent step compiles into a single XLA program. Keep shapes and dtypes stable across steps and move any print or .item() calls out of the hot path.

How do I vectorize BrainState simulations over trials or parameter sweeps?

Use brainstate.transform.vmap over the batch or ensemble axis, and explicitly decide which states are shared versus independent per trial using state_in_axes and state_out_axes. Map RNG axes as well so each trial receives independent randomness.

Should I use jax.jit or brainstate.transform.jit for stateful models?

Use brainstate.transform.jit for any code that reads or writes BrainState State, ParamState, or RandomState objects, since raw jax.jit can lose or mishandle state updates. Reserve raw jax transforms for pure functions with explicit array inputs and outputs.

Why does my jitted BrainState simulation recompile on every call?

Recompilation happens when shapes, dtypes, or PyTree structure change between calls, often from dynamic list appends or data-dependent shapes. Fix it with static configuration, padding, masks, or bucketing so the compiled function sees stable inputs.

When should I not apply jit or vmap to simulation code?

Avoid transforms when the workload is tiny and compile overhead dominates, when the hot path is already a large fused jnp operation, when runtime shapes genuinely change each call, or when the rewrite would densify sparse or event-based connectivity.