brainx-skill 1.0.14 → 1.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -1
- package/manifest.json +1 -1
- package/mcp-servers/codex/skills.json +1 -1
- package/package.json +1 -1
- package/skills/bio-neuro-lit/SKILL.md +4 -2
- package/skills/bio-neuro-lit/references/required-supplements.md +27 -0
- package/skills/brainx-acceleration/SKILL.md +30 -437
- package/skills/brainx-acceleration/references/audit-and-rewrite-patterns.md +326 -0
- package/skills/brainx-general-guard/SKILL.md +24 -8
- package/skills/brainx-install/SKILL.md +3 -3
- package/skills/brainx-install/references/compatibility-and-release-matching.md +28 -20
- package/skills/brainx-install/references/uninstall-and-cleanup.md +11 -4
- package/skills/brainx-modeling-loop/SKILL.md +143 -36
- package/skills/brainx-modeling-loop/agents/openai.yaml +2 -2
- package/skills/brainx-modeling-loop/references/mechanism-comparison.md +62 -0
- package/skills/brainx-modeling-loop/references/multiscale-coupling.md +16 -0
- package/skills/brainx-modeling-loop/references/paper-reproduction.md +42 -0
- package/skills/brainx-modeling-loop/references/parameter-fitting-workflow.md +14 -14
- package/skills/brainx-modeling-loop/references/run-experiment.md +1 -1
- package/skills/brainx-modeling-loop/references/training-workflow.md +10 -8
- package/skills/brainx-visualization/SKILL.md +6 -2
- package/skills/brainx-visualization/references/neural-data-visualization.md +1 -1
- package/skills/brainx-visualization/references/statistical-and-model-visualization.md +1 -1
- package/skills/package-skills/braincell/SKILL.md +23 -14
- package/skills/package-skills/braincell/references/braintools/input-current.md +1 -1
- package/skills/package-skills/braincell/references/braintools/metric.md +72 -46
- package/skills/package-skills/braincell/references/mixions-for-adaptation.md +1 -1
- package/skills/package-skills/braincell/references/multicompartment/braincell-manual-morphology-construction.md +1 -1
- package/skills/package-skills/braincell/references/multicompartment/cv-policy-reference.md +1 -1
- package/skills/package-skills/braincell/references/multicompartment/filter-function-library.md +3 -3
- package/skills/package-skills/braincell/references/multicompartment/morphology-io-loading-validation.md +1 -1
- package/skills/package-skills/braincell/references/multicompartment/multicompartment-cell-workflow.md +31 -43
- package/skills/package-skills/braincell/references/multicompartment/network-workflow.md +49 -0
- package/skills/package-skills/braincell/references/multicompartment/probe-reference.md +26 -114
- package/skills/package-skills/braincell/references/multicompartment/topology-building-and-visualization.md +40 -28
- package/skills/package-skills/braincell/references/scripts/cell_multicompartment_reference.py +13 -17
- package/skills/package-skills/brainevent/SKILL.md +0 -3
- package/skills/package-skills/brainevent/references/synaptic-plasticity.md +1 -1
- package/skills/package-skills/brainmass/SKILL.md +5 -3
- package/skills/package-skills/brainmass/references/brainstate/parameter-constraints-regularization.md +9 -7
- package/skills/package-skills/brainmass/references/brainstate/parameter-transforms-regularizers-catalog.md +4 -4
- package/skills/package-skills/brainmass/references/braintools/data-preprocessing.md +15 -7
- package/skills/package-skills/brainmass/references/braintools/metric.md +72 -46
- package/skills/package-skills/brainmass/references/coupling-network-api.md +3 -1
- package/skills/package-skills/brainmass/references/fitting-with-objectives-api.md +6 -6
- package/skills/package-skills/brainmass/references/horn-task-training.md +9 -9
- package/skills/package-skills/brainmass/references/modellibrary.md +12 -10
- package/skills/package-skills/brainmass/references/scripts/resting-state-meg-whole-brain-pipeline.py +5 -3
- package/skills/package-skills/brainmass/references/scripts/wilson-cowan-ei-dynamics.py +10 -6
- package/skills/package-skills/brainmass/references/simulator-input-monitor-api.md +3 -1
- package/skills/package-skills/brainmass/references/visualization-analysis-api.md +17 -9
- package/skills/package-skills/brainspike/SKILL.md +201 -0
- package/skills/package-skills/brainspike/references/braintools/connectivity.md +40 -0
- package/skills/package-skills/brainspike/references/braintools/data-preprocessing.md +39 -0
- package/skills/package-skills/brainspike/references/braintools/input-current.md +55 -0
- package/skills/package-skills/brainspike/references/braintools/metric.md +36 -0
- package/skills/package-skills/brainspike/references/braintools/optimizer.md +50 -0
- package/skills/package-skills/brainspike/references/braintools/parameter-initializer.md +43 -0
- package/skills/package-skills/brainspike/references/braintools/surrogate.md +40 -0
- package/skills/package-skills/brainspike/references/migration-boundary.md +38 -0
- package/skills/package-skills/brainspike/references/model-and-readout-selection.md +41 -0
- package/skills/package-skills/brainspike/references/multirate-coupling.md +31 -0
- package/skills/package-skills/brainspike/references/multiscale-composition.md +28 -0
- package/skills/package-skills/brainspike/references/native-composition.md +52 -0
- package/skills/package-skills/brainspike/references/native-delays.md +34 -0
- package/skills/package-skills/brainspike/references/native-projections.md +43 -0
- package/skills/package-skills/brainspike/references/native-training.md +36 -0
- package/skills/package-skills/{brainpy-state → brainspike}/references/nest-compatible/devices.md +33 -33
- package/skills/package-skills/{brainpy-state → brainspike}/references/nest-compatible/divergence-and-parity.md +15 -15
- package/skills/package-skills/{brainpy-state → brainspike}/references/nest-compatible/integration-categories.md +1 -1
- package/skills/package-skills/brainspike/references/nest-compatible/model-library.md +200 -0
- package/skills/package-skills/brainspike/references/nest-compatible/network-building.md +276 -0
- package/skills/package-skills/{brainpy-state → brainspike}/references/nest-compatible/scripts/brette_et_al_2007.py +23 -26
- package/skills/package-skills/{brainpy-state → brainspike}/references/nest-compatible/scripts/brunel_alpha.py +18 -21
- package/skills/package-skills/{brainpy-state → brainspike}/references/nest-compatible/scripts/brunel_delta.py +16 -19
- package/skills/package-skills/{brainpy-state → brainspike}/references/nest-compatible/scripts/clopath_synapse_spike_pairing.py +11 -12
- package/skills/package-skills/{brainpy-state → brainspike}/references/nest-compatible/scripts/evaluate_tsodyks2_synapse.py +10 -11
- package/skills/package-skills/{brainpy-state → brainspike}/references/nest-compatible/scripts/spatial_gaussex.py +18 -18
- package/skills/package-skills/{brainpy-state → brainspike}/references/nest-compatible/scripts/synapsecollection.py +26 -29
- package/skills/package-skills/brainspike/references/nest-compatible/synapse-and-connectivity.md +166 -0
- package/skills/package-skills/brainspike/references/nest-delay-boundaries.md +31 -0
- package/skills/package-skills/brainspike/references/nonlinear-state-sharing.md +26 -0
- package/skills/package-skills/{brainpy-state → brainspike}/references/perturbation-experiment-validity.md +2 -2
- package/skills/package-skills/brainspike/references/simulator-training.md +61 -0
- package/skills/package-skills/brainspike/references/temporal-task-training.md +36 -0
- package/skills/package-skills/brainspike/scripts/advanced_native_patterns.py +76 -0
- package/skills/package-skills/brainspike/scripts/delay_workflow.py +44 -0
- package/skills/package-skills/brainspike/scripts/delayed_cue_training.py +78 -0
- package/skills/package-skills/brainspike/scripts/lif_smoke.py +31 -0
- package/skills/package-skills/brainspike/scripts/multiscale_workflow.py +35 -0
- package/skills/package-skills/brainspike/scripts/native_ei_network.py +47 -0
- package/skills/package-skills/brainspike/scripts/native_workflows.py +77 -0
- package/skills/package-skills/brainspike/scripts/nest_boundary_workflows.py +108 -0
- package/skills/package-skills/brainspike/scripts/train_native_snn.py +65 -0
- package/skills/package-skills/brainspike/scripts/train_nest_simulator.py +69 -0
- package/skills/package-skills/brainspike/scripts/train_nest_simulator_two_weights.py +220 -0
- package/skills/package-skills/brainstate/SKILL.md +16 -21
- package/skills/package-skills/brainstate/references/brainstate/brainstate-control-flow-patterns.md +1 -138
- package/skills/package-skills/brainstate/references/brainstate/brainstate-transformed-diagnostics.md +1 -1
- package/skills/package-skills/brainstate/references/brainstate/delay-buffers.md +45 -0
- package/skills/package-skills/brainstate/references/brainstate/parameter-constraints-regularization.md +9 -7
- package/skills/package-skills/brainstate/references/brainstate/parameter-transforms-regularizers-catalog.md +4 -4
- package/skills/package-skills/brainstate/references/brainstate/randomness-and-reproducibility.md +6 -4
- package/skills/package-skills/brainstate/references/brainstate/transformation-grad-expansion.md +4 -4
- package/skills/package-skills/brainstate/references/brainstate/transformation-vmap-expansion.md +1 -1
- package/skills/package-skills/brainstate/references/braintools-optimizer-reference.md +16 -0
- package/skills/package-skills/brainstate/references/libraries/prebuilt-layer-library.md +1 -1
- package/skills/package-skills/brainstate/references/simulation-environment.md +5 -5
- package/skills/package-skills/braintrace/SKILL.md +17 -38
- package/skills/package-skills/braintrace/references/Drtrl.md +9 -26
- package/skills/package-skills/braintrace/references/algorithm selection.md +7 -12
- package/skills/package-skills/braintrace/references/batching.md +15 -35
- package/skills/package-skills/braintrace/references/compiler_internal.md +1 -1
- package/skills/package-skills/braintrace/references/custom algorithms.md +1 -2
- package/skills/package-skills/braintrace/references/customizing_primitive_transforms.md +26 -15
- package/skills/package-skills/braintrace/references/pp_pprop workflow.md +5 -139
- package/skills/package-skills/brainunit/SKILL.md +7 -2
- package/skills/package-skills/brainunit/references/array-mechanics/functional-structural-api.md +1 -1
- package/skills/package-skills/brainunit/references/math-function-library.md +2 -2
- package/skills/package-skills/brainunit/references/typing-and-runtime-validation.md +5 -2
- package/skills/package-skills/brainevent/references/scripts/102_EI_net_1996.py +0 -107
- package/skills/package-skills/brainevent/references/scripts/204_joglekar_2018_propagation.py +0 -168
- package/skills/package-skills/brainevent/references/scripts/coba_ei_teaching.py +0 -356
- package/skills/package-skills/brainpy-state/SKILL.md +0 -247
- package/skills/package-skills/brainpy-state/references/array-creation.md +0 -158
- package/skills/package-skills/brainpy-state/references/brain-dynamics-delay-protocol.md +0 -147
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/analysis.md +0 -150
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/brainpy legacy workflow.md +0 -373
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/built-in dynamic neuron model.md +0 -150
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/connecting neurons.md +0 -175
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/customize neuron and synpase.md +0 -286
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/infrastructure/Input generation.md +0 -111
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/infrastructure/More about simulation.md +0 -163
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/infrastructure/Multi-device array sharding.md +0 -113
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/infrastructure/Parallel experiment execution.md +0 -136
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/infrastructure/array creation and mechanics.md +0 -222
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/infrastructure/brainpy math environment setting.md +0 -123
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/infrastructure/delays.md +0 -107
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/infrastructure/object oriented transformations and control flows.md +0 -185
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/integrators.md +0 -181
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/route activity through connectivity.md +0 -102
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/synaptic projections.md +0 -147
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/synpase properties.md +0 -159
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/training/loss library.md +0 -127
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/training/optimizers.md +0 -167
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/training/parameter initializers.md +0 -107
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/training/prebuilt neural network layers.md +0 -186
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/training/surrogate gradients.md +0 -104
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/training/trainer library.md +0 -89
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/training/trainingworkflows.md +0 -253
- package/skills/package-skills/brainpy-state/references/braintools/brainstate-control-flow-patterns.md +0 -334
- package/skills/package-skills/brainpy-state/references/braintools/connectivity.md +0 -206
- package/skills/package-skills/brainpy-state/references/braintools/data-preprocessing.md +0 -79
- package/skills/package-skills/brainpy-state/references/braintools/input-current.md +0 -199
- package/skills/package-skills/brainpy-state/references/braintools/metric.md +0 -152
- package/skills/package-skills/brainpy-state/references/braintools/optimizer.md +0 -179
- package/skills/package-skills/brainpy-state/references/braintools/parameter-initializer.md +0 -183
- package/skills/package-skills/brainpy-state/references/braintools/surrogate.md +0 -147
- package/skills/package-skills/brainpy-state/references/component-selection.md +0 -288
- package/skills/package-skills/brainpy-state/references/nest-compatible/model-library.md +0 -200
- package/skills/package-skills/brainpy-state/references/nest-compatible/nest-workflow.md +0 -156
- package/skills/package-skills/brainpy-state/references/nest-compatible/network-building.md +0 -264
- package/skills/package-skills/brainpy-state/references/nest-compatible/synapse-and-connectivity.md +0 -153
- package/skills/package-skills/brainpy-state/references/projection-patterns.md +0 -127
- package/skills/package-skills/brainpy-state/references/scripts/103_COBA_2005.py +0 -86
- package/skills/package-skills/brainpy-state/references/scripts/106_COBA_HH_2007.py +0 -181
- package/skills/package-skills/brainpy-state/references/scripts/107_gamma_oscillation_1996.py +0 -156
- package/skills/package-skills/brainpy-state/references/scripts/109_fast_global_oscillation.py +0 -111
- package/skills/package-skills/brainpy-state/references/scripts/201_surrogate_grad_lif_fashion_mnist.py +0 -221
- package/skills/package-skills/brainpy-state/references/scripts/sound_localization.py +0 -240
- package/skills/package-skills/brainpy-state/references/scripts/training-snn.py +0 -119
|
@@ -1,247 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: brainpy-state
|
|
3
|
-
description: Use for point-neuron modeling, from individual neurons to spiking networks with synapses and projections. Use alone for point-neuron studies or together with BrainCell and/or BrainMass when point-neuron dynamics participate in a multiscale model. Use as the legacy BrainPy routing entry only when an existing codebase uses legacy `brainpy`, uses neither units nor BrainTrace, and the user explicitly asks to preserve it.
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
# BrainPy-State
|
|
7
|
-
|
|
8
|
-
## Purpose and boundary
|
|
9
|
-
|
|
10
|
-
Use this skill for the native `brainpy.state` modeling path: compose point neurons, synapses, communication operators, synaptic outputs, projections, inputs, plasticity, and readouts into simulations or trainable spiking neural networks.
|
|
11
|
-
|
|
12
|
-
Route NEST-compatible work to `references/nest-compatible/nest-workflow.md`, and online-learning execution to BrainTrace.
|
|
13
|
-
|
|
14
|
-
Open `references/brainPy(legacy)/brainpy legacy workflow.md` only when the workspace already contains legacy `brainpy` code, contains no BrainUnit quantities, unit-aware APIs, and when the user explicitly asks to preserve old BrainPy. Use native BrainPy-State for new project is HIGHLY RECOMMENDED; use BrainPy-State with BrainCell for all cellular modeling.
|
|
15
|
-
|
|
16
|
-
Treat that workflow as the only first-level legacy reference. Do not open or route directly to any other Markdown under `references/brainPy(legacy)/`; let the workflow select those second-level references.
|
|
17
|
-
|
|
18
|
-
## Underlying principle of BrainPy-State
|
|
19
|
-
|
|
20
|
-
BrainPy-State composes unit-aware, stateful neuron and synapse `Dynamics` into projections that separate `comm`, `syn`, `out`, and `post`; BrainState transforms run the same Module graph for simulation or surrogate-gradient training.
|
|
21
|
-
Align synaptic State to a neuron dimension instead of each connection, reduce that state from per-synapse to per-neuron, which makes simulation memory-efficient.
|
|
22
|
-
|
|
23
|
-
### API structure
|
|
24
|
-
|
|
25
|
-
| API family | Use |
|
|
26
|
-
|---|---|
|
|
27
|
-
| Base Classes | Find the shared dynamics, neuron, and synapse abstractions used to implement custom BrainPy-State components. |
|
|
28
|
-
| BrainPy-style Neurons | Select native point-neuron dynamics, from integrate-and-fire models to conductance-based models. |
|
|
29
|
-
| BrainPy-style Synapses | Select native synaptic dynamics, from simple temporal filters to biological receptor models. |
|
|
30
|
-
| BrainPy-style Projections | Connect populations through projection classes, projection helper functions, or gap-junction projections. |
|
|
31
|
-
| BrainPy-style Synaptic Outputs | Convert synaptic state into current- or conductance-based postsynaptic input. |
|
|
32
|
-
| BrainPy-style Plasticity | Add short-term facilitation or depression to synaptic transmission. |
|
|
33
|
-
| BrainPy-style Readouts | Decode spiking activity through native readout models. |
|
|
34
|
-
| BrainPy-style Input Generators | Generate spike trains or time-varying simulation inputs. |
|
|
35
|
-
|
|
36
|
-
### 1. Choose and run neuron dynamics
|
|
37
|
-
|
|
38
|
-
A neuron call advances one `dt`, mutates its registered dynamical State, and exposes the current spike through `get_spike()`; initialize before every independent rollout, set `V_initializer` whenever startup voltage affects the result, and lower the complete time loop through `brainstate.transform`.
|
|
39
|
-
|
|
40
|
-
| API | Description |
|
|
41
|
-
|---|---|
|
|
42
|
-
| `brainpy.state.LIFRef(..., V_initializer=...)` | Use for the canonical point-neuron rollout when leak and refractory timing are required; each call integrates one `dt`, updates membrane/refractory State, and returns the current spike. `V_rest` sets the resting dynamics but does not set the initial membrane State, so pass an intentional initializer when startup spikes or transients matter. |
|
|
43
|
-
| `braintools.init.Constant(value)` | Use as `V_initializer` when every neuron must start at one known voltage; initialization creates membrane State at that value. Use a documented distribution instead when initial heterogeneity is part of the model. |
|
|
44
|
-
| `brainstate.nn.init_all_states(model, batch_size=...)` | Use after construction and before a rollout; it allocates or resets dynamical State across the Module graph and adds a leading batch dimension when `batch_size` is given. |
|
|
45
|
-
| `brainstate.environ.context(dt=..., t=...)` | Use around the rollout for `dt` and inside the step for `t`; dynamics read the active values and the context restores previous settings on exit. |
|
|
46
|
-
| `brainstate.environ.get_dt()` | Use when constructing the time axis or a numerical update from the active simulation step; it returns `dt` and raises when no value is set. |
|
|
47
|
-
| `u.math.mean(current, axis=...)` | Use when a drive current should be the arithmetic mean of unit-aware samples; it reduces the selected axes and returns a quantity with the input current unit. |
|
|
48
|
-
| `brainstate.transform.for_loop(step, *xs)` | Use by default for a multi-step rollout whose model State carries hidden variables; it slices leading input axes and stacks returned monitors. |
|
|
49
|
-
| `neuron.get_spike()` | Use after advancing or when wiring the previous completed step into a projection; it returns the neuron's current spike output without advancing State. |
|
|
50
|
-
|
|
51
|
-
```python
|
|
52
|
-
import brainpy
|
|
53
|
-
import brainstate
|
|
54
|
-
import braintools
|
|
55
|
-
import brainunit as u
|
|
56
|
-
|
|
57
|
-
with brainstate.environ.context(dt=0.1 * u.ms):
|
|
58
|
-
neuron = brainpy.state.LIFRef(
|
|
59
|
-
1,
|
|
60
|
-
R=1.0 * u.ohm,
|
|
61
|
-
tau=20.0 * u.ms,
|
|
62
|
-
V_rest=-60.0 * u.mV,
|
|
63
|
-
V_th=-50.0 * u.mV,
|
|
64
|
-
V_reset=-60.0 * u.mV,
|
|
65
|
-
tau_ref=5.0 * u.ms,
|
|
66
|
-
V_initializer=braintools.init.Constant(-60.0 * u.mV),
|
|
67
|
-
)
|
|
68
|
-
brainstate.nn.init_all_states(neuron)
|
|
69
|
-
times = u.math.arange(
|
|
70
|
-
0.0 * u.ms,
|
|
71
|
-
200.0 * u.ms,
|
|
72
|
-
brainstate.environ.get_dt(),
|
|
73
|
-
)
|
|
74
|
-
|
|
75
|
-
def step(t):
|
|
76
|
-
with brainstate.environ.context(t=t):
|
|
77
|
-
neuron(25.0 * u.mA)
|
|
78
|
-
return neuron.V.value, neuron.get_spike()
|
|
79
|
-
|
|
80
|
-
voltages, spikes = brainstate.transform.for_loop(step, times)
|
|
81
|
-
|
|
82
|
-
assert voltages.shape == (2000, 1)
|
|
83
|
-
assert spikes.shape == (2000, 1)
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
Open `references/braintools/input-current.md` when a direct current protocol needs timed sections, pulses, waveforms, stochastic processes, or composition. Generate the complete time-major protocol once under the rollout `dt` and pass it as an input to `for_loop`; do not rebuild named sections or pulses from time predicates inside the model step. Open `references/array-creation.md` when constructing specialized unit-aware current ranges, grids, filled arrays, template-shaped arrays, or matrix patterns. Open `references/component-selection.md` when choosing among documented neuron, input, synapse, output, plasticity, or readout variants, for the decision boundary and complete category list. Open `references/braintools/brainstate-control-flow-patterns.md` when the rollout needs explicit carry, branching, or checkpointed control flow.
|
|
87
|
-
|
|
88
|
-
### 2. Compose synapses and projections
|
|
89
|
-
|
|
90
|
-
A projection deposits current into `post` before the postsynaptic neuron integrates the step, while its alignment determines which neuron dimension owns synaptic State and which kinetics remain exact; when recurrent excitation, mutual inhibition, or spike-driven connectivity is a point-neuron mechanism, represent it with explicit projections instead of a hand-written population-rate feedback `State`, and route aggregate rate coupling to BrainMass.
|
|
91
|
-
|
|
92
|
-
| API | Description |
|
|
93
|
-
|---|---|
|
|
94
|
-
| `brainstate.nn.EventFixedProb(...)` | Use for the canonical sparse binary-spike communication path; it maps presynaptic events to postsynaptic weighted input without materializing dense all-to-all activity. |
|
|
95
|
-
| `brainevent.BinaryArray(spikes) @ connectivity` | Use when the network must choose an explicit BrainEvent connectivity representation; it processes active presynaptic events through dense, CSR, generated, or fixed-degree storage and returns input for BrainPy synaptic dynamics. |
|
|
96
|
-
| `brainpy.state.Expon.desc(...)` | Use for the canonical linear exponential synaptic filter; the descriptor lets the projection construct and align the concrete synapse on the target. |
|
|
97
|
-
| `brainpy.state.COBA.desc(E=...)` | Use when synaptic current must depend on postsynaptic voltage and reversal potential; the descriptor lets the projection bind the output to `post`. |
|
|
98
|
-
| `brainpy.state.AlignPostProj(...)` | Use for exponential-family fan-in; it composes `comm`, `syn`, `out`, and `post`, stores exact synaptic State on the postsynaptic dimension, and deposits current before `post(...)` integrates. |
|
|
99
|
-
| `brainpy.state.align_pre_projection(...)` | Use instead for nonlinear synaptic kinetics or reusable one-to-many fan-out; it stores exact shared traces on the presynaptic dimension when outgoing parameters are homogeneous per source. |
|
|
100
|
-
|
|
101
|
-
```python
|
|
102
|
-
import brainpy
|
|
103
|
-
import brainstate
|
|
104
|
-
import braintools
|
|
105
|
-
import brainunit as u
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
class TwoPop(brainstate.nn.Module):
|
|
109
|
-
def __init__(self, n_pre=20, n_post=10):
|
|
110
|
-
super().__init__()
|
|
111
|
-
self.pre = brainpy.state.LIFRef(
|
|
112
|
-
n_pre,
|
|
113
|
-
tau=20.0 * u.ms,
|
|
114
|
-
tau_ref=5.0 * u.ms,
|
|
115
|
-
V_rest=-60.0 * u.mV,
|
|
116
|
-
V_th=-50.0 * u.mV,
|
|
117
|
-
V_reset=-60.0 * u.mV,
|
|
118
|
-
V_initializer=braintools.init.Constant(-60.0 * u.mV),
|
|
119
|
-
)
|
|
120
|
-
self.post = brainpy.state.LIFRef(
|
|
121
|
-
n_post,
|
|
122
|
-
tau=20.0 * u.ms,
|
|
123
|
-
tau_ref=5.0 * u.ms,
|
|
124
|
-
V_rest=-60.0 * u.mV,
|
|
125
|
-
V_th=-50.0 * u.mV,
|
|
126
|
-
V_reset=-60.0 * u.mV,
|
|
127
|
-
V_initializer=braintools.init.Constant(-60.0 * u.mV),
|
|
128
|
-
)
|
|
129
|
-
self.proj = brainpy.state.AlignPostProj(
|
|
130
|
-
comm=brainstate.nn.EventFixedProb(
|
|
131
|
-
n_pre,
|
|
132
|
-
n_post,
|
|
133
|
-
conn_num=0.5,
|
|
134
|
-
conn_weight=0.5 * u.mS,
|
|
135
|
-
),
|
|
136
|
-
syn=brainpy.state.Expon.desc(n_post, tau=5.0 * u.ms),
|
|
137
|
-
out=brainpy.state.COBA.desc(E=0.0 * u.mV),
|
|
138
|
-
post=self.post,
|
|
139
|
-
)
|
|
140
|
-
|
|
141
|
-
def update(self, t, drive):
|
|
142
|
-
with brainstate.environ.context(t=t):
|
|
143
|
-
pre_spikes = self.pre.get_spike() != 0.0
|
|
144
|
-
self.proj(pre_spikes)
|
|
145
|
-
self.pre(drive)
|
|
146
|
-
self.post(0.0 * u.mA)
|
|
147
|
-
return self.post.V.value, self.proj.syn.g.value
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
with brainstate.environ.context(dt=0.1 * u.ms):
|
|
151
|
-
net = TwoPop()
|
|
152
|
-
brainstate.nn.init_all_states(net)
|
|
153
|
-
times = u.math.arange(0.0 * u.ms, 200.0 * u.ms, brainstate.environ.get_dt())
|
|
154
|
-
post_voltage, conductance = brainstate.transform.for_loop(
|
|
155
|
-
lambda t: net.update(t, 30.0 * u.mA),
|
|
156
|
-
times,
|
|
157
|
-
)
|
|
158
|
-
|
|
159
|
-
assert post_voltage.shape == (2000, 10)
|
|
160
|
-
assert conductance.shape == (2000, 10)
|
|
161
|
-
```
|
|
162
|
-
|
|
163
|
-
Open `references/braintools/connectivity.md` first when geometry, distance, degree, modules, or another named topology determines which neuron pairs connect; generate the topology before choosing its BrainEvent representation. Open `references/projection-patterns.md` before implementing recurrent excitation, mutual inhibition, or other spike-driven connectivity; it owns AlignPre versus AlignPost, communication, delays, direct/delta input, short-term plasticity, and electrical coupling. Open `skills/package-skills/brainevent/references/scripts/coba_ei_teaching.py` when a BrainPy network should use BrainEvent for efficient event-driven communication; it keeps BrainPy neuron and synapse dynamics while replacing the communication step with `BinaryArray @ connectivity` over fixed-degree, CSR, or dense storage.
|
|
164
|
-
|
|
165
|
-
### 3. Train a spiking network
|
|
166
|
-
|
|
167
|
-
Training reuses the simulation graph: place a surrogate on each trained spiking nonlinearity, unroll with a differentiable transform loop, differentiate only `ParamState`, reset dynamical State for each independent batch, and update inside a compiled train step.
|
|
168
|
-
|
|
169
|
-
| API | Description |
|
|
170
|
-
|---|---|
|
|
171
|
-
| `neuron(..., spk_fun=braintools.surrogate.ReluGrad())` | Use on a spiking layer crossed by the loss gradient; it preserves hard forward spikes and supplies the backward derivative. |
|
|
172
|
-
| `model.states(brainstate.ParamState)` | Use to select trainable parameters; it excludes membrane voltage, conductance, spike history, and other rollout State. |
|
|
173
|
-
| `brainstate.transform.grad(loss_fn, params, return_value=True)` | Use to differentiate the stateful loss with respect to the selected State collection; calling the returned transform yields gradients and the loss. |
|
|
174
|
-
| `braintools.optim.Adam(...).register_trainable_weights(params)` | Use for the canonical optimizer lifecycle; register the same State collection used by `grad`, then call `optimizer.update(grads)`. |
|
|
175
|
-
| `brainstate.transform.jit(train_step)` | Use around the complete reset-gradient-update operation; compatible calls reuse the compiled training step while BrainState preserves State effects. |
|
|
176
|
-
|
|
177
|
-
```python
|
|
178
|
-
# Given a stateful net whose update() returns per-step logits [batch, classes].
|
|
179
|
-
params = net.states(brainstate.ParamState)
|
|
180
|
-
optimizer = braintools.optim.Adam(lr=3e-3)
|
|
181
|
-
optimizer.register_trainable_weights(params)
|
|
182
|
-
|
|
183
|
-
def loss_fn():
|
|
184
|
-
logits = brainstate.transform.for_loop(net.update, inputs)
|
|
185
|
-
logits = u.math.mean(logits, axis=0)
|
|
186
|
-
return braintools.metric.softmax_cross_entropy_with_integer_labels(
|
|
187
|
-
logits,
|
|
188
|
-
labels,
|
|
189
|
-
).mean()
|
|
190
|
-
|
|
191
|
-
@brainstate.transform.jit
|
|
192
|
-
def train_step():
|
|
193
|
-
brainstate.nn.init_all_states(net, batch_size=batch_size)
|
|
194
|
-
grads, loss = brainstate.transform.grad(
|
|
195
|
-
loss_fn,
|
|
196
|
-
params,
|
|
197
|
-
return_value=True,
|
|
198
|
-
)()
|
|
199
|
-
optimizer.update(grads)
|
|
200
|
-
return loss
|
|
201
|
-
|
|
202
|
-
loss = train_step()
|
|
203
|
-
```
|
|
204
|
-
|
|
205
|
-
Choose training variations from the first-level references below; open only the smallest reference that owns the decision. Use `references/scripts/training-snn.py` when a complete runnable training workflow is required.
|
|
206
|
-
|
|
207
|
-
## Reference routing
|
|
208
|
-
|
|
209
|
-
Open only the smallest reference that owns the decision.
|
|
210
|
-
|
|
211
|
-
### Training variation choices
|
|
212
|
-
|
|
213
|
-
| Reference | Open when |
|
|
214
|
-
|---|---|
|
|
215
|
-
| `references/braintools/data-preprocessing.md` | Encoding continuous values, events, or temporal features into time-major spike inputs before training |
|
|
216
|
-
| `references/braintools/parameter-initializer.md` | Selecting unit-aware parameter, weight, delay, variance-scaling, orthogonal, or spatial initialization |
|
|
217
|
-
| `references/braintools/surrogate.md` | Selecting a surrogate API style or gradient family, implementing a custom surrogate, or validating its gradient |
|
|
218
|
-
| `references/braintools/metric.md` | Selecting the training loss or evaluation metric and validating its input orientation, units, and reduction |
|
|
219
|
-
| `references/braintools/optimizer.md` | Selecting an optimizer, learning-rate scheduler, Optax bridge, SciPy optimizer, or Nevergrad optimizer |
|
|
220
|
-
| `references/braintools/brainstate-control-flow-patterns.md` | Choosing `for_loop` versus `scan`, adding transformed branches, or checkpointing a long differentiated rollout |
|
|
221
|
-
|
|
222
|
-
### Modeling variation choices
|
|
223
|
-
|
|
224
|
-
| Reference | Open when |
|
|
225
|
-
|---|---|
|
|
226
|
-
| `references/array-creation.md` | Constructing specialized unit-aware current ranges, grids, filled arrays, template-shaped arrays, or matrix patterns |
|
|
227
|
-
| `references/braintools/connectivity.md` | Selecting spatial, topological, biological E/I, kernel, or compartment-aware connection pairs and exporting a `ConnectionResult` to BrainEvent storage |
|
|
228
|
-
| `references/braintools/input-current.md` | Generating or composing direct unit-aware current sections, pulses, waveforms, or stochastic processes |
|
|
229
|
-
| `references/component-selection.md` | Choosing a neuron, synapse, synaptic output, plasticity model, input generator, or readout from the documented native API families |
|
|
230
|
-
| `references/projection-patterns.md` | Choosing projection alignment or API form, adding delays or short-term plasticity, using direct/delta projections, or adding gap junctions |
|
|
231
|
-
| `references/perturbation-experiment-validity.md` | Estimating baseline tuning or features before matched point-neuron perturbations, calibrating delivered target dose, or deciding whether activity and analysis support justify a formal causal run |
|
|
232
|
-
| `references/nest-compatible/nest-workflow.md` | Using NEST/PyNEST model names, `Simulator`, devices, connection rules, spatial networks, parity, porting, or the bundled NEST-compatible full scripts |
|
|
233
|
-
| `references/brainPy(legacy)/brainpy legacy workflow.md` | Use as the only first-level legacy entry when existing legacy `brainpy` has no BrainUnit, unit-aware, or BrainTrace code and the user explicitly requests it; this workflow routes all second-level legacy references |
|
|
234
|
-
| `skills/package-skills/brainevent/SKILL.md` | Selecting sparse event representations, connectivity formats, event operators, plasticity kernels, or custom kernels |
|
|
235
|
-
| `skills/package-skills/brainevent/references/scripts/coba_ei_teaching.py` | Learning how to incorporate efficient BrainEvent communication into a complete BrainPy COBA E/I network while preserving BrainPy dynamics and BrainState execution |
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
## Application script examples
|
|
239
|
-
| Reference | Open when |
|
|
240
|
-
|---|---|
|
|
241
|
-
| `references/scripts/103_COBA_2005.py` | Needing a complete canonical E/I COBA network built from native BrainPy-State projections |
|
|
242
|
-
| `references/scripts/106_COBA_HH_2007.py` | Reproducing a conductance-based E/I network with a custom Hodgkin-Huxley neuron |
|
|
243
|
-
| `references/scripts/107_gamma_oscillation_1996.py` | Reproducing gamma oscillations with custom neuron and synapse dynamics |
|
|
244
|
-
| `references/scripts/109_fast_global_oscillation.py` | Needing a complete `DeltaProj` network with delayed recurrent input |
|
|
245
|
-
| `references/scripts/sound_localization.py` | Needing a mapped delay-line coincidence network with heterogeneous integer event taps and BrainEvent fixed fan-out |
|
|
246
|
-
| `references/scripts/201_surrogate_grad_lif_fashion_mnist.py` | Needing a complete real-data surrogate-gradient LIF training workflow |
|
|
247
|
-
| `references/scripts/training-snn.py` | Needing a complete runnable surrogate-gradient SNN training workflow |
|
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
# Array creation
|
|
2
|
-
|
|
3
|
-
Use this reference for specialized unit-aware ranges, grids, filled arrays, template-shaped arrays, matrix patterns, index constructors, and tree-shaped arrays. Basic `Quantity`, `asarray()`, and `arange()` construction remains in the parent skill.
|
|
4
|
-
|
|
5
|
-
```python
|
|
6
|
-
import brainunit as u
|
|
7
|
-
import jax.numpy as jnp
|
|
8
|
-
```
|
|
9
|
-
|
|
10
|
-
## Contents
|
|
11
|
-
|
|
12
|
-
- [Choose interval values](#choose-interval-values)
|
|
13
|
-
- [Build coordinate and power grids](#build-coordinate-and-power-grids)
|
|
14
|
-
- [Fill a new shape](#fill-a-new-shape)
|
|
15
|
-
- [Follow an existing shape](#follow-an-existing-shape)
|
|
16
|
-
- [Build matrices and masks](#build-matrices-and-masks)
|
|
17
|
-
- [Locate triangular entries](#locate-triangular-entries)
|
|
18
|
-
- [Mirror pytrees](#mirror-pytrees)
|
|
19
|
-
- [Convert NumPy input](#convert-numpy-input)
|
|
20
|
-
- [Routing](#routing)
|
|
21
|
-
- [Cross-family gotchas](#cross-family-gotchas)
|
|
22
|
-
- [Sources mirrored](#sources-mirrored)
|
|
23
|
-
|
|
24
|
-
## Choose interval values
|
|
25
|
-
|
|
26
|
-
### `linspace`
|
|
27
|
-
|
|
28
|
-
| Exact signature | Use when | One-line description | Code and result |
|
|
29
|
-
|---|---|---|---|
|
|
30
|
-
| `linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None)` | Generate a fixed number of evenly spaced samples between two endpoints. | Return evenly spaced numbers over a specified interval. | `u.math.linspace(0 * u.second, 10 * u.second, 5)`<br>`# Quantity([ 0. 2.5 5. 7.5 10. ], "s")` |
|
|
31
|
-
|
|
32
|
-
### `logspace`
|
|
33
|
-
|
|
34
|
-
| Exact signature | Use when | One-line description | Code and result |
|
|
35
|
-
|---|---|---|---|
|
|
36
|
-
| `logspace(start, stop, num=50, endpoint=True, base=10.0, dtype=None)` | Generate values whose exponents are evenly spaced. | Return numbers spaced evenly on a log scale. | `u.math.logspace(0, 2, 3)`<br>`# Array([ 1., 10., 100.], dtype=float32)` |
|
|
37
|
-
|
|
38
|
-
## Build coordinate and power grids
|
|
39
|
-
|
|
40
|
-
### `meshgrid`
|
|
41
|
-
|
|
42
|
-
| Exact signature | Use when | One-line description | Code and result |
|
|
43
|
-
|---|---|---|---|
|
|
44
|
-
| `meshgrid(*xi, copy=True, sparse=False, indexing='xy')` | Expand 1-D coordinate vectors into dense or sparse coordinate grids. | Return coordinate matrices from coordinate vectors. | `x = jnp.array([1, 2]) * u.meter; t = jnp.array([0, 1, 2]) * u.second; x_grid, t_grid = u.math.meshgrid(x, t, indexing='ij')`<br>`# both shapes: (2, 3); units: meter and second` |
|
|
45
|
-
|
|
46
|
-
### `vander`
|
|
47
|
-
|
|
48
|
-
| Exact signature | Use when | One-line description | Code and result |
|
|
49
|
-
|---|---|---|---|
|
|
50
|
-
| `vander(x, N=None, increasing=False, unit=Unit('1'))` | Build a Vandermonde matrix from powers of a 1-D vector. | Generate a Vandermonde matrix. | `u.math.vander(jnp.array([1, 2]), N=3)`<br>`# Array([[1, 1, 1], [4, 2, 1]], dtype=int32)` |
|
|
51
|
-
|
|
52
|
-
## Fill a new shape
|
|
53
|
-
|
|
54
|
-
### Initialized arrays
|
|
55
|
-
|
|
56
|
-
| API | Description & result |
|
|
57
|
-
|---|---|
|
|
58
|
-
| `full(shape, fill_value, dtype=None)` | Fill a new shape with `fill_value`; a quantity fill produces a `Quantity` with that unit.<br>`u.math.full(2, 3 * u.second)`<br>`# Quantity([3, 3], "s")` |
|
|
59
|
-
| `ones(shape, dtype=None, unit=Unit('1'))` | Fill a new shape with ones. Returns a plain JAX array by default or a `Quantity` when a non-trivial unit is supplied.<br>`u.math.ones(2, unit=u.second)`<br>`# Quantity([1., 1.], "s")` |
|
|
60
|
-
| `zeros(shape, dtype=None, unit=Unit('1'))` | Fill a new shape with zeros. Returns a plain JAX array by default or a `Quantity` when a non-trivial unit is supplied.<br>`u.math.zeros(2)`<br>`# plain JAX array` |
|
|
61
|
-
|
|
62
|
-
### `empty`
|
|
63
|
-
|
|
64
|
-
| Exact signature | Use when | One-line description | Code and result |
|
|
65
|
-
|---|---|---|---|
|
|
66
|
-
| `empty(shape, dtype=None, unit=Unit('1'))` | Allocate a shape when every entry will be overwritten before it is read. | Return a new quantity or array of given shape and type, without initializing entries. | `buffer = u.math.empty((2, 2), unit=u.second); buffer.shape`<br>`# (2, 2); entry values are unspecified` |
|
|
67
|
-
|
|
68
|
-
## Follow an existing shape
|
|
69
|
-
|
|
70
|
-
### `full_like`
|
|
71
|
-
|
|
72
|
-
| Exact signature | Use when | One-line description | Code and result |
|
|
73
|
-
|---|---|---|---|
|
|
74
|
-
| `full_like(a, fill_value, dtype=None, shape=None)` | Fill an array using a prototype's shape and dtype. | Return a new quantity or array with the same shape and type as a given array or quantity, filled with `fill_value`. | `prototype = jnp.zeros(2) * u.second; u.math.full_like(prototype, 500 * u.ms)`<br>`# Quantity([0.5 0.5], "s")` |
|
|
75
|
-
|
|
76
|
-
### `empty_like`
|
|
77
|
-
|
|
78
|
-
| Exact signature | Use when | One-line description | Code and result |
|
|
79
|
-
|---|---|---|---|
|
|
80
|
-
| `empty_like(prototype, dtype=None, shape=None, unit=Unit('1'))` | Allocate an uninitialized buffer shaped and typed like a prototype. | Return a new quantity or array with the same shape and type as a given array. | `prototype = jnp.ones(3) * u.second; buffer = u.math.empty_like(prototype); buffer.shape`<br>`# (3,); unit: second; entry values are unspecified` |
|
|
81
|
-
|
|
82
|
-
### Create one or zero arrays
|
|
83
|
-
|
|
84
|
-
| API | Description & result |
|
|
85
|
-
|---|---|
|
|
86
|
-
| `ones_like(a, dtype=None, shape=None, unit=Unit('1'))` | Create ones with `a`'s shape and dtype. A `Quantity` prototype preserves its unit by default; a non-trivial `unit` attaches a unit to a plain prototype or requests a compatible conversion. |
|
|
87
|
-
| `zeros_like(a, dtype=None, shape=None, unit=Unit('1'))` | Create zeros with `a`'s shape and dtype. A `Quantity` prototype preserves its unit by default; a non-trivial `unit` attaches a unit to a plain prototype or requests a compatible conversion. |
|
|
88
|
-
|
|
89
|
-
## Build matrices and masks
|
|
90
|
-
|
|
91
|
-
### Identity-like and triangular constructors
|
|
92
|
-
|
|
93
|
-
| API | Description & result |
|
|
94
|
-
|---|---|
|
|
95
|
-
| `eye(N, M=None, k=0, dtype=None, unit=Unit('1'))` | Create an `N`-by-`M` array with ones on diagonal `k` and zeros elsewhere. Returns a plain JAX array by default or a `Quantity` with a non-trivial unit. |
|
|
96
|
-
| `identity(n, dtype=None, unit=Unit('1'))` | Create an `n`-by-`n` identity array. Returns a plain JAX array by default or a `Quantity` with a non-trivial unit. |
|
|
97
|
-
| `tri(N, M=None, k=0, dtype=None, unit=Unit('1'))` | Create an `N`-by-`M` array with ones at and below diagonal `k`. Returns a plain JAX array by default or a `Quantity` with a non-trivial unit. |
|
|
98
|
-
|
|
99
|
-
### `diag`
|
|
100
|
-
|
|
101
|
-
| Exact signature | Use when | One-line description | Code and result |
|
|
102
|
-
|---|---|---|---|
|
|
103
|
-
| `diag(v, k=0, unit=Unit('1'))` | Construct a diagonal matrix or extract a diagonal based on input rank. | Extract a diagonal or construct a diagonal array. | `vector = jnp.array([1, 2, 3]) * u.second; matrix = u.math.diag(vector); extracted = u.math.diag(matrix); (matrix.shape, extracted.shape)`<br>`# ((3, 3), (3,))` |
|
|
104
|
-
|
|
105
|
-
### Keep one triangle of an existing array
|
|
106
|
-
|
|
107
|
-
| API | Description & result |
|
|
108
|
-
|---|---|
|
|
109
|
-
| `tril(m, k=0, unit=Unit('1'))` | Return `m` with entries above diagonal `k` zeroed, applying to the final two axes when `m.ndim > 2`. It preserves a `Quantity` input's unit by default; `unit` can attach or request a compatible output unit.<br>`m = jnp.arange(1, 5).reshape(2, 2); u.math.tril(m)`<br>`# [[1, 0], [3, 4]]` |
|
|
110
|
-
| `triu(m, k=0, unit=Unit('1'))` | Return `m` with entries below diagonal `k` zeroed, applying to the final two axes when `m.ndim > 2`. It preserves a `Quantity` input's unit by default; `unit` can attach or request a compatible output unit.<br>`m = jnp.arange(1, 5).reshape(2, 2); u.math.triu(m)`<br>`# [[1, 2], [0, 4]]` |
|
|
111
|
-
|
|
112
|
-
### `fill_diagonal`
|
|
113
|
-
|
|
114
|
-
| Exact signature | Use when | One-line description | Code and result |
|
|
115
|
-
|---|---|---|---|
|
|
116
|
-
| `fill_diagonal(a, val, wrap=False, inplace=False)` | Replace the main diagonal of an existing array with one value. | Fill the main diagonal of the given array of any dimensionality. | `q = jnp.zeros((2, 2)) * u.second; filled = u.math.fill_diagonal(q, 500 * u.ms)`<br>`# Quantity([[0.5 0. ] [0. 0.5]], "s")` |
|
|
117
|
-
|
|
118
|
-
## Locate triangular entries
|
|
119
|
-
|
|
120
|
-
### Lower and upper triangle indices
|
|
121
|
-
|
|
122
|
-
| API | Description & result |
|
|
123
|
-
|---|---|
|
|
124
|
-
| `tril_indices(n, k=0, m=None)` | Return row and column indices for the lower triangle of an `(n, m)` array as two plain integer arrays. |
|
|
125
|
-
| `triu_indices(n, k=0, m=None)` | Return row and column indices for the upper triangle of an `(n, m)` array as two plain integer arrays. |
|
|
126
|
-
| `tril_indices_from(arr, k=0)` | Derive lower-triangle row and column indices from a 2-D array's shape. Returns two plain integer arrays; an input `Quantity` does not give the indices a unit. |
|
|
127
|
-
| `triu_indices_from(arr, k=0)` | Derive upper-triangle row and column indices from a 2-D array's shape. Returns two plain integer arrays; an input `Quantity` does not give the indices a unit. |
|
|
128
|
-
|
|
129
|
-
## Mirror pytrees
|
|
130
|
-
|
|
131
|
-
### One or zero in every leaf
|
|
132
|
-
|
|
133
|
-
| API | Description & result |
|
|
134
|
-
|---|---|
|
|
135
|
-
| `tree_ones_like(tree)` | Replace every pytree leaf with ones while preserving structure, leaf shape, dtype, and unit; plain leaves remain plain and quantity leaves remain quantities. |
|
|
136
|
-
| `tree_zeros_like(tree)` | Replace every pytree leaf with zeros while preserving structure, leaf shape, dtype, and unit; plain leaves remain plain and quantity leaves remain quantities. |
|
|
137
|
-
|
|
138
|
-
## Convert NumPy input
|
|
139
|
-
|
|
140
|
-
| API | Description & result |
|
|
141
|
-
|---|---|
|
|
142
|
-
| `from_numpy(x, unit=Unit('1'))` | Convert a NumPy array to the JAX backend. Returns a plain JAX array by default or a `Quantity` with the supplied non-trivial unit. |
|
|
143
|
-
|
|
144
|
-
## Routing
|
|
145
|
-
|
|
146
|
-
`array_split()` appears on the tutorial page, but it is a structural operation; route it to `array-mechanics.md`.
|
|
147
|
-
|
|
148
|
-
Backend extraction and `as_numpy()` belong in `array-mechanics.md` because they cross an existing array boundary rather than create a scientific quantity from source values.
|
|
149
|
-
|
|
150
|
-
## Cross-family gotchas
|
|
151
|
-
|
|
152
|
-
- For constructors with `unit=Unit('1')`, the unitless default produces a plain JAX array unless a quantity input supplies a unit; pass a non-trivial `Unit` to request a `Quantity`.
|
|
153
|
-
- The `dtype` and `shape` arguments on `*_like` functions override the prototype; otherwise its dtype and shape are retained.
|
|
154
|
-
|
|
155
|
-
## Sources mirrored
|
|
156
|
-
|
|
157
|
-
- https://brainx.chaobrain.com/brainunit/unit_operations/array_creation.html
|
|
158
|
-
- https://brainx.chaobrain.com/brainunit/apis/brainunit.math.html
|
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
# BrainPy projection delay protocol
|
|
2
|
-
|
|
3
|
-
Use this reference after choosing a native `brainpy.state` projection when presynaptic spikes or continuous values must reach the target after an axonal or synaptic transmission delay. This reference owns BrainPy projection integration; use the general BrainState delay protocol for arbitrary history buffers, named delay taps, delayed feedback State, or manual retrieval.
|
|
4
|
-
|
|
5
|
-
## Choose the delay integration point
|
|
6
|
-
|
|
7
|
-
Delay the signal before communication. Choose the API from how the projection receives that signal:
|
|
8
|
-
|
|
9
|
-
| Signal path | Use when | Call contract |
|
|
10
|
-
|---|---|---|
|
|
11
|
-
| `AlignPostProj(..., delay=delay)` | The step pushes a spike/event array directly into an AlignPost projection. | Call `proj(signal)`; the projection delays the supplied presynaptic input before `comm`. |
|
|
12
|
-
| `CurrentProj(..., delay=delay)` | The step pushes a continuous presynaptic value through communication and output conversion without synaptic dynamics. | Call `proj(signal)`; the projection delays the supplied value before `comm`. |
|
|
13
|
-
| `pre.prefetch("V").delay.at(delay)` | The projection pulls from a built-in neuron, which stores membrane potential rather than a separate historical spike State. | Build the projection once with the delayed prefetch and a spike decoder, then call `proj()` with no explicit signal. |
|
|
14
|
-
| General `brainstate.nn.Delay` APIs | The task needs reusable buffers, multiple named taps, manual updates, step-based retrieval, round interpolation, or custom delayed State. | Leave the BrainPy projection path and use the general BrainState protocol. |
|
|
15
|
-
|
|
16
|
-
Do not combine a delayed prefetch with an explicit signal at update time. The projection either pulls its configured delayed source or delays the value passed to `proj(signal)`.
|
|
17
|
-
|
|
18
|
-
## Push a delayed signal
|
|
19
|
-
|
|
20
|
-
Use `delay=` for a direct-input `AlignPostProj` or `CurrentProj`. A scalar time applies one homogeneous delay; an `(N_pre,)` quantity applies one delay per presynaptic neuron.
|
|
21
|
-
|
|
22
|
-
| API | Behavior |
|
|
23
|
-
|---|---|
|
|
24
|
-
| `AlignPostProj(..., delay=None)` | Keep the zero-overhead undelayed path. |
|
|
25
|
-
| `AlignPostProj(..., delay=scalar_time)` | Delay every presynaptic element by the same duration. |
|
|
26
|
-
| `AlignPostProj(..., delay=per_pre_time)` | Apply heterogeneous axonal delays; the delay array must have shape `(N_pre,)`. |
|
|
27
|
-
| `CurrentProj(..., delay=...)` | Apply the same scalar or per-presynaptic delay contract to continuous direct input. |
|
|
28
|
-
|
|
29
|
-
```python
|
|
30
|
-
proj = brainpy.state.AlignPostProj(
|
|
31
|
-
comm=brainstate.nn.EventFixedProb(
|
|
32
|
-
n_pre,
|
|
33
|
-
n_post,
|
|
34
|
-
conn_num=0.1,
|
|
35
|
-
conn_weight=0.5 * u.mS,
|
|
36
|
-
),
|
|
37
|
-
syn=brainpy.state.Expon.desc(n_post, tau=5.0 * u.ms),
|
|
38
|
-
out=brainpy.state.COBA.desc(E=0.0 * u.mV),
|
|
39
|
-
post=post,
|
|
40
|
-
delay=5.0 * u.ms,
|
|
41
|
-
)
|
|
42
|
-
|
|
43
|
-
# Inside the step, before post(...) integrates:
|
|
44
|
-
proj(pre.get_spike() != 0.0)
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
Sub-`dt` delays are linearly interpolated. `init_state()` sizes the buffer from `ceil(max(delay) / dt)`, so establish `dt` before State initialization and do not change it during that initialized run.
|
|
48
|
-
|
|
49
|
-
## Pull a delayed neuron signal
|
|
50
|
-
|
|
51
|
-
Use delayed prefetch when the projection owns presynaptic extraction. Built-in neurons expose historical `V`, not a separate stored spike history, so delay `V` and re-derive the spike from the delayed voltage.
|
|
52
|
-
|
|
53
|
-
```python
|
|
54
|
-
proj = brainpy.state.AlignPostProj(
|
|
55
|
-
pre.prefetch("V").delay.at(5.0 * u.ms),
|
|
56
|
-
lambda voltage: pre.get_spike(voltage) != 0.0,
|
|
57
|
-
comm=brainstate.nn.EventFixedProb(
|
|
58
|
-
n_pre,
|
|
59
|
-
n_post,
|
|
60
|
-
conn_num=0.1,
|
|
61
|
-
conn_weight=0.5 * u.mS,
|
|
62
|
-
),
|
|
63
|
-
syn=brainpy.state.Expon.desc(n_post, tau=5.0 * u.ms),
|
|
64
|
-
out=brainpy.state.COBA.desc(E=0.0 * u.mV),
|
|
65
|
-
post=post,
|
|
66
|
-
)
|
|
67
|
-
|
|
68
|
-
# The projection pulls the delayed voltage and decodes its spike.
|
|
69
|
-
proj()
|
|
70
|
-
pre(drive)
|
|
71
|
-
post(0.0 * u.mA)
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
Keep the projection-before-post order. The delayed signal must be communicated before `post(...)` integrates the current step.
|
|
75
|
-
|
|
76
|
-
## Initialize, reset, and verify
|
|
77
|
-
|
|
78
|
-
1. Enter `brainstate.environ.context(dt=...)`.
|
|
79
|
-
2. Construct the network and delay-bearing projection.
|
|
80
|
-
3. Call `brainstate.nn.init_all_states(net)` so neural State and delay buffers are initialized together.
|
|
81
|
-
4. Run time through `brainstate.transform.for_loop`.
|
|
82
|
-
5. For every independent rollout, call `init_all_states()` again.
|
|
83
|
-
6. Compare otherwise identical undelayed, short-delay, and long-delay runs; monitor the presynaptic spike and projection conductance/current to verify the expected arrival-time shift before interpreting postsynaptic spikes.
|
|
84
|
-
|
|
85
|
-
Do not validate a delay only from postsynaptic spike time. Membrane integration, thresholding, refractory State, and other inputs can shift or suppress the postsynaptic spike even when the transmission delay is correct.
|
|
86
|
-
|
|
87
|
-
## Use a manual BrainState delay
|
|
88
|
-
|
|
89
|
-
Insert the current sample before retrieval so step 0 always means current and step `d` means exactly `d` completed updates earlier.
|
|
90
|
-
|
|
91
|
-
| API | Description |
|
|
92
|
-
|---|---|
|
|
93
|
-
| `brainstate.nn.Delay(target_info, max_time)` | Use when model logic needs an explicit reusable history buffer rather than a projection-owned delay; it allocates enough history for `max_time` under the initialization `dt`. |
|
|
94
|
-
| `delay.update(value)` | Insert the current sample once per step before any retrieval that should include the updated history. |
|
|
95
|
-
| `delay.retrieve_at_step(step)` | Retrieve an integer-offset sample; after the current update, step 0 is `value` and step `d` is the value from `d` updates earlier. |
|
|
96
|
-
| `delay.retrieve_at_time(time)` | Retrieve by a unit-bearing time when the model is defined in physical time; select the documented interpolation behavior rather than manually rounding an off-grid delay. |
|
|
97
|
-
| `delay.register_entry(name, vector_delays, indices)` and `delay.at(name)` | Use for one named heterogeneous tap per selected source element; register before State initialization, then retrieve the selected delayed values after each update. |
|
|
98
|
-
|
|
99
|
-
```python
|
|
100
|
-
import brainstate
|
|
101
|
-
import brainunit as u
|
|
102
|
-
import jax
|
|
103
|
-
import jax.numpy as jnp
|
|
104
|
-
|
|
105
|
-
with brainstate.environ.context(dt=1.0 * u.ms):
|
|
106
|
-
delay = brainstate.nn.Delay(
|
|
107
|
-
jax.ShapeDtypeStruct((), jnp.float32),
|
|
108
|
-
3.0 * u.ms,
|
|
109
|
-
)
|
|
110
|
-
brainstate.nn.init_all_states(delay)
|
|
111
|
-
impulse = jnp.array([1.0, 0.0, 0.0, 0.0, 0.0])
|
|
112
|
-
|
|
113
|
-
def step(value):
|
|
114
|
-
delay.update(value)
|
|
115
|
-
return delay.retrieve_at_step(jnp.asarray(3, dtype=jnp.int32))
|
|
116
|
-
|
|
117
|
-
delayed = brainstate.transform.for_loop(step, impulse)
|
|
118
|
-
|
|
119
|
-
assert jnp.array_equal(delayed, jnp.array([0.0, 0.0, 0.0, 1.0, 0.0]))
|
|
120
|
-
```
|
|
121
|
-
|
|
122
|
-
If retrieval occurs before `update(value)`, the buffer still represents the previous completed step and the index for the same observed latency changes by one. Do not compensate with an unexplained `d - 1`; choose one call order, document it beside the step, and lock the convention with an impulse assertion before interpreting neural output.
|
|
123
|
-
|
|
124
|
-
Reinitialize the delay for every independent rollout. A silent input interval advances the buffer but does not establish an independent State lifecycle.
|
|
125
|
-
|
|
126
|
-
For grid-aligned binary spikes, retrieve exact integer steps or use named entries whose delays are integer multiples of `dt`. Linear time interpolation can produce fractional numeric values, which no longer satisfy binary-event semantics. Use continuous interpolation only when the modeled signal and off-grid timing require it.
|
|
127
|
-
|
|
128
|
-
When a unit-bearing event time feeds an integer delay bank, convert `time / dt` to one documented integer step before the rollout and generate the event on that grid. Do not rediscover its step inside the time loop with a half-open `abs(t - arrival) < dt / 2` window; exact half-step results can depend on floating representation.
|
|
129
|
-
|
|
130
|
-
## Map delay State across independent conditions
|
|
131
|
-
|
|
132
|
-
Keep every writable part of a delay on one compatible mapped axis. A ring buffer whose history is per lane but whose mutable write pointer remains scalar cannot be shared across a mapped step, even when every lane advances in lockstep.
|
|
133
|
-
|
|
134
|
-
Prefer `brainstate.nn.Delay` when its complete mutable State can be initialized and mapped per condition. If its bookkeeping cannot satisfy the State-axis policy, use a small pointer-free `HiddenState` shift register only for a fixed integer delay bank; keep step 0 as the current event and prove at least one nonzero tap with an impulse assertion. Do not generalize this fallback to long histories because shifting the full buffer costs work proportional to the maximum delay.
|
|
135
|
-
|
|
136
|
-
Open `references/scripts/sound_localization.py` when building a mapped multi-tap coincidence detector, for the verified pointer-free fallback, semantic State filters, integer event taps, and impulse check.
|
|
137
|
-
|
|
138
|
-
## General BrainState boundary
|
|
139
|
-
|
|
140
|
-
Open the official BrainState [Delay Protocol](https://brainx.chaobrain.com/brainstate/tutorials/brain_dynamics/02_synaptic_delays.html) when implementing `brainstate.nn.DelayAccess`, `brainstate.nn.StateWithDelay`, rotation versus concatenation buffers, named entries, multiple taps, or linear-versus-round interpolation. Those mechanisms are more general than BrainPy projection delays and should not be reconstructed inside a projection unless the projection APIs cannot express the required history.
|
|
141
|
-
|
|
142
|
-
## Official sources
|
|
143
|
-
|
|
144
|
-
- `https://brainx.chaobrain.com/brainpy-state/brainpy-style/howto/sim-delays.html`
|
|
145
|
-
- `https://brainx.chaobrain.com/brainpy-state/apis/generated/brainpy.state.AlignPostProj.html`
|
|
146
|
-
- `https://brainx.chaobrain.com/brainpy-state/apis/generated/brainpy.state.CurrentProj.html`
|
|
147
|
-
- `https://brainx.chaobrain.com/brainstate/tutorials/brain_dynamics/02_synaptic_delays.html`
|