brainx-skill 1.0.15 → 1.0.17

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 (180) hide show
  1. package/README.md +17 -1
  2. package/installation/lib/literature-mcp.js +7 -1
  3. package/manifest.json +1 -1
  4. package/mcp-servers/codex/README.md +46 -20
  5. package/mcp-servers/codex/UPSTREAM.md +20 -16
  6. package/mcp-servers/codex/app-server.mjs +177 -0
  7. package/mcp-servers/codex/cli-invocation.cjs +50 -0
  8. package/mcp-servers/codex/server.mjs +136 -69
  9. package/mcp-servers/codex/skills.json +1 -1
  10. package/mcp-servers/codex/test/fixtures/fake-codex.mjs +80 -3
  11. package/mcp-servers/codex/test/fixtures/run-server.mjs +7 -0
  12. package/mcp-servers/codex/test/server.test.mjs +188 -84
  13. package/package.json +1 -1
  14. package/skills/bio-neuro-lit/SKILL.md +4 -2
  15. package/skills/bio-neuro-lit/references/required-supplements.md +27 -0
  16. package/skills/brainx-acceleration/SKILL.md +30 -437
  17. package/skills/brainx-acceleration/references/audit-and-rewrite-patterns.md +326 -0
  18. package/skills/brainx-general-guard/SKILL.md +24 -8
  19. package/skills/brainx-install/SKILL.md +3 -3
  20. package/skills/brainx-install/references/compatibility-and-release-matching.md +28 -20
  21. package/skills/brainx-install/references/uninstall-and-cleanup.md +11 -4
  22. package/skills/brainx-modeling-loop/SKILL.md +117 -36
  23. package/skills/brainx-modeling-loop/agents/openai.yaml +2 -2
  24. package/skills/brainx-modeling-loop/references/mechanism-comparison.md +62 -0
  25. package/skills/brainx-modeling-loop/references/multiscale-coupling.md +16 -0
  26. package/skills/brainx-modeling-loop/references/paper-reproduction.md +42 -0
  27. package/skills/brainx-modeling-loop/references/parameter-fitting-workflow.md +14 -14
  28. package/skills/brainx-modeling-loop/references/run-experiment.md +1 -1
  29. package/skills/brainx-modeling-loop/references/training-workflow.md +10 -8
  30. package/skills/brainx-visualization/SKILL.md +6 -2
  31. package/skills/brainx-visualization/references/neural-data-visualization.md +1 -1
  32. package/skills/brainx-visualization/references/statistical-and-model-visualization.md +1 -1
  33. package/skills/package-skills/braincell/SKILL.md +23 -14
  34. package/skills/package-skills/braincell/references/braintools/input-current.md +1 -1
  35. package/skills/package-skills/braincell/references/braintools/metric.md +72 -46
  36. package/skills/package-skills/braincell/references/mixions-for-adaptation.md +1 -1
  37. package/skills/package-skills/braincell/references/multicompartment/braincell-manual-morphology-construction.md +1 -1
  38. package/skills/package-skills/braincell/references/multicompartment/cv-policy-reference.md +1 -1
  39. package/skills/package-skills/braincell/references/multicompartment/filter-function-library.md +3 -3
  40. package/skills/package-skills/braincell/references/multicompartment/morphology-io-loading-validation.md +1 -1
  41. package/skills/package-skills/braincell/references/multicompartment/multicompartment-cell-workflow.md +31 -43
  42. package/skills/package-skills/braincell/references/multicompartment/network-workflow.md +49 -0
  43. package/skills/package-skills/braincell/references/multicompartment/probe-reference.md +26 -114
  44. package/skills/package-skills/braincell/references/multicompartment/topology-building-and-visualization.md +40 -28
  45. package/skills/package-skills/braincell/references/scripts/cell_multicompartment_reference.py +13 -17
  46. package/skills/package-skills/brainevent/SKILL.md +0 -3
  47. package/skills/package-skills/brainevent/references/synaptic-plasticity.md +1 -1
  48. package/skills/package-skills/brainmass/SKILL.md +5 -3
  49. package/skills/package-skills/brainmass/references/brainstate/parameter-constraints-regularization.md +9 -7
  50. package/skills/package-skills/brainmass/references/brainstate/parameter-transforms-regularizers-catalog.md +4 -4
  51. package/skills/package-skills/brainmass/references/braintools/data-preprocessing.md +15 -7
  52. package/skills/package-skills/brainmass/references/braintools/metric.md +72 -46
  53. package/skills/package-skills/brainmass/references/coupling-network-api.md +3 -1
  54. package/skills/package-skills/brainmass/references/fitting-with-objectives-api.md +6 -6
  55. package/skills/package-skills/brainmass/references/horn-task-training.md +9 -9
  56. package/skills/package-skills/brainmass/references/modellibrary.md +12 -10
  57. package/skills/package-skills/brainmass/references/scripts/resting-state-meg-whole-brain-pipeline.py +5 -3
  58. package/skills/package-skills/brainmass/references/scripts/wilson-cowan-ei-dynamics.py +10 -6
  59. package/skills/package-skills/brainmass/references/simulator-input-monitor-api.md +3 -1
  60. package/skills/package-skills/brainmass/references/visualization-analysis-api.md +17 -9
  61. package/skills/package-skills/brainspike/SKILL.md +201 -0
  62. package/skills/package-skills/brainspike/references/braintools/connectivity.md +40 -0
  63. package/skills/package-skills/brainspike/references/braintools/data-preprocessing.md +39 -0
  64. package/skills/package-skills/brainspike/references/braintools/input-current.md +55 -0
  65. package/skills/package-skills/brainspike/references/braintools/metric.md +36 -0
  66. package/skills/package-skills/brainspike/references/braintools/optimizer.md +50 -0
  67. package/skills/package-skills/brainspike/references/braintools/parameter-initializer.md +43 -0
  68. package/skills/package-skills/brainspike/references/braintools/surrogate.md +40 -0
  69. package/skills/package-skills/brainspike/references/migration-boundary.md +38 -0
  70. package/skills/package-skills/brainspike/references/model-and-readout-selection.md +41 -0
  71. package/skills/package-skills/brainspike/references/multirate-coupling.md +31 -0
  72. package/skills/package-skills/brainspike/references/multiscale-composition.md +28 -0
  73. package/skills/package-skills/brainspike/references/native-composition.md +52 -0
  74. package/skills/package-skills/brainspike/references/native-delays.md +34 -0
  75. package/skills/package-skills/brainspike/references/native-projections.md +43 -0
  76. package/skills/package-skills/brainspike/references/native-training.md +36 -0
  77. package/skills/package-skills/{brainpy-state → brainspike}/references/nest-compatible/devices.md +33 -33
  78. package/skills/package-skills/{brainpy-state → brainspike}/references/nest-compatible/divergence-and-parity.md +15 -15
  79. package/skills/package-skills/{brainpy-state → brainspike}/references/nest-compatible/integration-categories.md +1 -1
  80. package/skills/package-skills/brainspike/references/nest-compatible/model-library.md +200 -0
  81. package/skills/package-skills/brainspike/references/nest-compatible/network-building.md +276 -0
  82. package/skills/package-skills/{brainpy-state → brainspike}/references/nest-compatible/scripts/brette_et_al_2007.py +23 -26
  83. package/skills/package-skills/{brainpy-state → brainspike}/references/nest-compatible/scripts/brunel_alpha.py +18 -21
  84. package/skills/package-skills/{brainpy-state → brainspike}/references/nest-compatible/scripts/brunel_delta.py +16 -19
  85. package/skills/package-skills/{brainpy-state → brainspike}/references/nest-compatible/scripts/clopath_synapse_spike_pairing.py +11 -12
  86. package/skills/package-skills/{brainpy-state → brainspike}/references/nest-compatible/scripts/evaluate_tsodyks2_synapse.py +10 -11
  87. package/skills/package-skills/{brainpy-state → brainspike}/references/nest-compatible/scripts/spatial_gaussex.py +18 -18
  88. package/skills/package-skills/{brainpy-state → brainspike}/references/nest-compatible/scripts/synapsecollection.py +26 -29
  89. package/skills/package-skills/brainspike/references/nest-compatible/synapse-and-connectivity.md +166 -0
  90. package/skills/package-skills/brainspike/references/nest-delay-boundaries.md +31 -0
  91. package/skills/package-skills/brainspike/references/nonlinear-state-sharing.md +26 -0
  92. package/skills/package-skills/{brainpy-state → brainspike}/references/perturbation-experiment-validity.md +2 -2
  93. package/skills/package-skills/brainspike/references/simulator-training.md +61 -0
  94. package/skills/package-skills/brainspike/references/temporal-task-training.md +36 -0
  95. package/skills/package-skills/brainspike/scripts/advanced_native_patterns.py +76 -0
  96. package/skills/package-skills/brainspike/scripts/delay_workflow.py +44 -0
  97. package/skills/package-skills/brainspike/scripts/delayed_cue_training.py +78 -0
  98. package/skills/package-skills/brainspike/scripts/lif_smoke.py +31 -0
  99. package/skills/package-skills/brainspike/scripts/multiscale_workflow.py +35 -0
  100. package/skills/package-skills/brainspike/scripts/native_ei_network.py +47 -0
  101. package/skills/package-skills/brainspike/scripts/native_workflows.py +77 -0
  102. package/skills/package-skills/brainspike/scripts/nest_boundary_workflows.py +108 -0
  103. package/skills/package-skills/brainspike/scripts/train_native_snn.py +65 -0
  104. package/skills/package-skills/brainspike/scripts/train_nest_simulator.py +69 -0
  105. package/skills/package-skills/brainspike/scripts/train_nest_simulator_two_weights.py +220 -0
  106. package/skills/package-skills/brainstate/SKILL.md +16 -21
  107. package/skills/package-skills/brainstate/references/brainstate/brainstate-control-flow-patterns.md +1 -138
  108. package/skills/package-skills/brainstate/references/brainstate/brainstate-transformed-diagnostics.md +1 -1
  109. package/skills/package-skills/brainstate/references/brainstate/delay-buffers.md +45 -0
  110. package/skills/package-skills/brainstate/references/brainstate/parameter-constraints-regularization.md +9 -7
  111. package/skills/package-skills/brainstate/references/brainstate/parameter-transforms-regularizers-catalog.md +4 -4
  112. package/skills/package-skills/brainstate/references/brainstate/randomness-and-reproducibility.md +6 -4
  113. package/skills/package-skills/brainstate/references/brainstate/transformation-grad-expansion.md +4 -4
  114. package/skills/package-skills/brainstate/references/brainstate/transformation-vmap-expansion.md +1 -1
  115. package/skills/package-skills/brainstate/references/braintools-optimizer-reference.md +16 -0
  116. package/skills/package-skills/brainstate/references/libraries/prebuilt-layer-library.md +1 -1
  117. package/skills/package-skills/brainstate/references/simulation-environment.md +5 -5
  118. package/skills/package-skills/braintrace/SKILL.md +17 -38
  119. package/skills/package-skills/braintrace/references/Drtrl.md +9 -26
  120. package/skills/package-skills/braintrace/references/algorithm selection.md +7 -12
  121. package/skills/package-skills/braintrace/references/batching.md +15 -35
  122. package/skills/package-skills/braintrace/references/compiler_internal.md +1 -1
  123. package/skills/package-skills/braintrace/references/custom algorithms.md +1 -2
  124. package/skills/package-skills/braintrace/references/customizing_primitive_transforms.md +26 -15
  125. package/skills/package-skills/braintrace/references/pp_pprop workflow.md +5 -139
  126. package/skills/package-skills/brainunit/SKILL.md +7 -2
  127. package/skills/package-skills/brainunit/references/array-mechanics/functional-structural-api.md +1 -1
  128. package/skills/package-skills/brainunit/references/math-function-library.md +2 -2
  129. package/skills/package-skills/brainunit/references/typing-and-runtime-validation.md +5 -2
  130. package/skills/package-skills/brainevent/references/scripts/102_EI_net_1996.py +0 -107
  131. package/skills/package-skills/brainevent/references/scripts/204_joglekar_2018_propagation.py +0 -168
  132. package/skills/package-skills/brainevent/references/scripts/coba_ei_teaching.py +0 -356
  133. package/skills/package-skills/brainpy-state/SKILL.md +0 -247
  134. package/skills/package-skills/brainpy-state/references/array-creation.md +0 -158
  135. package/skills/package-skills/brainpy-state/references/brain-dynamics-delay-protocol.md +0 -147
  136. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/analysis.md +0 -150
  137. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/brainpy legacy workflow.md +0 -373
  138. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/built-in dynamic neuron model.md +0 -150
  139. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/connecting neurons.md +0 -175
  140. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/customize neuron and synpase.md +0 -286
  141. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/infrastructure/Input generation.md +0 -111
  142. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/infrastructure/More about simulation.md +0 -163
  143. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/infrastructure/Multi-device array sharding.md +0 -113
  144. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/infrastructure/Parallel experiment execution.md +0 -136
  145. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/infrastructure/array creation and mechanics.md +0 -222
  146. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/infrastructure/brainpy math environment setting.md +0 -123
  147. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/infrastructure/delays.md +0 -107
  148. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/infrastructure/object oriented transformations and control flows.md +0 -185
  149. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/integrators.md +0 -181
  150. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/route activity through connectivity.md +0 -102
  151. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/synaptic projections.md +0 -147
  152. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/synpase properties.md +0 -159
  153. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/training/loss library.md +0 -127
  154. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/training/optimizers.md +0 -167
  155. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/training/parameter initializers.md +0 -107
  156. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/training/prebuilt neural network layers.md +0 -186
  157. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/training/surrogate gradients.md +0 -104
  158. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/training/trainer library.md +0 -89
  159. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/training/trainingworkflows.md +0 -253
  160. package/skills/package-skills/brainpy-state/references/braintools/brainstate-control-flow-patterns.md +0 -334
  161. package/skills/package-skills/brainpy-state/references/braintools/connectivity.md +0 -206
  162. package/skills/package-skills/brainpy-state/references/braintools/data-preprocessing.md +0 -79
  163. package/skills/package-skills/brainpy-state/references/braintools/input-current.md +0 -199
  164. package/skills/package-skills/brainpy-state/references/braintools/metric.md +0 -152
  165. package/skills/package-skills/brainpy-state/references/braintools/optimizer.md +0 -179
  166. package/skills/package-skills/brainpy-state/references/braintools/parameter-initializer.md +0 -183
  167. package/skills/package-skills/brainpy-state/references/braintools/surrogate.md +0 -147
  168. package/skills/package-skills/brainpy-state/references/component-selection.md +0 -288
  169. package/skills/package-skills/brainpy-state/references/nest-compatible/model-library.md +0 -200
  170. package/skills/package-skills/brainpy-state/references/nest-compatible/nest-workflow.md +0 -156
  171. package/skills/package-skills/brainpy-state/references/nest-compatible/network-building.md +0 -264
  172. package/skills/package-skills/brainpy-state/references/nest-compatible/synapse-and-connectivity.md +0 -153
  173. package/skills/package-skills/brainpy-state/references/projection-patterns.md +0 -127
  174. package/skills/package-skills/brainpy-state/references/scripts/103_COBA_2005.py +0 -86
  175. package/skills/package-skills/brainpy-state/references/scripts/106_COBA_HH_2007.py +0 -181
  176. package/skills/package-skills/brainpy-state/references/scripts/107_gamma_oscillation_1996.py +0 -156
  177. package/skills/package-skills/brainpy-state/references/scripts/109_fast_global_oscillation.py +0 -111
  178. package/skills/package-skills/brainpy-state/references/scripts/201_surrogate_grad_lif_fashion_mnist.py +0 -221
  179. package/skills/package-skills/brainpy-state/references/scripts/sound_localization.py +0 -240
  180. package/skills/package-skills/brainpy-state/references/scripts/training-snn.py +0 -119
