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.
Files changed (171) hide show
  1. package/README.md +17 -1
  2. package/manifest.json +1 -1
  3. package/mcp-servers/codex/skills.json +1 -1
  4. package/package.json +1 -1
  5. package/skills/bio-neuro-lit/SKILL.md +4 -2
  6. package/skills/bio-neuro-lit/references/required-supplements.md +27 -0
  7. package/skills/brainx-acceleration/SKILL.md +30 -437
  8. package/skills/brainx-acceleration/references/audit-and-rewrite-patterns.md +326 -0
  9. package/skills/brainx-general-guard/SKILL.md +24 -8
  10. package/skills/brainx-install/SKILL.md +3 -3
  11. package/skills/brainx-install/references/compatibility-and-release-matching.md +28 -20
  12. package/skills/brainx-install/references/uninstall-and-cleanup.md +11 -4
  13. package/skills/brainx-modeling-loop/SKILL.md +143 -36
  14. package/skills/brainx-modeling-loop/agents/openai.yaml +2 -2
  15. package/skills/brainx-modeling-loop/references/mechanism-comparison.md +62 -0
  16. package/skills/brainx-modeling-loop/references/multiscale-coupling.md +16 -0
  17. package/skills/brainx-modeling-loop/references/paper-reproduction.md +42 -0
  18. package/skills/brainx-modeling-loop/references/parameter-fitting-workflow.md +14 -14
  19. package/skills/brainx-modeling-loop/references/run-experiment.md +1 -1
  20. package/skills/brainx-modeling-loop/references/training-workflow.md +10 -8
  21. package/skills/brainx-visualization/SKILL.md +6 -2
  22. package/skills/brainx-visualization/references/neural-data-visualization.md +1 -1
  23. package/skills/brainx-visualization/references/statistical-and-model-visualization.md +1 -1
  24. package/skills/package-skills/braincell/SKILL.md +23 -14
  25. package/skills/package-skills/braincell/references/braintools/input-current.md +1 -1
  26. package/skills/package-skills/braincell/references/braintools/metric.md +72 -46
  27. package/skills/package-skills/braincell/references/mixions-for-adaptation.md +1 -1
  28. package/skills/package-skills/braincell/references/multicompartment/braincell-manual-morphology-construction.md +1 -1
  29. package/skills/package-skills/braincell/references/multicompartment/cv-policy-reference.md +1 -1
  30. package/skills/package-skills/braincell/references/multicompartment/filter-function-library.md +3 -3
  31. package/skills/package-skills/braincell/references/multicompartment/morphology-io-loading-validation.md +1 -1
  32. package/skills/package-skills/braincell/references/multicompartment/multicompartment-cell-workflow.md +31 -43
  33. package/skills/package-skills/braincell/references/multicompartment/network-workflow.md +49 -0
  34. package/skills/package-skills/braincell/references/multicompartment/probe-reference.md +26 -114
  35. package/skills/package-skills/braincell/references/multicompartment/topology-building-and-visualization.md +40 -28
  36. package/skills/package-skills/braincell/references/scripts/cell_multicompartment_reference.py +13 -17
  37. package/skills/package-skills/brainevent/SKILL.md +0 -3
  38. package/skills/package-skills/brainevent/references/synaptic-plasticity.md +1 -1
  39. package/skills/package-skills/brainmass/SKILL.md +5 -3
  40. package/skills/package-skills/brainmass/references/brainstate/parameter-constraints-regularization.md +9 -7
  41. package/skills/package-skills/brainmass/references/brainstate/parameter-transforms-regularizers-catalog.md +4 -4
  42. package/skills/package-skills/brainmass/references/braintools/data-preprocessing.md +15 -7
  43. package/skills/package-skills/brainmass/references/braintools/metric.md +72 -46
  44. package/skills/package-skills/brainmass/references/coupling-network-api.md +3 -1
  45. package/skills/package-skills/brainmass/references/fitting-with-objectives-api.md +6 -6
  46. package/skills/package-skills/brainmass/references/horn-task-training.md +9 -9
  47. package/skills/package-skills/brainmass/references/modellibrary.md +12 -10
  48. package/skills/package-skills/brainmass/references/scripts/resting-state-meg-whole-brain-pipeline.py +5 -3
  49. package/skills/package-skills/brainmass/references/scripts/wilson-cowan-ei-dynamics.py +10 -6
  50. package/skills/package-skills/brainmass/references/simulator-input-monitor-api.md +3 -1
  51. package/skills/package-skills/brainmass/references/visualization-analysis-api.md +17 -9
  52. package/skills/package-skills/brainspike/SKILL.md +201 -0
  53. package/skills/package-skills/brainspike/references/braintools/connectivity.md +40 -0
  54. package/skills/package-skills/brainspike/references/braintools/data-preprocessing.md +39 -0
  55. package/skills/package-skills/brainspike/references/braintools/input-current.md +55 -0
  56. package/skills/package-skills/brainspike/references/braintools/metric.md +36 -0
  57. package/skills/package-skills/brainspike/references/braintools/optimizer.md +50 -0
  58. package/skills/package-skills/brainspike/references/braintools/parameter-initializer.md +43 -0
  59. package/skills/package-skills/brainspike/references/braintools/surrogate.md +40 -0
  60. package/skills/package-skills/brainspike/references/migration-boundary.md +38 -0
  61. package/skills/package-skills/brainspike/references/model-and-readout-selection.md +41 -0
  62. package/skills/package-skills/brainspike/references/multirate-coupling.md +31 -0
  63. package/skills/package-skills/brainspike/references/multiscale-composition.md +28 -0
  64. package/skills/package-skills/brainspike/references/native-composition.md +52 -0
  65. package/skills/package-skills/brainspike/references/native-delays.md +34 -0
  66. package/skills/package-skills/brainspike/references/native-projections.md +43 -0
  67. package/skills/package-skills/brainspike/references/native-training.md +36 -0
  68. package/skills/package-skills/{brainpy-state → brainspike}/references/nest-compatible/devices.md +33 -33
  69. package/skills/package-skills/{brainpy-state → brainspike}/references/nest-compatible/divergence-and-parity.md +15 -15
  70. package/skills/package-skills/{brainpy-state → brainspike}/references/nest-compatible/integration-categories.md +1 -1
  71. package/skills/package-skills/brainspike/references/nest-compatible/model-library.md +200 -0
  72. package/skills/package-skills/brainspike/references/nest-compatible/network-building.md +276 -0
  73. package/skills/package-skills/{brainpy-state → brainspike}/references/nest-compatible/scripts/brette_et_al_2007.py +23 -26
  74. package/skills/package-skills/{brainpy-state → brainspike}/references/nest-compatible/scripts/brunel_alpha.py +18 -21
  75. package/skills/package-skills/{brainpy-state → brainspike}/references/nest-compatible/scripts/brunel_delta.py +16 -19
  76. package/skills/package-skills/{brainpy-state → brainspike}/references/nest-compatible/scripts/clopath_synapse_spike_pairing.py +11 -12
  77. package/skills/package-skills/{brainpy-state → brainspike}/references/nest-compatible/scripts/evaluate_tsodyks2_synapse.py +10 -11
  78. package/skills/package-skills/{brainpy-state → brainspike}/references/nest-compatible/scripts/spatial_gaussex.py +18 -18
  79. package/skills/package-skills/{brainpy-state → brainspike}/references/nest-compatible/scripts/synapsecollection.py +26 -29
  80. package/skills/package-skills/brainspike/references/nest-compatible/synapse-and-connectivity.md +166 -0
  81. package/skills/package-skills/brainspike/references/nest-delay-boundaries.md +31 -0
  82. package/skills/package-skills/brainspike/references/nonlinear-state-sharing.md +26 -0
  83. package/skills/package-skills/{brainpy-state → brainspike}/references/perturbation-experiment-validity.md +2 -2
  84. package/skills/package-skills/brainspike/references/simulator-training.md +61 -0
  85. package/skills/package-skills/brainspike/references/temporal-task-training.md +36 -0
  86. package/skills/package-skills/brainspike/scripts/advanced_native_patterns.py +76 -0
  87. package/skills/package-skills/brainspike/scripts/delay_workflow.py +44 -0
  88. package/skills/package-skills/brainspike/scripts/delayed_cue_training.py +78 -0
  89. package/skills/package-skills/brainspike/scripts/lif_smoke.py +31 -0
  90. package/skills/package-skills/brainspike/scripts/multiscale_workflow.py +35 -0
  91. package/skills/package-skills/brainspike/scripts/native_ei_network.py +47 -0
  92. package/skills/package-skills/brainspike/scripts/native_workflows.py +77 -0
  93. package/skills/package-skills/brainspike/scripts/nest_boundary_workflows.py +108 -0
  94. package/skills/package-skills/brainspike/scripts/train_native_snn.py +65 -0
  95. package/skills/package-skills/brainspike/scripts/train_nest_simulator.py +69 -0
  96. package/skills/package-skills/brainspike/scripts/train_nest_simulator_two_weights.py +220 -0
  97. package/skills/package-skills/brainstate/SKILL.md +16 -21
  98. package/skills/package-skills/brainstate/references/brainstate/brainstate-control-flow-patterns.md +1 -138
  99. package/skills/package-skills/brainstate/references/brainstate/brainstate-transformed-diagnostics.md +1 -1
  100. package/skills/package-skills/brainstate/references/brainstate/delay-buffers.md +45 -0
  101. package/skills/package-skills/brainstate/references/brainstate/parameter-constraints-regularization.md +9 -7
  102. package/skills/package-skills/brainstate/references/brainstate/parameter-transforms-regularizers-catalog.md +4 -4
  103. package/skills/package-skills/brainstate/references/brainstate/randomness-and-reproducibility.md +6 -4
  104. package/skills/package-skills/brainstate/references/brainstate/transformation-grad-expansion.md +4 -4
  105. package/skills/package-skills/brainstate/references/brainstate/transformation-vmap-expansion.md +1 -1
  106. package/skills/package-skills/brainstate/references/braintools-optimizer-reference.md +16 -0
  107. package/skills/package-skills/brainstate/references/libraries/prebuilt-layer-library.md +1 -1
  108. package/skills/package-skills/brainstate/references/simulation-environment.md +5 -5
  109. package/skills/package-skills/braintrace/SKILL.md +17 -38
  110. package/skills/package-skills/braintrace/references/Drtrl.md +9 -26
  111. package/skills/package-skills/braintrace/references/algorithm selection.md +7 -12
  112. package/skills/package-skills/braintrace/references/batching.md +15 -35
  113. package/skills/package-skills/braintrace/references/compiler_internal.md +1 -1
  114. package/skills/package-skills/braintrace/references/custom algorithms.md +1 -2
  115. package/skills/package-skills/braintrace/references/customizing_primitive_transforms.md +26 -15
  116. package/skills/package-skills/braintrace/references/pp_pprop workflow.md +5 -139
  117. package/skills/package-skills/brainunit/SKILL.md +7 -2
  118. package/skills/package-skills/brainunit/references/array-mechanics/functional-structural-api.md +1 -1
  119. package/skills/package-skills/brainunit/references/math-function-library.md +2 -2
  120. package/skills/package-skills/brainunit/references/typing-and-runtime-validation.md +5 -2
  121. package/skills/package-skills/brainevent/references/scripts/102_EI_net_1996.py +0 -107
  122. package/skills/package-skills/brainevent/references/scripts/204_joglekar_2018_propagation.py +0 -168
  123. package/skills/package-skills/brainevent/references/scripts/coba_ei_teaching.py +0 -356
  124. package/skills/package-skills/brainpy-state/SKILL.md +0 -247
  125. package/skills/package-skills/brainpy-state/references/array-creation.md +0 -158
  126. package/skills/package-skills/brainpy-state/references/brain-dynamics-delay-protocol.md +0 -147
  127. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/analysis.md +0 -150
  128. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/brainpy legacy workflow.md +0 -373
  129. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/built-in dynamic neuron model.md +0 -150
  130. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/connecting neurons.md +0 -175
  131. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/customize neuron and synpase.md +0 -286
  132. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/infrastructure/Input generation.md +0 -111
  133. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/infrastructure/More about simulation.md +0 -163
  134. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/infrastructure/Multi-device array sharding.md +0 -113
  135. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/infrastructure/Parallel experiment execution.md +0 -136
  136. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/infrastructure/array creation and mechanics.md +0 -222
  137. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/infrastructure/brainpy math environment setting.md +0 -123
  138. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/infrastructure/delays.md +0 -107
  139. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/infrastructure/object oriented transformations and control flows.md +0 -185
  140. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/integrators.md +0 -181
  141. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/route activity through connectivity.md +0 -102
  142. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/synaptic projections.md +0 -147
  143. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/synpase properties.md +0 -159
  144. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/training/loss library.md +0 -127
  145. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/training/optimizers.md +0 -167
  146. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/training/parameter initializers.md +0 -107
  147. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/training/prebuilt neural network layers.md +0 -186
  148. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/training/surrogate gradients.md +0 -104
  149. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/training/trainer library.md +0 -89
  150. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/training/trainingworkflows.md +0 -253
  151. package/skills/package-skills/brainpy-state/references/braintools/brainstate-control-flow-patterns.md +0 -334
  152. package/skills/package-skills/brainpy-state/references/braintools/connectivity.md +0 -206
  153. package/skills/package-skills/brainpy-state/references/braintools/data-preprocessing.md +0 -79
  154. package/skills/package-skills/brainpy-state/references/braintools/input-current.md +0 -199
  155. package/skills/package-skills/brainpy-state/references/braintools/metric.md +0 -152
  156. package/skills/package-skills/brainpy-state/references/braintools/optimizer.md +0 -179
  157. package/skills/package-skills/brainpy-state/references/braintools/parameter-initializer.md +0 -183
  158. package/skills/package-skills/brainpy-state/references/braintools/surrogate.md +0 -147
  159. package/skills/package-skills/brainpy-state/references/component-selection.md +0 -288
  160. package/skills/package-skills/brainpy-state/references/nest-compatible/model-library.md +0 -200
  161. package/skills/package-skills/brainpy-state/references/nest-compatible/nest-workflow.md +0 -156
  162. package/skills/package-skills/brainpy-state/references/nest-compatible/network-building.md +0 -264
  163. package/skills/package-skills/brainpy-state/references/nest-compatible/synapse-and-connectivity.md +0 -153
  164. package/skills/package-skills/brainpy-state/references/projection-patterns.md +0 -127
  165. package/skills/package-skills/brainpy-state/references/scripts/103_COBA_2005.py +0 -86
  166. package/skills/package-skills/brainpy-state/references/scripts/106_COBA_HH_2007.py +0 -181
  167. package/skills/package-skills/brainpy-state/references/scripts/107_gamma_oscillation_1996.py +0 -156
  168. package/skills/package-skills/brainpy-state/references/scripts/109_fast_global_oscillation.py +0 -111
  169. package/skills/package-skills/brainpy-state/references/scripts/201_surrogate_grad_lif_fashion_mnist.py +0 -221
  170. package/skills/package-skills/brainpy-state/references/scripts/sound_localization.py +0 -240
  171. package/skills/package-skills/brainpy-state/references/scripts/training-snn.py +0 -119
