brainx-skill 1.0.12 → 1.0.13

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 (194) hide show
  1. package/README.md +4 -0
  2. package/installation/lib/bundle.js +51 -13
  3. package/manifest.json +2 -0
  4. package/mcp-servers/codex/README.md +62 -0
  5. package/mcp-servers/codex/UPSTREAM.md +20 -0
  6. package/mcp-servers/codex/server.mjs +140 -0
  7. package/mcp-servers/codex/skills.json +10 -0
  8. package/mcp-servers/codex/system-prompt.md +62 -0
  9. package/mcp-servers/codex/test/fixtures/fake-codex.mjs +6 -0
  10. package/mcp-servers/codex/test/server.test.mjs +88 -0
  11. package/package.json +6 -9
  12. package/skills/brainx-acceleration/SKILL.md +459 -0
  13. package/skills/brainx-general-guard/SKILL.md +14 -9
  14. package/skills/brainx-modeling-loop/SKILL.md +268 -0
  15. package/skills/brainx-modeling-loop/agents/openai.yaml +4 -0
  16. package/skills/brainx-modeling-loop/references/monitor-experiment.md +49 -0
  17. package/skills/brainx-modeling-loop/references/parameter-fitting-workflow/scripts/fitting_hh_neuron.py +254 -0
  18. package/skills/brainx-modeling-loop/references/parameter-fitting-workflow.md +232 -0
  19. package/skills/brainx-modeling-loop/references/run-experiment.md +179 -0
  20. package/skills/brainx-modeling-loop/references/training-workflow.md +270 -0
  21. package/skills/{braincell → package-skills/braincell}/SKILL.md +2 -1
  22. package/skills/{braincell → package-skills/braincell}/references/multicompartment/multicompartment-cell-workflow.md +2 -2
  23. package/skills/package-skills/braincell/references/scripts/fitting_hh_neuron.py +254 -0
  24. package/skills/{brainmass → package-skills/brainmass}/references/brainstate/parameter-constraints-regularization.md +1 -1
  25. package/skills/{brainmass → package-skills/brainmass}/references/coupling-network-api.md +121 -3
  26. package/skills/{brainmass → package-skills/brainmass}/references/modellibrary.md +79 -1
  27. package/skills/package-skills/brainmass/references/parameter-sweeps-and-regime-analysis.md +188 -0
  28. package/skills/{brainmass → package-skills/brainmass}/references/visualization-analysis-api.md +6 -6
  29. package/skills/{brainpy-state → package-skills/brainpy-state}/SKILL.md +4 -3
  30. package/skills/{brainpy-state → package-skills/brainpy-state}/references/braintools/connectivity.md +1 -1
  31. package/skills/{brainpy-state → package-skills/brainpy-state}/references/braintools/input-current.md +1 -1
  32. package/skills/package-skills/brainpy-state/references/perturbation-experiment-validity.md +76 -0
  33. package/skills/{brainpy-state → package-skills/brainpy-state}/references/projection-patterns.md +1 -1
  34. package/skills/{brainstate → package-skills/brainstate}/SKILL.md +1 -0
  35. package/skills/{brainstate → package-skills/brainstate}/references/brainstate/brainstate-transformed-diagnostics.md +1 -1
  36. package/skills/{brainstate → package-skills/brainstate}/references/brainstate/parameter-constraints-regularization.md +1 -1
  37. package/skills/{brainstate → package-skills/brainstate}/references/brainstate/randomness-and-reproducibility.md +1 -1
  38. package/skills/{brainstate → package-skills/brainstate}/references/brainstate/transformation-grad-expansion.md +2 -2
  39. package/skills/{brainstate → package-skills/brainstate}/references/brainstate/transformation-vmap-expansion.md +1 -1
  40. package/skills/{brainstate → package-skills/brainstate}/references/libraries/prebuilt-layer-library.md +1 -1
  41. package/skills/package-skills/brainstate/references/paired-perturbation-execution.md +113 -0
  42. package/skills/package-skills/braintrace/SKILL.md +187 -0
  43. package/skills/package-skills/braintrace/references/Drtrl.md +133 -0
  44. package/skills/{braintrace → package-skills/braintrace}/references/ETP operators.md +31 -4
  45. package/skills/package-skills/braintrace/references/algorithm selection.md +64 -0
  46. package/skills/package-skills/braintrace/references/batching.md +140 -0
  47. package/skills/{braintrace → package-skills/braintrace}/references/compiler_internal.md +2 -2
  48. package/skills/{braintrace → package-skills/braintrace}/references/custom algorithms.md +8 -10
  49. package/skills/package-skills/braintrace/references/pp_pprop workflow.md +179 -0
  50. package/skills/{braintrace → package-skills/braintrace}/references/pre-built-braintrace-layer.md +2 -2
  51. package/skills/brainmass/references/parameter-sweeps-and-regime-analysis.md +0 -130
  52. package/skills/braintrace/SKILL.md +0 -161
  53. package/skills/braintrace/references/Drtrl.md +0 -179
  54. package/skills/braintrace/references/algorithm selection.md +0 -120
  55. package/skills/braintrace/references/batching.md +0 -150
  56. package/skills/braintrace/references/pp_pprop workflow.md +0 -196
  57. /package/skills/{braincell → package-skills/braincell}/references/area-scaled-hh-pattern.md +0 -0
  58. /package/skills/{braincell → package-skills/braincell}/references/braincell-custom-ion-channel-authoring.md +0 -0
  59. /package/skills/{braincell → package-skills/braincell}/references/channel-library.md +0 -0
  60. /package/skills/{braincell → package-skills/braincell}/references/ion-library.md +0 -0
  61. /package/skills/{braincell → package-skills/braincell}/references/mixions-for-adaptation.md +0 -0
  62. /package/skills/{braincell → package-skills/braincell}/references/multicompartment/braincell-manual-morphology-construction.md +0 -0
  63. /package/skills/{braincell → package-skills/braincell}/references/multicompartment/cv-policy-reference.md +0 -0
  64. /package/skills/{braincell → package-skills/braincell}/references/multicompartment/filter-function-library.md +0 -0
  65. /package/skills/{braincell → package-skills/braincell}/references/multicompartment/morphology-io-loading-validation.md +0 -0
  66. /package/skills/{braincell → package-skills/braincell}/references/multicompartment/probe-reference.md +0 -0
  67. /package/skills/{braincell → package-skills/braincell}/references/multicompartment/topology-building-and-visualization.md +0 -0
  68. /package/skills/{braincell → package-skills/braincell}/references/scripts/calcium_channel_gating.py +0 -0
  69. /package/skills/{braincell → package-skills/braincell}/references/scripts/cell_multicompartment_reference.py +0 -0
  70. /package/skills/{braincell → package-skills/braincell}/references/scripts/channel_ablation.py +0 -0
  71. /package/skills/{braincell → package-skills/braincell}/references/scripts/fi_curve.py +0 -0
  72. /package/skills/{braincell → package-skills/braincell}/references/scripts/hh_neuron_basics.py +0 -0
  73. /package/skills/{braincell → package-skills/braincell}/references/scripts/spike_frequency_adaptation.py +0 -0
  74. /package/skills/{braincell → package-skills/braincell}/references/scripts/t_current_rebound.py +0 -0
  75. /package/skills/{braincell → package-skills/braincell}/references/scripts/thalamic_neurons.py +0 -0
  76. /package/skills/{braincell → package-skills/braincell}/references/solver-library-with-effects.md +0 -0
  77. /package/skills/{brainevent → package-skills/brainevent}/SKILL.md +0 -0
  78. /package/skills/{brainevent → package-skills/brainevent}/references/connectivity-variants.md +0 -0
  79. /package/skills/{brainevent → package-skills/brainevent}/references/custom-operators-cpu.md +0 -0
  80. /package/skills/{brainevent → package-skills/brainevent}/references/custom-operators-gpu.md +0 -0
  81. /package/skills/{brainevent → package-skills/brainevent}/references/scripts/102_EI_net_1996.py +0 -0
  82. /package/skills/{brainevent → package-skills/brainevent}/references/scripts/204_joglekar_2018_propagation.py +0 -0
  83. /package/skills/{brainevent → package-skills/brainevent}/references/scripts/coba_ei_teaching.py +0 -0
  84. /package/skills/{brainevent → package-skills/brainevent}/references/sparse-formats.md +0 -0
  85. /package/skills/{brainevent → package-skills/brainevent}/references/synaptic-plasticity.md +0 -0
  86. /package/skills/{brainmass → package-skills/brainmass}/SKILL.md +0 -0
  87. /package/skills/{brainmass → package-skills/brainmass}/references/batch-transform-acceleration.md +0 -0
  88. /package/skills/{brainmass → package-skills/brainmass}/references/brainstate/parameter-transforms-regularizers-catalog.md +0 -0
  89. /package/skills/{brainmass → package-skills/brainmass}/references/braintools/cogtask.md +0 -0
  90. /package/skills/{brainmass → package-skills/brainmass}/references/braintools/data-preprocessing.md +0 -0
  91. /package/skills/{brainmass → package-skills/brainmass}/references/braintools/metric.md +0 -0
  92. /package/skills/{brainmass → package-skills/brainmass}/references/braintools/optimizer.md +0 -0
  93. /package/skills/{brainmass → package-skills/brainmass}/references/braintools/parameter-initializer.md +0 -0
  94. /package/skills/{brainmass → package-skills/brainmass}/references/braintools/surrogate.md +0 -0
  95. /package/skills/{brainmass → package-skills/brainmass}/references/datasets-api.md +0 -0
  96. /package/skills/{brainmass → package-skills/brainmass}/references/fitting-with-objectives-api.md +0 -0
  97. /package/skills/{brainmass → package-skills/brainmass}/references/forward-observation-api.md +0 -0
  98. /package/skills/{brainmass → package-skills/brainmass}/references/horn-task-training.md +0 -0
  99. /package/skills/{brainmass → package-skills/brainmass}/references/noiseprocesses.md +0 -0
  100. /package/skills/{brainmass → package-skills/brainmass}/references/scripts/eeg-fitting-with-gradients.py +0 -0
  101. /package/skills/{brainmass → package-skills/brainmass}/references/scripts/gradient-free-fitting.py +0 -0
  102. /package/skills/{brainmass → package-skills/brainmass}/references/scripts/hopf-bifurcation-single-node.py +0 -0
  103. /package/skills/{brainmass → package-skills/brainmass}/references/scripts/horn-cognitive-task-training.py +0 -0
  104. /package/skills/{brainmass → package-skills/brainmass}/references/scripts/jansen-rit-eeg-proxy.py +0 -0
  105. /package/skills/{brainmass → package-skills/brainmass}/references/scripts/kuramoto-synchronization.py +0 -0
  106. /package/skills/{brainmass → package-skills/brainmass}/references/scripts/linear-baseline-node.py +0 -0
  107. /package/skills/{brainmass → package-skills/brainmass}/references/scripts/resting-state-meg-whole-brain-pipeline.py +0 -0
  108. /package/skills/{brainmass → package-skills/brainmass}/references/scripts/seizure-epileptor-case-study.py +0 -0
  109. /package/skills/{brainmass → package-skills/brainmass}/references/scripts/wilson-cowan-ei-dynamics.py +0 -0
  110. /package/skills/{brainmass → package-skills/brainmass}/references/scripts/wong-wang-decision-making.py +0 -0
  111. /package/skills/{brainmass → package-skills/brainmass}/references/scripts/wong-wang-dmf-resting-state.py +0 -0
  112. /package/skills/{brainmass → package-skills/brainmass}/references/simulator-input-monitor-api.md +0 -0
  113. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/array-creation.md +0 -0
  114. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brain-dynamics-delay-protocol.md +0 -0
  115. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/analysis.md +0 -0
  116. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/brainpy legacy workflow.md +0 -0
  117. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/built-in dynamic neuron model.md +0 -0
  118. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/connecting neurons.md +0 -0
  119. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/customize neuron and synpase.md +0 -0
  120. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/infrastructure/Input generation.md +0 -0
  121. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/infrastructure/More about simulation.md +0 -0
  122. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/infrastructure/Multi-device array sharding.md +0 -0
  123. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/infrastructure/Parallel experiment execution.md +0 -0
  124. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/infrastructure/array creation and mechanics.md +0 -0
  125. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/infrastructure/brainpy math environment setting.md +0 -0
  126. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/infrastructure/delays.md +0 -0
  127. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/infrastructure/object oriented transformations and control flows.md +0 -0
  128. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/integrators.md +0 -0
  129. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/route activity through connectivity.md +0 -0
  130. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/synaptic projections.md +0 -0
  131. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/synpase properties.md +0 -0
  132. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/training/loss library.md +0 -0
  133. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/training/optimizers.md +0 -0
  134. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/training/parameter initializers.md +0 -0
  135. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/training/prebuilt neural network layers.md +0 -0
  136. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/training/surrogate gradients.md +0 -0
  137. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/training/trainer library.md +0 -0
  138. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/training/trainingworkflows.md +0 -0
  139. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/braintools/brainstate-control-flow-patterns.md +0 -0
  140. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/braintools/data-preprocessing.md +0 -0
  141. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/braintools/metric.md +0 -0
  142. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/braintools/optimizer.md +0 -0
  143. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/braintools/parameter-initializer.md +0 -0
  144. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/braintools/surrogate.md +0 -0
  145. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/component-selection.md +0 -0
  146. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/nest-compatible/devices.md +0 -0
  147. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/nest-compatible/divergence-and-parity.md +0 -0
  148. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/nest-compatible/integration-categories.md +0 -0
  149. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/nest-compatible/model-library.md +0 -0
  150. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/nest-compatible/nest-workflow.md +0 -0
  151. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/nest-compatible/network-building.md +0 -0
  152. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/nest-compatible/scripts/brette_et_al_2007.py +0 -0
  153. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/nest-compatible/scripts/brunel_alpha.py +0 -0
  154. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/nest-compatible/scripts/brunel_delta.py +0 -0
  155. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/nest-compatible/scripts/clopath_synapse_spike_pairing.py +0 -0
  156. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/nest-compatible/scripts/evaluate_tsodyks2_synapse.py +0 -0
  157. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/nest-compatible/scripts/spatial_gaussex.py +0 -0
  158. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/nest-compatible/scripts/synapsecollection.py +0 -0
  159. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/nest-compatible/synapse-and-connectivity.md +0 -0
  160. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/scripts/103_COBA_2005.py +0 -0
  161. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/scripts/106_COBA_HH_2007.py +0 -0
  162. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/scripts/107_gamma_oscillation_1996.py +0 -0
  163. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/scripts/109_fast_global_oscillation.py +0 -0
  164. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/scripts/201_surrogate_grad_lif_fashion_mnist.py +0 -0
  165. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/scripts/sound_localization.py +0 -0
  166. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/scripts/training-snn.py +0 -0
  167. /package/skills/{brainstate → package-skills/brainstate}/agents/openai.yaml +0 -0
  168. /package/skills/{brainstate → package-skills/brainstate}/references/brainstate/brainstate-control-flow-patterns.md +0 -0
  169. /package/skills/{brainstate → package-skills/brainstate}/references/brainstate/parameter-transforms-regularizers-catalog.md +0 -0
  170. /package/skills/{brainstate → package-skills/brainstate}/references/brainstate/transformation-jit-expansion.md +0 -0
  171. /package/skills/{brainstate → package-skills/brainstate}/references/collective_model_operations.md +0 -0
  172. /package/skills/{brainstate → package-skills/brainstate}/references/extension_mechanisms.md +0 -0
  173. /package/skills/{brainstate → package-skills/brainstate}/references/libraries/prebuilt-activation-library.md +0 -0
  174. /package/skills/{brainstate → package-skills/brainstate}/references/model-interop-and-migration.md +0 -0
  175. /package/skills/{brainstate → package-skills/brainstate}/references/simulation-environment.md +0 -0
  176. /package/skills/{brainstate → package-skills/brainstate}/references/size-inference-variations.md +0 -0
  177. /package/skills/{brainstate → package-skills/brainstate}/references/state-graph-operations.md +0 -0
  178. /package/skills/{brainstate → package-skills/brainstate}/references/state_collections_and_utilities.md +0 -0
  179. /package/skills/{brainstate → package-skills/brainstate}/scripts/integrator_rnn.py +0 -0
  180. /package/skills/{brainstate → package-skills/brainstate}/scripts/lif_neuron_model.py +0 -0
  181. /package/skills/{brainstate → package-skills/brainstate}/scripts/modern_cnn.py +0 -0
  182. /package/skills/{brainstate → package-skills/brainstate}/scripts/resnet.py +0 -0
  183. /package/skills/{braintrace → package-skills/braintrace}/references/custom ETP primitives.md +0 -0
  184. /package/skills/{braintrace → package-skills/braintrace}/references/customizing_primitive_transforms.md +0 -0
  185. /package/skills/{brainunit → package-skills/brainunit}/SKILL.md +0 -0
  186. /package/skills/{brainunit → package-skills/brainunit}/references/array-creation.md +0 -0
  187. /package/skills/{brainunit → package-skills/brainunit}/references/array-mechanics/functional-structural-api.md +0 -0
  188. /package/skills/{brainunit → package-skills/brainunit}/references/array-mechanics.md +0 -0
  189. /package/skills/{brainunit → package-skills/brainunit}/references/math-function-library.md +0 -0
  190. /package/skills/{brainunit → package-skills/brainunit}/references/physical-constant-library.md +0 -0
  191. /package/skills/{brainunit → package-skills/brainunit}/references/prefix-library.md +0 -0
  192. /package/skills/{brainunit → package-skills/brainunit}/references/quantity-inspection-and-conversion.md +0 -0
  193. /package/skills/{brainunit → package-skills/brainunit}/references/typing-and-runtime-validation.md +0 -0
  194. /package/skills/{brainunit → package-skills/brainunit}/references/unit-structure-and-definition.md +0 -0
