brainx-skill 1.0.6 → 1.0.9

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 (120) hide show
  1. package/README.md +10 -8
  2. package/adapters/gemini.js +7 -0
  3. package/adapters/opencode.js +7 -0
  4. package/adapters/windsurf.js +7 -0
  5. package/installation/lib/installer.js +4 -1
  6. package/manifest.json +6 -1
  7. package/package.json +8 -2
  8. package/skills/braincell/SKILL.md +182 -0
  9. package/skills/braincell/references/area-scaled-hh-pattern.md +54 -0
  10. package/skills/braincell/references/braincell-custom-ion-channel-authoring.md +273 -0
  11. package/skills/braincell/references/channel-library.md +85 -0
  12. package/skills/braincell/references/ion-library.md +87 -0
  13. package/skills/braincell/references/mixions-for-adaptation.md +81 -0
  14. package/skills/braincell/references/multicompartment/braincell-manual-morphology-construction.md +180 -0
  15. package/skills/braincell/references/multicompartment/cv-policy-reference.md +133 -0
  16. package/skills/braincell/references/multicompartment/filter-function-library.md +154 -0
  17. package/skills/braincell/references/multicompartment/morphology-io-loading-validation.md +135 -0
  18. package/skills/braincell/references/multicompartment/multicompartment-cell-workflow.md +391 -0
  19. package/skills/braincell/references/multicompartment/probe-reference.md +128 -0
  20. package/skills/braincell/references/multicompartment/topology-building-and-visualization.md +260 -0
  21. package/skills/braincell/references/scripts/calcium_channel_gating.py +66 -0
  22. package/skills/braincell/references/scripts/cell_multicompartment_reference.py +221 -0
  23. package/skills/braincell/references/scripts/channel_ablation.py +61 -0
  24. package/skills/braincell/references/scripts/fi_curve.py +68 -0
  25. package/skills/braincell/references/scripts/hh_neuron_basics.py +59 -0
  26. package/skills/braincell/references/scripts/spike_frequency_adaptation.py +75 -0
  27. package/skills/braincell/references/scripts/t_current_rebound.py +72 -0
  28. package/skills/braincell/references/scripts/thalamic_neurons.py +228 -0
  29. package/skills/braincell/references/solver-library-with-effects.md +188 -0
  30. package/skills/brainevent/SKILL.md +268 -0
  31. package/skills/brainevent/references/connectivity-variants.md +312 -0
  32. package/skills/brainevent/references/custom-operators-cpu.md +304 -0
  33. package/skills/brainevent/references/custom-operators-gpu.md +468 -0
  34. package/skills/brainevent/references/scripts/102_EI_net_1996.py +107 -0
  35. package/skills/brainevent/references/scripts/204_joglekar_2018_propagation.py +168 -0
  36. package/skills/brainevent/references/scripts/coba_ei_teaching.py +356 -0
  37. package/skills/brainevent/references/sparse-formats.md +182 -0
  38. package/skills/brainevent/references/synaptic-plasticity.md +285 -0
  39. package/skills/brainmass/SKILL.md +290 -0
  40. package/skills/brainmass/references/batch-transform-acceleration.md +136 -0
  41. package/skills/brainmass/references/brainstate/parameter-constraints-regularization.md +214 -0
  42. package/skills/brainmass/references/brainstate/parameter-transforms-regularizers-catalog.md +171 -0
  43. package/skills/brainmass/references/braintools/cogtask.md +190 -0
  44. package/skills/brainmass/references/braintools/data-preprocessing.md +83 -0
  45. package/skills/brainmass/references/braintools/metric.md +157 -0
  46. package/skills/brainmass/references/braintools/optimizer.md +187 -0
  47. package/skills/brainmass/references/braintools/parameter-initializer.md +187 -0
  48. package/skills/brainmass/references/braintools/surrogate.md +151 -0
  49. package/skills/brainmass/references/coupling-network-api.md +148 -0
  50. package/skills/brainmass/references/datasets-api.md +72 -0
  51. package/skills/brainmass/references/fitting-with-objectives-api.md +146 -0
  52. package/skills/brainmass/references/forward-observation-api.md +131 -0
  53. package/skills/brainmass/references/horn-task-training.md +199 -0
  54. package/skills/brainmass/references/modellibrary.md +104 -0
  55. package/skills/brainmass/references/noiseprocesses.md +121 -0
  56. package/skills/brainmass/references/parameter-sweeps-and-regime-analysis.md +130 -0
  57. package/skills/brainmass/references/scripts/eeg-fitting-with-gradients.py +230 -0
  58. package/skills/brainmass/references/scripts/gradient-free-fitting.py +106 -0
  59. package/skills/brainmass/references/scripts/hopf-bifurcation-single-node.py +78 -0
  60. package/skills/brainmass/references/scripts/horn-cognitive-task-training.py +211 -0
  61. package/skills/brainmass/references/scripts/jansen-rit-eeg-proxy.py +76 -0
  62. package/skills/brainmass/references/scripts/kuramoto-synchronization.py +81 -0
  63. package/skills/brainmass/references/scripts/linear-baseline-node.py +81 -0
  64. package/skills/brainmass/references/scripts/resting-state-meg-whole-brain-pipeline.py +249 -0
  65. package/skills/brainmass/references/scripts/seizure-epileptor-case-study.py +126 -0
  66. package/skills/brainmass/references/scripts/wilson-cowan-ei-dynamics.py +86 -0
  67. package/skills/brainmass/references/scripts/wong-wang-decision-making.py +167 -0
  68. package/skills/brainmass/references/scripts/wong-wang-dmf-resting-state.py +72 -0
  69. package/skills/brainmass/references/visualization-analysis-api.md +130 -0
  70. package/skills/brainpy-state/SKILL.md +232 -0
  71. package/skills/brainpy-state/references/array-creation.md +158 -0
  72. package/skills/brainpy-state/references/brain-dynamics-delay-protocol.md +96 -0
  73. package/skills/brainpy-state/references/braintools/brainstate-control-flow-patterns.md +334 -0
  74. package/skills/brainpy-state/references/braintools/data-preprocessing.md +79 -0
  75. package/skills/brainpy-state/references/braintools/metric.md +152 -0
  76. package/skills/brainpy-state/references/braintools/optimizer.md +179 -0
  77. package/skills/brainpy-state/references/braintools/parameter-initializer.md +183 -0
  78. package/skills/brainpy-state/references/braintools/surrogate.md +147 -0
  79. package/skills/brainpy-state/references/component-selection.md +273 -0
  80. package/skills/brainpy-state/references/nest-compatible/devices.md +157 -0
  81. package/skills/brainpy-state/references/nest-compatible/divergence-and-parity.md +114 -0
  82. package/skills/brainpy-state/references/nest-compatible/integration-categories.md +41 -0
  83. package/skills/brainpy-state/references/nest-compatible/model-library.md +200 -0
  84. package/skills/brainpy-state/references/nest-compatible/nest-workflow.md +156 -0
  85. package/skills/brainpy-state/references/nest-compatible/network-building.md +264 -0
  86. package/skills/brainpy-state/references/nest-compatible/scripts/brette_et_al_2007.py +320 -0
  87. package/skills/brainpy-state/references/nest-compatible/scripts/brunel_alpha.py +108 -0
  88. package/skills/brainpy-state/references/nest-compatible/scripts/brunel_delta.py +93 -0
  89. package/skills/brainpy-state/references/nest-compatible/scripts/clopath_synapse_spike_pairing.py +171 -0
  90. package/skills/brainpy-state/references/nest-compatible/scripts/evaluate_tsodyks2_synapse.py +147 -0
  91. package/skills/brainpy-state/references/nest-compatible/scripts/spatial_gaussex.py +112 -0
  92. package/skills/brainpy-state/references/nest-compatible/scripts/synapsecollection.py +198 -0
  93. package/skills/brainpy-state/references/nest-compatible/synapse-and-connectivity.md +153 -0
  94. package/skills/brainpy-state/references/projection-patterns.md +125 -0
  95. package/skills/brainpy-state/references/scripts/103_COBA_2005.py +86 -0
  96. package/skills/brainpy-state/references/scripts/106_COBA_HH_2007.py +181 -0
  97. package/skills/brainpy-state/references/scripts/107_gamma_oscillation_1996.py +156 -0
  98. package/skills/brainpy-state/references/scripts/109_fast_global_oscillation.py +111 -0
  99. package/skills/brainpy-state/references/scripts/201_surrogate_grad_lif_fashion_mnist.py +221 -0
  100. package/skills/brainpy-state/references/scripts/training-snn.py +119 -0
  101. package/skills/brainstate/SKILL.md +1 -1
  102. package/skills/brainstate/references/brainstate/brainstate-control-flow-patterns.md +250 -399
  103. package/skills/brainstate/references/brainstate/brainstate-transformed-diagnostics.md +6 -2
  104. package/skills/brainstate/references/brainstate/parameter-constraints-regularization.md +16 -2
  105. package/skills/brainstate/references/brainstate/parameter-transforms-regularizers-catalog.md +8 -3
  106. package/skills/brainstate/references/brainstate/randomness-and-reproducibility.md +64 -143
  107. package/skills/brainstate/references/brainstate/transformation-grad-expansion.md +13 -1
  108. package/skills/brainstate/references/brainstate/transformation-jit-expansion.md +11 -1
  109. package/skills/brainstate/references/brainstate/transformation-vmap-expansion.md +35 -7
  110. package/skills/brainstate/references/collective_model_operations.md +9 -9
  111. package/skills/brainstate/references/extension_mechanisms.md +12 -1
  112. package/skills/brainstate/references/libraries/prebuilt-activation-library.md +106 -97
  113. package/skills/brainstate/references/libraries/prebuilt-layer-library.md +102 -176
  114. package/skills/brainstate/references/model-interop-and-migration.md +11 -1
  115. package/skills/brainstate/references/size-inference-variations.md +11 -0
  116. package/skills/brainstate/references/state-graph-operations.md +13 -15
  117. package/skills/brainstate/references/state_collections_and_utilities.md +12 -1
  118. package/skills/brainx-general-guard/SKILL.md +68 -0
  119. package/skills/brainstate/references/braintools-optimizer-reference.md +0 -133
  120. package/skills/brainstate/references/libraries/solver-library-with-effects.md +0 -85