@@ -1,6 +1,6 @@
1
1
  # BrainState constrained and regularized parameters
2
2
 
3
- Use this reference after `skills/package-skills/brainstate/SKILL.md` has selected
3
+ Use this reference after `brainstate` → `SKILL.md` has selected
4
4
  `brainstate.nn.Param` for a value that needs a valid-domain transform, a
5
5
  regularization penalty, a modeling prior, or fixed parameter-like storage. It
6
6
  owns the operational workflow and common patterns. Open
@@ -20,7 +20,7 @@ Keep `brainstate.nn` parameter transforms separate from execution transforms suc
20
20
 
21
21
  ## Parameter contract
22
22
 
23
- A `ParamState` is a bare trainable array. `brainstate.nn.Param` layers two orthogonal concerns on top of it: a constraint transform and a regularization term.
23
+ A `ParamState` holds a trainable array or PyTree. `brainstate.nn.Param` layers two orthogonal concerns on top of it: a constraint transform and a regularization term.
24
24
 
25
25
  - `param.val` is the underlying `ParamState`; optimizers update its unconstrained array.
26
26
  - `param.value()` applies the forward transform and returns the constrained model-space value. With the default `IdentityT`, constrained and unconstrained values coincide.
@@ -44,6 +44,7 @@ This workflow keeps optimizer targets in unconstrained `ParamState`s, reads tran
44
44
  import brainstate
