brainpy-state

Build and train point-neuron spiking networks with BrainPy-State projections and dynamics.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires brainpy, brainstate, braintools, brainunit, jax, matplotlib, and includes references (resource) components.

What problem does it solve? Designing spiking neural network simulations requires correctly composing neuron dynamics, synaptic filters, projections, delays, and training loops, and mistakes in alignment, units, or state initialization silently corrupt results. This Skill guides an agent through the native brainpy.state modeling path so simulations and surrogate-gradient training runs are constructed correctly. ## Core Features & Use Cases - Point-neuron simulation: Compose LIF, Izhikevich, Hodgkin-Huxley, and other neuron models with unit-aware parameters, explicit State initialization, and brainstate.transform time loops. - Projection and synapse composition: Wire AlignPost/AlignPre projections with event-based communication, exponential or receptor-kinetic synapses, COBA/CUBA outputs, delays, and short-term plasticity. - Surrogate-gradient SNN training: Train spiking networks with surrogate gradients, ParamState selection, JIT-compiled train steps, and complete runnable example scripts such as COBA E/I networks and Fashion-MNIST SNN training. - Use Case: Reproduce a Vogels-Abbott balanced E/I network by selecting LIFRef neurons, EventFixedProb communication, and exponential synapses, then simulate 1000 ms of activity with verified shapes. ## Quick Start Ask the agent to build a BrainPy-State spiking network simulation, for example a conductance-based E/I network of LIF neurons simulated for 200 ms with exponential synapses.

Frequently Asked Questions about brainpy-state

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

FAQPage Schema
How do I simulate a spiking neural network with BrainPy-State?

Construct neuron populations such as brainpy.state.LIFRef, initialize them with brainstate.nn.init_all_states, and run the rollout with brainstate.transform.for_loop inside a brainstate.environ.context that sets dt. Each neuron call advances one dt and get_spike() returns the current spike.

When should I use AlignPostProj versus align_pre_projection?

Use AlignPostProj for linear exponential-family synapses with convergent fan-in, storing exact synaptic State on the postsynaptic dimension. Use align_pre_projection for nonlinear receptor kinetics like AMPA or NMDA, or reusable one-to-many fan-out with homogeneous per-source parameters.

How do I train a spiking neural network with surrogate gradients?

Pass a surrogate function such as braintools.surrogate.ReluGrad to each spiking layer, select trainable weights with net.states(brainstate.ParamState), differentiate the loss with brainstate.transform.grad, and update via braintools.optim.Adam inside a JIT-compiled train step that resets State each batch.

Does BrainPy-State support synaptic transmission delays?

Yes. Pass a scalar or per-presynaptic delay to AlignPostProj or CurrentProj, or use delayed prefetch of membrane voltage with a spike decoder. Establish dt before State initialization, since delay buffers are sized from ceil(max delay / dt).

When should I use the legacy brainpy workflow instead of brainpy.state?

Use the legacy path only when an existing codebase already uses legacy brainpy, contains no BrainUnit quantities or BrainTrace code, and you explicitly need to preserve it. For all new projects, the native brainpy.state path is recommended.

Why does my BrainPy simulation produce wrong spike counts or shapes?

Common causes are missing init_all_states before each independent rollout, forgetting that V_rest does not set initial membrane State (pass V_initializer), or calling projections after post(...) instead of before it integrates the step.