brainx-skill 1.0.15 → 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 +117 -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
@@ -4,7 +4,7 @@
4
4
 
5
5
  Use this reference to inspect distributions and assumptions, compare groups, explore associations, diagnose regression, and evaluate classification or learning behavior. Plot the sampling structure that supports the scientific claim; a visual summary does not replace the statistical analysis.
6
6
 
7
- Route BrainMass-owned FC/FCD, spectral, or dynamical summaries to `skills/package-skills/brainmass/references/visualization-analysis-api.md` before plotting them here.
7
+ Route BrainMass-owned FC/FCD, spectral, or dynamical summaries to `brainmass` → `references/visualization-analysis-api.md` before plotting them here.
8
8
 
9
9
  ## Choose the statistical family
10
10
 
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: braincell
3
- description: Use for cell modeling with conductance-based or Hodgkin-Huxley ions, channels, compartments, or morphology. Use alone for cell studies or together with BrainPy-State and/or BrainMass when cellular mechanisms participate in a multiscale model.
3
+ description: Use for cell modeling with conductance-based or Hodgkin-Huxley ions, channels, compartments, or morphology. Use alone for cell studies or together with BrainSpike and/or BrainMass when cellular mechanisms participate in a multiscale model.
4
4
  ---
5
5
 
6
6
  # BrainCell
@@ -13,7 +13,7 @@ Use BrainCell for cellular biophysics at either of its two supported spatial sca
13
13
  - Use `Cell` when soma, dendrite, axon, branch geometry, spatial channel distribution, or location-specific stimulation and recording affect the result.
14
14
 
15
15
 
16
- Keep network wiring, projections, and network training outside this skill. Open `skills/package-skills/brainpy-state/SKILL.md` when multiple cells must communicate.
16
+ Use `braincell.Network` when events must reach synapses placed on detailed cells. Open `brainspike` → `SKILL.md` for point-neuron networks.
17
17
 
18
18
  ## Underlying principle of BrainCell
19
19
 
@@ -34,7 +34,8 @@ Keep network wiring, projections, and network training outside this skill. Open
34
34
  | `braincell.ion` | Choose sodium, potassium, and calcium ion models and their reversal-potential or concentration dynamics. |
35
35
  | `braincell.channel` | Choose built-in membrane-channel dynamics for calcium, HCN, leak, potassium, potassium-calcium, and sodium currents. |
36
36
  | `braincell.synapse` | Choose built-in AMPA, GABAa, and NMDA Markov synapse models. |
37
- | `braincell.mech` | Declare what a multicompartment `Cell` installs: cable properties, density ions and channels, point mechanisms, and probes. |
37
+ | `braincell.mech` | Declare what a multicompartment `Cell` installs: cable properties, density ions and channels, and point mechanisms. |
38
+ | `braincell.observe` | Select State, currents, or mechanism fields for named recordings. |
38
39
  | `braincell.filter` | Build regions for `paint()` and locsets for `place()`, including composed spatial selections. |
39
40
  | `braincell.io` | Load, validate, checkpoint, and retrieve morphologies from supported file formats and NeuroMorpho.Org. |
40
41
  | `braincell.quad` | Define differential-equation modules and choose, inspect, or register numerical integrators. |
@@ -113,7 +114,7 @@ Open `references/braintools/input-current.md` when generating timed sections, pu
113
114
 
114
115
  ## Build and run a multicompartment cell
115
116
 
116
- A `Cell` lowers morphology, spatial selectors, and declarative mechanisms into coupled control-volume State, then returns only the traces defined by placed probes.
117
+ A `Cell` lowers morphology and declarative mechanisms into coupled control-volume State. The voltage layout is `pop_size + (n_cv,)` before any separate trial batch axis, including a leading size-one population axis for one cell.
117
118
 
118
119
  | API | Description |
119
120
  |---|---|
@@ -121,19 +122,25 @@ A `Cell` lowers morphology, spatial selectors, and declarative mechanisms into c
121
122
  | `braincell.Cell(morpho, cv_policy=..., solver=...)` | Use when spatial structure matters; it clones the morphology, applies a CV policy, and owns distinct declaration and initialized runtime phases. |
122
123
  | `braincell.CVPolicy` | Use to control spatial resolution; it divides branches into isopotential control volumes, trading accuracy against State size and computation. |
123
124
  | `cell.paint(region, *mechanisms)` | Use for cable properties and density mechanisms; it records declarations over a cable region and returns the cell for chaining. |
124
- | `cell.place(locset, *mechanisms)` | Use for clamps, probes, and other point mechanisms; it records declarations at selected locations and returns the cell for chaining. |
125
- | `cell.init_state()` | Use after all `paint()` and `place()` calls; it lowers declarations and allocates runtime State, and it raises if the cell is already initialized. |
126
- | `cell.run(dt=..., duration=...)` | Use to advance the initialized cell and collect probe traces; it initializes on first use when needed and requires at least one placed probe. |
125
+ | `cell.place(locset, *mechanisms)` | Use for clamps and other point mechanisms at selected locations; it returns the cell for chaining. |
126
+ | `cell.loc(locset).record(name, observable)` | Use before initialization to sample a named observable at the selected locations, such as `braincell.observe.state("v")` for membrane voltage. |
127
+ | `cell.init_state()` | Use after declaring mechanisms and recordings to allocate runtime State explicitly. It raises if the cell is already initialized. |
128
+ | `cell.run(dt=..., duration=...)` | Use for a standalone cell. It initializes on first use and returns named recording blocks in `result.samples`. |
127
129
  | `cell.reset_state()` / `cell.reset()` | Use `reset_state()` to reseed State while remaining initialized; use `reset()` to discard runtime State and return to the declaration phase before changing `paint()` or `place()` rules. |
128
130
 