@@ -1,175 +0,0 @@
1
- # Legacy BrainPy connectivity
2
-
3
- Use this reference to choose and materialize explicit legacy `brainpy.connect` connectivity, convert among dense/COO/CSR forms, or perform transmission with an implicit random matrix through `brainpy.math.jitconn`. Keep synapse dynamics and projection assembly in `synaptic projections.md` or `customize neuron and synpase.md`.
4
-
5
- ## Choose explicit or implicit connectivity
6
-
7
- Explicit connectors define a reusable wiring object whose representations can be inspected; JIT connectivity generates a random matrix during each matrix-vector operation and does not store the connection graph.
8
-
9
- | Need | Use | Constraint |
10
- |---|---|---|
11
- | Inspect edges, degrees, or a connection matrix | `brainpy.connect` | Materialize the required representation with `.require(...)`. |
12
- | Reuse the exact graph across different operations | `brainpy.connect` | Keep the connector or extracted indices. |
13
- | Apply sparse or event-driven transmission over stored CSR edges | `bm.sparse.csrmv` or `bm.event.csrmv` | Supply `indices`, `indptr`, and values that share one orientation. |
14
- | Avoid storing a large random matrix | `bm.jitconn.*` | Supply shape, distribution parameters, probability, and an explicit integer seed. |
15
-
16
- Do not use `jitconn` when downstream analysis must recover individual edges or modify a specific synapse.
17
-
18
- ## Build explicit connectivity
19
-
20
- Call a connector with `(pre_size, post_size)` unless those sizes were supplied as `pre=` and `post=` constructor arguments.
21
-
22
- ### Construct from known edges
23
-
24
- | API | Description |
25
- |---|---|
26
- | `bp.connect.MatConn(conn_mat)` | Use an existing dense connection matrix. |
27
- | `bp.connect.IJConn(i, j)` | Use paired presynaptic and postsynaptic edge indices. |
28
- | `bp.connect.CSRConn(indices, indptr)` | Use an existing CSR representation. |
29
- | `bp.connect.SparseMatConn(sparse_mat)` | Use an existing supported sparse matrix. |
30
-
31
- ### Generate random graphs
32
-
33
- | API | Description |
34
- |---|---|
35
- | `bp.connect.FixedProb(prob, pre_ratio=1.0, include_self=True, allow_multi_conn=False, seed=None)` | Connect possible pairs independently with fixed probability. |
36
- | `bp.connect.FixedPreNum(num, ...)` | Give each postsynaptic neuron a fixed number of presynaptic inputs. |
37
- | `bp.connect.FixedPostNum(num, ...)` | Give each presynaptic neuron a fixed number of postsynaptic targets. |
38
- | `bp.connect.FixedTotalNum(num, ...)` | Generate a fixed total number of connections. |
39
- | `bp.connect.GaussianProb(sigma, ...)` | Make connection probability decay with Gaussian distance inside one population. |
40
- | `bp.connect.ProbDist(dist, prob, ...)` | Connect pairs within a maximum distance at a specified probability. |
41
- | `bp.connect.SmallWorld(...)` | Build a Watts-Strogatz small-world graph. |
42
- | `bp.connect.ScaleFreeBA(...)` | Build a Barabasi-Albert preferential-attachment graph. |
43
- | `bp.connect.ScaleFreeBADual(...)` | Build the dual Barabasi-Albert variant. |
44
- | `bp.connect.PowerLaw(...)` | Build the Holme-Kim power-law graph with clustering. |
45
-
46
- ### Generate regular graphs
47
-
48
- | API | Description |
49
- |---|---|
50
- | `bp.connect.One2One()` | Connect equal-size groups by matching indices. |
51
- | `bp.connect.All2All(include_self=True)` | Connect every presynaptic neuron to every postsynaptic neuron. |
52
- | `bp.connect.GridFour(...)` | Connect four nearest grid neighbors. |
53
- | `bp.connect.GridEight(...)` | Connect eight nearest grid neighbors. |
54
- | `bp.connect.GridN(N, ...)` | Connect the neighborhood defined by radius `N`. |
55
-
56
- ```python
57
- import brainpy as bp
58
- import brainpy.math as bm
59
-
60
- pre_num, post_num = 4, 3
61
- connector = bp.connect.FixedProb(prob=0.5, seed=123)(pre_num, post_num)
62
-
63
- conn_mat = connector.require('conn_mat')
64
- indices, indptr = connector.require('pre2post')
65
-
66
- assert conn_mat.shape == (pre_num, post_num)
67
- assert indptr.shape == (pre_num + 1,)
68
- assert indices.ndim == 1
69
- ```
70
-
71
- **Invariant:** Preserve representation orientation. In `pre2post`, `indptr` partitions edges by presynaptic neuron and `indices` stores postsynaptic indices.
72
-
73
- ## Convert connection representations
74
-
75
- Use conversion helpers when source data and the selected communication operator require different formats.
76
-
77
- | API | Description |
78
- |---|---|
79
- | `bp.connect.mat2coo(mat)` | Convert a dense matrix to paired COO indices. |
80
- | `bp.connect.mat2csr(mat)` | Convert a dense matrix to CSR `indices` and `indptr`. |
81
- | `bp.connect.mat2csc(mat)` | Convert a dense matrix to CSC. |
82
- | `bp.connect.coo2csr(pre_ids, post_ids, ...)` | Group COO edges into presynaptic-oriented CSR. |
83
- | `bp.connect.coo2csc(pre_ids, post_ids, ...)` | Group COO edges into postsynaptic-oriented CSC. |
84
- | `bp.connect.coo2mat(pre_ids, post_ids, ...)` | Materialize a dense matrix from COO edges. |
85
- | `bp.connect.csr2coo(indices, indptr)` | Expand CSR into paired edge indices. |
86
- | `bp.connect.csr2csc(indices, indptr, ...)` | Change sparse orientation. |
87
- | `bp.connect.csr2mat(indices, indptr, ...)` | Materialize a dense matrix from CSR. |
88
-
89
- Keep edge-aligned weights in the same order as their sparse indices. If a conversion returns a permutation, apply it to the weight vector before transmission.
90
-
91
- ## Transmit through stored sparse connectivity
92
-
93
- Use sparse matrix-vector multiplication for graded presynaptic activity and event-driven multiplication when the presynaptic vector is boolean or spike-like.
94
-
95
- | API | Description |
96
- |---|---|
97
- | `bm.sparse.csrmv(data, indices, indptr, vector, shape, transpose=...)` | Multiply a CSR matrix by a dense graded vector. |
98
- | `bm.event.csrmv(data, indices, indptr, events, shape, transpose=...)` | Skip inactive presynaptic events during CSR transmission. |
99
-
100
- ```python
101
- weights = bm.ones(indices.shape)
102
- pre_activity = bm.asarray([1.0, 0.0, 2.0, 0.0])
103
- pre_spikes = bm.asarray([True, False, True, False])
104
-
105
- graded_post = bm.sparse.csrmv(
106
- weights,
107
- indices=indices,
108
- indptr=indptr,
109
- vector=pre_activity,
110
- shape=(pre_num, post_num),
111
- transpose=True,
112
- )
113
- event_post = bm.event.csrmv(
114
- weights,
115
- indices=indices,
116
- indptr=indptr,
117
- events=pre_spikes,
118
- shape=(pre_num, post_num),
119
- transpose=True,
120
- )
121
-
122
- assert graded_post.shape == event_post.shape == (post_num,)
123
- ```
124
-
125
- Use the event operator only when zero/nonzero or boolean event semantics match the presynaptic signal. Do not convert continuous rates to booleans merely to select the event kernel.
126
-
127
- ## Generate connectivity during transmission
128
-
129
- The six `jitconn` operators combine random connection generation with matrix-vector multiplication.
130
-
131
- | API | Weight model and input |
132
- |---|---|
133
- | `bm.jitconn.mv_prob_homo(vector, weight, conn_prob, seed, *, shape, ...)` | Graded vector; one scalar weight on every generated edge. |
134
- | `bm.jitconn.mv_prob_uniform(vector, w_low, w_high, conn_prob, seed, *, shape, ...)` | Graded vector; edge weights sampled uniformly. |
135
- | `bm.jitconn.mv_prob_normal(vector, w_mu, w_sigma, conn_prob, seed, *, shape, ...)` | Graded vector; edge weights sampled normally. |
136
- | `bm.jitconn.event_mv_prob_homo(events, weight, conn_prob, seed, *, shape, ...)` | Event vector; one scalar weight on every generated edge. |
137
- | `bm.jitconn.event_mv_prob_uniform(events, w_low, w_high, conn_prob, seed, *, shape, ...)` | Event vector; edge weights sampled uniformly. |
138
- | `bm.jitconn.event_mv_prob_normal(events, w_mu, w_sigma, conn_prob, seed, *, shape, ...)` | Event vector; edge weights sampled normally. |
139
-
140
- ```python
141
- post = bm.jitconn.event_mv_prob_normal(
142
- pre_spikes,
143
- w_mu=0.5,
144
- w_sigma=0.1,
145
- conn_prob=0.2,
146
- seed=123,
147
- shape=(pre_num, post_num),
148
- transpose=True,
149
- )
150
-
151
- assert post.shape == (post_num,)
152
- ```
153
-
154
- Always pass an explicit integer `seed`. With `seed=None`, the implementation draws a host NumPy seed on each eager call, but a JAX trace captures that seed as a Python constant and reuses it on subsequent jitted calls.
155
-
156
- Do not assume separate calls with `transpose=False` and `transpose=True` sample an identical matrix/transposed-matrix pair. The API documents `outdim_parallel=True` as the setting for that equivalence, with a possible speed cost; validate equivalence for the exact operator before depending on it.
157
-
158
- ## Common failures
159
-
160
- - Do not materialize `conn_mat` for a large sparse graph unless an operation truly needs the dense matrix.
161
- - Do not interpret `pre2post` indices as postsynaptic-oriented CSC data.
162
- - Do not separate edge weights from the index order that defines them.
163
- - Do not use an event kernel for graded activity.
164
- - Do not omit the `jitconn` seed inside `jit`, `vmap`, or repeated experiment code.
165
- - Do not use implicit JIT connectivity when exact edge inspection, plasticity, or edge-specific modification is required.
166
-
167
- ## Routing
168
-
169
- Open `route activity through connectivity.md` for communication-layer selection and weighted transmission. Open `synaptic projections.md` for projection anatomy and update order. Open `synpase properties.md` for synaptic state and output semantics.
170
-
171
- ## Sources mirrored
172
-
173
- - https://brainpy.readthedocs.io/apis/connect.html
174
- - https://brainpy.readthedocs.io/tutorial_math/Dedicated_Operators.html
175
- - https://brainpy.readthedocs.io/apis/brainpy.math.jitconn.html
@@ -1,286 +0,0 @@
1
- # Customize legacy BrainPy neurons and synapses
2
-
3
- Use this reference when a legacy BrainPy 2.x model needs custom neuron equations, spike/reset logic, synapse dynamics, synaptic output, communication, or projection composition. Use `built-in dynamic neuron model.md` first when a supplied `brainpy.dyn` model already matches the required mechanism.
4
-
5
- ## Choose the extension point
6
-
7
- A custom neuron owns state evolution and event transitions; a custom projection composes presynaptic events, optional delay, communication, synapse dynamics, output current, and postsynaptic input binding.
8
-
9
- | Need | Extend or compose |
10
- |---|---|
11
- | New neuron equations or spike/reset rule | `bp.dyn.NeuDyn` |
12
- | New synaptic state equations | `bp.dyn.SynDyn` |
13
- | New conductance-to-current rule | `bp.dyn.SynOut` |
14
- | New weighted connectivity operation | `bp.dnn.Layer` or another `DynamicalSystem` used as `comm` |
15
- | State aligned to postsynaptic neurons | `bp.dyn.ProjAlignPostMg2` |
16
- | State aligned to presynaptic neurons | `bp.dyn.ProjAlignPreMg2` |
17
- | Reusable projection wrapper | `bp.Projection` |
18
-
19
- Keep these mechanisms separate. A projection chooses their order and ownership; it should not duplicate neuron or synapse differential equations.
20
-
21
- ## Implement a custom neuron
22
-
23
- `NeuDyn` supplies population shape and model lifecycle, while the subclass declares every evolving value as `bm.Variable` and implements one time step in `update()`.
24
-
25
- | API | Description |
26
- |---|---|
27
- | `bp.dyn.NeuDyn(size, keep_size=False, method='exp_auto', ...)` | Initialize population metadata and common neuronal-dynamics behavior. |
28
- | `bm.Variable(initial_value)` | Register voltage, gating, spike, refractory, and last-event state for transformed mutation. |
29
- | `bp.odeint(f, method=...)` | Build an integrator for continuous state equations. |
30
- | `bp.share['t']` | Read the current simulation time supplied by the runner or `step_run`. |
31
- | `bp.share['dt']` | Read the active integration step. |
32
- | `bm.where(condition, x, y)` | Apply discontinuous reset or refractory transitions without Python branching on traced arrays. |
33
- | `update(input=None)` | Advance exactly one step, update Variables, and return the step output if callers need it. |
34
-
35
- ```python
36
- import brainpy as bp
37
- import brainpy.math as bm
38
-
39
-
40
- class LegacyLIF(bp.dyn.NeuDyn):
41
- def __init__(
42
- self,
43
- size,
44
- V_rest=0.0,
45
- V_reset=-5.0,
46
- V_th=20.0,
47
- R=1.0,
48
- tau=10.0,
49
- tau_ref=5.0,
50
- **kwargs,
51
- ):
52
- super().__init__(size=size, **kwargs)
53
- self.V_rest = V_rest
54
- self.V_reset = V_reset
55
- self.V_th = V_th
56
- self.R = R
57
- self.tau = tau
58
- self.tau_ref = tau_ref
59
-
60
- self.V = bm.Variable(bm.ones(self.num) * V_reset)
61
- self.spike = bm.Variable(bm.zeros(self.num, dtype=bool))
62
- self.refractory = bm.Variable(bm.zeros(self.num, dtype=bool))
63
- self.t_last_spike = bm.Variable(bm.ones(self.num) * -1e7)
64
-
65
- self.integral = bp.odeint(self.dV, method='exp_auto')
66
-
67
- def dV(self, V, t, current):
68
- return (-V + self.V_rest + self.R * current) / self.tau
69
-
70
- def update(self, current=None):
71
- t = bp.share['t']
72
- dt = bp.share['dt']
73
- current = 0.0 if current is None else current
74
-
75
- refractory = (t - self.t_last_spike) <= self.tau_ref
76
- next_V = self.integral(self.V, t, current, dt=dt)
77
- next_V = bm.where(refractory, self.V, next_V)
78
- spike = next_V >= self.V_th
79
-
80
- self.spike.value = spike
81
- self.t_last_spike.value = bm.where(spike, t, self.t_last_spike)
82
- self.V.value = bm.where(spike, self.V_reset, next_V)
83
- self.refractory.value = bm.logical_or(refractory, spike)
84
- return self.spike.value
85
- ```
86
-
87
- This example separates continuous integration from the discontinuous threshold/reset transition. For a continuous Hodgkin-Huxley-style model, create one integrator per equation or a joint integrator, update gating variables from the old state consistently, detect threshold crossings, then commit the new Variables.
88
-
89
- **Invariant:** Compute the next state before assigning any dependent `Variable.value` unless the equations intentionally use a sequential update. Premature assignment silently changes which time level later equations read.
90
-
91
- ### Run the custom neuron
92
-
93
- ```python
94
- neurons = LegacyLIF(10)
95
- runner = bp.DSRunner(neurons, monitors=['V', 'spike'])
96
- runner.run(inputs=bm.ones(1000) * 22.0)
97
-
98
- assert runner.mon['V'].shape == (1000, 10)
99
- assert runner.mon['spike'].shape == (1000, 10)
100
- ```
101
-
102
- Open `integrators.md` when choosing a solver, implementing coupled ODEs/SDEs, passing delays to integrators, or validating equation argument order.
103
-
104
- ## Decompose a custom chemical synapse
105
-
106
- A legacy chemical projection is a chain: presynaptic event -> optional delay -> communication -> synapse state -> output current -> postsynaptic input.
107
-
108
- | Component | Role | Typical base/API |
109
- |---|---|---|
110
- | `pre` | Produces spike or graded presynaptic activity. | `NeuDyn`, `SpikeTimeGroup`, or another `DynamicalSystem` |
111
- | `delay` | Selects an earlier presynaptic event. | Projection `delay=` and pre delay support |
112
- | `comm` | Maps pre-aligned activity to the post population with weights and connectivity. | `EventCSRLinear`, `CSRLinear`, `AllToAll`, `OneToOne`, or custom `bp.dnn.Layer` |
113
- | `syn` | Evolves conductance, gating, or transmitter state. | `bp.dyn.SynDyn` descriptor |
114
- | `out` | Converts synaptic state to current. | `bp.dyn.SynOut` descriptor or instance, according to the projection signature |
115
- | `post` | Receives the bound current before its own update. | Postsynaptic neuron group |
116
-
117
- Use `.desc(...)` for `syn` in both merging projections. `ProjAlignPostMg2` also takes an `out` descriptor; `ProjAlignPreMg2` takes a concrete `SynOut` instance because it binds condition data directly.
118
-
119
- ## Implement postsynaptic-aligned exponential conductance
120
-
121
- The tutorial's postsynaptic-aligned path is for exponential synapse dynamics whose incoming events can be communicated first and accumulated into one conductance state per postsynaptic neuron.
122
-
123
- | API | Description |
124
- |---|---|
125
- | `bp.dyn.SynDyn` | Base class for evolving synapse state. |
126
- | `bp.mixin.AlignPost` | Mark dynamics that support postsynaptic alignment and accumulated current. |
127
- | `add_current(x)` | Add communicated event increments to the postsynaptic-aligned state. |
128
- | `return_info()` | Expose the state information required by projection merging. |
129
- | `bp.dyn.ProjAlignPostMg2(...)` | Compose `delay -> comm -> postsynaptic synapse -> output -> post`. |
130
-
131
- ```python
132
- class ExponentialConductance(bp.dyn.SynDyn, bp.mixin.AlignPost):
133
- def __init__(self, size, tau=5.0):
134
- super().__init__(size=size)
135
- self.tau = tau
136
- self.g = bm.Variable(bm.zeros(self.num))
137
- self.integral = bp.odeint(
138
- lambda g, t: -g / self.tau,
139
- method='exp_auto',
140
- )
141
-
142
- def update(self, increment=None):
143
- self.g.value = self.integral(
144
- self.g,
145
- bp.share['t'],
146
- dt=bp.share['dt'],
147
- )
148
- if increment is not None:
149
- self.add_current(increment)
150
- return self.g.value
151
-
152
- def add_current(self, increment):
153
- self.g += increment
154
-
155
- def return_info(self):
156
- return self.g
157
-
158
-
159
- class COBAOutput(bp.dyn.SynOut):
160
- def __init__(self, E=0.0):
161
- super().__init__()
162
- self.E = E
163
-
164
- def update(self, conductance, potential):
165
- return conductance * (self.E - potential)
166
-
167
-
168
- class ExponentialCOBA(bp.Projection):
169
- def __init__(
170
- self,
171
- pre,
172
- post,
173
- prob,
174
- g_max,
175
- tau=5.0,
176
- E=0.0,
177
- delay=None,
178
- seed=None,
179
- ):
180
- super().__init__()
181
- connector = bp.conn.FixedProb(
182
- prob,
183
- pre=pre.num,
184
- post=post.num,
185
- seed=seed,
186
- )
187
- self.proj = bp.dyn.ProjAlignPostMg2(
188
- pre=pre,
189
- delay=delay,
190
- comm=bp.dnn.EventCSRLinear(connector, weight=g_max),
191
- syn=ExponentialConductance.desc(post.num, tau=tau),
192
- out=COBAOutput.desc(E=E),
193
- post=post,
194
- )
195
- ```
196
-
197
- The communication result is postsynaptic-sized, so `ExponentialConductance.desc(post.num, ...)` must use the postsynaptic population size.
198
-
199
- ## Use presynaptic alignment for event-history dynamics
200
-
201
- Use `ProjAlignPreMg2` when each presynaptic neuron owns kinetic state that must update before communication, as in the tutorial's AMPA model with spike-arrival time.
202
-
203
- | API | Description |
204
- |---|---|
205
- | `bp.dyn.ProjAlignPreMg2(pre, syn, delay, comm, out, post, ...)` | Compose `presynaptic synapse -> delay -> communication -> output -> post`. |
206
- | `AMPA.desc(pre.num, ...)` | Allocate one custom AMPA state per presynaptic neuron. |
207
- | `bp.dnn.CSRLinear(connector, weight=...)` | Transform graded pre-aligned synapse state into postsynaptic conductance. |
208
- | `MgBlock(...)` | Pass a concrete custom output instance for postsynaptic condition binding. |
209
-
210
- ```python
211
- # Given a custom AMPA SynDyn and MgBlock SynOut:
212
- self.proj = bp.dyn.ProjAlignPreMg2(
213
- pre=pre,
214
- syn=AMPA.desc(pre.num, alpha=0.98, beta=0.18, T=0.5, T_dur=0.5),
215
- delay=delay,
216
- comm=bp.dnn.CSRLinear(connector, weight=g_max),
217
- out=MgBlock(E=0.0),
218
- post=post,
219
- )
220
- ```
221
-
222
- The tutorial restricts postsynaptic alignment to exponential synapse dynamics. Do not move AMPA-like event-history state after communication merely to reduce its size; doing so changes the represented mechanism.
223
-
224
- ## Execute projection before the postsynaptic neuron
225
-
226
- Projection output must be bound before the postsynaptic group sums inputs and integrates its current step.
227
-
228
- ```python
229
- class TwoNeuronNetwork(bp.DynSysGroup):
230
- def __init__(self):
231
- super().__init__()
232
- self.pre = bp.dyn.SpikeTimeGroup(
233
- 1,
234
- indices=(0, 0, 0, 0),
235
- times=(10.0, 30.0, 50.0, 70.0),
236
- )
237
- self.post = bp.dyn.LifRef(
238
- 1,
239
- V_rest=-60.0,
240
- V_reset=-60.0,
241
- V_th=-50.0,
242
- tau=20.0,
243
- tau_ref=5.0,
244
- V_initializer=bp.init.Constant(-60.0),
245
- )
246
- self.syn = ExponentialCOBA(
247
- self.pre,
248
- self.post,
249
- prob=1.0,
250
- g_max=0.1,
251
- E=0.0,
252
- seed=123,
253
- )
254
-
255
- def update(self):
256
- self.pre()
257
- self.syn()
258
- self.post()
259
- return self.post.V.value
260
-
261
-
262
- network = TwoNeuronNetwork()
263
- runner = bp.DSRunner(network, monitors=['post.V', 'post.spike'])
264
- runner.run(100.0)
265
- ```
266
-
267
- **Invariant:** Call `pre`, then the chemical projection, then `post` for each step. Calling `post` first delays the new synaptic current by one integration step.
268
-
269
- ## Common failures
270
-
271
- - Do not store evolving voltage, gating, conductance, spike, or event-time state as an ordinary array.
272
- - Do not use Python `if` on traced per-neuron spike conditions; use `bm.where` or boolean array operations.
273
- - Do not update one coupled state before computing derivatives that require all old states.
274
- - Do not confuse postsynaptic alignment with presynaptic alignment; descriptor size and operation order must agree.
275
- - Do not guess descriptor ownership: both merging projections take a `syn` descriptor, `ProjAlignPostMg2` takes an `out` descriptor, and `ProjAlignPreMg2` takes a concrete `out` instance.
276
- - Do not call the postsynaptic neuron before its chemical projection.
277
- - Do not embed a dense communication matrix in custom synapse dynamics; keep connectivity and kinetics independently selectable.
278
-
279
- ## Routing
280
-
281
- Open `integrators.md` for numerical methods and coupled equation signatures. Open `connecting neurons.md` for connector representations and JIT connectivity. Open `synaptic projections.md` for built-in projection families. Open `synpase properties.md` for built-in synapse dynamics and output choices. Open `infrastructure/delays.md` for delayed presynaptic events.
282
-
283
- ## Sources mirrored
284
-
285
- - https://brainpy.readthedocs.io/tutorial_building/customize_neuron_models.html
286
- - https://brainpy.readthedocs.io/tutorial_building/how_to_customze_a_synapse.html
@@ -1,111 +0,0 @@
1
- # Legacy BrainPy input generation
2
-
3
- Use this reference to construct time-major stimulus arrays with
4
- `brainpy.inputs` for a legacy BrainPy simulation. Use the resulting arrays as
5
- iterable `DSRunner` inputs; do not substitute Braintools input objects or
6
- `brainpy.state` APIs in legacy code.
7
-
8
- ## Choose an input family
9
-
10
- All input constructors use `dt` to discretize physical duration. Choose by the
11
- shape of the intended stimulus.
12
-
13
- ### Piecewise and transient inputs
14
-
15
- | API | Description |
16
- |---|---|
17
- | `bp.inputs.section_input(values, durations, dt=None, return_length=False)` | Use for consecutive sections with independently specified values and durations; set `return_length=True` to also return total duration. |
18
- | `bp.inputs.constant_input(I_and_duration, dt=None)` | Use for the older `(value, duration)` piecewise-constant form. Prefer `section_input()` in new legacy-compatible code. |
19
- | `bp.inputs.spike_input(sp_times, sp_lens, sp_sizes, duration, dt=None)` | Use for short current pulses at explicit times; lengths and sizes may be scalars or one value per spike. |
20
- | `bp.inputs.ramp_input(c_start, c_end, duration, t_start=0, t_end=None, dt=None)` | Use for a linear ramp between `t_start` and `t_end` within a longer stimulus. |
21
-
22
- ### Stochastic inputs
23
-
24
- | API | Description |
25
- |---|---|
26
- | `bp.inputs.wiener_process(duration, dt=None, n=1, t_start=0.0, t_end=None, seed=None)` | Use for Wiener increments sampled from a zero-mean normal distribution with scale `sqrt(dt)`. |
27
- | `bp.inputs.ou_process(mean, sigma, tau, duration, dt=None, n=1, t_start=0.0, t_end=None, seed=None)` | Use for a mean-reverting Ornstein-Uhlenbeck process. |
28
-
29
- Set `seed=` whenever a stochastic stimulus must be reproducible. Set `n=` to
30
- generate multiple independent traces.
31
-
32
- ### Periodic inputs
33
-
34
- | API | Description |
35
- |---|---|
36
- | `bp.inputs.sinusoidal_input(amplitude, frequency, duration, dt=None, t_start=0.0, t_end=None, bias=False)` | Use for a sinusoidal waveform active over the selected time interval. |
37
- | `bp.inputs.square_input(amplitude, frequency, duration, dt=None, bias=False, t_start=0.0, t_end=None)` | Use for an oscillatory square waveform active over the selected time interval. |
38
-
39
- ## Construct an injection-ready stimulus
40
-
41
- The leading axis is simulation time. Make the constructor `dt` equal to the
42
- runner `dt`, then mark the array as iterable when injecting it through
43
- `DSRunner`.
44
-
45
- ```python
46
- import brainpy as bp
47
-
48
- dt = 0.1
49
- current, duration = bp.inputs.section_input(
50
- values=[0.0, 1.0, 0.0],
51
- durations=[100.0, 300.0, 100.0],
52
- dt=dt,
53
- return_length=True,
54
- )
55
-
56
- assert duration == 500.0
57
- assert current.shape == (5000,)
58
-
59
- runner = bp.DSRunner(
60
- target=model,
61
- inputs=[('input', current, 'iter')],
62
- monitors=['V'],
63
- dt=dt,
64
- )
65
- runner.run(duration)
66
- ```
67
-
68
- If `dt` is omitted, the constructor uses BrainPy's global default. An array
69
- created under one `dt` and consumed under another silently changes its physical
70
- duration, so pass the same explicit value at both boundaries.
71
-
72
- ## Compose values and shapes
73
-
74
- Input constructors broadcast heterogeneous section values to their maximum
75
- compatible shape. For example, scalar, vector, and matrix sections become one
76
- time-major array with the broadcast data shape after the leading time axis.
77
-
78
- ```python
79
- import brainpy as bp
80
- import brainpy.math as bm
81
-
82
- current = bp.inputs.section_input(
83
- values=[0.0, bm.ones(10), bm.ones((3, 10))],
84
- durations=[100.0, 300.0, 100.0],
85
- dt=0.1,
86
- )
87
-
88
- assert current.shape == (5000, 3, 10)
89
- ```
90
-
91
- Build a more complex stimulus by combining compatible generated arrays with
92
- ordinary BrainPy math operations. Align `duration`, `dt`, and broadcast shape
93
- before addition or multiplication; the constructors do not align two already
94
- generated time grids for you.
95
-
96
- ## Source-backed failures
97
-
98
- - Treat axis 0 as time. Do not pass a batch-major array as an unbatched iterable
99
- `DSRunner` input.
100
- - Use `return_length=True` only with `section_input()`; `constant_input()`
101
- returns its legacy current-and-duration result directly.
102
- - Give `sp_times`, `sp_lens`, and `sp_sizes` compatible lengths when the latter
103
- two are not scalars.
104
- - Keep `rate`, probability, and event encoders out of this reference; these
105
- functions construct currents and stochastic processes, not Braintools data
106
- preprocessing pipelines.
107
-
108
- ## Official sources
109
-
110
- - `https://brainpy.readthedocs.io/apis/inputs.html`
111
- - `https://brainpy.readthedocs.io/tutorial_toolbox/inputs.html`