@@ -0,0 +1,200 @@
1
+ # Model library
2
+
3
+ Use this reference when selecting a NEST-compatible neuron family, locating an exact `brainpy.state` model name, or recognizing the model-specific capability that changes construction or routing. Use upstream NEST documentation for equations, parameter meanings, physiology, and scientific references.
4
+
5
+ All constructor rows use the canonical `Simulator.create()` surface. Pass a reusable NEST-style parameter mapping with `params=parameters`, or replace it with explicit keyword parameters.
6
+
7
+ ## Current-based IAF neurons
8
+
9
+ Use these models for linear integrate-and-fire dynamics driven by postsynaptic currents; choose delta, alpha, exponential, precise-spiking, or multisynapse behavior from the requested NEST model.
10
+
11
+ | Constructor | Use when |
12
+ |---|---|
13
+ | `sim.create(bp.iaf_psc_delta, size, params=parameters)` | Use delta-shaped input that produces an instantaneous membrane-voltage jump. |
14
+ | `sim.create(bp.iaf_psc_delta_ps, size, params=parameters)` | Use delta input with precise spike timing between grid points. |
15
+ | `sim.create(bp.iaf_psc_alpha, size, params=parameters)` | Use alpha-shaped excitatory and inhibitory current kernels. |
16
+ | `sim.create(bp.iaf_psc_alpha_multisynapse, size, params=parameters)` | Use alpha currents with multiple receptor ports or time constants. |
17
+ | `sim.create(bp.iaf_psc_alpha_ps, size, params=parameters)` | Use alpha currents with precise spike timing. |
18
+ | `sim.create(bp.iaf_psc_exp, size, params=parameters)` | Use exponential postsynaptic-current kernels. |
19
+ | `sim.create(bp.iaf_psc_exp_multisynapse, size, params=parameters)` | Use exponential currents with multiple receptor ports or time constants. |
20
+ | `sim.create(bp.iaf_psc_exp_htum, size, params=parameters)` | Use the NEST `iaf_psc_exp_htum` variant required by the model being ported. |
21
+ | `sim.create(bp.iaf_psc_exp_ps, size, params=parameters)` | Use exponential currents with precise spike timing. |
22
+ | `sim.create(bp.iaf_psc_exp_ps_lossless, size, params=parameters)` | Use exponential precise-spiking dynamics with lossless spike detection. |
23
+
24
+ **Invariant:** Use voltage weights such as `mV` for `iaf_psc_delta`; alpha and exponential current-event examples use current weights such as `pA`.
25
+
26
+ ## Conductance-based IAF neurons
27
+
28
+ Use these models when synaptic input changes conductance rather than adding a postsynaptic current.
29
+
30
+ | Constructor | Use when |
31
+ |---|---|
32
+ | `sim.create(bp.iaf_cond_alpha, size, params=parameters)` | Use alpha-shaped synaptic conductances. |
33
+ | `sim.create(bp.iaf_cond_alpha_mc, size, params=parameters)` | Use the multi-compartment alpha-conductance variant; check parity coverage before claiming NEST validation. |
34
+ | `sim.create(bp.iaf_cond_beta, size, params=parameters)` | Use beta-shaped synaptic conductances. |
35
+ | `sim.create(bp.iaf_cond_exp, size, params=parameters)` | Use exponential synaptic conductances. |
36
+ | `sim.create(bp.iaf_cond_exp_sfa_rr, size, params=parameters)` | Use exponential conductances with spike-frequency adaptation and relative refractory dynamics. |
37
+
38
+ ## Specialized IAF neurons
39
+
40
+ Use these APIs only when the requested paper or source NEST model names the specialized variant.
41
+
42
+ | Constructor | Use when |
43
+ |---|---|
44
+ | `sim.create(bp.iaf_bw_2001, size, params=parameters)` | Use the NEST-compatible `iaf_bw_2001` model. |
45
+ | `sim.create(bp.iaf_bw_2001_exact, size, params=parameters)` | Use the exact per-synapse NMDA form of `iaf_bw_2001`. |
46
+ | `sim.create(bp.iaf_chs_2007, size, params=parameters)` | Use the `iaf_chs_2007` spike-response model. |
47
+ | `sim.create(bp.iaf_chxk_2008, size, params=parameters)` | Use alpha synapses with the `iaf_chxk_2008` precise AHP timing. |
48
+ | `sim.create(bp.iaf_tum_2000, size, params=parameters)` | Use the `iaf_tum_2000` neuron required by the port. |
49
+
50
+ ## Adaptive exponential IF neurons
51
+
52
+ Use these APIs for Brette-Gerstner adaptive exponential dynamics, selecting current versus conductance input and any required astrocyte, multisynapse, or Clopath interface.
53
+
54
+ | Constructor | Use when |
55
+ |---|---|
56
+ | `sim.create(bp.aeif_cond_alpha, size, params=parameters)` | Use adaptive exponential dynamics with alpha-shaped conductances. |
57
+ | `sim.create(bp.aeif_cond_alpha_astro, size, params=parameters)` | Use the astrocyte-compatible alpha-conductance variant. |
58
+ | `sim.create(bp.aeif_cond_alpha_multisynapse, size, params=parameters)` | Use alpha conductances with multiple receptor ports. |
59
+ | `sim.create(bp.aeif_cond_beta_multisynapse, size, params=parameters)` | Use beta conductances with multiple receptor ports. |
60
+ | `sim.create(bp.aeif_cond_exp, size, params=parameters)` | Use adaptive exponential dynamics with exponential conductances. |
61
+ | `sim.create(bp.aeif_psc_alpha, size, params=parameters)` | Use adaptive exponential dynamics with alpha-shaped currents. |
62
+ | `sim.create(bp.aeif_psc_delta, size, params=parameters)` | Use adaptive exponential dynamics with delta input. |
63
+ | `sim.create(bp.aeif_psc_delta_clopath, size, params=parameters)` | Use delta input while exposing the voltage filters consumed by `clopath_synapse`. |
64
+ | `sim.create(bp.aeif_psc_exp, size, params=parameters)` | Use adaptive exponential dynamics with exponential currents. |
65
+
66
+ ## Generalized IF neurons
67
+
68
+ Use these APIs for generalized integrate-and-fire dynamics, choosing current versus conductance input, population dynamics, or multiple synaptic time constants.
69
+
70
+ | Constructor | Use when |
71
+ |---|---|
72
+ | `sim.create(bp.gif_cond_exp, size, params=parameters)` | Use conductance-based GIF dynamics with exponential synapses. |
73
+ | `sim.create(bp.gif_cond_exp_multisynapse, size, params=parameters)` | Use conductance-based GIF dynamics with multiple synaptic time constants. |
74
+ | `sim.create(bp.gif_pop_psc_exp, size, params=parameters)` | Use population GIF dynamics with exponential postsynaptic currents. |
75
+ | `sim.create(bp.gif_psc_exp, size, params=parameters)` | Use current-based GIF dynamics with exponential postsynaptic currents. |
76
+ | `sim.create(bp.gif_psc_exp_multisynapse, size, params=parameters)` | Use current-based GIF dynamics with multiple synaptic time constants. |
77
+
78
+ ## Generalized LIF neurons
79
+
80
+ Use these APIs for Allen Institute generalized leaky integrate-and-fire dynamics.
81
+
82
+ | Constructor | Use when |
83
+ |---|---|
84
+ | `sim.create(bp.glif_cond, size, params=parameters)` | Use conductance-based GLIF dynamics. |
85
+ | `sim.create(bp.glif_psc, size, params=parameters)` | Use current-based GLIF dynamics. |
86
+ | `sim.create(bp.glif_psc_double_alpha, size, params=parameters)` | Use current-based GLIF dynamics with double-alpha postsynaptic currents. |
87
+
88
+ ## Multi-timescale adaptive-threshold neurons
89
+
90
+ Use these APIs when the requested NEST model uses MAT or adaptive MAT threshold dynamics.
91
+
92
+ | Constructor | Use when |
93
+ |---|---|
94
+ | `sim.create(bp.mat2_psc_exp, size, params=parameters)` | Use the two-timescale MAT model with exponential currents. |
95
+ | `sim.create(bp.amat2_psc_exp, size, params=parameters)` | Use the adaptive MAT variant with exponential currents. |
96
+
97
+ ## Hodgkin-Huxley neurons
98
+
99
+ Use these APIs for biophysical conductance-based dynamics, selecting Clopath or gap-junction support only when the network requires it.
100
+
101
+ | Constructor | Use when |
102
+ |---|---|
103
+ | `sim.create(bp.hh_psc_alpha, size, params=parameters)` | Use Hodgkin-Huxley dynamics with alpha-shaped postsynaptic currents. |
104
+ | `sim.create(bp.hh_psc_alpha_clopath, size, params=parameters)` | Use alpha currents while exposing voltage State required by `clopath_synapse`. |
105
+ | `sim.create(bp.hh_psc_alpha_gap, size, params=parameters)` | Use alpha currents in a gap-junction network. |
106
+ | `sim.create(bp.hh_cond_exp_traub, size, params=parameters)` | Use the Traub Hodgkin-Huxley model with exponential conductances. |
107
+ | `sim.create(bp.hh_cond_beta_gap_traub, size, params=parameters)` | Use Traub dynamics with beta conductances and gap junctions. |
108
+ | `sim.create(bp.ht_neuron, size, params=parameters)` | Use the Hill-Tononi thalamocortical neuron. |
109
+
110
+ ## Izhikevich neurons
111
+
112
+ Use this family when the source model explicitly requires NEST-compatible Izhikevich dynamics.
113
+
114
+ | Constructor | Use when |
115
+ |---|---|
116
+ | `sim.create(bp.izhikevich, size, params=parameters)` | Use the NEST-compatible Izhikevich neuron. |
117
+
118
+ ## Point-process neurons
119
+
120
+ Use these APIs for delta point-process dynamics or the two-compartment interface required by Urbanczik-Senn learning.
121
+
122
+ | Constructor | Use when |
123
+ |---|---|
124
+ | `sim.create(bp.pp_psc_delta, size, params=parameters)` | Use a point-process neuron with leaky integration of delta-shaped currents. |
125
+ | `sim.create(bp.pp_cond_exp_mc_urbanczik, size, params=parameters)` | Use the two-compartment conductance model read by `urbanczik_synapse`. |
126
+
127
+ ## Rate neurons
128
+
129
+ Use these APIs for vectorized rate, noisy-rate, template, or mean-field dynamics rather than spike-resolved neurons.
130
+
131
+ | Constructor | Use when |
132
+ |---|---|
133
+ | `sim.create(bp.lin_rate_ipn, size, params=parameters)` | Use a linear rate unit with input noise. |
134
+ | `sim.create(bp.lin_rate_opn, size, params=parameters)` | Use a linear rate unit with output noise. |
135
+ | `sim.create(bp.tanh_rate_ipn, size, params=parameters)` | Use a tanh rate unit with input noise. |
136
+ | `sim.create(bp.tanh_rate_opn, size, params=parameters)` | Use a tanh rate unit with output noise. |
137
+ | `sim.create(bp.sigmoid_rate_ipn, size, params=parameters)` | Use a sigmoid rate unit with input noise. |
138
+ | `sim.create(bp.sigmoid_rate_gg_1998_ipn, size, params=parameters)` | Use the `sigmoid_rate_gg_1998_ipn` nonlinear-rate variant with input noise. |
139
+ | `sim.create(bp.gauss_rate_ipn, size, params=parameters)` | Use a Gaussian rate unit with input noise. |
140
+ | `sim.create(bp.threshold_lin_rate_ipn, size, params=parameters)` | Use threshold-linear rate dynamics with input noise. |
141
+ | `sim.create(bp.threshold_lin_rate_opn, size, params=parameters)` | Use threshold-linear rate dynamics with output noise. |
142
+ | `sim.create(bp.rate_neuron_ipn, size, params=parameters)` | Use the input-noise rate-neuron template. |
143
+ | `sim.create(bp.rate_neuron_opn, size, params=parameters)` | Use the output-noise rate-neuron template. |
144
+ | `sim.create(bp.rate_transformer_node, size, params=parameters)` | Use the NEST-compatible rate-transformer template. |
145
+ | `sim.create(bp.siegert_neuron, size, params=parameters)` | Use the Siegert mean-field diffusion-rate model. |
146
+
147
+ ## Binary neurons
148
+
149
+ Use these APIs for deterministic or stochastic binary-state dynamics.
150
+
151
+ | Constructor | Use when |
152
+ |---|---|
153
+ | `sim.create(bp.mcculloch_pitts_neuron, size, params=parameters)` | Use deterministic binary activation with a Heaviside gain. |
154
+ | `sim.create(bp.ginzburg_neuron, size, params=parameters)` | Use stochastic binary activation with a sigmoidal or affine gain. |
155
+ | `sim.create(bp.erfc_neuron, size, params=parameters)` | Use stochastic binary activation with a complementary error-function gain. |
156
+
157
+ ## Relay and utility neurons
158
+
159
+ Use these APIs to relay spikes without transforming them or to emit fixed-interval spikes.
160
+
161
+ | Constructor | Use when |
162
+ |---|---|
163
+ | `sim.create(bp.parrot_neuron, size, params=parameters)` | Use a one-to-one spike relay, including ports that need an intermediate neuron. |
164
+ | `sim.create(bp.ignore_and_fire, size, params=parameters)` | Use a fixed-interval spike source. |
165
+
166
+ ## Canonical construction
167
+
168
+ Use NEST parameter names with BrainUnit quantities. The same `Simulator.create()` pattern applies across all families.
169
+
170
+ ```python
171
+ import brainunit as u
172
+ from brainpy import state as bp
173
+
174
+ sim = bp.Simulator(dt=0.1 * u.ms)
175
+ parameters = {
176
+ "C_m": 250.0 * u.pF,
177
+ "tau_m": 20.0 * u.ms,
178
+ "V_th": -55.0 * u.mV,
179
+ "I_e": 350.0 * u.pA,
180
+ }
181
+ population = sim.create(bp.iaf_psc_alpha, 100, params=parameters)
182
+ ```
183
+
184
+ **Invariant:** Preserve NEST parameter names but never strip their physical units. This directory identifies the BrainPy-State API surface; use upstream NEST documentation for model physiology.
185
+
186
+ ## Selection boundaries
187
+
188
+ - Choose `iaf_psc_delta`, `iaf_psc_alpha`, or `iaf_psc_exp` from the requested postsynaptic response; when the response shape is unspecified, preserve the upstream NEST model rather than guessing a substitute.
189
+ - Do not replace a `psc` model with a `cond` model during a port.
190
+ - Choose a `_ps` variant only when sub-grid spike timing matters; route its validation to event-count and spike-time parity.
191
+ - Choose a multisynapse variant when receptor ports or multiple time constants are part of the model; do not silently collapse channels.
192
+ - Use `aeif_psc_delta_clopath` or `hh_psc_alpha_clopath` with `clopath_synapse`.
193
+ - Use `pp_cond_exp_mc_urbanczik` with `urbanczik_synapse`.
194
+ - Open `references/nest-compatible/integration-categories.md` after selecting a family when numerical behavior matters.
195
+ - Open `references/nest-compatible/divergence-and-parity.md` before claiming parity for multi-compartment, stochastic, precise-spiking, plastic, or network-level behavior.
196
+
197
+ ## Official sources
198
+
199
+ - https://brainx.chaobrain.com/brainpy-state/nest-style/models.html
200
+ - https://brainx.chaobrain.com/brainpy-state/apis/nest-neurons.html
@@ -0,0 +1,156 @@
1
+ # NEST-Compatible Workflow
2
+
3
+ ## Purpose and boundary
4
+
5
+ Use this reference for the NEST-compatible `brainpy.state` path: create NEST-named neurons and devices, connect them with NEST-style rules and synapse specs, execute an explicit `Simulator`, inspect results, or port PyNEST code.
6
+
7
+ Canonical path:
8
+
9
+ `create Simulator -> create nodes and devices -> connect sources, populations, and recorders -> simulate -> read SimulationResult`
10
+
11
+ Keep this path separate from native BrainPy-State composition. Do not mix `Simulator` networks with native projection APIs such as `AlignPostProj`, `align_pre_projection`, or manual BrainState rollout loops. Open the routed NEST reference for model catalogs, plasticity, spatial networks, or parity details; use the parent BrainPy-State skill only for native models.
12
+
13
+ ## Underlying principle of the NEST-compatible path
14
+
15
+ Use one explicit `Simulator` instead of PyNEST's global kernel; it owns creation, connectivity, rollout State, recording, and results. Preserve NEST names with BrainUnit quantities, while connection rules select edges, synapse specs define edge behavior, and source/observer roles determine device direction.
16
+
17
+ ### API structure
18
+
19
+ | API family | Use |
20
+ |---|---|
21
+ | `brainpy.state.Simulator` | Own node creation, connection construction, simulation lifecycle, and result collection. |
22
+ | `brainpy.state` NEST models | Select NEST-compatible neurons, synapses, plasticity rules, generators, recorders, and detectors by NEST-style name. |
23
+ | `brainpy.state.network` | Inspect the underlying `Network`, `Builder`, `NodeView`, `SimulationResult`, projection, connection-rule, and `SynapseCollection` APIs. |
24
+ | `brainpy.state.spatial` | Place populations in 2-D or 3-D space and construct distance-dependent kernels, masks, and connection rules. |
25
+ | `brainunit` | Supply physical time, voltage, current, conductance, capacitance, rate, weight, and delay quantities. |
26
+
27
+ ### 1. Create the simulator and nodes
28
+
29
+ Create every population and device through one `Simulator`; each `create()` call returns a `NodeView` that preserves population identity while supporting concatenation and slicing.
30
+
31
+ | API | Description |
32
+ |---|---|
33
+ | `bp.Simulator(dt=...)` | Use to start an independent NEST-compatible network; it owns the timestep, graph, rollout, and results. |
34
+ | `sim.create(model, size=1, *, params=None, positions=None, **kwargs)` | Use for neurons and devices; it instantiates the selected NEST-compatible model and returns a `NodeView`. Pass a large parameter set with `params=dict(...)` or individual parameters as keywords. |
35
+ | `left + right` | Use to concatenate `NodeView` objects while preserving their segment boundaries; the result can be passed to one `connect()` call. |
36
+ | `view[slice]` | Use to select a subset of a single population for connectivity or recording without creating another population. |
37
+
38
+ ```python
39
+ import brainunit as u
40
+ from brainpy import state as bp
41
+
42
+ sim = bp.Simulator(dt=0.1 * u.ms)
43
+ neurons = sim.create(
44
+ bp.iaf_psc_alpha,
45
+ 100,
46
+ params={"I_e": 350.0 * u.pA},
47
+ )
48
+ sample = neurons[:5]
49
+ ```
50
+
51
+ Open `references/nest-compatible/model-library.md` when choosing a neuron family or exact NEST-compatible model name. Open `references/nest-compatible/network-building.md` when using `Builder`, `Network`, multi-segment `NodeView` operations, or spatial placement.
52
+
53
+ ### 2. Connect populations and devices
54
+
55
+ Connect source to target with a connection rule plus a unitful synapse spec, and reverse the call only for analog recorders that observe a population.
56
+
57
+ | API | Description |
58
+ |---|---|
59
+ | `sim.connect(pre, post, *, rule=..., weight=..., delay=..., ...)` | Use to build a projection, attach a source device, or register a recorder tap; it returns projection handles for realized projections and `None` for recorder taps or current injectors. |
60
+ | `bp.all_to_all` | Use when every source must connect to every target; this is the default generator fan-out rule. |
61
+ | `bp.fixed_indegree(k)` | Use when every target must draw exactly `k` presynaptic edges; set `seed` for reproducible BrainPy-State wiring and `comm="sparse"` for large event fan-in. |
62
+ | `synapse=bp.<synapse_model>(...)` | Use when the edge is plastic or needs behavior beyond static weight and delay; keep rule parameters on the synapse spec. |
63
+ | `sim.connect(generator, neuron)` | Use for current and spike sources; generators drive their targets. |
64
+ | `sim.connect(neuron, spike_recorder)` | Use to tap emitted spikes. |
65
+ | `sim.connect(multimeter, neuron)` | Use for analog observation; `multimeter` follows NEST's reversed recorder direction. |
66
+
67
+ ```python
68
+ drive = sim.create(bp.poisson_generator, rate=8000.0 * u.Hz, rng_seed=0)
69
+ spike_recorder = sim.create(bp.spike_recorder)
70
+ meter = sim.create(
71
+ bp.multimeter,
72
+ record_from=["V_m"],
73
+ interval=0.1 * u.ms,
74
+ )
75
+
76
+ sim.connect(
77
+ drive,
78
+ neurons,
79
+ rule=bp.all_to_all,
80
+ weight=10.0 * u.pA,
81
+ delay=1.0 * u.ms,
82
+ )
83
+ sim.connect(neurons, spike_recorder)
84
+ sim.connect(meter, sample)
85
+ ```
86
+
87
+ Open `references/nest-compatible/synapse-and-connectivity.md` when selecting a static, special, STP, STDP, or voltage-based synapse; choosing a rule; or inspecting realized edges. Open `references/nest-compatible/devices.md` when selecting a generator, recorder, detector, or result-readback method.
88
+
89
+ ### 3. Simulate and read results
90
+
91
+ `simulate()` starts from freshly initialized State and returns one in-memory `SimulationResult` whose common time axis indexes spike and analog recordings.
92
+
93
+ | API | Description |
94
+ |---|---|
95
+ | `sim.simulate(duration, *, dt=None)` | Use for an independent run from initialized State and time zero; it returns a `SimulationResult`. |
96
+ | `result.times` | Use for the run's common `(n_steps,)` time axis. |
97
+ | `result.spikes(recorder)` | Use for a spike recorder's `(n_steps, n_recorded)` spike matrix. |
98
+ | `result.rate(recorder)` | Use for the mean firing rate in spikes per second over the recorded neurons. |
99
+ | `result.trace(recorder, recordable)` | Use for a multimeter trace in the model State's natural unit; it raises `KeyError` when the recordable was not registered. |
100
+
101
+ ```python
102
+ result = sim.simulate(100.0 * u.ms)
103
+
104
+ spikes = result.spikes(spike_recorder)
105
+ voltage = result.trace(meter, "V_m")
106
+ rate = result.rate(spike_recorder)
107
+
108
+ assert spikes.shape[0] == result.times.shape[0]
109
+ assert voltage.shape[0] == result.times.shape[0]
110
+ ```
111
+
112
+ Open `references/nest-compatible/network-building.md` when continuing State across windows with `cont()`, resetting persistent rollout State, recording plastic weights, inspecting `SynapseCollection`, or selecting spatial primitives.
113
+
114
+ ## Reference routing
115
+
116
+ Open only the smallest reference that owns the decision.
117
+
118
+ | Reference | Open when |
119
+ |---|---|
120
+ | `references/nest-compatible/model-library.md` | Selecting or identifying a NEST-compatible neuron family or exact model name, or locating its neuron API entry |
121
+ | `references/nest-compatible/synapse-and-connectivity.md` | Selecting static or special synapses, STP/STDP rules, connection rules, weight/delay specs, or realized-connectivity inspection |
122
+ | `references/nest-compatible/devices.md` | Selecting generators, recorders, detectors, source semantics, connection direction, or result readback |
123
+ | `references/nest-compatible/network-building.md` | Using `Builder`, `Network`, `Simulator`, `NodeView`, `SimulationResult`, `SynapseCollection`, projection classes, connection-rule helpers, or spatial networks |
124
+ | `references/nest-compatible/divergence-and-parity.md` | Porting NEST code, locating STDP parameters, explaining a mismatch, choosing trace versus distributional validation, or checking documented parity bands |
125
+ | `references/nest-compatible/integration-categories.md` | Determining how a model family is numerically updated and which validation category to consult next |
126
+
127
+ ## Full workflow scripts
128
+
129
+ Use these standalone scripts when the canonical inline workflow is too small for the task. Keep the scripts separate from the Markdown references so their complete source remains directly runnable.
130
+
131
+ | Script | Open when |
132
+ |---|---|
133
+ | `references/nest-compatible/scripts/brunel_alpha.py` | Building an alpha-synapse Brunel network |
134
+ | `references/nest-compatible/scripts/brunel_delta.py` | Checking delta-synapse voltage-weight semantics in a Brunel network |
135
+ | `references/nest-compatible/scripts/brette_et_al_2007.py` | Reproducing the comparative network workflow from Brette et al. (2007) |
136
+ | `references/nest-compatible/scripts/synapsecollection.py` | Inspecting or manipulating realized synapses through `SynapseCollection` |
137
+ | `references/nest-compatible/scripts/evaluate_tsodyks2_synapse.py` | Evaluating short-term plasticity behavior against the Tsodyks2 protocol |
138
+ | `references/nest-compatible/scripts/clopath_synapse_spike_pairing.py` | Running the Clopath voltage-based plasticity spike-pairing protocol |
139
+ | `references/nest-compatible/scripts/spatial_gaussex.py` | Building spatial connectivity with a Gaussian distance-dependent rule |
140
+
141
+ ## Boundaries and common failures
142
+
143
+ - Do not mix this workflow with native BrainPy-State projections or manual rollout code; keep the whole NEST-compatible graph under one `Simulator`.
144
+
145
+
146
+ ## Official sources
147
+
148
+ - https://brainx.chaobrain.com/brainpy-state/nest-style/models.html
149
+ - https://brainx.chaobrain.com/brainpy-state/nest-style/connectivity.html
150
+ - https://brainx.chaobrain.com/brainpy-state/nest-style/devices.html
151
+ - https://brainx.chaobrain.com/brainpy-state/nest-style/tutorials/03-connect-network.html
152
+ - https://brainx.chaobrain.com/brainpy-state/apis/nest-network.html
153
+ - https://brainx.chaobrain.com/brainpy-state/nest-style/divergences/index.html
154
+ - https://brainx.chaobrain.com/brainpy-state/nest-style/validation-status.html
155
+ - https://brainx.chaobrain.com/brainpy-state/nest-style/divergences/stdp.html
156
+ - https://brainx.chaobrain.com/brainpy-state/nest-style/integration-categories.html
@@ -0,0 +1,264 @@
1
+ # Network building
2
+
3
+ Use this reference when the canonical `Simulator` workflow needs lifecycle control, `NodeView` composition, `SimulationResult`, `SynapseCollection`, projection or connection-rule lookup, declarative `Network`/`Builder` APIs, or spatially structured populations and connectivity.
4
+
5
+ ## Network construction
6
+
7
+ Use these APIs to choose the declarative or imperative network surface and create its populations, devices, and connections.
8
+
9
+ | API | Use when | Important result |
10
+ |---|---|---|
11
+ | `bp.Simulator(*, dt)` | Use for the NEST-flavored create/connect/run workflow. | Owns the graph, timestep, rollout State, recording, and result construction. |
12
+ | `bp.network.Network(*args, **kwargs)` | Use when subclassing the lower-level network base and registering populations, projections, and devices as attributes. | `update()` walks immediate children in projection-first, then dynamics order. |
13
+ | `bp.network.Builder(*args, **kwargs)` | Use for the imperative variant of `Network`. | `add()` registers named modules and `connect()` registers projections. |
14
+ | `sim.create(model_cls, size=1, *, params=None, positions=None, **kw)` | Use to instantiate a population or device. | Returns a `NodeView`; spatial `positions` attach coordinates. |
15
+ | `sim.connect(pre, post, *, rule=bp.all_to_all, weight=None, delay=None, comm="dense", receptor_type=None, synapse=None, vt=None, allow_autapses=True, allow_multapses=True, seed=None)` | Use to create a projection, attach a source, or register a recorder. | Returns a projection handle, a list for multi-segment fan-out, or `None` for taps/injectors. |
16
+
17
+ ## Simulation execution
18
+
19
+ Use these methods to choose whether a run starts from fresh State or continues a persistent biological timeline.
20
+
21
+ | API | Use when | Important result |
22
+ |---|---|---|
23
+ | `sim.simulate(duration, *, dt=None)` | Use for an independent run. | Reinitializes all State, starts at time zero, and returns `SimulationResult`. |
24
+ | `sim.cont(duration, *, dt=None)` | Use to continue biological time across host-controlled windows. | Preserves State and returns a window result with absolute times. |
25
+ | `sim.reset_rollout(*, dt=None)` | Use before restarting a persistent `cont()` workflow. | Reinitializes all State and resets accumulated time and step index to zero. |
26
+
27
+ Do not interchange `simulate()` and `cont()` casually. Use `simulate()` for independent trials; use `cont()` only when State and biological time must persist across windows.
28
+
29
+ ## NodeView composition
30
+
31
+ Use `NodeView` composition when one connection or recording operation must address a full population, a slice, or several preserved population segments.
32
+
33
+ | Operation | Use |
34
+ |---|---|
35
+ | `left + right` | Concatenate views while preserving segment boundaries, such as `exc + inh` for a common target. |
36
+ | `view[start:stop]` | Slice one population segment for recording or partial connectivity. |
37
+ | `bp.network.NodeView.of(population)` | Build a full-population view over an existing population. |
38
+ | `view.segments` | Inspect the population-and-local-index segments when an API needs the concrete underlying population. |
39
+
40
+ Source and target indices reported by connectivity inspection are population-local. Do not reinterpret them as NEST global node IDs.
41
+
42
+ ## Connection-rule lookup
43
+
44
+ Pass rule objects to `Simulator.connect()`; let the rule select edges and the synapse spec select edge behavior.
45
+
46
+ | Rule helper | Choose when |
47
+ |---|---|
48
+ | `bp.all_to_all` | Every source-target pair must exist. |
49
+ | `bp.one_to_one` | Source `i` must connect to target `i`. |
50
+ | `bp.fixed_indegree(k)` | Every target must receive exactly `k` incoming edges. |
51
+ | `bp.fixed_total_number(n)` | Exactly `n` edges must be drawn over the source-target grid. |
52
+ | `bp.pairwise_bernoulli(p)` | Every possible pair must receive an independent Bernoulli draw. |
53
+ | `bp.explicit_edges(pre_idx, post_idx)` | The exact source and target edge-index arrays are already known. |
54
+ | `bp.third_factor_bernoulli_with_pool(p=..., pool_size=..., pool_type=...)` | A tripartite pre-post-third-factor network needs Bernoulli pairing with an astrocyte pool. |
55
+
56
+ Use `seed` to reproduce one BrainPy-State realization, `allow_autapses` and `allow_multapses` to control self and repeated edges, and `comm="sparse"` for memory-light event communication.
57
+
58
+ ## Projection-class lookup
59
+
60
+ For standard construction, pass a rule or synapse spec to `Simulator.connect()` and inspect the returned handle. Use the classes below when reading API behavior or extending the network layer.
61
+
62
+ | Projection class | Represents |
63
+ |---|---|
64
+ | `bp.network.OneToOneProj(*args, **kwargs)` | Edge `(i, i)` for every paired index. |
65
+ | `bp.network.AllToAllProj(*args, **kwargs)` | Full all-to-all connectivity. |
66
+ | `bp.network.PairwiseBernoulliProj(*args, **kwargs)` | Independent Bernoulli sampling for every source-target pair. |
67
+ | `bp.network.SymmetricPairwiseBernoulliProj(*args, **kwargs)` | Symmetric Bernoulli connectivity where an edge implies its reverse. |
68
+ | `bp.network.FixedIndegreeProj(*args, **kwargs)` | Exactly `k` incoming edges per postsynaptic neuron. |
69
+ | `bp.network.FixedOutdegreeProj(*args, **kwargs)` | Exactly `k` outgoing edges per presynaptic neuron. |
70
+ | `bp.network.FixedTotalNumberProj(*args, **kwargs)` | Exactly `n` edges over the full source-target grid. |
71
+ | `bp.network.PairwisePoissonProj(*args, **kwargs)` | A Poisson-distributed edge multiplicity for each source-target pair. |
72
+ | `bp.network.EventProjection(*args, **kwargs)` | Delayed, weighted static event transmission. |
73
+ | `bp.network.EventPlasticProj(*args, **kwargs)` | Event-driven plastic transmission. |
74
+ | `bp.network.VoltageCoupledPlasticProj(*args, **kwargs)` | Plasticity coupled to postsynaptic voltage State. |
75
+
76
+ ## Canonical sparse E/I construction
77
+
78
+ Use `NodeView` algebra and a seeded fixed-indegree rule to express Brunel-style wiring without materializing a dense edge list.
79
+
80
+ ```python
81
+ import brainunit as u
82
+ from brainpy import state as bp
83
+
84
+ sim = bp.Simulator(dt=0.1 * u.ms)
85
+ params = {
86
+ "C_m": 1.0 * u.pF,
87
+ "tau_m": 20.0 * u.ms,
88
+ "t_ref": 2.0 * u.ms,
89
+ "E_L": 0.0 * u.mV,
90
+ "V_reset": 0.0 * u.mV,
91
+ "V_th": 20.0 * u.mV,
92
+ }
93
+ exc = sim.create(bp.iaf_psc_delta, 400, params=params)
94
+ inh = sim.create(bp.iaf_psc_delta, 100, params=params)
95
+ all_neurons = exc + inh
96
+
97
+ sim.connect(
98
+ exc,
99
+ all_neurons,
100
+ rule=bp.fixed_indegree(40),
101
+ weight=0.1 * u.mV,
102
+ delay=1.5 * u.ms,
103
+ comm="sparse",
104
+ allow_multapses=True,
105
+ seed=1,
106
+ )
107
+ sim.connect(
108
+ inh,
109
+ all_neurons,
110
+ rule=bp.fixed_indegree(10),
111
+ weight=-0.5 * u.mV,
112
+ delay=1.5 * u.ms,
113
+ comm="sparse",
114
+ allow_multapses=True,
115
+ seed=2,
116
+ )
117
+ ```
118
+
119
+ **Invariant:** Delta-neuron weights are voltage jumps in `mV`. Do not reuse current weights from an alpha- or exponential-PSC network.
120
+
121
+ ## Result readback
122
+
123
+ Use these APIs after simulation to read the common time axis, spike observables, analog traces, or registered plastic-weight trajectories.
124
+
125
+ | API | Use |
126
+ |---|---|
127
+ | `result.times` | Read the common time axis. |
128
+ | `result.spikes(node)` | Read a per-step spike matrix. |
129
+ | `result.rate(node)` | Read the mean population firing rate. |
130
+ | `result.trace(recorder, recordable="V_m")` | Read a registered analog trace. |
131
+ | `sim.record_weight(proj)` | Register the returned plastic projection for per-step weight capture. |
132
+ | `result.weight_trace(proj)` | Read the registered `(n_steps, n_edges)` weight trajectory. |
133
+
134
+ ## Realized-connection inspection
135
+
136
+ Use these APIs after construction to obtain a lazy view over realized edges and read or update supported live connection attributes.
137
+
138
+ | API | Use |
139
+ |---|---|
140
+ | `sim.get_connections(source=None, target=None, synapse=None)` | Obtain a filtered, lazy `SynapseCollection` over realized edges. |
141
+ | `connections.get(key)` | Read live `source`, `target`, `weight`, or `delay` values. |
142
+ | `connections.set(key, value)` | Write supported static weight or delay values; plastic and homogeneous constraints can reject the write. |
143
+
144
+ ## Spatial layouts
145
+
146
+ Use these constructors to build concrete or deferred 2-D/3-D node positions.
147
+
148
+ | Constructor | Use when |
149
+ |---|---|
150
+ | `bp.spatial.Layer(coords, ndim, shape=None, extent=None, center=None, sampler=None)` | Use when constructing a layer directly from coordinates or a sampler. |
151
+ | `bp.spatial.grid(shape, extent=None, center=None)` | Use a regular cell-centered lattice. |
152
+ | `bp.spatial.free(positions, extent=None, num_dimensions=None)` | Use explicit or sampled free positions. |
153
+
154
+ ## Spatial position expressions
155
+
156
+ Use these expression roots when a kernel depends on absolute, source, or target coordinates.
157
+
158
+ | API | Use when |
159
+ |---|---|
160
+ | `bp.spatial.pos` | Use `.x`, `.y`, or `.z` for the current position expression. |
161
+ | `bp.spatial.source_pos` | Use `.x`, `.y`, or `.z` for source-coordinate expressions. |
162
+ | `bp.spatial.target_pos` | Use `.x`, `.y`, or `.z` for target-coordinate expressions. |
163
+
164
+ ## Spatial distance and displacement
165
+
166
+ Use these APIs to compute pairwise geometric relationships between source and target nodes or layers.
167
+
168
+ | API | Use when |
169
+ |---|---|
170
+ | `bp.spatial.displacement(pre_pos, post_pos)` | Use the vector displacement `post - pre`. |
171
+ | `bp.spatial.pairwise_distance(pre_pos, post_pos)` | Use pairwise Euclidean distance between coordinate arrays. |
172
+ | `bp.spatial.Distance(layer_a, layer_b)` | Use a reusable distance expression between two layers. |
173
+
174
+ ## Spatial probability kernels
175
+
176
+ Use these constructors to map distance or displacement to connection probability.
177
+
178
+ | Constructor | Use when |
179
+ |---|---|
180
+ | `bp.spatial.gaussian(x=bp.spatial.distance, mean=0.0, std=1.0)` | Use a Gaussian probability profile. |
181
+ | `bp.spatial.exponential(x=bp.spatial.distance, beta=1.0)` | Use an exponential probability profile. |
182
+ | `bp.spatial.gamma(x=bp.spatial.distance, kappa=1.0, theta=1.0)` | Use a gamma probability profile. |
183
+ | `bp.spatial.gabor(x=None, y=None, theta=0.0, gamma=1.0, std=1.0, lam=1.0, psi=0.0)` | Use a rectified Gabor profile over 2-D displacement. |
184
+ | `bp.spatial.gaussian2D(x=None, y=None, mean_x=0.0, mean_y=0.0, std_x=1.0, std_y=1.0, rho=0.0)` | Use a correlated bivariate-Gaussian profile. |
185
+
186
+ ## Spatial masks
187
+
188
+ Use these constructors to restrict candidate targets to a 2-D or 3-D region.
189
+
190
+ | Constructor | Use when |
191
+ |---|---|
192
+ | `bp.spatial.circular(radius)` | Use a circular 2-D cutoff. |
193
+ | `bp.spatial.spherical(radius)` | Use a spherical 3-D cutoff. |
194
+ | `bp.spatial.box(lower_left, upper_right)` | Use an axis-aligned 2-D or 3-D box. |
195
+ | `bp.spatial.rectangular(lower_left, upper_right, azimuth_angle=0.0)` | Use a rotated 2-D rectangle. |
196
+ | `bp.spatial.doughnut(inner_radius, outer_radius)` | Use a 2-D annulus. |
197
+ | `bp.spatial.elliptical(major_axis, minor_axis, azimuth_angle=0.0, anchor=None)` | Use a rotated 2-D ellipse. |
198
+ | `bp.spatial.ellipsoidal(major_axis, minor_axis, polar_axis, azimuth_angle=0.0, polar_angle=0.0, anchor=None)` | Use a rotated 3-D ellipsoid. |
199
+
200
+ ## Spatial connection rules
201
+
202
+ Use these constructors to combine a probability law with an optional mask before passing the rule to `Simulator.connect()`.
203
+
204
+ | Constructor | Use when |
205
+ |---|---|
206
+ | `bp.spatial.SpatialConnRule(p, mask=None, allow_autapses=True, _pre_pos=None, _post_pos=None)` | Use the concrete spatial rule type when positions are already bound. |
207
+ | `bp.spatial.spatial_pairwise_bernoulli(p, mask=None, allow_autapses=True)` | Use the public distance-dependent pairwise-Bernoulli builder. |
208
+
209
+ ## Spatial node selection and introspection
210
+
211
+ Use these APIs to select nodes by geometry or inspect realized spatial targets.
212
+
213
+ | API | Use when |
214
+ |---|---|
215
+ | `bp.spatial.center_element(layer)` | Use the node nearest the layer centroid. |
216
+ | `bp.spatial.nearest_element(layer, locations, find_all=False)` | Use the node nearest each query location. |
217
+ | `bp.spatial.select_nodes_by_mask(layer, anchor, mask)` | Use local indices inside a mask anchored at a position. |
218
+ | `bp.spatial.target_nodes(sim, source, target)` | Use realized target indices for each source. |
219
+ | `bp.spatial.target_positions(sim, source, target)` | Use coordinates of each source node's realized targets. |
220
+
221
+ ## Spatial export and visualization
222
+
223
+ Use these APIs to export layer data or visualize positions, realized edges, and probability fields.
224
+
225
+ | API | Use when |
226
+ |---|---|
227
+ | `bp.spatial.dump_layer_nodes(sim, pop, outname)` | Use to write local node indices and coordinates. |
228
+ | `bp.spatial.dump_layer_connections(sim, source, target, outname)` | Use to write realized edges, weights, delays, and displacement. |
229
+ | `bp.spatial.plot_layer(layer, fig=None, nodecolor="b", nodesize=20)` | Use to plot layer positions. |
230
+ | `bp.spatial.plot_targets(sim, src_node, target, fig=None, src_color="red", src_size=50, tgt_color="b", tgt_size=20)` | Use to highlight one source node's realized targets. |
231
+ | `bp.spatial.plot_sources(sim, source, tgt_node, fig=None, src_color="b", src_size=20, tgt_color="red", tgt_size=50)` | Use to highlight one target node's realized sources. |
232
+ | `bp.spatial.plot_probability_parameter(kernel, mask=None, extent=(-0.5, 0.5, -0.5, 0.5), shape=(100, 100), fig=None, cmap="Greys")` | Use to plot a 2-D probability field. |
233
+
234
+ ## Spatial workflow
235
+
236
+ Use the same `Simulator.create()` and `Simulator.connect()` lifecycle after selecting the layout, kernel, mask, and spatial rule.
237
+
238
+ ```python
239
+ positions = bp.spatial.grid([4, 3], extent=[2.0, 1.5])
240
+ source = sim.create(bp.iaf_psc_alpha, positions=positions)
241
+ target = sim.create(bp.iaf_psc_alpha, positions=positions)
242
+
243
+ rule = bp.spatial.spatial_pairwise_bernoulli(
244
+ p=bp.spatial.gaussian(bp.spatial.distance, std=0.5),
245
+ mask=bp.spatial.circular(3.0),
246
+ )
247
+ sim.connect(
248
+ source,
249
+ target,
250
+ rule=rule,
251
+ weight=1.0 * u.pA,
252
+ delay=1.0 * u.ms,
253
+ seed=0,
254
+ )
255
+ ```
256
+
257
+ Spatial random draws differ between NEST and JAX even when the probability law matches. Validate the empirical probability-versus-distance curve distributionally, not edge by edge.
258
+
259
+ ## Official sources
260
+
261
+ - https://brainx.chaobrain.com/brainpy-state/nest-style/tutorials/03-connect-network.html
262
+ - https://brainx.chaobrain.com/brainpy-state/apis/nest-network.html
263
+ - https://brainx.chaobrain.com/brainpy-state/apis/nest-spatial.html
264
+ - https://brainx.chaobrain.com/brainpy-state/nest-style/spatial.html