129
131
  ```python
130
132
  import braincell
131
133
  import braincell.mech as mech
132
134
  import brainunit as u
133
- from braincell.filter import AllRegion, RootLocation, at, branch_in
135
+ from braincell.filter import AllRegion, RootLocation, branch_in
134
136
 
135
137
 
136
- morphology = braincell.Morphology.from_swc("neuron.swc")
138
+ soma = braincell.Branch.from_points(
139
+ points=[[0.0, 0.0, 0.0], [20.0, 0.0, 0.0]] * u.um,
140
+ radii=[5.0, 5.0] * u.um,
141
+ type="soma",
142
+ )
143
+ morphology = braincell.Morphology.from_root(soma, name="soma")
137
144
  cell = braincell.Cell(
138
145
  morphology,
139
146
  cv_policy=braincell.CVPerBranch(cv_per_branch=2),
@@ -154,25 +161,26 @@ cell.paint(
154
161
  mech.Channel("Na_HH1952", g_max=120.0 * u.mS / u.cm**2),
155
162
  mech.Channel("K_HH1952", g_max=36.0 * u.mS / u.cm**2),
156
163
  )
164
+ soma_midpoint = RootLocation(x=0.5)
157
165
  cell.place(
158
- RootLocation(x=0.5),
166
+ soma_midpoint,
159
167
  mech.CurrentClamp(
160
168
  delay=20.0 * u.ms,
161
169
  durations=60.0 * u.ms,
162
170
  amplitudes=0.2 * u.nA,
163
171
  ),
164
172
  )
165
- cell.place(at("soma", 0.5), mech.StateProbe())
173
+ cell.loc(soma_midpoint).record("soma_v", braincell.observe.state("v"))
166
174
 
167
175
  cell.init_state()
168
176
  result = cell.run(dt=0.1 * u.ms, duration=100.0 * u.ms)
169
177
 
170
- assert "soma(0.5)_v" in result.traces
178
+ assert result.samples["soma_v"].values.shape == (1000, 1)
171
179
  ```
172
180
 
173
- Use `paint()` only with regions and density mechanisms. Use `place()` only with locsets and point mechanisms. Declare all mechanisms before `init_state()`; call `reset()` before altering the declaration of an initialized cell.
181
+ Use regions for `paint()` and locsets for `place()`. Declare mechanisms and recordings before `init_state()`. Call `reset()` before changing a declaration on an initialized cell.
174
182
 
175
- Open `references/multicompartment/multicompartment-cell-workflow.md` for the complete advanced morphology-to-simulation path. Let that workflow select the exclusive morphology, filter, CV-policy, probe, or topology reference; do not open those leaves directly from this root skill.
183
+ Open `references/multicompartment/multicompartment-cell-workflow.md` for the complete advanced morphology-to-simulation path. Let that workflow select the exclusive morphology, filter, CV-policy, recording, or topology reference.
176
184
 
177
185
  ## Reference routing
178
186
 
@@ -190,4 +198,5 @@ Open only the smallest reference that owns the non-canonical decision.
190
198
  | `references/ion-library.md` | Choosing fixed, Nernst-initialized, or dynamic ions and their concentration behavior. |
191
199
  | `references/mixions-for-adaptation.md` | Adding calcium-dependent adaptation, AHP/KCa currents, rebound, dynamic calcium, or multi-ion channel dependencies. |
192
200
  | `references/multicompartment/multicompartment-cell-workflow.md` | Extending the canonical `Morphology -> Cell -> paint/place -> run` path and selecting the exclusive multicompartment references. |
201
+ | `references/multicompartment/network-workflow.md` | Connecting event sources to spatially placed synapses on detailed cells, managing the network lifecycle, or reading population results. |
193
202
  | `references/solver-library-with-effects.md` | Comparing registered integrators, stability, accuracy, and solver-dependent trace effects. |
@@ -116,7 +116,7 @@ Do not reconstruct the same sections with comparisons against `t` inside
116
116
  `step`. For a mapped parameter sweep that shares this protocol, keep the
117
117
  per-step current sample unmapped (`in_axes=None`) while mapping the independent
118
118
  condition parameters and dynamical State. Open
119
- `skills/package-skills/brainstate/references/brainstate/transformation-vmap-expansion.md` for
119
+ `brainstate` → `references/brainstate/transformation-vmap-expansion.md` for
120
120
  the mapped-State contract.
121
121
 
122
122
  ## Basic currents
@@ -1,36 +1,40 @@
1
- # Braintools metrics
1
+ # BrainTools losses and analysis
2
2
 
3
3
  Use this reference to select supervised losses and neuroscience metrics for
4
4
  classification, regression, spike trains, local field potentials, correlation,
5
5
  connectivity, and pairwise comparison. Verify input orientation, units, and
6
6
  reduction before treating any returned array as a scalar objective.
7
7
 
8
+ Use `braintools.metric` for training losses and vector comparisons. Use
9
+ `braintools.analysis` for neuroscience analysis. The analysis examples require
10
+ BrainTools 0.4.0 or newer.
11
+
8
12
  ## Choose a metric family
9
13
 
10
14
  | Task | Use | Important constraint |
11
15
  |---|---|---|
12
16
  | Independent binary or multilabel classification | Sigmoid binary cross entropy or focal loss | Logits and labels must have broadcast-compatible class structure. |
13
17
  | Mutually exclusive classes | Softmax cross entropy | Choose one-hot/probability labels or the integer-label variant explicitly. |
14
- | Continuous fitting | Squared, absolute, Huber, log-cosh, or cosine losses | Set `reduction` rather than assuming a scalar result. |
18
+ | Continuous fitting | Squared, absolute, Huber, log-cosh, or cosine losses | Check the function-specific reduction and reduce explicitly when a scalar is required. |
15
19
  | Spike timing | Victor-Purpura or van Rossum distance | Inputs are spike-time trains, not dense spike matrices. |
16
20
  | Population spiking | Firing-rate and synchrony metrics | Dense spike matrices are time-major unless the API says otherwise. |