45
45
  from brainstate import nn
46
46
  import brainunit as u
47
+ import braintools
47
48
  import jax.numpy as jnp
48
49
 
49
50
 
@@ -68,6 +69,8 @@ class ConstrainedLinear(nn.Module):
68
69
 
69
70
  model = ConstrainedLinear(4, 2)
70
71
  params = model.states(brainstate.ParamState)
72
+ optimizer = braintools.optim.SGD(lr=0.1)
73
+ optimizer.register_trainable_weights(params)
71
74
  x = brainstate.random.randn(16, 4)
72
75
  y = brainstate.random.randn(16, 2)
73
76
 
@@ -81,11 +84,10 @@ def loss_fn():
81
84
  def train_step():
82
85
  grads, loss = brainstate.transform.grad(
83
86
  loss_fn,
84
- params,
87
+ grad_states=params,
85
88
  return_value=True,
86
89
  )()
87
- for key in params:
88
- params[key].value -= 0.1 * grads[key]
90
+ optimizer.update(grads)
89
91
  return loss
90
92
  ```
91
93
 
@@ -160,7 +162,7 @@ Open `parameter-transforms-regularizers-catalog.md` to select classical, structu
160
162
  Official sources:
161
163
 
162
164
  - https://brainx.chaobrain.com/brainstate/tutorials/core/05_parameters_transforms_regularization.html
163
- - https://brainx.chaobrain.com/brainstate/apis/nn/regularization.html
165
+ - https://brainx.chaobrain.com/brainstate/apis/nn/parameters.html#standard-regularizations
164
166
  - https://brainx.chaobrain.com/brainstate/apis/generated/brainstate.nn.ChainedReg.html
165
167
 
166
168
  ## Fixed values with `nn.Const`
@@ -208,6 +210,6 @@ Official sources:
208
210
  - https://brainx.chaobrain.com/brainstate/tutorials/core/05_parameters_transforms_regularization.html
209
211
  - https://brainx.chaobrain.com/brainstate/how_to/constrain_and_regularize_parameters.html
210
212
  - https://brainx.chaobrain.com/brainstate/apis/nn/parameters.html
211
- - https://brainx.chaobrain.com/brainstate/apis/nn/regularization.html
213
+ - https://brainx.chaobrain.com/brainstate/apis/nn/parameters.html#standard-regularizations
212
214
  - https://brainx.chaobrain.com/brainstate/apis/generated/brainstate.nn.Param.html
213
215
  - https://brainx.chaobrain.com/brainstate/apis/generated/brainstate.nn.Const.html
@@ -100,7 +100,7 @@ Official sources:
100
100
 
101
101
  Official sources:
102
102
 
103
- - https://brainx.chaobrain.com/brainstate/apis/nn/regularization.html
103
+ - https://brainx.chaobrain.com/brainstate/apis/nn/parameters.html#standard-regularizations
104
104
  - https://brainx.chaobrain.com/brainstate/apis/generated/brainstate.nn.Regularization.html
105
105
  - https://brainx.chaobrain.com/brainstate/apis/generated/brainstate.nn.ChainedReg.html
106
106
  - https://github.com/chaobrain/brainstate/blob/main/brainstate/nn/_regularization.py
@@ -124,7 +124,7 @@ Official sources:
124
124
 
125
125
  Use the generated class page for exact axes, reduction behavior, weights, and initialization arguments; these differ by regularizer and should not be inferred from neighboring classes.
126
126
 
127
- Official source: https://brainx.chaobrain.com/brainstate/apis/nn/regularization.html
127
+ Official source: https://brainx.chaobrain.com/brainstate/apis/nn/parameters.html#standard-regularizations
128
128
 
129
129
  ## Prior-distribution regularizer selection
130
130
 
@@ -146,7 +146,7 @@ Prior regularizers encode distributional assumptions for Bayesian-inspired param
146
146
  | Variable selection | `SpikeAndSlabReg` |
147
147
  | Probability simplex | `DirichletReg` |
148
148
 
149
- Official source: https://brainx.chaobrain.com/brainstate/apis/nn/regularization.html
149
+ Official source: https://brainx.chaobrain.com/brainstate/apis/nn/parameters.html#prior-distribution-based-regularizations
150
150
 
151
151
  ## Interaction safeguards
152
152
 
@@ -163,7 +163,7 @@ Official source: https://brainx.chaobrain.com/brainstate/apis/nn/regularization.
163
163
  ## Mirror source urls
164
164
 
165
165
  - https://brainx.chaobrain.com/brainstate/apis/nn/parameters.html
166
- - https://brainx.chaobrain.com/brainstate/apis/nn/regularization.html
166
+ - https://brainx.chaobrain.com/brainstate/apis/nn/parameters.html#standard-regularizations
167
167
  - https://brainx.chaobrain.com/brainstate/tutorials/core/05_parameters_transforms_regularization.html
168
168
  - https://brainx.chaobrain.com/brainstate/how_to/constrain_and_regularize_parameters.html
169
169
  - https://github.com/chaobrain/brainstate/blob/main/brainstate/nn/_param.py
@@ -1,6 +1,6 @@
1
1
  # Brainstate randomness and reproducibility
2
2
 
3
- Use this reference after `skills/package-skills/brainstate/SKILL.md` for advanced randomness. It covers independent streams, stochastic transforms, key control, parallel keys, replay, and checkpointing.
3
+ Use this reference after `SKILL.md` for advanced randomness. It covers independent streams, stochastic transforms, key control, parallel keys, replay, and checkpointing.
4
4
 
5
5
  The root skill owns `brainstate.random.DEFAULT` and ordinary seeding. This reference owns advanced stream and key control.
6
6
 
@@ -10,7 +10,7 @@ Use one `RandomState` per independent concern. Calls consume successive keys fro
10
10
 
11
11
  | API | Description |
12
12
  |---|---|
13
- | `RandomState(seed=...)` | Create an independent stateful random stream. |
13
+ | `RandomState(seed_or_key=None)` | Create an independent stateful random stream from a seed or key; pass a seed positionally, as below. |
14
14
  | `rng.seed(seed)` | Restart a custom stream from a seed. |
15
15
  | `rng.value` | Inspect the custom stream's current key. |
16
16
 
@@ -18,8 +18,8 @@ Use one `RandomState` per independent concern. Calls consume successive keys fro
18
18
  import brainstate
19
19
  import jax.numpy as jnp
20
20
 
21
- init_rng = brainstate.random.RandomState(seed=42)
22
- augment_rng = brainstate.random.RandomState(seed=123)
21
+ init_rng = brainstate.random.RandomState(42)
22
+ augment_rng = brainstate.random.RandomState(123)
23
23
 
24
24
  initial_weights = init_rng.randn(5)
25
25
  augmented_values = augment_rng.randn(5)
@@ -27,6 +27,8 @@ augmented_values = augment_rng.randn(5)
27
27
  assert not jnp.allclose(initial_weights, augmented_values)
28
28
  ```