@@ -0,0 +1,459 @@
1
+ ---
2
+ name: brainx-acceleration
3
+ description: Audits and refactors BrainX/BrainState simulation code for performance using state-aware BrainState transform patterns. Use for speed, acceleration, GPU performance, batching, vectorization, parameter sweeps, many neurons/trials, compile/runtime separation, memory reduction, throughput, multi-device execution, or performance-audit requests.
4
+ ---
5
+
6
+ # BrainX Acceleration
7
+
8
+ Use when auditing or refactoring BrainX/BrainState simulation code for performance. Systematically finds NumPy/Python-loop inefficiencies and rewrites them into state-aware BrainState transform patterns: `jit`, scan/control flow, `vmap`, `grad`, `checkpointed_scan`, `pmap2`/`shard_map`, `State`/`ParamState`/`RandomState`, PyTrees, batching, RNG, and shape-stable compiled simulation logic.
9
+
10
+ Usually reached from `skills/brainstate/SKILL.md` when speed, acceleration, GPU performance, batching, vectorization, parameter sweeps, many neurons/trials, compile/runtime separation, memory reduction, throughput, multi-device execution, or a performance audit becomes the user request.
11
+
12
+ Use this skill to turn slow BrainX/BrainState simulation code into transform-friendly, state-aware array programs. The goal is not “sprinkle `jit` everywhere.” The goal is to expose the correct simulation axes to BrainState transformations while preserving state semantics, RNG behavior, shapes, gradients, and numerical results.
13
+
14
+ Optimize in this order: **correctness -> state/RNG safety -> shape stability -> warm runtime -> memory -> multi-device scale**.
15
+
16
+ ## Reference usage
17
+
18
+ For any nontrivial State-aware rewrite, route through `skills/brainstate/SKILL.md` first. Load this skill's local references only when the specific rewrite needs exact transform or randomness semantics.
19
+
20
+ Do not invent BrainState arguments. If the exact API is uncertain, inspect local usage/tests or reference markdowns and state the assumption in the patch notes.
21
+
22
+ ## Core mental model
23
+
24
+ Convert this:
25
+
26
+ ```text
27
+ Python controls loops and mutable objects; arrays are small operations inside the loop.
28
+ ```
29
+
30
+ into this:
31
+
32
+ ```text
33
+ Arrays/states represent populations; BrainState transforms control repeated execution.
34
+ ```
35
+
36
+ Axis map:
37
+
38
+ | Axis | Meaning | Slow NumPy/Python pattern | BrainState rewrite target |
39
+ |---|---|---|---|
40
+ | `N` | neurons, synapses, features, compartments | loop over scalar cells/synapses | population-shaped arrays + `jnp` ops inside `jit` |
41
+ | `T` | time/recurrent steps | Python loop calling `step` | `scan`, `for_loop`, `while_loop`; usually wrapped by `jit` |
42
+ | `B` | batch, trials, stimuli, subjects | loop over examples/trials | `vmap` or explicitly batched state |
43
+ | `E` | ensemble, parameter sweep, initial conditions, seeds | loop over model copies/configs | `vmap` with mapped states/parameters/RNG |
44
+ | `P` | trainable parameters/sensitivities | finite differences/manual perturbation loops | `grad`, `value_and_grad`, `jacrev`, `jacfwd` over args or `ParamState` |
45
+ | `D` | devices | multiprocessing/manual sharding | `pmap2`, `shard_map`, explicit sharding after single-device cleanup |
46
+
47
+ ## Non-negotiable rules
48
+
49
+ - Use `brainstate.transform.*` for stateful BrainState code. Use raw `jax.*` transforms only for pure functions with explicit array inputs/outputs and no BrainState state writes.
50
+ - Use `jax.numpy as jnp` in transformed numerical paths. Keep `numpy as np` only for host preprocessing, file I/O, offline analysis, or static setup outside transforms.
51
+ - Mutable simulation quantities belong in explicit `State`, `ParamState`, or BrainState random-stream objects. Do not hide changing transformed values in ordinary Python attributes.
52
+ - Hot-path shapes, dtypes, and PyTree structure must be stable. Use masks, padding, bucketing, or static config instead of runtime shape creation.
53
+ - Do not automatically densify sparse/event/structured connectivity. First choose the right mathematical representation, then transform it.
54
+ - Do not claim acceleration from the first call. Separate compile time from warm execution time.
55
+ - Prefer small reviewable diffs with tiny deterministic equivalence tests.
56
+
57
+ ## Investigation protocol
58
+
59
+ ### 1. Build a hot-path inventory
60
+
61
+ For each candidate function (`step`, `update`, `forward`, `run`, `simulate`, `loss`, `train_step`, data/RNG helper), record:
62
+
63
+ ```text
64
+ function/call site:
65
+ inputs: shapes, dtypes, axis meanings
66
+ states read: State/ParamState/RandomState, shapes, shared or per-trial
67
+ states written: State/ParamState/RandomState, shapes, shared or per-trial
68
+ loops: axis, trip count, nested axes
69
+ current transforms: none / raw jax / brainstate.transform
70
+ outputs: full history vs summary metrics
71
+ RNG: source, key/stream split policy, per-step/per-trial independence
72
+ shape changes: yes/no, cause
73
+ host interaction: print/log/float/item/np.asarray/callbacks
74
+ connectivity: dense/sparse/event/structured
75
+ ```
76
+
77
+ Use searches as a first pass, then read the code before editing:
78
+
79
+ ```bash
80
+ rg -n "import numpy|np\." .
81
+ rg -n "for .*range|while " .
82
+ rg -n "\.append\(|np\.array\(|np\.stack\(|jnp\.stack\(|concatenate\(" .
83
+ rg -n "jax\.jit|jax\.grad|jax\.vmap|brainstate\.transform" .
84
+ rg -n "\.value\s*=|\[[^\]]+\]\s*=" .
85
+ rg -n "random|np\.random|jax\.random|RandomState|split_key|seed" .
86
+ rg -n "finite|epsilon|eps|perturb|theta_plus|theta_minus|jacobian|hessian" .
87
+ rg -n "\.item\(|float\(|int\(|bool\(|np\.asarray|print\(|logging\." .
88
+ rg -n "jit\(|grad\(|vmap\(|scan\(" .
89
+ ```
90
+
91
+ ### 2. Classify every inefficient pattern
92
+
93
+ Use these labels in audit notes and patch comments when useful.
94
+
95
+ | Label | Evidence | Why slow/risky | Rewrite target |
96
+ |---|---|---|---|
97
+ | `loop-N-scalar` | `for i in range(N)` updates neuron/synapse scalars | Python overhead; no fused population kernel | array-shaped state + `jnp.where`/broadcast/scatter/sparse ops under `jit` |
98
+ | `object-neurons` | list/dict of neuron/synapse objects updated one by one | compiler sees Python objects, not arrays | one population/module with state arrays shaped `[N,...]` |
99
+ | `loop-T-python` | Python loop calls `step(x[t])` | dispatch per step; no compiled recurrent loop | `scan`, `for_loop`, or `while_loop` inside `jit` |
100
+ | `dynamic-list-history` | append outputs/states then stack | dynamic Python accumulation; memory waste | `scan` outputs or summary carry |
101
+ | `memory-T-full-history` | stores all `V[t]`/state when only rates/loss needed | unnecessary memory; worse autodiff storage | carry summary; record sparse snapshots; `checkpointed_scan` for differentiable long runs |
102
+ | `loop-B-python` | loop over trials/batch/stimuli | serial Python batch | `vmap` or batched state |
103
+ | `loop-E-sweep` | loop over seeds/configs/model copies | serial ensemble sweep | `vmap` with leading `[E,...]` state/param/RNG axes |
104
+ | `loop-P-finite-diff` | `eps`, `theta_plus`, `theta_minus`, perturb each param | O(P) or O(2P) simulations; noisy gradients | `grad`/`value_and_grad` over args or `ParamState` |
105
+ | `raw-jax-stateful` | `jax.jit/grad/vmap` wraps BrainState module/state writes | state updates may be lost or mishandled | `brainstate.transform.*` or explicit split/pass/return/merge |
106
+ | `np-in-transform` | `np.*` in code used by `jit/grad/vmap/scan` | host execution, tracer conversion, frozen constants | replace with `jnp.*` or move outside transform |
107
+ | `python-control-array` | Python `if/while/bool/int/float` depends on array value | tracer errors or host sync | `jnp.where`, `cond`, `while_loop`, `for_loop`, masks |
108
+ | `wrong-jit-boundary` | jitting tiny helpers, or making jitted functions inside loops | compile overhead; poor fusion | jit largest stable unit: `run`, `loss`, `train_step` |
109
+ | `transform-inside-loop` | `jit(...)`, `vmap(...)`, `grad(...)` constructed repeatedly | repeated tracing/compilation | define transforms once at module/init scope |
110
+ | `dynamic-shape` | shape depends on data/spikes/runtime length | recompilation or unsupported traced shape | static config, padding, masks, bucketing |
111
+ | `hidden-mutable-attr` | ordinary attrs mutated in transformed method | untracked state semantics | `State`/`ParamState`/explicit return value |
112
+ | `state-vmap-ambiguous` | `vmap` over stateful model without explicit state-axis decision | shared vs independent state bugs | set/verify `state_in_axes`, `state_out_axes`, unexpected state policy |
113
+ | `rng-reuse` | same key/seed reused across trials/time; `np.random` in hot path | correlated trials; unreproducible behavior | BrainState random streams or explicit split; map RNG axis under `vmap` |
114
+ | `host-sync` | `print`, `.item()`, `float(x)`, `np.asarray(x)` in hot loop | device-host synchronization | aggregate metrics; log outside compiled loop; debug-only callbacks |
115
+ | `accidental-densify` | converts sparse/event connectivity to dense `[N,N]` | memory/bandwidth blow-up | preserve sparse/event/structured representation |
116
+ | `already-fused` | large `jnp` matmul/conv/reduction already dominates | transforms may not help much | benchmark first; avoid churn |
117
+
118
+ ### 3. Rank findings before rewriting
119
+
120
+ Score each finding:
121
+
122
+ ```text
123
+ impact = loop trip count × work per iteration × call frequency
124
+ risk = state/RNG/gradient/memory semantic risk
125
+ confidence = evidence quality + shape clarity + API certainty
126
+ ```
127
+
128
+ Rewrite high-impact, high-confidence items first. Do not refactor low-impact style issues unless they block a larger transform.
129
+
130
+ ## Rewrite playbook
131
+
132
+ ### A. Population axis `N`: scalar/object loop -> array state
133
+
134
+ Bad:
135
+
136
+ ```python
137
+ for i in range(num_neurons):
138
+ v[i] += dt * (-v[i] + i_ext[i]) / tau[i]
139
+ if v[i] > threshold[i]:
140
+ spike[i] = 1
141
+ v[i] = reset[i]
142
+ ```
143
+
144
+ Good shape pattern:
145
+
146
+ ```python
147
+ v_new = V.value + dt * (-V.value + i_ext) / tau
148
+ spike = v_new > threshold
149
+ V.value = jnp.where(spike, reset, v_new)
150
+ ```
151
+
152
+ Use `jnp.where`/masks for elementwise conditional reset. Use `.at[]` scatter or segment/sparse/event operations when updates are indexed. Avoid Python object-per-neuron design in hot paths.
153
+
154
+ ### B. Time axis `T`: Python simulation loop -> transformed control flow
155
+
156
+ Bad:
157
+
158
+ ```python
159
+ ys = []
160
+ for t in range(T):
161
+ ys.append(step(xs[t]))
162
+ y = jnp.stack(ys)
163
+ ```
164
+
165
+ Good full-history pattern:
166
+
167
+ ```python
168
+ def body(carry, x_t):
169
+ y_t = net(x_t) # may read/write BrainState State
170
+ return carry, y_t
171
+
172
+ @brainstate.transform.jit
173
+ def run(xs_T):
174
+ _, ys_T = brainstate.transform.scan(body, None, xs_T)
175
+ return ys_T
176
+ ```
177
+
178
+ Good summary-only pattern:
179
+
180
+ ```python
181
+ def body(summary, x_t):
182
+ y_t = net(x_t)
183
+ summary = summary + metric(y_t)
184
+ return summary, None
185
+ ```
186
+
187
+ Use `checkpointed_scan` when differentiating through long `T` and activation/state storage dominates memory. Before applying exact control-flow APIs, read `references/brainstate/brainstate-control-flow-patterns.md` if present.
188
+
189
+ ### C. Batch/trial axis `B`: Python batch loop -> `vmap` or batched state
190
+
191
+ Bad:
192
+
193
+ ```python
194
+ outs = []
195
+ for b in range(B):
196
+ outs.append(run_one(xs_B[b]))
197
+ outs = jnp.stack(outs)
198
+ ```
199
+
200
+ Good pattern:
201
+
202
+ ```python
203
+ run_batch = brainstate.transform.jit(
204
+ brainstate.transform.vmap(run_one, in_axes=0, out_axes=0)
205
+ )
206
+ outs = run_batch(xs_B)
207
+ ```
208
+
209
+ Before rewriting, decide for every state:
210
+
211
+ ```text
212
+ shared across B? parameters, shared read-only config, global constants
213
+ independent per B? membrane voltage, refractory state, synaptic traces, trial RNG, optimizer-free simulation state
214
+ written back? final per-trial state, shared aggregate, or discarded temporary?
215
+ ```
216
+
217
+ If independent state is required, use BrainState `vmap` state-axis controls such as `state_in_axes`/`state_out_axes` according to the local API. Read `references/brainstate/transformation-vmap-expansion.md` before editing exact arguments.
218
+
219
+ ### D. Ensemble/sweep axis `E`: serial model copies -> mapped states/params
220
+
221
+ Bad:
222
+
223
+ ```python
224
+ for e in range(E):
225
+ set_params(params[e])
226
+ results.append(run(inputs, seed=e))
227
+ ```
228
+
229
+ Good shape intent:
230
+
231
+ ```text
232
+ params/state/RNG: [E, ...]
233
+ inputs: [E, T, ...] or shared [T, ...]
234
+ outputs: [E, T, ...] or [E, summary]
235
+ ```
236
+
237
+ Good transform intent:
238
+
239
+ ```python
240
+ run_ensemble = brainstate.transform.jit(
241
+ brainstate.transform.vmap(
242
+ run_one_model,
243
+ in_axes=..., out_axes=...,
244
+ state_in_axes=..., state_out_axes=...,
245
+ )
246
+ )
247
+ ```
248
+
249
+ Use this for parameter sweeps, random initial conditions, seeds, lesions, perturbations, and independent circuit replicas. Verify memory: mapping `E` full histories can be huge.
250
+
251
+ ### E. Parameter axis `P`: manual gradients -> `grad`
252
+
253
+ Bad finite differences:
254
+
255
+ ```python
256
+ for i in range(num_params):
257
+ theta_p = theta.at[i].add(eps)
258
+ theta_m = theta.at[i].add(-eps)
259
+ g = (loss(theta_p) - loss(theta_m)) / (2 * eps)
260
+ ```
261
+
262
+ Good training intent:
263
+
264
+ ```python
265
+ params = model.states(brainstate.ParamState)
266
+
267
+ def loss_fn(x, target):
268
+ pred = run(x)
269
+ return jnp.mean((pred - target) ** 2)
270
+
271
+ grad_fn = brainstate.transform.grad(loss_fn, grad_states=params, return_value=True)
272
+
273
+ @brainstate.transform.jit
274
+ def train_step(x, target):
275
+ grads, loss = grad_fn(x, target)
276
+ optimizer.update(grads)
277
+ return loss
278
+ ```
279
+
280
+ Use `grad(loss_over_batch)` for normal batch training. Use `vmap(grad(single_loss))` only for per-sample gradients, influence functions, uncertainty, or diagnostics; it can be memory-heavy. Read `references/brainstate/transformation-grad-expansion.md` before exact state/argument gradient edits.
281
+
282
+ ### F. JIT boundary: compile the largest stable unit
283
+
284
+ Prefer:
285
+
286
+ ```python
287
+ @brainstate.transform.jit
288
+ def train_step(batch):
289
+ loss = ...
290
+ grads = ...
291
+ optimizer.update(grads)
292
+ return loss, metrics
293
+ ```
294
+
295
+ Avoid:
296
+
297
+ ```python
298
+ for t in range(T):
299
+ y = brainstate.transform.jit(tiny_op)(x[t])
300
+ ```
301
+
302
+ Common good boundaries:
303
+
304
+ ```text
305
+ step if called many times and shape-stable
306
+ run when it contains scan/control flow
307
+ loss_fn when repeatedly evaluated
308
+ train_step best boundary for training: forward + loss + grad + optimizer update
309
+ ```
310
+
311
+ Read `references/brainstate/transformation-jit-expansion.md` before changing static args, diagnosing recompilation, or replacing raw `jax.jit` around stateful code.
312
+
313
+ ### G. Composition patterns
314
+
315
+ Use these as intent patterns, then adapt to local BrainState API:
316
+
317
+ ```text
318
+ single trial over time: jit(scan(step))
319
+ batch of independent trials: jit(vmap(run_one_trial))
320
+ time loop with batched state: jit(scan(vmapped_step_or_batched_step))
321
+ ensemble of models: jit(vmap(run_one_model, mapped states))
322
+ normal training: jit(train_step using grad(loss_over_batch))
323
+ per-sample gradients: jit(vmap(grad(single_sample_loss)))
324
+ long differentiable sequence: jit(checkpointed_scan(step))
325
+ multi-device batch/ensemble/shard: pmap2/shard_map after single-device cleanup
326
+ ```
327
+
328
+ Axis order matters. Choose the order that preserves state semantics and minimizes memory. For example, `vmap(scan(step))` creates independent trials with independent recurrent state; `scan(vmap(step))` uses a time loop whose step is already batched.
329
+
330
+ ### H. Randomness
331
+
332
+ Tiny RNG block: use one reproducible root seed or stream, then split/fold/map independent randomness for trials, parameter sweeps, stochastic dynamics, dropout/noise, and transformed execution. Route deeper seed/key restoration details to `references/brainstate-randomness-reproducibility/randomness-and-reproducibility.md`.
333
+
334
+ Bad:
335
+
336
+ ```python
337
+ for b in range(B):
338
+ y = run_one(xs[b], key) # same key reused
339
+ ```
340
+
341
+ Good intent:
342
+
343
+ ```text
344
+ one reproducible root seed/stream
345
+ split/fold/map independent keys for B/E/trials
346
+ split or advance per time step when stochastic dynamics require it
347
+ store RNG in BrainState-compatible state/stream if transformed code mutates it
348
+ ```
349
+
350
+ Under `vmap`, verify each mapped element receives independent randomness. RNG correctness is part of validation, not a style preference.
351
+
352
+ ### I. Multi-device `D`
353
+
354
+ Use `pmap2`, `shard_map`, or explicit sharding only after the single-device program is already transform-friendly. Good candidates: large independent trials, large ensembles, or explicit population/connectivity shards. Bad candidates: tiny Python-bound loops, logging-heavy code, shape-changing workloads, or dense memory blow-ups.
355
+
356
+ ## Implementation sequence for Codex-style agents
357
+
358
+ 1. **Do not rewrite immediately.** First produce an inventory and pattern table.
359
+ 2. **Pick the highest-impact axis.** Usually `T`, then `N`, then `B/E`, then `P`, then `D`.
360
+ 3. **Read reference markdowns only for transforms you will actually use.** Do not load all references by default.
361
+ 4. **Write or identify a tiny deterministic test before refactoring.** Include final state checks, not only outputs.
362
+ 5. **Refactor one semantic unit at a time.** Keep public APIs stable unless the user asks for deeper redesign.
363
+ 6. **Preserve exact state ownership.** When changing `vmap`, explicitly document which states are shared, mapped, written back, or discarded.
364
+ 7. **Preserve RNG semantics or intentionally improve them.** Document seed/key splitting.
365
+ 8. **Avoid cosmetic churn.** Do not convert low-impact host setup code from `np` to `jnp` unless it enters transforms.
366
+ 9. **Benchmark warm execution only after correctness.** Include compile time separately if measured.
367
+ 10. **Leave API assumptions visible.** If BrainState syntax is uncertain, mark it and point to the needed reference markdown/test.
368
+
369
+ ## Validation gates
370
+
371
+ A rewrite is not done until these are addressed:
372
+
373
+ | Gate | Required check |
374
+ |---|---|
375
+ | Outputs | old vs new on tiny deterministic input, with tolerance stated |
376
+ | Final state | compare final `State`/`ParamState` values where semantics require it |
377
+ | Shape stability | same shapes/dtypes/PyTree across repeated calls; no accidental recompiles |
378
+ | RNG | independent mapped trials/seeds; reproducible root seed behavior |
379
+ | Gradients | finite gradients; intended `ParamState`s receive grads; tiny training step moves loss or parameter in expected direction |
380
+ | Timing | cold compile separated from warm runtime; synchronize before timing when needed |
381
+ | Memory | full-history vs summary scan choice justified; no accidental dense `[N,N]` blow-up |
382
+ | State under `vmap` | shared vs independent state documented and tested |
383
+ | Host sync | no print/item/float/np.asarray in hot path except debug-only code |
384
+
385
+ ## When not to transform
386
+
387
+ Be realistic. A transform may not help when:
388
+
389
+ - the workload is tiny and compile overhead dominates;
390
+ - the hot path is already a large fused `jnp`/XLA operation;
391
+ - runtime shapes genuinely change each call and cannot be bucketed/masked;
392
+ - performance is limited by memory bandwidth or sparse representation choices;
393
+ - I/O, logging, plotting, or Python data loading dominates;
394
+ - the proposed rewrite would densify a sparse/event model;
395
+ - state/RNG semantics are not understood well enough to preserve correctness.
396
+
397
+ In these cases, report the bottleneck and propose a safer benchmark or representation change instead of forcing `jit`/`vmap`.
398
+
399
+ ## Required response format when using this skill
400
+
401
+ ```markdown
402
+ ## BrainX acceleration audit
403
+
404
+ | File/area | Pattern | Evidence | Axis | Impact | Risk | Rewrite | Confidence |
405
+ |---|---|---|---|---|---|---|---|
406
+ | ... | `loop-T-python` | `for t ... step(...)` | T | High | Medium | `scan` inside `jit` | High |
407
+
408
+ ## Patch / rewrite plan
409
+
410
+ [Small concrete diff or code blocks. State which reference markdown was used for exact transform semantics. State API assumptions if any.]
411
+
412
+ ## Validation plan
413
+
414
+ [Old/new tiny test, final-state check, RNG check, shape/recompile check, gradient check if training, warm timing method.]
415
+
416
+ ## Remaining risks
417
+
418
+ [State sharing, RNG independence, sparse/dense memory, dynamic shapes, numerical differences, unresolved API questions.]
419
+ ```
420
+
421
+ If the user asks for an actual code rewrite, include the patch. If the user asks only for an audit, do not rewrite yet; provide the table and prioritized plan.
422
+
423
+
424
+ ## Reference routing
425
+
426
+ Do not guess exact BrainState transform syntax when changing transform behavior. `skills/brainstate/SKILL.md` is the required upstream route before any nontrivial State-aware rewrite.
427
+
428
+ This skill owns local transform and randomness references for the exact semantics it audits:
429
+
430
+ ```text
431
+ brainx-acceleration-audit/
432
+ ├── brainstate/
433
+ │ ├── brainstate-control-flow-patterns.md
434
+ │ ├── transformation-jit-expansion.md
435
+ │ ├── transformation-vmap-expansion.md
436
+ │ └── transformation-grad-expansion.md
437
+ └── brainstate-randomness-reproducibility/
438
+ └── randomness-and-reproducibility.md
439
+ └── advanced-randomness.md
440
+ ```
441
+
442
+ ### First-layer routes
443
+
444
+ | Route | Open when |
445
+ |---|---|
446
+ | `skills/brainstate/SKILL.md` | Any nontrivial State-aware rewrite |
447
+ | `skills/brainx-acceleration-audit/references/brainstate/transformation-jit-expansion.md` | JIT boundaries, static arguments, recompilation, or benchmarking |
448
+ | `skills/brainx-acceleration-audit/references/brainstate/transformation-vmap-expansion.md` | Batch, trial, ensemble, State-axis, or RNG mapping |
449
+ | `skills/brainx-acceleration-audit/references/brainstate/transformation-grad-expansion.md` | Finite-difference replacement, training gradients, or `ParamState` differentiation |
450
+ | `skills/brainx-acceleration-audit/references/brainstate/brainstate-control-flow-patterns.md` | Time or recurrent loops, `scan`, `for_loop`, `while_loop`, or checkpointing |
451
+ | `skills/brainx-acceleration-audit/references/brainstate-randomness-reproducibility/randomness-and-reproducibility.md` | Seed/key restoration or independent mapped randomness |
452
+
453
+ ### Nested randomness
454
+
455
+ The acceleration skill and its transform references route only to the local randomness parent. That parent alone may select `skills/brainx-acceleration-audit/references/brainstate-randomness-reproducibility/advanced-randomness.md` for advanced stream, mapped-key, or restoration behavior. Do not route directly to the advanced child.
456
+
457
+ ## Script references
458
+
459
+ No fixed or standalone script is bundled with this skill. Build validation cases from the code under audit.
@@ -42,17 +42,21 @@ Keep the implementation at the selected scale. Do not introduce aggregate popula
42
42
 