17
- | LFP spectrum or coupling | PSD, coherence, PAC, CSD, entropy, or phase coherence | Pass the sample interval as `dt`, not sampling frequency as `fs`. |
21
+ | LFP spectrum or coupling | PSD, coherence, PAC, CSD, entropy, or phase coherence | For spectral routines with `dt`, pass the sample interval. CSD takes electrode spacing. |
18
22
  | Functional connectivity | Correlation and connectivity functions | Time series use `(num_time, num_signals)`. |
19
23
 
20
- ## Classification losses
24
+ ## Classification losses (`braintools.metric`)
21
25
 
22
26
  | API | Description |
23
27
  |---|---|
24
28
  | `sigmoid_binary_cross_entropy(logits, labels)` | Use for independent binary classes; returns element-wise sigmoid cross entropy. |
25
29
  | `softmax_cross_entropy(logits, labels)` | Use for mutually exclusive classes represented by one-hot or probability labels. |
26
- | `softmax_cross_entropy_with_integer_labels(logits, labels)` | Use the more direct integer-index form for mutually exclusive classes. Validate every label yourself. |
30
+ | `softmax_cross_entropy_with_integer_labels(logits, labels)` | Use the more direct integer-index form for mutually exclusive classes. |
27
31
  | `hinge_loss(...)` | Use for binary margin classification. |
28
32
  | `perceptron_loss(...)` | Use for the binary perceptron objective. |
29
33
  | `multiclass_hinge_loss(...)` | Use for a multiclass margin objective. |
30
34
  | `multiclass_perceptron_loss(...)` | Use for a multiclass perceptron objective. |
31
35
  | `poly_loss_cross_entropy(...)` | Use when the specified method requires PolyLoss cross entropy. |
32
- | `kl_divergence(...)` | Compare probability distributions. |
33
- | `kl_divergence_with_log_targets(...)` | Use when predictions and targets are already in log space. |
36
+ | `kl_divergence(log_predictions, targets)` | Compare target probabilities with predicted log probabilities. |
37
+ | `kl_divergence_with_log_targets(...)` | Use when both predicted and target probabilities are supplied in log space. |
34
38
  | `convex_kl_divergence(...)` | Use when the convex KL variant is required. |
35
39
  | `ctc_loss(...)` | Use for sequence alignment without frame-level labels. |
36
40
  | `ctc_loss_with_forward_probs(...)` | Use when the CTC forward probabilities are also needed. |
@@ -54,19 +58,18 @@ loss = jnp.mean(per_example)
54
58
  assert loss.ndim == 0
55
59
  ```
56
60
 
57
- **Critical exception:** JAX gather silently clamps out-of-range integer labels
58
- in `softmax_cross_entropy_with_integer_labels`. Validate
59
- `0 <= labels < logits.shape[-1]`; the function does not raise for invalid
60
- labels.
61
+ Validate integer labels against `0 <= labels < logits.shape[-1]` before
62
+ computing the loss. Invalid indices can select a different class or return
63
+ `NaN` without raising.
61
64
 
62
- ## Regression and pairwise metrics
65
+ ## Regression and pairwise metrics (`braintools.metric`)
63
66
 
64
67
  | API | Description |
65
68
  |---|---|
66
- | `squared_error(predictions, targets=None, axis=None, reduction='none')` | Use for element-wise squared error; choose `mean` or another supported reduction explicitly when a scalar is required. |
69
+ | `squared_error(predictions, targets=None, axis=None, reduction='none')` | Use for element-wise squared error. Targets must match prediction shape; choose `reduction="mean"` for a scalar MSE with `axis=None`. |
67
70
  | `absolute_error(...)` | Use for element-wise absolute error. |
68
- | `l1_loss(...)` | Use for mean absolute-error behavior according to its axis/reduction options. |
69
- | `l2_loss(...)` | Use for squared L2 loss. |
71
+ | `l1_loss(logits, targets, reduction="mean")` | Average absolute error over non-batch axes first; use `reduction="none"` to keep one value per sample. |
72
+ | `l2_loss(...)` | Use for half the squared error. |
70
73
  | `l2_norm(...)` | Return the L2 norm of prediction error. |
71
74
  | `safe_norm(...)` | Use when a differentiable lower bound must prevent an unstable zero norm. |
72
75
  | `huber_loss(predictions, targets=None, delta=1.0, axis=None, reduction='none')` | Use for quadratic small residuals and linear large residuals; tune `delta` in target units. |
@@ -80,38 +83,42 @@ Do not conflate element-wise loss with final optimization reduction. Preserve
80
83
  batch and time axes until the scientific loss definition determines how to
81
84
  reduce them.
82
85
 
83
- ## Correlation and functional connectivity
86
+ ## Correlation and functional connectivity (`braintools.analysis`)
84
87
 
85
88
  | API | Description |
86
89
  |---|---|
87
- | `cross_correlation(spikes, bin, dt)` | Calculate a cross-correlation synchrony index from a time-major spike matrix. |
88
- | `voltage_fluctuation(voltages)` | Estimate synchrony from population voltage variance. |
89
- | `matrix_correlation(a, b)` | Correlate upper-triangular entries of two square matrices. |
90
- | `weighted_correlation(x, y, weights)` | Compute weighted Pearson correlation for two one-dimensional series. |
91
- | `functional_connectivity(activities)` | Return the pairwise Pearson correlation matrix for `(num_time, num_signals)` data; NaNs are replaced with zero. |
92
- | `functional_connectivity_dynamics(activities, window_size, step_size)` | Compare sliding-window connectivity matrices to produce functional-connectivity dynamics. |
90
+ | `spike.cross_correlation(spikes, bin, dt=None, ...)` | Calculate a cross-correlation synchrony index from a time-major spike matrix. |
91
+ | `population.voltage_fluctuation(potentials, ...)` | Estimate synchrony from population voltage variance. |
92
+ | `stats.matrix_correlation(x, y)` | Correlate the strict upper triangles of two matching connectivity matrices. |
93
+ | `stats.weighted_correlation(x, y, w)` | Compute weighted Pearson correlation for two one-dimensional series. |
94
+ | `population.functional_connectivity(activities)` | Return the pairwise Pearson correlation matrix for `(num_time, num_signals)` data; NaNs are replaced with zero. |
95
+ | `population.functional_connectivity_dynamics(activities, window_size, step_size)` | Correlate the strict upper triangles of windowed FC matrices. Specify window size and step in samples. |
93
96
 
94
97
  ## Spike-train metrics
95
98
 
99
+ Pass physical time quantities on BrainTools 0.4. Bare `dt` values are in
100
+ seconds for `firing_rate`, `phase_locking_value`, and spectral functions.
101
+ Most other spike-matrix routines use milliseconds.
102
+
96
103
  | API | Description |
97
104
  |---|---|
98
- | `raster_plot(spikes, times)` | Extract neuron indices and spike times from a dense spike matrix; this is a metric/data helper, not the visualization API. |
99
- | `firing_rate(spikes, width, dt=None)` | Average across neurons and smooth population rate with a rectangular window of physical width. |
100
- | `victor_purpura_distance(spike_times_1, spike_times_2, cost_factor=1.0)` | Measure edit cost from insertions, deletions, and temporal shifts. |
101
- | `van_rossum_distance(spike_times_1, spike_times_2, tau=...)` | Compare exponentially filtered spike trains. |
102
- | `spike_train_synchrony(spikes, window_size, dt=None)` | Compute SPIKE-style synchronization on a population matrix. |
103
- | `burst_synchrony_index(spikes, dt=None, ...)` | Measure co-occurring burst events. |
104
- | `phase_locking_value(spikes, reference_freq, dt=None, ...)` | Measure spike phase locking to a reference oscillation. |
105
- | `spike_time_tiling_coefficient(spikes, dt=None, tau=...)` | Compute STTC within a temporal tolerance. |
106
- | `correlation_index(spikes, window_size, dt=None)` | Compute a windowed spike-train correlation index. |
105
+ | `spike.firing_rate(spikes, width, dt=None)` | Return a time series of population rate in Hz. Pass physical time quantities for `width` and `dt` to make units explicit. |
106
+ | `spike.victor_purpura_distance(spike_times_1, spike_times_2, cost_factor=1.0)` | Measure edit cost from insertions, deletions, and temporal shifts. |
107
+ | `spike.van_rossum_distance(spike_times_1, spike_times_2, tau=1.0, t_max=None)` | Compare exponentially filtered spike trains. |
108
+ | `spike.spike_train_synchrony(spike_matrix, window_size, dt=None)` | Average pairwise spike coincidences within a time window. Silent-neuron pairs are omitted; check activity before interpreting the score. |
109
+ | `spike.burst_synchrony_index(spike_matrix, burst_threshold=3, max_isi=100.0, dt=None)` | Measure co-occurring burst events. |
110
+ | `spike.phase_locking_value(spike_matrix, reference_freq, dt=None)` | Measure spike phase locking at a specified reference frequency; this score does not give a signed phase lag. |
111
+ | `spike.spike_time_tiling_coefficient(spike_matrix, dt=None, tau=5.0)` | Compute STTC within a temporal tolerance. |
112
+ | `spike.correlation_index(spike_matrix, window_size, dt=None)` | Compute a windowed spike-train correlation index. |
107
113
 
108
114
  ```python