29
29
 
30
+ Use the [generated `RandomState` constructor contract](https://brainx.chaobrain.com/brainstate/apis/generated/brainstate.random.RandomState.html), which names `seed_or_key`; do not copy `seed=` from the module-overview example.
31
+
30
32
  Do not pass a custom stream to the global `set_key(...)`. The sources document `rng.value` inspection and `rng.seed(...)` reseeding. They do not document restoring a saved custom-stream key.
31
33
 
32
34
  ## Stochastic calls under transforms
@@ -1,8 +1,8 @@
1
1
  # BrainState gradient and autodiff expansion
2
2
 
3
- Use this reference after `skills/package-skills/brainstate/SKILL.md` when a task needs gradient targets beyond the main skill's minimal parameter update, exact `return_value`/`has_aux` destructuring, state discovery in an arbitrary function, vector- or matrix-valued sensitivities, second derivatives, or an optimizer-integrated fitting step. The main skill owns the canonical `ParamState` collection and manual update; the parameter reference owns the choice between `ParamState` and `nn.Param`.
3
+ Use this reference after the BrainState skill's `SKILL.md` when a task needs gradient targets beyond the canonical training step, exact `return_value`/`has_aux` destructuring, state discovery in an arbitrary function, vector- or matrix-valued sensitivities, second derivatives, or an optimizer-integrated fitting step. The parameter reference owns the choice between `ParamState` and `nn.Param`.
4
4
 
5
- These three sources do not establish BrainCell solver, reset, or conductance-fitting semantics. Specialized dynamics belongs to the matching BrainCell or BrainPy-State skill; use this reference only for the source-supported autodiff contract around that computation.
5
+ These three sources do not establish BrainCell solver, reset, or conductance-fitting semantics. Specialized dynamics belongs to the matching BrainCell or BrainSpike skill; use this reference only for the source-supported autodiff contract around that computation.
6
6
 
7
7
  Official sources:
8
8
 
@@ -440,7 +440,7 @@ def train_step(x, y):
440
440
  return loss
441
441
  ```
442
442
 
443
- Return to `skills/package-skills/brainstate/SKILL.md` for the general training structure. Open `references/braintools-optimizer-reference.md` only for optimizer or scheduler selection.
443
+ Return to `SKILL.md` for the general training structure. Open `references/braintools-optimizer-reference.md` only for optimizer or scheduler selection.
444
444
 
445
445
  Official source: https://brainx.chaobrain.com/brainstate/tutorials/core/07_training_and_metrics.html
446
446
 
@@ -453,7 +453,7 @@ Official source: https://brainx.chaobrain.com/brainstate/tutorials/core/07_train
453
453
  - Choose `jacrev` versus `jacfwd` from the documented input/output-size tradeoff, and remember that `jacobian` aliases `jacrev`.
454
454
  - Do not assume only `ParamState` can receive gradients; any explicit `State` can be a sensitivity target.
455
455
  - Do not assume an attached regularizer changes fitting unless its penalty is added to the scalar loss.
456
- - Do not infer BrainCell integration, reset, unit, or solver semantics from these sources; route specialized dynamics to the matching BrainCell or BrainPy-State skill.
456
+ - Do not infer BrainCell integration, reset, unit, or solver semantics from these sources; route specialized dynamics to the matching BrainCell or BrainSpike skill.
457
457
 
458
458
  ## Mirror source urls
459
459
 
@@ -1,7 +1,7 @@
1
1
  # BrainState vmap expansion
2
2
 
3
3
  Use this reference after the minimal `brainstate.transform.vmap` example in
4
- `skills/package-skills/brainstate/SKILL.md` when argument axes, State axes, random-key policy,
4
+ `SKILL.md` when argument axes, State axes, random-key policy,
5
5
  nested mappings, or unexpected State writes require explicit control.
6
6
 
7
7
  This reference covers only behavior demonstrated by these routed official tutorials:
@@ -0,0 +1,16 @@
1
+ # Optimizers for BrainState training
2
+
3
+ Use this reference after choosing the trainable State collection and loss. The optimizer owns the update and its auxiliary State while the model owns the parameter values.
4
+
5
+ | Need | Use |
6
+ |---|---|
7
+ | A simple gradient-step baseline | Use `braintools.optim.SGD(lr=...)`. Register the `ParamState` collection once, then call `update(grads)` with the gradient PyTree for the same collection. |
8
+ | Adaptive minibatch training | Use `braintools.optim.Adam(lr=...)`. Its moments are separate from model State. Include optimizer State when saving or restoring an exact training continuation. |
9
+ | A scheduled learning rate | Choose a scheduler from the optimization API and advance it at the documented step or epoch boundary. Check the rate sequence in a short run before training. |
10
+ | An existing Optax transformation | Use the documented BrainTools bridge and keep the same registered gradient and parameter PyTrees. |
11
+ | Standalone SciPy or Nevergrad fitting | Use the active model package's fitting workflow. These wrappers own a search over explicit candidates and use a different lifecycle from `register_trainable_weights()` and `update()`. |
12
+
13
+ Open `brainstate` → `SKILL.md` for the compiled training step. Register after constructing the model and before tracing the step. Preserve both the State paths and the nested value structure. Keep optimizer moments across training steps and start with fresh optimizer State for independent candidates.
14
+
15
+ - [BrainTools optimization API](https://brainx.chaobrain.com/braintools/apis/optim.html)
16
+ - [BrainState training tutorial](https://brainx.chaobrain.com/brainstate/tutorials/core/07_training_and_metrics.html)
@@ -130,7 +130,7 @@ feature_extractor = nn.Sequential(
130
130
  )
131
131
  ```
132
132
 
133
- Open `skills/package-skills/brainstate/scripts/modern_cnn.py` for the full convolution,
133
+ Open `scripts/modern_cnn.py` for the full convolution,
134
134
  normalization, pooling, dropout, and dense workflow.
135
135
 
136
136
  ## Official sources
@@ -12,13 +12,13 @@ Sources:
12
12
 
13
13
  Put values that describe the run, rather than one Module, in `brainstate.environ`. The environment is a stack of settings:
14
14
 
15
- - `set()` installs a persistent default that remains active until changed or reset.
16
- - `context()` pushes temporary values and restores the previous values on exit, including exceptional exit.
15
+ - In BrainState `0.6.0`, `set()` installs a persistent default on the selected environment object. Every thread using that object sees the default until it changes or resets.
16
+ - `context()` pushes temporary overrides for the calling thread and restores the previous values on exit, including exceptional exit.
17
17
  - `get(key, default=...)` searches the active context before persistent settings; it returns the value or explicit default and otherwise raises `KeyError`.
18
18
  - Typed accessors such as `get_dt()`, `get_precision()`, and `get_platform()` enforce the corresponding setting contract.
19
19
  - A nested context inherits its outer context and overrides only the keys it supplies.
20
20
 
21
- Do not treat `EnvironmentState` as model `State`. It stores thread-local environment configuration and does not belong in a Module graph or State collection.
21
+ Keep `EnvironmentState` outside Module graphs and State collections. A separate object has its own defaults and per-thread override stack.
22
22
 
23
23
  Choose the narrowest lifetime:
24
24
 
@@ -27,9 +27,9 @@ Choose the narrowest lifetime:
27
27
  | One simulation, training phase, evaluation phase, or step | `brainstate.environ.context(...)` |
28
28
  | A persistent default in the selected environment | `brainstate.environ.set(...)` |
29
29
  | The same context on every call to one Module | Use `brainstate.nn.EnvironContext(layer, **context)`; the wrapper executes the Module with the stored settings, merges optional call-specific settings, and returns the Module's result |
30
- | Configuration isolated from the default environment | Create `brainstate.environ.EnvironmentState()` and pass it through every `env=` argument; operations then use its independent thread-local setting stack instead of the default environment |
30
+ | Configuration isolated from the default environment | Create `brainstate.environ.EnvironmentState()` and pass it through every `env=` argument so operations use that object's defaults and overrides. |
31
31
 
32
- Prefer `context()` for normal simulation and training. Use `set()` only when later code should intentionally inherit the setting.
32
+ Prefer `context()` for normal simulation and training. Set a separate context inside each worker when concurrent runs need different `dt` values.
33
33
 
34
34
  ## Advanced environment configuration
35
35
 
@@ -13,9 +13,9 @@ Follow this path:
13
13
 
14
14
  `build with braintrace.nn -> choose a trace representation -> compile once -> inspect -> reset both State systems -> accumulate sequence gradients -> update once -> verify`
15
15
 
16
- This skill targets BrainTrace `0.2.4`, bundled by BrainX `v2026.7.9`. Do not use `etrace_grad()`, `etrace_evolve()`, `SequenceDriverMixin`, or `ETraceVmap`; those APIs start in BrainTrace `0.2.5`.
16
+ Use this workflow with BrainTrace `0.2.8`, bundled by BrainX `2026.10.25`.
17
17
 
18
- Route general `State`, `Module`, transformations, mapped lifecycle operations, and optimizers to BrainState. Route neuron and synapse dynamics to BrainPy-State or BrainCell. Use ordinary BrainState training when offline BPTT is acceptable.
18
+ Route general `State`, `Module`, transformations, mapped lifecycle operations, and optimizers to BrainState. Route neuron and synapse dynamics to BrainSpike or BrainCell. Use ordinary BrainState training when offline BPTT is acceptable.
19
19
 
20
20
  ## Underlying principle of BrainTrace
21
21
 
@@ -86,18 +86,17 @@ Open `references/pre-built-braintrace-layer.md` when selecting another ETP-aware
86
86
 
87
87
  ## Train and evaluate a sequence
88
88
 
89
- Differentiate exactly one learner call per time step, carry the accumulated gradient through `brainstate.transform.scan`, and update parameters once after the sequence.
89
+ Use the learner to drive time. Each step loss calls the learner once, and the optimizer applies the accumulated gradient after the sequence.
90
90
 
91
91
  | API | Description |
92
92
  |---|---|
93
93
  | `brainstate.nn.reset_all_states(model, batch_size=...)` | Use at an independent sequence boundary to reset recurrent State. |
94
94
  | `learner.reset_state(batch_size=...)` | Use at the same boundary to reset eligibility State and the running index. |
95
- | `brainstate.transform.grad(step_loss, weights, ...)` | Use around one learner call; BrainTrace supplies the online parameter gradient from current eligibility State. |
96
- | `brainstate.transform.scan(body, initial_grads, sequence)` | Use to advance time and sum per-step gradients in an explicit carry. |
95
+ | `learner.etrace_grad(*sequences, step_fn=..., reduction=..., return_value=True)` | Use to advance hidden and eligibility State while accumulating online gradients and returning step losses. Choose the gradient reduction explicitly. |
96
+ | `learner.etrace_evolve(inputs, return_outputs=True)` | Use for evaluation or warm-up. It advances both State systems without accumulating gradients. |
97
97
  | `optimizer.update(grads)` | Use once after the complete sequence gradient has been accumulated. |
98
98
 
99
99
  ```python
100
- import jax
101
100
  import braintools
102
101
 
103
102
  targets = 0.7 * inputs + 0.2
@@ -115,33 +114,14 @@ def step_loss(x, target):
115
114
  return jnp.mean((learner(x) - target) ** 2)
116
115
 
117
116
 
118
- loss_grad = brainstate.transform.grad(
119
- step_loss,
120
- weights,
121
- return_value=True,
122
- )
123
-
124
-
125
117
  def train_epoch(_):
126
118
  reset_sequence()
127
- initial_grads = jax.tree.map(
128
- jnp.zeros_like,
129
- {key: state.value for key, state in weights.items()},
130
- )
131
-
132
- def accumulate(grads, sample):
133
- step_grads, loss = loss_grad(*sample)
134
- grads = jax.tree.map(
135
- lambda total, value: total + value,
136
- grads,
137
- step_grads,
138
- )
139
- return grads, loss
140
-
141
- grads, losses = brainstate.transform.scan(
142
- accumulate,
143
- initial_grads,
144
- (inputs, targets),
119
+ grads, losses = learner.etrace_grad(
120
+ inputs,
121
+ targets,
122
+ step_fn=step_loss,
123
+ reduction='sum',
124
+ return_value=True,
145
125
  )
146
126
  optimizer.update(grads)
147
127
  return losses.mean()
@@ -149,7 +129,7 @@ def train_epoch(_):
149
129
 
150
130
  losses = brainstate.transform.for_loop(train_epoch, jnp.arange(5))
151
131
  reset_sequence()
152
- predictions = brainstate.transform.for_loop(learner, inputs)
132
+ predictions = learner.etrace_evolve(inputs, return_outputs=True)
153
133
 
154
134
  assert losses[-1] < losses[0]
155
135
  assert predictions.shape == targets.shape
@@ -164,14 +144,14 @@ Escalate model construction from prebuilt layers to built-in ETP operations, the
164
144
  | Reference | Open when | Contains |
165
145
  |---|---|---|
166
146
  | `references/pre-built-braintrace-layer.md` | Selecting another ETP-aware layer or composing the default model. | Layer families, parameterized-operation choices, and BrainState-owned supporting layers. |
167
- | `references/Drtrl.md` | Using or validating parameter-shaped D-RTRL traces. | Memory scaling, recurrence, sequence resets, scan accumulation, and the BPTT boundary. |
147
+ | `references/Drtrl.md` | Using or validating parameter-shaped D-RTRL traces. | Memory scaling, recurrence, sequence resets, sequence drivers, and the BPTT boundary. |
168
148
  | `references/pp_pprop workflow.md` | Parameter-shaped traces are too costly or a recurrent SNN needs factorized traces. | Input/output factorization, SNN integration, report-window training, and validation. |
169
- | `references/algorithm selection.md` | Neither canonical memory strategy fits the estimator requirements. | BrainTrace `0.2.4` estimators, guarantees, and configuration options. |
170
- | `references/batching.md` | Adding a batch axis, mapped model, or multi-step wrapper. | Mapping ownership, batched compilation, mapped resets, and sequence scan shape. |
149
+ | `references/algorithm selection.md` | Neither canonical memory strategy fits the estimator requirements. | Public estimators, guarantees, and configuration options. |
150
+ | `references/batching.md` | Adding a batch axis, mapped model, or multi-step wrapper. | Mapping ownership, batched compilation, mapped resets, and time-major shapes. |
171
151
  | `references/ETP operators.md` | A prebuilt layer cannot express the required parameterized operation. | Built-in ETP operations, participation rules, sparse inputs, units, and transform behavior. |
172
152
  | `references/custom ETP primitives.md` | No built-in ETP operation can express the computation. | Primitive registration, ETP rules, compiler integration, and validation. |
173
153
  | `references/customizing_primitive_transforms.md` | An ETP weight needs masking, constraints, normalization, LoRA, or a bias transform. | Transform hooks and raw-parameter gradient attachment. |
174
- | `references/custom algorithms.md` | No built-in BrainTrace `0.2.4` algorithm expresses the research method. | Estimator bases, trace lifecycle, solve hooks, and inspection. |
154
+ | `references/custom algorithms.md` | No built-in algorithm expresses the research method. | Estimator bases, trace lifecycle, solve hooks, and inspection. |
175
155
  | `references/compiler_internal.md` | Structured report fields cannot explain custom graph behavior. | Discovery, graph execution, control-flow policy, and low-level diagnostics. |
176
156
 
177
157
  ## Boundaries and common failures
@@ -182,6 +162,5 @@ Escalate model construction from prebuilt layers to built-in ETP operations, the
182
162
  - Do not treat every warning or excluded candidate as a failed parameter. Inspect `etrace_weights`, `excluded_weights`, and level-2 diagnostics together.
183
163
  - Reset both recurrent State and eligibility State between independent sequences and verify mapped shapes survive a mapped reset.
184
164
  - Use exactly one batching owner. Prefer `braintrace.compile(..., vmap=True)` for independent per-sample State or native batched compilation when the model supports it.
185
- - Do not update the optimizer inside the temporal scan when the intended schedule is one update per sequence.
186
- - Do not use BrainTrace `0.2.5` sequence-driver APIs with the bundled `0.2.4` release.
165
+ - Update the optimizer after `etrace_grad` returns when the schedule calls for one update per sequence.
187
166
  - Use `pp_prop` in new code; `ES_D_RTRL` is its compatibility alias.
@@ -1,6 +1,6 @@
1
1
  # D-RTRL
2
2
 
3
- Use this reference when implementing or validating the parameter-dimensional D-RTRL workflow in BrainTrace `0.2.4`. Open `algorithm selection.md` when choosing another estimator and `batching.md` before adding a batch axis.
3
+ Use this reference when implementing or validating the parameter-dimensional D-RTRL workflow. Open `algorithm selection.md` when choosing another estimator and `batching.md` before adding a batch axis.
4
4
 
5
5
  ## Understand the approximation
6
6
 
@@ -10,8 +10,7 @@ Use this reference when implementing or validating the parameter-dimensional D-R
10
10
  |---|---|
11
11
  | `braintrace.D_RTRL` | Use when parameter-shaped trace memory is feasible; it computes approximate online gradients without retaining the full sequence graph. |
12
12
  | `braintrace.compile(model, braintrace.D_RTRL, example_step, ...)` | Use once to initialize State, construct the learner, and compile the ETP graph from a representative step. |
13
- | `brainstate.transform.grad(step_loss, weights, ...)` | Use around exactly one learner call to obtain the current online parameter gradient. |
14
- | `brainstate.transform.scan(body, initial_grads, sequence)` | Use to carry the summed gradient across time while the learner advances hidden and eligibility State. |
13
+ | `learner.etrace_grad(..., step_fn=..., reduction=...)` | Use to accumulate online gradients across one sequence. |
15
14
 
16
15
  Trace memory scales as `O(B * |theta|)`, where `B` is batch size and `theta` is the participating parameter set. Do not describe D-RTRL as generally identical to BPTT; equality depends on the recurrence and mathematical regime being tested.
17
16
 
@@ -25,11 +24,10 @@ Reset recurrent and eligibility State together, accumulate gradients across the
25
24
  | 2. Compile | Call `braintrace.compile(...)` once with one real per-step input. | The graph and State layout are reused. |
26
25
  | 3. Inspect | Show report level 2 and inspect structured participation fields. | Intended recurrent weights are confirmed rather than inferred from warning text. |
27
26
  | 4. Reset | Reset model State and learner State at every independent sequence. | Hidden State, eligibility traces, and running index share one boundary. |
28
- | 5. Accumulate | Differentiate one learner call inside a `scan` with an explicit gradient carry. | Every time step advances online State while gradients sum across time. |
29
- | 6. Update | Clip if needed and call the optimizer once after the scan. | The printed sequence count matches the optimizer schedule. |
27
+ | 5. Accumulate | Call `etrace_grad` with one learner call per step loss. | Every time step advances online State while gradients sum across time. |
28
+ | 6. Update | Clip if needed and call the optimizer once after the sequence. | The printed sequence count matches the optimizer schedule. |
30
29
 
31
30
  ```python
32
- import jax
33
31
  import jax.numpy as jnp
34
32
  import brainstate
35
33
  import braintrace
@@ -71,25 +69,10 @@ def step_loss(x, target):
71
69
  return jnp.mean((learner(x) - target) ** 2)
72
70
 
73
71
 
74
- loss_grad = brainstate.transform.grad(step_loss, weights, return_value=True)
75
-
76
-
77
72
  def train_sequence():
78
73
  reset_sequence()
79
- initial_grads = jax.tree.map(
80
- jnp.zeros_like,
81
- {key: state.value for key, state in weights.items()},
82
- )
83
-
84
- def accumulate(grads, sample):
85
- step_grads, loss = loss_grad(*sample)
86
- grads = jax.tree.map(lambda x, y: x + y, grads, step_grads)
87
- return grads, loss
88
-
89
- grads, losses = brainstate.transform.scan(
90
- accumulate,
91
- initial_grads,
92
- (inputs, targets),
74
+ grads, losses = learner.etrace_grad(
75
+ inputs, targets, step_fn=step_loss, reduction='sum', return_value=True,
93
76
  )
94
77
  optimizer.update(grads)
95
78
  return losses.mean()
@@ -99,7 +82,7 @@ loss = train_sequence()
99
82
  assert jnp.isfinite(loss)
100
83
  ```
101
84
 
102
- Hoist `loss_grad` outside the scan body. Apply a temporal loss mask inside `step_loss` when only selected steps produce learning signals; still call the learner on every step so hidden and eligibility State advance throughout the sequence.
85
+ Pass a time-major `mask` to `etrace_grad` when only selected steps contribute to the loss. The learner still advances both State systems at masked steps.
103
86
 
104
87
  ## Reset both State domains
105
88
 
@@ -129,5 +112,5 @@ Use a reduced matched task as a BPTT oracle only when the estimator's documented
129
112
 
130
113
  ## Sources
131
114
 
132
- - [BrainTrace `v0.2.4` D-RTRL examples](https://github.com/chaobrain/braintrace/tree/v0.2.4/examples/drtrl)
133
- - [BrainTrace `v0.2.4` algorithms API source](https://github.com/chaobrain/braintrace/blob/v0.2.4/docs/apis/algorithms.rst)
115
+ - [D-RTRL tutorial](https://brainx.chaobrain.com/braintrace/tutorials/drtrl.html)
116
+ - [Algorithms API](https://brainx.chaobrain.com/braintrace/apis/algorithms.html)
@@ -1,6 +1,6 @@
1
1
  # Algorithm selection
2
2
 
3
- Use this reference when choosing a BrainTrace `0.2.4` estimator beyond the default `D_RTRL`. Use `Drtrl.md` or `pp_pprop workflow.md` for the two canonical training workflows; open `custom algorithms.md` only when no built-in class expresses the method.
3
+ Use this reference when choosing a BrainTrace estimator beyond the default `D_RTRL`. Use `Drtrl.md` or `pp_pprop workflow.md` for the two canonical training workflows; open `custom algorithms.md` only when no built-in class expresses the method.
4
4
 
5
5
  ## Choose an estimator
6
6
 
@@ -17,8 +17,6 @@ Choose by trace representation, recurrence approximation, learning signal, and s
17
17
  | `OTTT` | Use for very large SNNs using the implemented presynaptic trace rule. | Requires `leak`; report the selected mode. |
18
18
  | `OSTTP` | Use for target-projection learning with supplied per-layer feedback matrices. | Requires `B_list`; declare target timing. |
19
19
 
20
- `SnAp`, `UORO`, `ThreeFactor`, `DNI`, `SyntheticGradient`, and `ETraceConfig` are not public BrainTrace `0.2.4` APIs. Do not select them from newer documentation when targeting BrainX `v2026.7.9`.
21
-
22
20
  ## Compile the chosen algorithm
23
21
 
24
22
  `braintrace.compile` is the shared entry point; options are forwarded to the selected algorithm constructor.
@@ -45,20 +43,17 @@ learner = braintrace.compile(
45
43
  learner.module.report.show(2)
46
44
  ```
47
45
 
48
- ## Drive the sequence in `0.2.4`
49
-
50
- BrainTrace `0.2.4` advances hidden and eligibility State on every learner call; BrainState owns the explicit temporal carry and gradient accumulation.
46
+ ## Drive the sequence
51
47
 
52
48
  | API | Description |
53
49
  |---|---|
54
- | `brainstate.transform.grad(step_loss, weights, ...)` | Use around one learner call to obtain the current online gradient. |
55
- | `brainstate.transform.scan(...)` | Use when an explicit gradient carry must sum across time. |
56
- | `braintrace.SingleStepData(data)` | Use to mark one current input; a plain array is equivalent. |
50
+ | `learner.etrace_grad(..., step_fn=...)` | Use for online sequence gradients. Call the learner once per step loss. |
51
+ | `learner.etrace_evolve(inputs, ...)` | Use for warm-up or evaluation that advances State without accumulating gradients. |
52
+ | `braintrace.SingleStepData(data)` | Use to mark one current input. |
57
53
  | `braintrace.MultiStepData(sequence)` | Use when one learner call intentionally consumes a multi-step window. |
58
54
 
59
- Do not use `etrace_grad`, `etrace_evolve`, `SequenceDriverMixin`, or `ETraceVmap`; they start in BrainTrace `0.2.5`. Open `batching.md` for mapped and native-batch reset patterns.
55
+ Open `batching.md` for mapped and native-batch reset patterns.
60
56
 
61
57
  ## Sources
62
58
 
63
- - [BrainTrace `v0.2.4` algorithms API source](https://github.com/chaobrain/braintrace/blob/v0.2.4/docs/apis/algorithms.rst)
64
- - [BrainTrace `v0.2.4` public API](https://github.com/chaobrain/braintrace/blob/v0.2.4/braintrace/__init__.py)
59
+ - [Algorithms API](https://brainx.chaobrain.com/braintrace/apis/algorithms.html)
@@ -1,6 +1,6 @@
1
1
  # Batching
2
2
 
3
- Use this reference when adding a batch axis to BrainTrace `0.2.4`, selecting native batched execution or independent mapped lanes, resetting mapped State, or scanning time-major data.
3
+ Use this reference when adding a batch axis, selecting native batched execution or independent mapped lanes, resetting mapped State, or scanning time-major data.
4
4
 
5
5
  ## Choose one batching owner
6
6
 
@@ -25,7 +25,6 @@ Compile-owned vmap creates per-lane State and returns a `brainstate.nn.Vmap`; it
25
25
  | `brainstate.transform.vmap(in_states=mapped_states)` | Use to map reset over exactly the State created by compile-owned vmap. |
26
26
 
27
27
  ```python
28
- import jax
29
28
  import jax.numpy as jnp
30
29
  import brainstate
31
30
  import braintrace
@@ -34,7 +33,7 @@ import braintrace
34
33
  class SimpleGRU(brainstate.nn.Module):
35
34
  def __init__(self, n_in, n_rec, n_out):
36
35
  super().__init__()
37
- self.rnn = braintrace.nn.GRUCell(n_in, n_rec)
36
+ self.rnn = braintrace.nn.MiniGRU(in_size=n_in, out_size=n_rec)
38
37
  self.out = braintrace.nn.Linear(n_rec, n_out)
39
38
 
40
39
  def update(self, x):
@@ -82,41 +81,23 @@ Reset native batched execution with `brainstate.nn.reset_all_states(model, batch
82
81
 
83
82
  ## Accumulate time-major gradients
84
83
 
85
- Keep time on axis 0 and batch on axis 1. The scan owns time; compilation owns batch.
84
+ Keep time on axis 0 and batch on axis 1. The sequence driver owns time. Compilation owns the batch axis.
86
85
 
87
86
  ```python
88
- weights = model.states(brainstate.ParamState)
89
-
90
-
91
- def step_loss(inp, target, mask):
87
+ def step_loss(inp, target):
92
88
  prediction = mapped_learner(inp)
93
- loss = jnp.mean((prediction - target) ** 2)
94
- return loss * mask, prediction
89
+ return jnp.mean((prediction - target) ** 2), prediction
95
90
 
96
91
 
97
- step_grad = brainstate.transform.grad(
98
- step_loss,
99
- weights,
92
+ grads, losses, outputs = mapped_learner.etrace_grad(
93
+ inputs,
94
+ targets,
95
+ step_fn=step_loss,
100
96
  has_aux=True,
97
+ mask=loss_mask,
98
+ reduction='sum',
101
99
  return_value=True,
102
100
  )
103
-
104
-
105
- def accumulate(grads, sample):
106
- current, loss, prediction = step_grad(*sample)
107
- grads = jax.tree.map(lambda total, value: total + value, grads, current)
108
- return grads, (loss, prediction)
109
-
110
-
111
- initial_grads = jax.tree.map(
112
- jnp.zeros_like,
113
- {key: state.value for key, state in weights.items()},
114
- )
115
- grads, (losses, outputs) = brainstate.transform.scan(
116
- accumulate,
117
- initial_grads,
118
- (inputs, targets, loss_mask),
119
- )
120
101
  optimizer.update(grads)
121
102
  ```
122
103
 
@@ -129,12 +110,11 @@ Every step must call the learner exactly once, including masked cue and delay st
129
110
  | `braintrace.SingleStepData(data)` | Use to mark `data` as one step; a plain array has the same interpretation. |
130
111
  | `braintrace.MultiStepData(sequence)` | Use when one learner call should consume axis 0 as a multi-step window. |
131
112
 
132
- Do not use `MultiStepData` as a substitute for the explicit scan when the workflow needs per-step masks, outputs, losses, or a gradient sum followed by one optimizer update.
113
+ Use `etrace_grad` for a sequence with per-step masks, outputs, or a single accumulated gradient update.
133
114
 
134
- Open `Drtrl.md` or `pp_pprop workflow.md` for estimator-specific training. Open `skills/package-skills/brainstate/references/collective_model_operations.md` when an explicit mapped lifecycle is unavoidable.
115
+ Open `Drtrl.md` or `pp_pprop workflow.md` for estimator-specific training. Open `brainstate` → `references/collective_model_operations.md` when an explicit mapped lifecycle is unavoidable.
135
116
 
136
117
  ## Sources
137
118
 
138
- - [BrainTrace `v0.2.4` compile modes](https://github.com/chaobrain/braintrace/blob/v0.2.4/examples/tests/test_compile_modes.py)
139
- - [BrainTrace `v0.2.4` mapped batching example](https://github.com/chaobrain/braintrace/blob/v0.2.4/examples/pp_prop/05-batching-vmap.py)
140
- - [BrainTrace `v0.2.4` native batching example](https://github.com/chaobrain/braintrace/blob/v0.2.4/examples/pp_prop/06-batching-batched.py)
119
+ - [Batching strategies](https://brainx.chaobrain.com/braintrace/advanced/batching.html)
120
+ - [Algorithms API](https://brainx.chaobrain.com/braintrace/apis/algorithms.html)
@@ -114,7 +114,7 @@ The graph executor runs the compiled forward graph and produces the hidden-to-we
114
114
  | `ETraceGraphExecutor` | Use as the base executor when developing a custom algorithm that consumes an `ETraceGraph`. It runs the forward graph and exposes its Jacobian calculations. |
115
115
  | `ETraceVjpGraphExecutor` | Use for algorithms in the `ETraceVjpAlgorithm` family. It provides the VJP-based executor used by the built-in estimators. |
116
116
 
117
- Keep executor calls inside the algorithm lifecycle. Application code should call the compiled learner inside a BrainState loop or scan rather than driving the executor directly. In BrainTrace `0.2.4`, use `brainstate.transform.grad` around one learner call and carry accumulated gradients through `brainstate.transform.scan`; sequence-driver methods begin in `0.2.5`.
117
+ Keep executor calls inside the algorithm lifecycle. Application code should use the compiled learner’s sequence drivers. Use `etrace_grad` to accumulate online gradients and `etrace_evolve` to advance State without accumulating gradients.
118
118
 
119
119
  ## Control-flow policy
120
120
 
@@ -191,12 +191,11 @@ assert int(learner.running_index.value) == 0
191
191
  ## Execution and validation rules
192
192
 
193
193
  - Compile the custom algorithm once for a stable model structure; do not rebuild it per step.
194
- - Differentiate exactly one learner call per step and use `brainstate.transform.scan` when gradients must be accumulated across a sequence. Apply the optimizer after the scan.
194
+ - Call the learner exactly once per step and accumulate online gradients with `learner.etrace_grad`. Apply the optimizer once after the sequence.
195
195
  - Compare an unmodified subclass against its parent before testing the new rule.
196
196
  - Verify trace shapes, finite values, reset-to-zero behavior, parameter-gradient keys, and parameter updates.
197
197
  - Use a reduced BPTT oracle only in a regime where the parent estimator documents equivalence. `D_RTRL` uses a diagonal recurrent-Jacobian approximation and is not generally equal to BPTT.
198
198
  - Do not reimplement graph tracing, hidden grouping, Jacobian calculation, or State write-back unless the research method genuinely requires a new base engine.
199
- - This reference targets BrainTrace `0.2.4`; do not use sequence-driver methods introduced in `0.2.5`.
200
199
 
201
200
  ## Sources
202
201