43
43
  Start from the scientific concept and use the selected BrainX skills to construct the workflow. Keep ordinary Python, NumPy, or JAX at explicit boundaries for documented dimensionless model inputs, host-side statistics, serialization, timing, device reporting, or custom presentation logic. Preserve units and State until that boundary, and verify an API gap before writing generic numerical infrastructure.
44
44
 
45
- ## Enforce absolute coding simplicity
46
-
47
- Invest substantial effort before coding. Study every routed skill, relevant example and reference, and authoritative BrainX API needed to understand the task and discover which BrainX operations remove custom logic. Then deliver absolutely simple code. Simplicity is an output criterion, not permission to skip study or guess an API.
45
+ ## Import package namespaces once
48
46
 
49
- Use the smallest clear composition that completely satisfies the scientific contract. Minimize concepts, layers, functions, classes, State objects, transforms, branches, conversions, dependencies, files, monitors, and outputs.
47
+ Import each required BrainX package once, then access its APIs through the package namespace. Use `import brainunit as u` for BrainUnit and the full package name for other BrainX packages. This keeps API ownership visible and avoids parallel aliases for the same package.
50
48
 
51
- Keep an element only when removing it would change scientific meaning, correctness, required performance, verification of a costly failure, or requested output quality. Remove pass-through wrappers, duplicate representations, speculative configuration, redundant transforms, repeated calculations, defensive branches for impossible inputs, and unrequested artifacts. Prefer one direct data flow, one owner for each State, one stable transform boundary, and one canonical execution path.
49
+ ```python
50
+ import brainmass
51
+ import brainstate
52
+ import braintools
53
+ import brainunit as u
54
+ ```
55
+ Do not import functions or classes individually.
56
+ ## Enforce absolute coding simplicity
52
57
 