109
115
  import brainunit as u
110
- from braintools.metric import firing_rate, spike_train_synchrony
116
+ import braintools
117
+ import jax.numpy as jnp
111
118
 
112
- # Shape: (num_time, num_neurons)
113
- rate = firing_rate(spikes, width=10 * u.ms, dt=1 * u.ms)
114
- synchrony = spike_train_synchrony(
119
+ spikes = jnp.zeros((200, 5)).at[50:53, :].set(1.0)
120
+ rate = braintools.analysis.spike.firing_rate(spikes, width=10 * u.ms, dt=1 * u.ms)
121
+ synchrony = braintools.analysis.spike.spike_train_synchrony(
115
122
  spikes,
116
123
  window_size=5 * u.ms,
117
124
  dt=1 * u.ms,
@@ -120,26 +127,40 @@ synchrony = spike_train_synchrony(
120
127
 
121
128
  Keep dense spike matrices and lists of spike times distinct. Distance metrics
122
129
  consume event times; population rate and synchrony metrics consume matrices.
130
+ Use [`braintools.spike.SpikeTrains.from_dense`](https://brainx.chaobrain.com/braintools/apis/generated/braintools.spike.SpikeTrains.html#braintools.spike.SpikeTrains.from_dense)
131
+ to convert a regularly sampled matrix to spike trains; use
132
+ [`braintools.visualize.spike_raster`](https://brainx.chaobrain.com/braintools/apis/generated/braintools.visualize.spike_raster.html)
133
+ to draw a raster.
123
134
 
124
135
  ## Local field potential analysis
125
136
 
126
137
  | API | Description |
127
138
  |---|---|
128
- | `unitary_LFP(times, spikes, neuron_type, seed=None, ...)` | Construct unitary LFP contributions from spikes; use the documented `'exc'` or `'inh'` neuron type. |
129
- | `power_spectral_density(lfp, dt, nperseg=None, noverlap=None, freq_range=None)` | Return one-sided Welch frequencies and PSD. |
130
- | `coherence_analysis(signal1, signal2, dt, ...)` | Return frequency-resolved magnitude-squared coherence. |
131
- | `phase_amplitude_coupling(lfp, dt, phase_freq_range, amplitude_freq_range, ...)` | Return Tort modulation index plus phase-bin details. |
132
- | `theta_gamma_coupling(lfp, dt, ...)` | Return theta-gamma coupling using standard bands. |
133
- | `current_source_density(lfp, electrode_spacing, axis=0, ...)` | Estimate laminar CSD along the electrode axis. |
134
- | `spectral_entropy(lfp, dt, ...)` | Return normalized spectral entropy. |
135
- | `lfp_phase_coherence(lfp, dt, freq_band, ...)` | Compute pairwise phase coherence across channels. |
139
+ | `field.unitary_LFP(times, spikes, spike_type, ...)` | Construct unitary LFP contributions from spikes. Supply times in milliseconds and choose `'exc'` or `'inh'`. |
140
+ | `spectral.power_spectral_density(lfp, dt, nperseg=None, noverlap=None, freq_range=None)` | Return one-sided Welch frequencies in Hz and PSD for `(time,)` or `(time, channels)` input. |
141
+ | `spectral.spectrogram(x, dt, nperseg, noverlap=None, window='hann', detrend='constant')` | Use when segment spectra or explicit window/detrending controls are required; returns frequencies, segment centers and PSD shaped `(frequency, segment, ...)`. |
142
+ | `spectral.coherence_analysis(lfp1, lfp2, dt, ...)` | Return frequency-resolved magnitude-squared coherence. |
143
+ | `spectral.phase_amplitude_coupling(lfp, dt, phase_freq_range, amplitude_freq_range, ...)` | Return Tort modulation index plus phase-bin details. |
144
+ | `spectral.theta_gamma_coupling(lfp, dt)` | Return theta-gamma coupling using standard bands. |
145
+ | `field.current_source_density(lfp_laminar, electrode_spacing, conductivity=1.0, axis=-1)` | Estimate laminar CSD using electrode spacing. Set `axis` explicitly when electrodes are not on the last axis. |
146
+ | `spectral.spectral_entropy(lfp, dt, ...)` | Return normalized spectral entropy. |
147
+ | `spectral.lfp_phase_coherence(lfp_signals, dt, freq_band=(8, 12))` | Compute pairwise phase coherence across channels. |
148
+
149
+ Use `power_spectral_density` when its estimator defaults match the protocol.
150
+ For a fixed Welch estimator requiring explicit window and detrending controls,
151
+ use [`spectral.spectrogram`](https://brainx.chaobrain.com/braintools/apis/generated/braintools.analysis.spectral.spectrogram.html)
152
+ and take `u.math.mean(segment_psd, axis=1)` over segments. Set `noverlap`
153
+ explicitly: its default is `nperseg // 8`, not 50%. `window='hann'` selects
154
+ a periodic Hann window; `detrend='constant'` removes each segment's mean.
155
+ For a Quantity signal with unit `U`, the segment PSD and its mean retain
156
+ `U**2 / Hz`. Preserve the frozen estimator when comparing implementations.
136
157
 
137
158
  `power_spectral_density(..., freq_range=...)` uses boolean-mask indexing and
138
159
  therefore has a data-dependent output length; that path is not JIT-compatible.
139
160
  Compute the full spectrum inside JIT and filter outside when compilation is
140
161
  required.
141
162
 
142
- ## Structured, ranking, and smoothing losses
163
+ ## Structured, ranking, and smoothing losses (`braintools.metric`)
143
164
 
144
165
  | API | Description |
145
166
  |---|---|
@@ -147,6 +168,11 @@ required.
147
168
  | `ranking_softmax_loss(scores, labels, ...)` | Use for list-wise learning-to-rank objectives. |
148
169
  | `smooth_labels(labels, alpha=...)` | Apply label smoothing to one-hot targets. |
149
170
 
150
- ## Official source
171
+ ## Official sources
172
+
173
+ Open the [analysis API](https://brainx.chaobrain.com/braintools/apis/analysis.html)
174
+ for PSTH, interspike-interval statistics, or band power. Open the
175
+ [fitting API](https://brainx.chaobrain.com/braintools/apis/fit.html) when firing
176
+ rate, PSD, or FC is a fitting objective.
151
177
 
152
- - `https://brainx.chaobrain.com/braintools/apis/metric.html`
178
+ - [Training losses and deprecated alias routing](https://brainx.chaobrain.com/braintools/apis/metric.html)
@@ -2,7 +2,7 @@
2
2
 
3
3
  Use this reference when adding a calcium-activated potassium current, calcium-dependent afterhyperpolarization, spike-frequency adaptation, or a thalamic/rebound variant that needs dynamic calcium plus a K/Ca mixed current.
4
4
 
5
- In single-compartment models, use the class pattern below directly. In multicompartment `Cell` work, use this reference for ion/channel composition choices, but keep morphology, targeting, `paint`, `place`, CV policy, clamps, and probes in `references/multicompartment/multicompartment-cell-workflow.md`.
5
+ In single-compartment models, use the class pattern below directly. In multicompartment `Cell` work, use this reference for ion/channel composition choices, but keep morphology, targeting, `paint`, `place`, CV policy, clamps, and recordings in `references/multicompartment/multicompartment-cell-workflow.md`.
6
6
 
7
7
  ## Rule
8
8
 
@@ -1,6 +1,6 @@
1
1
  # BrainCell manual morphology construction
2
2
 
3
- Use this reference after opening `references/multicompartment/multicompartment-cell-workflow.md` when no existing reconstruction should be loaded and the task requires explicit branch geometry, anatomical types, or parent-child topology. Return to the workflow before choosing CVs, mechanisms, probes, or a solver.
3
+ Use this reference after opening `references/multicompartment/multicompartment-cell-workflow.md` when no existing reconstruction should be loaded and the task requires explicit branch geometry, anatomical types, or parent-child topology. Return to the workflow before choosing CVs, mechanisms, recordings, or a solver.
4
4
 
5
5
  ## Mental model
6
6
 
@@ -114,7 +114,7 @@ Treat CV policy as a numerical assumption, not a visualization preference.
114
114
  1. Choose a policy from the spatial question and inspect `cell.n_cv` and `cell.cvs`.
115
115
  2. Run the scientific protocol with fixed morphology, mechanisms, stimulus, solver, and `dt`.
116
116
  3. Refine only the CV policy: increase `cv_per_branch`, reduce `max_cv_len`, or reduce `d_lambda`.
117
- 4. Compare the relevant traces, spike timing, peaks, attenuation, or other spatial observable at the same probe locations.
117
+ 4. Compare the relevant traces, spike timing, peaks, attenuation, or other spatial observable at the same recording locations.
118
118
  5. Accept the coarser policy only when the observable remains within the task's stated tolerance.
119
119
 
120
120
  Do not change `dt`, solver, and CV policy in the same convergence comparison. A stable CV count does not establish time-step or solver convergence.
@@ -70,7 +70,7 @@ Overlapping slices are normalized in the materialized mask. Inspect `morphology.
70
70
 
71
71
  ## Locset selectors
72
72
 
73
- Use locsets for clamps, probes, synapses, junctions, and other point declarations.
73
+ Use locsets for clamps, synapses, and spatial recording views.
74
74
 
75
75
  | API | Use when | Important behavior and result |
76
76
  |---|---|---|
@@ -125,11 +125,11 @@ cell.paint(
125
125
  E=-65.0 * u.mV,
126
126
  ),
127
127
  )
128
- cell.place(terminal_sites, mech.StateProbe())
128
+ cell.loc(terminal_sites).record("terminal_v", braincell.observe.state("v"))
129
129
  cell.init_state()
130
130
  ```
131
131
 
132
- Use a region only with `paint()` and a locset only with `place()`. A selector that resolves correctly against `Morphology` can still map unexpectedly after discretization; open `references/multicompartment/topology-building-and-visualization.md` to inspect CV ownership and runtime placement.
132
+ Use a region for `paint()` and a locset for `place()` or `cell.loc()`. A selector that resolves correctly against `Morphology` can still map unexpectedly after discretization. Open `references/multicompartment/topology-building-and-visualization.md` to inspect CV ownership and runtime placement.
133
133
 
134
134
  ## Exported but unavailable selectors
135
135
 
@@ -79,7 +79,7 @@ from braincell.io import NeuroMlReader
79
79
  morphology = NeuroMlReader().read("neuron.cell.nml")
80
80
  ```
81
81
 
82
- Declare ions, channels, clamps, probes, and network structure separately. BrainCell does not import those NeuroML2 definitions automatically.
82
+ Declare ions, channels, clamps, recordings, and network structure separately. BrainCell does not import those NeuroML2 definitions automatically.
83
83
 
84
84
  ### NeuroMorpho.Org
85
85
 
@@ -2,13 +2,13 @@
2
2
 
3
3
  ## Purpose and boundary
4
4
 
5
- Use this reference when a BrainCell simulation depends on geometry, axial current, regional biophysics, or location-specific stimulation and recording. Keep isopotential cells in `skills/package-skills/braincell/SKILL.md` and cross-cell connections or training in `skills/package-skills/brainpy-state/SKILL.md`; never model compartments with `SingleCompartment.size`.
5
+ Use this reference when a BrainCell simulation depends on geometry, axial current, regional biophysics, or location-specific stimulation and recording. Use `SingleCompartment` for isopotential cells. Keep independent cells on the population axis and resolve compartments through the morphology and CV policy.
6
6
 
7
7
  ## Underlying principle of BrainCell multicompartment cells
8
8
 
9
9
  `braincell.filter` expressions represent spatial targets. Regions select cable for `paint()`; locsets select points for `place()`.
10
10
 
11
- `braincell.mech` declarations represent cellular biophysics and point processes. Paint cable properties, ions, and channels over regions; place clamps and probes at locsets.
11
+ `braincell.mech` declarations represent cellular biophysics and point processes. Paint cable properties, ions, and channels over regions. Place clamps and synapses at locsets. Declare recordings on the cell or a spatial view.
12
12
 
13
13
  ## Workflow map
14
14
 
@@ -133,7 +133,7 @@ for cv in cell.cvs[:3]:
133
133
 
134
134
  Validate every policy by refining it and comparing the target observable. Resolve cable properties before `DLambda`; split capacitance or axial-resistivity changes at branch boundaries.
135
135
 
136
- Open `references/multicompartment/cv-policy-reference.md` for by-type or composite policies, probe mapping, and convergence.
136
+ Open `references/multicompartment/cv-policy-reference.md` for by-type or composite policies, recording-site mapping, and convergence.
137
137
 
138
138
  ## Declare distributed biophysics
139
139
 
@@ -174,9 +174,9 @@ BrainCell area-scales capacitance and conductance densities during lowering; kee
174
174
 
175
175
  Open `references/multicompartment/filter-function-library.md` for composed or geometry-based regions, `references/ion-library.md` or `references/channel-library.md` for non-canonical mechanisms, and `references/mixions-for-adaptation.md` for calcium-dependent or multi-ion coupling.
176
176
 
177
- ## Place stimuli and probes
177
+ ## Place stimuli and declare recordings
178
178
 
179
- Point declarations define where current enters and what the simulation exposes; use locsets for both and place at least one probe before `run()`.
179
+ Place current clamps at locsets. Register observables on a selected view before initialization.
180
180
 
181
181
  | API | Description |
182
182
  |---|---|
@@ -184,9 +184,7 @@ Point declarations define where current enters and what the simulation exposes;
184
184
  | `braincell.filter.at(branch, position)` | Use for one named branch position; the branch argument identifies a branch, not an anatomical type. |
185
185
  | `braincell.filter.Terminals()` | Use when a point declaration must resolve at every terminal tip. |
186
186
  | `braincell.mech.CurrentClamp(...)` | Use for piecewise current injection; declare delay, durations, and amplitudes with time and current units. Currents from clamps at the same runtime point add. |
187
- | `braincell.mech.StateProbe(field="v")` | Use to record cell-owned membrane voltage; `v` is the current multicompartment State field. |
188
- | `braincell.mech.MechanismProbe(mechanism=..., field=...)` | Use to record a real runtime State field on a named channel or ion; do not request a static parameter or derived property. |
189
- | `braincell.mech.CurrentProbe(...)` | Use to record one mechanism current or the total current owned by a named ion. |
187
+ | `cell.loc(locset).record(name, observable)` | Use to record over the CVs selected by a locset. Select membrane voltage with `braincell.observe.state("v")`. |
190
188
  | `cell.place(locset, *point_mechanisms)` | Use only in DECLARING; it records point declarations at every resolved location and returns the cell for chaining. |
191
189
 
192
190
  ```python
@@ -202,12 +200,10 @@ cell.place(
202
200
  amplitudes=0.2 * u.nA,
203
201
  ),
204
202
  )
205
- cell.place(soma_midpoint, mech.StateProbe())
203
+ cell.loc(soma_midpoint).record("soma_v", braincell.observe.state("v"))
206
204
  ```
207
205
 
208
- A multi-point locset creates one probe per resolved point. Inspect `sample_probes()` for keys; assign unique names only when stable keys are required.
209
-
210
- Open `references/multicompartment/filter-function-library.md` for composed locsets and `references/multicompartment/probe-reference.md` for probe selection or missing and ambiguous keys.
206
+ Open `references/multicompartment/filter-function-library.md` for composed locsets and `references/multicompartment/probe-reference.md` for observable selection, sample schedules, result schemas, or legacy probe migration.
211
207
 
212
208
  ## Initialize and inspect the lowered runtime
213
209
 
@@ -215,35 +211,32 @@ Open `references/multicompartment/filter-function-library.md` for composed locse
215
211
 
216
212
  | API | Description |
217
213
  |---|---|
218
- | `cell.init_state(batch_size=None)` | Use after every `paint()` and `place()` call; it lowers declarations, allocates evolving model State, materializes clamp and probe layouts, and raises if the cell is already initialized. |
214
+ | `cell.init_state(batch_size=None)` | Use after declaring mechanisms and recordings. It lowers declarations, allocates evolving model State, and raises if the cell is already initialized. |
219
215
  | `cell.node_tree` | Use after initialization to inspect the point-and-edge execution topology derived from the CV tree. |
220
216
  | `cell.layouts` | Use after initialization to inspect each lowered mechanism layout, including its kind, target, active count, source CVs, and runtime point indices. |
221
- | `cell.sample_probe(name)` | Use after initialization to read the current value of one probe by its resolved name. |
222
- | `cell.sample_probes()` | Use after initialization to read all current probe values and discover the exact probe-key surface. |
223
217
 
224
218
  ```python
225
219
  cell.init_state()
226
220
 
227
- samples = cell.sample_probes()
228
- print("probe keys:", sorted(samples))
221
+ assert cell.V.value.shape == cell.pop_size + (cell.n_cv,)
229
222
  print("runtime nodes:", len(cell.node_tree.nodes))
230
223
  for layout in cell.layouts:
231
224
  print(layout.kind, layout.target, layout.n_active)
232
225
  ```
233
226
 
234
- Inspect `cell.cvs` before initialization; inspect `cell.node_tree`, `cell.layouts`, and probes afterward. Runtime surfaces raise in DECLARING; call `reset()` before changing `paint()` or `place()` rules.
227
+ Inspect `cell.cvs` before initialization and runtime voltage and mechanism layouts afterward. In BrainCell 0.2.0 the unbatched voltage has population axes followed by the CV axis, even for a singleton population.
235
228
 
236
229
  Open `references/multicompartment/topology-building-and-visualization.md` to visualize CV, branch, node, or placement topology; open `references/multicompartment/probe-reference.md` for sampling failures.
237
230
 
238
231
  ## Run and interpret the result
239
232
 
240
- `run()` advances the initialized cell from its current time and samples every placed probe at each step, so repeated calls continue the same simulation unless State is reset.
233
+ `run()` advances from the current cell time. Each recording block carries the times for its own sample schedule.
241
234
 
242
235
  | API | Description |
243
236
  |---|---|
244
- | `cell.run(dt=..., duration=...)` | Use with positive time quantities to advance the cell; it calls `init_state()` only when still DECLARING and raises `ValueError` when no probe is placed. |
237
+ | `cell.run(dt=..., duration=...)` | Use with positive time quantities and a duration divisible by `dt`. It initializes a standalone cell on first use. |
245
238
  | `braincell.RunResult.time` | Use as the unit-aware `(n_steps,)` time axis spanning `[start_t, start_t + duration)`. |
246
- | `braincell.RunResult.traces` | Use as the probe-name to trace mapping; every trace has the same leading time dimension as `RunResult.time`. |
239
+ | `braincell.RunResult.samples` | Look up a named recording block and use its `time`, `values`, and `schema` together. |
247
240
  | `cell.current_time` | Use after a run to inspect the endpoint from which the next `run()` call will continue. |
248
241
  | `Quantity.to_decimal(unit)` | Use only at plotting, serialization, or external-library boundaries to obtain values in an explicit compatible unit. |
249
242
 
@@ -253,12 +246,10 @@ result = cell.run(
253
246
  duration=100.0 * u.ms,
254
247
  )
255
248
 
256
- voltage_key = next(key for key in result.traces if key.endswith("_v"))
257
- voltage = result.traces[voltage_key]
258
-
259
- assert result.time.shape[0] == voltage.shape[0]
260
- times_ms = result.time.to_decimal(u.ms)
261
- voltage_mV = voltage.to_decimal(u.mV)
249
+ voltage = result.samples["soma_v"]
250
+ assert voltage.values.shape == (voltage.time.size, 1)
251
+ times_ms = voltage.time.to_decimal(u.ms)
252
+ voltage_mV = voltage.values[:, 0].to_decimal(u.mV)
262
253
  ```
263
254
 
264
255
  Keep quantities unit-aware and convert only at external boundaries. Validate `dt` by comparing the target observable at `dt / 2`.
@@ -267,7 +258,7 @@ Open `references/solver-library-with-effects.md` for cable-solver choice or meth
267
258
 
268
259
  ## Canonical end-to-end workflow
269
260
 
270
- This current-clamp pattern uses an explicit passive baseline, `DLambda` with staggered integration, somatic active channels, runtime target checks, and one voltage probe.
261
+ This current-clamp pattern uses an explicit passive baseline, `DLambda` with staggered integration, somatic active channels, runtime target checks, and one voltage recording. Supply a valid SWC file containing a soma at `neuron.swc`.
271
262
 
272
263
  ```python
273
264
  import braincell
@@ -331,7 +322,7 @@ cell.place(
331
322
  amplitudes=0.2 * u.nA,
332
323
  ),
333
324
  )
334
- cell.place(soma_midpoint, mech.StateProbe())
325
+ cell.loc(soma_midpoint).record("soma_v", braincell.observe.state("v"))
335
326
 
336
327
  # 5. Inspect the final spatial layout before allocating runtime State.
337
328
  print("n_cv:", cell.n_cv)
@@ -340,25 +331,21 @@ for cv in cell.cvs[:3]:
340
331
 
341
332
  # 6. Lower declarations, verify resolved targets, and run.
342
333
  cell.init_state()
343
- initial_samples = cell.sample_probes()
344
- assert len(initial_samples) == 1
345
- voltage_key = next(iter(initial_samples))
346
- assert voltage_key.endswith("_v")
334
+ assert cell.V.value.shape == (1, cell.n_cv)
347
335
 
348
336
  for layout in cell.layouts:
349
337
  print(layout.kind, layout.target, layout.n_active)
350
338
 
351
339
  result = cell.run(dt=0.05 * u.ms, duration=100.0 * u.ms)
352
- voltage = result.traces[voltage_key]
353
-
354
- assert result.time.shape[0] == voltage.shape[0]
355
- times_ms = result.time.to_decimal(u.ms)
356
- voltage_mV = voltage.to_decimal(u.mV)
340
+ voltage = result.samples["soma_v"]
341
+ assert voltage.values.shape == (voltage.time.size, 1)
342
+ times_ms = voltage.time.to_decimal(u.ms)
343
+ voltage_mV = voltage.values[:, 0].to_decimal(u.mV)
357
344
  ```
358
345
 
359
346
  Replace the example morphology, mechanisms, stimulus, readout, `dt`, and CV policy, then validate the target observable under numerical refinement.
360
347
 
361
- Open `references/scripts/cell_multicompartment_reference.py` for the full tutorial with CV, node-tree, layout, policy, and plotting inspection.
348
+ Open `references/scripts/cell_multicompartment_reference.py` for the full tutorial with CV, node-tree, layout, policy, and plotting inspection. Pass the path to a soma-and-dendrite SWC as the script's first argument.
362
349
 
363
350
  ## Reset, continue, or revise
364
351
 
@@ -368,20 +355,21 @@ Use continuation, State reset, declaration reset, or a new cell according to wha
368
355
  |---|---|---|
369
356
  | Continue the same trajectory | Call `cell.run(...)` again. | The next run starts at `cell.current_time`; the cell is not reinitialized. |
370
357
  | Repeat the same declaration from reset State | Call `cell.reset_state()`, then `cell.run(...)`. | The cell remains INITIALIZED while voltage, spike, time, and mechanism State are reseeded through their reset hooks. |
371
- | Change mechanisms, regions, locsets, or probes | Call `cell.reset()`, edit with `paint()` or `place()`, then call `init_state()`. | Runtime State is discarded and the cell returns to DECLARING while its declaration rules remain available for revision. |
358
+ | Change the declaration | Call `cell.reset()` to reopen declaration before adding mechanisms or recordings. Build a fresh cell when replacing an existing recording name. | Runtime State is discarded. Existing declarations are retained. |
372
359
  | Compare CV policies or independent numerical trials | Construct separate cells from one model-building function. | Each comparison has independent declarations, runtime State, and time. |
373
360
 
374
361
  ## Reference routing
375
362
 
376
- Open the smallest child for the next decision; `skills/package-skills/braincell/SKILL.md` routes multicompartment work here before these children.
363
+ Open the smallest child for the next decision.
377
364
 
378
365
  | Reference | Open when |
379
366
  |---|---|
380
367
  | `references/multicompartment/morphology-io-loading-validation.md` | Loading SWC, ASC, NeuroML2, NeuroMorpho.Org, or checkpoint data; configuring validation; or checking loaded geometry. |
381
368
  | `references/multicompartment/braincell-manual-morphology-construction.md` | Constructing branches, points, radii, types, and parent-child topology without an existing morphology file. |
382
369
  | `references/multicompartment/filter-function-library.md` | Selecting or composing non-canonical regions and locsets for `paint()` and `place()`. |
383
- | `references/multicompartment/cv-policy-reference.md` | Selecting advanced CV policies or evaluating spatial resolution, cost, probe mapping, and convergence. |
384
- | `references/multicompartment/probe-reference.md` | Selecting State, mechanism, or current probes; stabilizing trace keys; or resolving empty and ambiguous traces. |
370
+ | `references/multicompartment/cv-policy-reference.md` | Selecting advanced CV policies or evaluating spatial resolution, cost, recording-site mapping, and convergence. |
371
+ | `references/multicompartment/probe-reference.md` | Selecting voltage, mechanism State, or current, checking sampling schedules and result rows, or migrating legacy probes. |
372
+ | `references/multicompartment/network-workflow.md` | Delivering events to spatially placed synapses, registering populations, or running and resetting connected cells. |
385
373
  | `references/multicompartment/topology-building-and-visualization.md` | Inspecting and visualizing morphology, branch, CV, node, region, locset, or runtime topology. |
386
374
  | `references/ion-library.md` | Choosing fixed, Nernst, or dynamic ion declarations and concentration behavior. |
387
375
  | `references/channel-library.md` | Choosing registered sodium, potassium, calcium, leak, HCN, or mixed-ion density channels. |