53
- Keep a one-off scientific demonstration concrete. Add a configuration object, result class, helper layer, command-line option, or extra artifact only when the request requires variation or reuse, or when that structure removes more complexity than it adds.
58
+ Invest substantial effort before coding. Study every routed skill, relevant example and reference, and authoritative BrainX API needed to understand the task and discover which BrainX operations remove custom logic. Then deliver absolutely simple code. Simplicity is an output criterion, not permission to skip study or guess an API.
54
59
 
55
- Do not simplify away units, explicit State lifecycles, numerical validity, scientifically necessary mechanisms, performance-critical compilation or batching, focused checks, or requested output quality. These are requirements, not optional complexity.
56
60
 
57
61
  ## Prefer high-level BrainX APIs
58
62
 
@@ -106,9 +110,9 @@ Use the owning package's orchestrator for workflows it already implements. When
106
110
 
107
111
  Do not add a transform only to construct parameter axes or satisfy a named-API checklist. When the owning package already represents independent conditions through a native batch or `size` axis, use that path and reserve `vmap` for a callable the owning package does not already batch.
108
112
 
109
- Map only independent operations. If trial N mutates weights or other State that trial N+1 consumes, keep those trials sequential; batch only independent evaluation trials or ensembles, with separate dynamical State and deliberately shared read-only State. Mapping input construction or offline scoring does not batch the stateful simulation itself. Open `skills/brainstate/references/brainstate/transformation-vmap-expansion.md` when a complete mapped operation reads or writes State, for the State-axis contracts and independent-lane pattern.
113
+ Map only independent operations. If trial N mutates weights or other State that trial N+1 consumes, keep those trials sequential; batch only independent evaluation trials or ensembles, with separate dynamical State and deliberately shared read-only State. Mapping input construction or offline scoring does not batch the stateful simulation itself. Open `skills/package-skills/brainstate/references/brainstate/transformation-vmap-expansion.md` when a complete mapped operation reads or writes State, for the State-axis contracts and independent-lane pattern.
110
114
 
111
- A mapped complete per-step transition called inside one `for_loop` is a stateful simulation batch: the mapping owns independent conditions and the loop owns time. Select mapped State by semantic role, such as `Any(OfType(HiddenState), OfType(ShortTermState))`; do not infer State ownership from array rank, shape, or a coincidental leading size. Open `skills/brainstate/references/brainstate/transformation-vmap-expansion.md` for the canonical initialization, mapping, and loop composition.
115
+ A mapped complete per-step transition called inside one `for_loop` is a stateful simulation batch: the mapping owns independent conditions and the loop owns time. Select mapped State by semantic role, such as `Any(OfType(HiddenState), OfType(ShortTermState))`; do not infer State ownership from array rank, shape, or a coincidental leading size. Open `skills/package-skills/brainstate/references/brainstate/transformation-vmap-expansion.md` for the canonical initialization, mapping, and loop composition.
112
116
 
113
117
  Describe the transform that actually runs. Native batched State, vmapped input construction, and vmapped host scoring are not stateful `vmap`. When the user explicitly requires `vmap`, map the complete independent operation or report why the requirement cannot be met.
114
118
 
@@ -121,6 +125,7 @@ Use raw JAX transformations only for pure array or PyTree functions that do not
121
125
  ## Boundaries and common failures
122
126
 
123
127
  - Generic NumPy or JAX used as the starting architecture for a BrainX simulation.
128
+ - BrainX functions or classes imported individually when the package namespace already exposes them.
124
129
  - Point-neuron and aggregate population mechanisms mixed without selecting both owning skills or declaring the multiscale boundary.
125
130
  - A custom BrainState loop that duplicates the selected package's runner, inputs, monitoring, initialization, or sampling.
126
131
  - Manual array or mathematical machinery that duplicates BrainUnit or BrainTools.