brainx-skill 1.0.11 → 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 (198) 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 +67 -37
  14. package/skills/brainx-install/SKILL.md +21 -24
  15. package/skills/brainx-modeling-loop/SKILL.md +268 -0
  16. package/skills/brainx-modeling-loop/agents/openai.yaml +4 -0
  17. package/skills/brainx-modeling-loop/references/monitor-experiment.md +49 -0
  18. package/skills/brainx-modeling-loop/references/parameter-fitting-workflow/scripts/fitting_hh_neuron.py +254 -0
  19. package/skills/brainx-modeling-loop/references/parameter-fitting-workflow.md +232 -0
  20. package/skills/brainx-modeling-loop/references/run-experiment.md +179 -0
  21. package/skills/brainx-modeling-loop/references/training-workflow.md +270 -0
  22. package/skills/{braincell → package-skills/braincell}/SKILL.md +3 -16
  23. package/skills/{braincell → package-skills/braincell}/references/mixions-for-adaptation.md +26 -3
  24. package/skills/{braincell → package-skills/braincell}/references/multicompartment/multicompartment-cell-workflow.md +2 -2
  25. package/skills/package-skills/braincell/references/scripts/fitting_hh_neuron.py +254 -0
  26. package/skills/package-skills/braincell/references/scripts/spike_frequency_adaptation.py +135 -0
  27. package/skills/{brainevent → package-skills/brainevent}/SKILL.md +0 -1
  28. package/skills/package-skills/brainevent/references/synaptic-plasticity.md +129 -0
  29. package/skills/{brainmass → package-skills/brainmass}/SKILL.md +10 -5
  30. package/skills/{brainmass → package-skills/brainmass}/references/batch-transform-acceleration.md +44 -3
  31. package/skills/{brainmass → package-skills/brainmass}/references/brainstate/parameter-constraints-regularization.md +1 -1
  32. package/skills/{brainmass → package-skills/brainmass}/references/coupling-network-api.md +121 -3
  33. package/skills/{brainmass → package-skills/brainmass}/references/modellibrary.md +90 -1
  34. package/skills/package-skills/brainmass/references/parameter-sweeps-and-regime-analysis.md +188 -0
  35. package/skills/package-skills/brainmass/references/simulator-input-monitor-api.md +98 -0
  36. package/skills/{brainmass → package-skills/brainmass}/references/visualization-analysis-api.md +6 -6
  37. package/skills/{brainpy-state → package-skills/brainpy-state}/SKILL.md +17 -8
  38. package/skills/{brainpy-state → package-skills/brainpy-state}/references/brain-dynamics-delay-protocol.md +52 -1
  39. package/skills/package-skills/brainpy-state/references/braintools/connectivity.md +206 -0
  40. package/skills/package-skills/brainpy-state/references/braintools/input-current.md +199 -0
  41. package/skills/{brainpy-state → package-skills/brainpy-state}/references/component-selection.md +20 -5
  42. package/skills/package-skills/brainpy-state/references/perturbation-experiment-validity.md +76 -0
  43. package/skills/{brainpy-state → package-skills/brainpy-state}/references/projection-patterns.md +3 -1
  44. package/skills/package-skills/brainpy-state/references/scripts/sound_localization.py +240 -0
  45. package/skills/{brainstate → package-skills/brainstate}/SKILL.md +12 -15
  46. package/skills/package-skills/brainstate/agents/openai.yaml +4 -0
  47. package/skills/{brainstate → package-skills/brainstate}/references/brainstate/brainstate-control-flow-patterns.md +8 -0
  48. package/skills/{brainstate → package-skills/brainstate}/references/brainstate/brainstate-transformed-diagnostics.md +1 -1
  49. package/skills/{brainstate → package-skills/brainstate}/references/brainstate/parameter-constraints-regularization.md +1 -1
  50. package/skills/{brainstate → package-skills/brainstate}/references/brainstate/randomness-and-reproducibility.md +1 -1
  51. package/skills/{brainstate → package-skills/brainstate}/references/brainstate/transformation-grad-expansion.md +2 -2
  52. package/skills/{brainstate → package-skills/brainstate}/references/brainstate/transformation-vmap-expansion.md +58 -8
  53. package/skills/{brainstate → package-skills/brainstate}/references/collective_model_operations.md +26 -27
  54. package/skills/{brainstate → package-skills/brainstate}/references/libraries/prebuilt-layer-library.md +1 -1
  55. package/skills/package-skills/brainstate/references/paired-perturbation-execution.md +113 -0
  56. package/skills/package-skills/braintrace/SKILL.md +187 -0
  57. package/skills/package-skills/braintrace/references/Drtrl.md +133 -0
  58. package/skills/{braintrace → package-skills/braintrace}/references/ETP operators.md +31 -4
  59. package/skills/package-skills/braintrace/references/algorithm selection.md +64 -0
  60. package/skills/package-skills/braintrace/references/batching.md +140 -0
  61. package/skills/{braintrace → package-skills/braintrace}/references/compiler_internal.md +2 -2
  62. package/skills/{braintrace → package-skills/braintrace}/references/custom algorithms.md +8 -10
  63. package/skills/package-skills/braintrace/references/pp_pprop workflow.md +179 -0
  64. package/skills/{braintrace → package-skills/braintrace}/references/pre-built-braintrace-layer.md +2 -2
  65. package/skills/{brainpy-state → package-skills/brainunit}/references/array-creation.md +2 -2
  66. package/skills/braincell/references/scripts/spike_frequency_adaptation.py +0 -75
  67. package/skills/brainevent/references/synaptic-plasticity.md +0 -285
  68. package/skills/brainmass/references/parameter-sweeps-and-regime-analysis.md +0 -130
  69. package/skills/brainstate/references/braintools/optimizer.md +0 -179
  70. package/skills/braintrace/SKILL.md +0 -161
  71. package/skills/braintrace/references/Drtrl.md +0 -179
  72. package/skills/braintrace/references/algorithm selection.md +0 -120
  73. package/skills/braintrace/references/batching.md +0 -150
  74. package/skills/braintrace/references/pp_pprop workflow.md +0 -196
  75. /package/skills/{braincell → package-skills/braincell}/references/area-scaled-hh-pattern.md +0 -0
  76. /package/skills/{braincell → package-skills/braincell}/references/braincell-custom-ion-channel-authoring.md +0 -0
  77. /package/skills/{braincell → package-skills/braincell}/references/channel-library.md +0 -0
  78. /package/skills/{braincell → package-skills/braincell}/references/ion-library.md +0 -0
  79. /package/skills/{braincell → package-skills/braincell}/references/multicompartment/braincell-manual-morphology-construction.md +0 -0
  80. /package/skills/{braincell → package-skills/braincell}/references/multicompartment/cv-policy-reference.md +0 -0
  81. /package/skills/{braincell → package-skills/braincell}/references/multicompartment/filter-function-library.md +0 -0
  82. /package/skills/{braincell → package-skills/braincell}/references/multicompartment/morphology-io-loading-validation.md +0 -0
  83. /package/skills/{braincell → package-skills/braincell}/references/multicompartment/probe-reference.md +0 -0
  84. /package/skills/{braincell → package-skills/braincell}/references/multicompartment/topology-building-and-visualization.md +0 -0
  85. /package/skills/{braincell → package-skills/braincell}/references/scripts/calcium_channel_gating.py +0 -0
  86. /package/skills/{braincell → package-skills/braincell}/references/scripts/cell_multicompartment_reference.py +0 -0
  87. /package/skills/{braincell → package-skills/braincell}/references/scripts/channel_ablation.py +0 -0
  88. /package/skills/{braincell → package-skills/braincell}/references/scripts/fi_curve.py +0 -0
  89. /package/skills/{braincell → package-skills/braincell}/references/scripts/hh_neuron_basics.py +0 -0
  90. /package/skills/{braincell → package-skills/braincell}/references/scripts/t_current_rebound.py +0 -0
  91. /package/skills/{braincell → package-skills/braincell}/references/scripts/thalamic_neurons.py +0 -0
  92. /package/skills/{braincell → package-skills/braincell}/references/solver-library-with-effects.md +0 -0
  93. /package/skills/{brainevent → package-skills/brainevent}/references/connectivity-variants.md +0 -0
  94. /package/skills/{brainevent → package-skills/brainevent}/references/custom-operators-cpu.md +0 -0
  95. /package/skills/{brainevent → package-skills/brainevent}/references/custom-operators-gpu.md +0 -0
  96. /package/skills/{brainevent → package-skills/brainevent}/references/scripts/102_EI_net_1996.py +0 -0
  97. /package/skills/{brainevent → package-skills/brainevent}/references/scripts/204_joglekar_2018_propagation.py +0 -0
  98. /package/skills/{brainevent → package-skills/brainevent}/references/scripts/coba_ei_teaching.py +0 -0
  99. /package/skills/{brainevent → package-skills/brainevent}/references/sparse-formats.md +0 -0
  100. /package/skills/{brainmass → package-skills/brainmass}/references/brainstate/parameter-transforms-regularizers-catalog.md +0 -0
  101. /package/skills/{brainmass → package-skills/brainmass}/references/braintools/cogtask.md +0 -0
  102. /package/skills/{brainmass → package-skills/brainmass}/references/braintools/data-preprocessing.md +0 -0
  103. /package/skills/{brainmass → package-skills/brainmass}/references/braintools/metric.md +0 -0
  104. /package/skills/{brainmass → package-skills/brainmass}/references/braintools/optimizer.md +0 -0
  105. /package/skills/{brainmass → package-skills/brainmass}/references/braintools/parameter-initializer.md +0 -0
  106. /package/skills/{brainmass → package-skills/brainmass}/references/braintools/surrogate.md +0 -0
  107. /package/skills/{brainmass → package-skills/brainmass}/references/datasets-api.md +0 -0
  108. /package/skills/{brainmass → package-skills/brainmass}/references/fitting-with-objectives-api.md +0 -0
  109. /package/skills/{brainmass → package-skills/brainmass}/references/forward-observation-api.md +0 -0
  110. /package/skills/{brainmass → package-skills/brainmass}/references/horn-task-training.md +0 -0
  111. /package/skills/{brainmass → package-skills/brainmass}/references/noiseprocesses.md +0 -0
  112. /package/skills/{brainmass → package-skills/brainmass}/references/scripts/eeg-fitting-with-gradients.py +0 -0
  113. /package/skills/{brainmass → package-skills/brainmass}/references/scripts/gradient-free-fitting.py +0 -0
  114. /package/skills/{brainmass → package-skills/brainmass}/references/scripts/hopf-bifurcation-single-node.py +0 -0
  115. /package/skills/{brainmass → package-skills/brainmass}/references/scripts/horn-cognitive-task-training.py +0 -0
  116. /package/skills/{brainmass → package-skills/brainmass}/references/scripts/jansen-rit-eeg-proxy.py +0 -0
  117. /package/skills/{brainmass → package-skills/brainmass}/references/scripts/kuramoto-synchronization.py +0 -0
  118. /package/skills/{brainmass → package-skills/brainmass}/references/scripts/linear-baseline-node.py +0 -0
  119. /package/skills/{brainmass → package-skills/brainmass}/references/scripts/resting-state-meg-whole-brain-pipeline.py +0 -0
  120. /package/skills/{brainmass → package-skills/brainmass}/references/scripts/seizure-epileptor-case-study.py +0 -0
  121. /package/skills/{brainmass → package-skills/brainmass}/references/scripts/wilson-cowan-ei-dynamics.py +0 -0
  122. /package/skills/{brainmass → package-skills/brainmass}/references/scripts/wong-wang-decision-making.py +0 -0
  123. /package/skills/{brainmass → package-skills/brainmass}/references/scripts/wong-wang-dmf-resting-state.py +0 -0
  124. /package/skills/{brainunit → package-skills/brainpy-state}/references/array-creation.md +0 -0
  125. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/analysis.md +0 -0
  126. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/brainpy legacy workflow.md +0 -0
  127. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/built-in dynamic neuron model.md +0 -0
  128. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/connecting neurons.md +0 -0
  129. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/customize neuron and synpase.md +0 -0
  130. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/infrastructure/Input generation.md +0 -0
  131. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/infrastructure/More about simulation.md +0 -0
  132. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/infrastructure/Multi-device array sharding.md +0 -0
  133. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/infrastructure/Parallel experiment execution.md +0 -0
  134. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/infrastructure/array creation and mechanics.md +0 -0
  135. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/infrastructure/brainpy math environment setting.md +0 -0
  136. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/infrastructure/delays.md +0 -0
  137. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/infrastructure/object oriented transformations and control flows.md +0 -0
  138. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/integrators.md +0 -0
  139. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/route activity through connectivity.md +0 -0
  140. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/synaptic projections.md +0 -0
  141. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/synpase properties.md +0 -0
  142. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/training/loss library.md +0 -0
  143. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/training/optimizers.md +0 -0
  144. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/training/parameter initializers.md +0 -0
  145. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/training/prebuilt neural network layers.md +0 -0
  146. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/training/surrogate gradients.md +0 -0
  147. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/training/trainer library.md +0 -0
  148. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/brainPy(legacy)/training/trainingworkflows.md +0 -0
  149. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/braintools/brainstate-control-flow-patterns.md +0 -0
  150. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/braintools/data-preprocessing.md +0 -0
  151. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/braintools/metric.md +0 -0
  152. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/braintools/optimizer.md +0 -0
  153. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/braintools/parameter-initializer.md +0 -0
  154. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/braintools/surrogate.md +0 -0
  155. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/nest-compatible/devices.md +0 -0
  156. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/nest-compatible/divergence-and-parity.md +0 -0
  157. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/nest-compatible/integration-categories.md +0 -0
  158. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/nest-compatible/model-library.md +0 -0
  159. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/nest-compatible/nest-workflow.md +0 -0
  160. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/nest-compatible/network-building.md +0 -0
  161. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/nest-compatible/scripts/brette_et_al_2007.py +0 -0
  162. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/nest-compatible/scripts/brunel_alpha.py +0 -0
  163. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/nest-compatible/scripts/brunel_delta.py +0 -0
  164. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/nest-compatible/scripts/clopath_synapse_spike_pairing.py +0 -0
  165. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/nest-compatible/scripts/evaluate_tsodyks2_synapse.py +0 -0
  166. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/nest-compatible/scripts/spatial_gaussex.py +0 -0
  167. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/nest-compatible/scripts/synapsecollection.py +0 -0
  168. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/nest-compatible/synapse-and-connectivity.md +0 -0
  169. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/scripts/103_COBA_2005.py +0 -0
  170. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/scripts/106_COBA_HH_2007.py +0 -0
  171. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/scripts/107_gamma_oscillation_1996.py +0 -0
  172. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/scripts/109_fast_global_oscillation.py +0 -0
  173. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/scripts/201_surrogate_grad_lif_fashion_mnist.py +0 -0
  174. /package/skills/{brainpy-state → package-skills/brainpy-state}/references/scripts/training-snn.py +0 -0
  175. /package/skills/{brainstate → package-skills/brainstate}/references/brainstate/parameter-transforms-regularizers-catalog.md +0 -0
  176. /package/skills/{brainstate → package-skills/brainstate}/references/brainstate/transformation-jit-expansion.md +0 -0
  177. /package/skills/{brainstate → package-skills/brainstate}/references/extension_mechanisms.md +0 -0
  178. /package/skills/{brainstate → package-skills/brainstate}/references/libraries/prebuilt-activation-library.md +0 -0
  179. /package/skills/{brainstate → package-skills/brainstate}/references/model-interop-and-migration.md +0 -0
  180. /package/skills/{brainstate → package-skills/brainstate}/references/simulation-environment.md +0 -0
  181. /package/skills/{brainstate → package-skills/brainstate}/references/size-inference-variations.md +0 -0
  182. /package/skills/{brainstate → package-skills/brainstate}/references/state-graph-operations.md +0 -0
  183. /package/skills/{brainstate → package-skills/brainstate}/references/state_collections_and_utilities.md +0 -0
  184. /package/skills/{brainstate → package-skills/brainstate}/scripts/integrator_rnn.py +0 -0
  185. /package/skills/{brainstate → package-skills/brainstate}/scripts/lif_neuron_model.py +0 -0
  186. /package/skills/{brainstate → package-skills/brainstate}/scripts/modern_cnn.py +0 -0
  187. /package/skills/{brainstate → package-skills/brainstate}/scripts/resnet.py +0 -0
  188. /package/skills/{braintrace → package-skills/braintrace}/references/custom ETP primitives.md +0 -0
  189. /package/skills/{braintrace → package-skills/braintrace}/references/customizing_primitive_transforms.md +0 -0
  190. /package/skills/{brainunit → package-skills/brainunit}/SKILL.md +0 -0
  191. /package/skills/{brainunit → package-skills/brainunit}/references/array-mechanics/functional-structural-api.md +0 -0
  192. /package/skills/{brainunit → package-skills/brainunit}/references/array-mechanics.md +0 -0
  193. /package/skills/{brainunit → package-skills/brainunit}/references/math-function-library.md +0 -0
  194. /package/skills/{brainunit → package-skills/brainunit}/references/physical-constant-library.md +0 -0
  195. /package/skills/{brainunit → package-skills/brainunit}/references/prefix-library.md +0 -0
  196. /package/skills/{brainunit → package-skills/brainunit}/references/quantity-inspection-and-conversion.md +0 -0
  197. /package/skills/{brainunit → package-skills/brainunit}/references/typing-and-runtime-validation.md +0 -0
  198. /package/skills/{brainunit → package-skills/brainunit}/references/unit-structure-and-definition.md +0 -0
@@ -0,0 +1,179 @@
1
+ # BrainX experiment runner
2
+
3
+ Sources:
4
+
5
+ - [BrainX installing the ecosystem](https://brainx.chaobrain.com/summ/install.html)
6
+ - [BrainX change log](https://brainx.chaobrain.com/summ/CHANGELOG.html)
7
+ - [BrainState simulation environment](https://brainx.chaobrain.com/brainstate/concepts/time_and_environment.html)
8
+ - [JAX GPU memory allocation](https://docs.jax.dev/en/latest/gpu_memory_allocation.html)
9
+
10
+ ## Purpose and boundary
11
+
12
+ Use this reference to turn a ready BrainX entry point into an inspectable launch: preflight the exact environment and compute target, verify any resume checkpoint, freeze provenance, launch one declared run level, then hand the recorded run to `monitor-experiment.md`.
13
+
14
+ Keep scientific design and iteration in `brainx-modeling-loop`. Open `brainx-install` when the selected environment is absent, incompatible, or missing the required CPU/CUDA extra; do not repair an environment inside this workflow. Open `brainx-acceleration` before production when performance, memory, batching, or multi-device work still needs design changes.
15
+
16
+ This reference may execute a run the user requested. It does not authorize provisioning paid compute, changing a scientific configuration, installing packages, destroying a remote instance, or accepting scientific claims.
17
+
18
+ ## Underlying principle of BrainX experiment execution
19
+
20
+ A run snapshot represents one immutable scientific execution contract. It binds the specification, code, data, BrainX release tuple, BrainState environment, device, precision, seeds, command, and expected artifacts to one run ID.
21
+
22
+ A compute target represents the backend on which JAX and BrainX execute. Process-level JAX selection and the model's BrainState `platform` setting must agree before any BrainX or JAX import.
23
+
24
+ A run level represents execution intent. `smoke` proves mechanics at reduced scale, `production` executes the locked experiment, and `replication` repeats valid production conditions across declared seeds, subjects, protocols, or controls.
25
+
26
+ A run status represents process state, not scientific truth. `done` means the command completed and required artifacts passed mechanical checks; it never means the result is accepted.
27
+
28
+ ## Execution surface overview
29
+
30
+ | Surface | Owns |
31
+ |---|---|
32
+ | `brainx-install` | Coherent BrainX release tuple, Python environment, and CPU/CUDA/TPU extra |
33
+ | `jax.devices()` and `jax.default_backend()` | Runtime-visible devices and selected JAX backend |
34
+ | `brainstate.environ` | Model run settings such as `dt`, `fit`, precision, and BrainState platform |
35
+ | `RUN_SPEC.md` and `config.json` | Immutable human-readable and machine-readable run contracts |
36
+ | Process or scheduler handle | Liveness, exit state, and cancellation |
37
+ | Logs, checkpoints, raw outputs, and metrics | Inspectable execution evidence |
38
+
39
+ ## Start or resume from an explicit contract
40
+
41
+ Treat a new launch and a resumed checkpoint as separate paths that share the same preflight and provenance gates.
42
+
43
+ | API | Description |
44
+ |---|---|
45
+ | Project instructions and locked specification | Use first to recover the intended environment, entry point, run level, scientific configuration, seeds, inputs, outputs, resource estimate, and stop conditions; missing scientific choices return to the modeling workflow. |
46
+ | `python -m pip list --format=json` | Use with the exact target interpreter to record installed distributions without importing the stack; it returns package/version evidence for the snapshot. |
47
+ | `import BrainX, jax` | Use only after backend environment variables are set; it verifies imports in the selected process. |
48
+ | `jax.devices()` | Use in preflight to list devices visible to that process; it returns runtime device objects but does not prove the experiment fits or authorize a target. |
49
+ | `jax.default_backend()` | Use to compare the active JAX backend with the declared compute target; a mismatch fails preflight. |
50
+
51
+ Classify the request before launch:
52
+
53
+ | Entry case | Use when | Required next action |
54
+ |---|---|---|
55
+ | `new` | No prior run is being continued | Create a new run ID and snapshot. |
56
+ | `resume` | A compatible checkpoint must continue | Apply the checkpoint gate below, then create a new run ID linked to the source run. |
57
+ | `monitor` | A run handle or run directory already exists | Open `monitor-experiment.md`; do not relaunch. |
58
+
59
+ ```bash
60
+ RUN_PYTHON=/absolute/path/to/python
61
+ JAX_PLATFORMS=cpu "$RUN_PYTHON" -c \
62
+ "import BrainX, jax; print('BrainX OK'); print('backend:', jax.default_backend()); print('devices:', jax.devices())"
63
+ ```
64
+
65
+ Replace the CPU selector with the confirmed GPU selector only after choosing the device path below.
66
+
67
+ ## Select CPU or GPU before import
68
+
69
+ Choose the backend from the workload and locked experiment contract, not from device visibility alone.
70
+
71
+ | API | Description |
72
+ |---|---|
73
+ | `JAX_PLATFORMS=cpu` | Use for CPU execution; set it before the first BrainX/JAX import and require `jax.default_backend() == "cpu"`. |
74
+ | `CUDA_VISIBLE_DEVICES=<physical-id>` | Use before import to isolate one selected NVIDIA GPU; record the physical ID and the JAX-visible logical device because CUDA remaps it inside the process. |
75
+ | `JAX_PLATFORMS=cuda` | Use for NVIDIA GPU execution; fail preflight if CUDA initialization fails or JAX falls back to CPU. |
76
+ | `nvidia-smi` | Use as host-side evidence for GPU identity, free memory, utilization, driver, and active processes; it does not replace the JAX device check. |
77
+ | `brainstate.environ.set_platform("cpu" | "gpu")` | Use in the model's process-level setup when the entry point owns BrainState platform selection; it must agree with the JAX backend and must not be changed through a scoped `context()`. |
78
+
79
+ Use CPU for small smoke tests, debugging, modest models, or runs whose warm benchmark does not justify accelerator dispatch. Use GPU for compatible, sufficiently array-oriented workloads whose memory estimate fits the selected device and whose production contract declares CUDA. A CPU smoke run does not satisfy a GPU smoke gate; run a target-device smoke before GPU production.
80
+
81
+ ```bash
82
+ RUN_PYTHON=/absolute/path/to/python
83
+ CUDA_VISIBLE_DEVICES=2 JAX_PLATFORMS=cuda "$RUN_PYTHON" -c \
84
+ "import BrainX, jax; print('BrainX OK'); print('backend:', jax.default_backend()); print('devices:', jax.devices())"
85
+ ```
86
+
87
+ JAX normally preallocates 75% of GPU memory. Keep that default when one process owns the GPU. Use `XLA_PYTHON_CLIENT_MEM_FRACTION=<fraction>` only for an explicit multi-process memory plan, or `XLA_PYTHON_CLIENT_PREALLOCATE=false` for debugging/coexistence while accepting greater fragmentation risk. Record every override in the run snapshot.
88
+
89
+ Launch independent runs on separate GPUs only when their State, RNG, data writes, checkpoints, and output directories are independent. Do not assume multiple visible GPUs accelerate one run; route `pmap2`, `shard_map`, and model/data sharding to `brainx-acceleration`.
90
+
91
+ For an existing remote environment, use the project's declared host, interpreter, code directory, sync method, scheduler/process manager, storage, and cost rules. Verify remote hashes and BrainX/JAX devices before launch. Do not invent a host, provision paid compute, install packages, or destroy an instance without explicit authorization.
92
+
93
+ ## Verify checkpoint compatibility
94
+
95
+ A checkpoint is compatible only when its scientific contract and complete continuation State match the proposed run.
96
+
97
+ | Check | Pass condition |
98
+ |---|---|
99
+ | Identity | Source run ID, checkpoint hash, completion marker, format, and recorded step/epoch/time are present. |
100
+ | Scientific contract | Specification, config, data/preprocessing, protocol, solver, `dt`, precision, and seed policy match. |
101
+ | Environment | BrainX release tuple, JAX/JAXlib, backend, device count, and numerical settings match, or a tested migration is declared. |
102
+ | State graph | Parameter, dynamical, optimizer, RNG, online-learning, and progress State have matching names, roles, PyTree structure, shapes, dtypes, units, and transforms. |
103
+ | Witness | A read-only restore plus one representative target-backend step preserves expected shapes, units, finite values, and progress. |
104
+
105
+ Classify the result as `exact-resume`, `compatible-migration`, `weights-only-start`, or `incompatible`. A weights-only load is a new scientific run, not continuation. Never overwrite or convert the source checkpoint in place; save migrated output under the new run and preserve both hashes.
106
+
107
+ ## Freeze and launch one run
108
+
109
+ Freeze the run before execution; append logs and status afterward without rewriting the contract.
110
+
111
+ | API | Description |
112
+ |---|---|
113
+ | `RUN_SPEC.md` | Use for the readable run contract; write the run identity, hashes, backend, precision, seed policy, command, expected artifacts, estimates, and stop conditions before launch, then never edit it. |
114
+ | `config.json` | Use as the exact machine-readable scientific configuration consumed by the entry point; any scientific change creates a new run ID. |
115
+ | `run.log` | Use as the append-only combined process log when separate streams are unnecessary; preserve the entry-point exit status when piping through `tee`. |
116
+ | Process manager or scheduler | Use the project's established local session, cluster scheduler, or remote process manager for long runs; record its handle and submitted command. |
117
+
118
+ Use this minimum run layout:
119
+
120
+ ```text
121
+ runs/<run-id>/
122
+ |-- RUN_SPEC.md
123
+ |-- config.json
124
+ |-- environment.json
125
+ |-- command.txt
126
+ |-- code.diff
127
+ |-- status.json
128
+ |-- run.log
129
+ |-- exit_code
130
+ |-- checkpoints/
131
+ |-- raw/
132
+ `-- metrics/
133
+ ```
134
+
135
+ Record the specification/config hashes; commit and dirty diff hash; data and preprocessing hashes; absolute interpreter and BrainX/JAX package tuple; physical and process-visible device identities; BrainState platform, precision, seeds, and determinism expectation; checkpoint source; exact command; expected outputs; resource estimate; timeout, retry budget, and stop conditions. Never store credentials or secret values.
136
+
137
+ Keep `RUN_SPEC.md`, `config.json`, `environment.json`, `command.txt`, and `code.diff` immutable after launch. Keep `status.json` mutable and `run.log` append-only. Any scientific, backend, precision, or seed-policy change creates a new run ID.
138
+
139
+ Follow this fixed order:
140
+
141
+ 1. Confirm `smoke`, `production`, or `replication` and the `new` or `resume` entry case.
142
+ 2. Read project instructions and identify the exact interpreter, environment, entry point, data, output root, backend, precision, seeds, resource budget, expected artifacts, and kill conditions.
143
+ 3. Verify the BrainX meta-package environment without changing it. Route any incompatibility to `brainx-install`.
144
+ 4. Preflight CPU or GPU resources and verify the selected backend in a fresh process.
145
+ 5. Create a smoke run ID and immutable snapshot, run it on the declared target, then verify construction, State initialization/reset, output paths, finite representative outputs, and a checkpoint write when checkpoints are required.
146
+ 6. Create a separate immutable production or replication snapshot only after the applicable readiness and acceleration gates pass.
147
+ 7. Launch the exact recorded command in the exact recorded working directory and preserve its process or scheduler handle.
148
+ 8. Verify liveness, log creation, target-device use, and expected early artifacts before reporting the launch.
149
+
150
+ ```bash
151
+ set -o pipefail
152
+ JAX_PLATFORMS=cpu "$RUN_PYTHON" experiment.py --config "$RUN_DIR/config.json" \
153
+ 2>&1 | tee -a "$RUN_DIR/run.log"
154
+ RUN_EXIT=${PIPESTATUS[0]}
155
+ printf '%s\n' "$RUN_EXIT" > "$RUN_DIR/exit_code"
156
+ exit "$RUN_EXIT"
157
+ ```
158
+
159
+ Use the GPU environment from the preceding section for a CUDA run. Do not rewrite `RUN_SPEC.md` or `config.json` after this command starts.
160
+
161
+ ## Hand off to monitoring
162
+
163
+ After launch, open `monitor-experiment.md` for liveness, progress, resource health, stopping, retry, collection, and reporting. Pass the run directory and recorded process/scheduler handle. Process completion remains mechanical evidence and never implies scientific acceptance.
164
+
165
+ Open `skills/package-skills/brainstate/references/simulation-environment.md` only when exact `dt`, `fit`, precision, platform, or isolated-environment behavior needs verification. Open `brainx-install` when the environment is incompatible, and `brainx-acceleration` when OOM, precision, sharding, batching, or performance changes would alter execution semantics.
166
+
167
+ ## Boundaries and common failures
168
+
169
+ - Do not design, tune, or revise the scientific experiment from observed results.
170
+ - Do not treat a visible GPU, an idle GPU, or a faster device as permission to select it.
171
+ - Do not install individual BrainX/JAX components on the run host; preserve the coherent BrainX environment or route to `brainx-install`.
172
+ - Do not use PyTorch CUDA/MPS checks for BrainX. Verify through JAX; Apple MPS is not an official BrainX install target.
173
+ - Do not silently accept CPU fallback from a failed CUDA initialization.
174
+ - Do not run multiple JAX processes on one GPU without an explicit memory-allocation plan.
175
+ - Do not assume multiple GPUs accelerate one run; use independent run processes only for independent runs, and route sharded model execution to `brainx-acceleration`.
176
+ - Do not overwrite configs, logs, checkpoints, or failed-run evidence during retry.
177
+ - Do not copy only `*.py` files to a remote host when configs, package metadata, modules, or data manifests are required by the frozen snapshot.
178
+ - Do not make W&B, SSH, `screen`, `tmux`, a cloud provider, or one operating system mandatory.
179
+ - Do not equate process completion, a decreasing loss, or a best seed with scientific acceptance.
@@ -0,0 +1,270 @@
1
+ # BrainX task-training workflow
2
+
3
+ Use this reference when `NeuroSpecification.md` selects `task-training` or the
4
+ training phase of `hybrid`. It owns the experimental contract around task data,
5
+ BrainX State, optimization, monitoring, tuning, checkpoint selection, and
6
+ held-out evaluation. The routed package skills still own model equations,
7
+ construction, simulation, and package-specific APIs.
8
+
9
+ Use task training to optimize model or readout weights over many input-target
10
+ examples. Use `parameter-fitting-workflow.md` instead to estimate
11
+ scientific model parameters against observations. In `hybrid`, keep the two
12
+ objectives, trainable State collections, data partitions, checkpoints, and
13
+ reported evidence distinct.
14
+
15
+ ## Underlying training principle
16
+
17
+ Training reuses the scientific forward model: reset runtime State at the
18
+ declared independence boundary, execute the same BrainX rollout used for
19
+ evaluation, reduce aligned outputs and targets to one scalar loss,
20
+ differentiate only the declared parameter State, and apply one optimizer update
21
+ at the declared cadence.
22
+
23
+ `ParamState` represents learned values that persist across batches. Hidden,
24
+ short-term, random, delay, eligibility, monitor, membrane, conductance, and
25
+ other runtime State represent the condition of one rollout; reset or preserve
26
+ each role according to the scientific protocol, never because an optimizer or
27
+ batch loop makes reset convenient.
28
+
29
+ Do not put a framework-neutral learner around a BrainX simulator callback. Keep
30
+ the forward model, trainable State, runtime State, reset lifecycle, temporal
31
+ execution, physical units, and represented biological scale BrainX-native.
32
+
33
+ ## Lock the training contract
34
+
35
+ Declare the experiment before writing the train step. A later change to the
36
+ task, target, independence unit, data inclusion, primary metric, or accepted
37
+ claim changes the locked specification; do not treat it as hyperparameter
38
+ tuning.
39
+
40
+ | Contract field | Required decision |
41
+ |---|---|
42
+ | Samples | Identify the independence unit: trial, sequence, subject, animal, session, recording, or another declared unit. |
43
+ | Axes and units | Name batch, time, feature, neuron, region, and target axes; record every transpose, temporal alignment, reduction, and unit boundary. |
44
+ | Partitions | Split immutable sample IDs by the independence unit before fitting preprocessing; prevent subject, session, temporal-neighbor, augmentation, and preprocessing leakage. |
45
+ | State lifecycle | Declare which State resets at sample, batch, sequence, phase, training/evaluation, and seed boundaries and which learned State persists. |
46
+ | Trainables | Select only intended parameter State; enumerate every excluded runtime State and any frozen parameter State. |
47
+ | Objective | Lock loss inputs, target alignment, reduction axes, units, regularization, primary metric, metric direction, and chance or null baseline. |
48
+ | Update cadence | Declare whether one optimizer update follows a timestep, window, complete sequence, batch, or accumulated set of batches. |
49
+ | Selection | Lock validation metric, checkpoint rule, seed aggregation, search space, budget, minimum evidence, patience, and stop rule before tuning. |
50
+ | Held-out use | Reserve held-out data until configuration and checkpoint selection are complete; never use it to continue, stop, tune, or choose a seed. |
51
+
52
+ Record the contract as an iteration artifact:
53
+
54
+ ```yaml
55
+ training_contract:
56
+ independence_unit: subject
57
+ axes:
58
+ input: [batch, time, feature]
59
+ target: [batch, class]
60
+ rollout_input: [time, batch, feature]
61
+ reset_boundary: independent_sequence
62
+ trainable_state: declared ParamState collection only
63
+ split_fit_scope: training subjects
64
+ update_cadence: one update per minibatch of complete sequences
65
+ primary_metric: validation loss
66
+ metric_direction: minimize
67
+ checkpoint_rule: minimum validation loss within each run
68
+ config_selection_rule: minimum mean validation loss across declared seeds
69
+ seed_aggregation: mean and declared uncertainty interval
70
+ tuning_budget: 12 completed or invalidated configurations
71
+ held_out_access: after all model and checkpoint selection
72
+ ```
73
+
74
+ Replace the example values with the locked scientific design. Store exact
75
+ sample IDs, preprocessing state, seeds, code/data/environment identity, and
76
+ configuration outside this compact contract and point to those artifacts.
77
+
78
+ ## Pass the mechanical gates
79
+
80
+ Do not start a production baseline until every gate passes on a small case.
81
+
82
+ | Gate | Required evidence |
83
+ |---|---|
84
+ | Data and leakage | Disjoint split IDs, training-only preprocessing fit, expected shapes/units, target range, class or target distribution, and explicit time alignment. |
85
+ | Forward parity | Training and evaluation call the same scientific rollout and observation path; only declared fit/evaluation behavior differs. |
86
+ | State reset | Replaying one sample from the same declared initial State reproduces its output; reordering independent samples does not change their predictions. |
87
+ | Gradient reach | Loss and every intended gradient are finite; expected trainables receive nonzero signal; excluded State is absent from the gradient and optimizer trees. |
88
+ | Update isolation | One update changes intended trainables and optimizer State only; it does not silently change frozen parameters, data transforms, or persistent scientific configuration. |
89
+ | Temporal reduction | A synthetic target at a known timestep changes only the intended scored output or window; masks exclude padding and ignored phases. |
90
+ | Tiny-case overfit | The unchanged pipeline can overfit a tiny batch or short sequence and move the declared metric in the expected direction. |
91
+ | Replay and compilation | Declared seeds replay exactly where promised, and repeated shape-compatible calls reuse the model graph without State-shape drift. |
92
+
93
+ Treat failure as diagnostic evidence. Fix data, State, alignment, gradient, or
94
+ objective mechanics before changing learning rate, optimizer, surrogate,
95
+ architecture, or model dynamics.
96
+
97
+ ## Establish the baseline and run ledger
98
+
99
+ Run 0 is the unchanged declared baseline. Give every run an immutable identity
100
+ and append it to one ledger before interpreting results.
101
+
102
+ | Run field | Record |
103
+ |---|---|
104
+ | Identity | Run ID, parent or warm-start ancestor, status, start/end time, and artifact paths. |
105
+ | Provenance | Exact code revision, data/split manifest, preprocessing state, package/environment identity, device, seed, and command or entry point. |
106
+ | Configuration | Complete resolved model, training, optimizer, schedule, reset, batching, and stopping configuration; do not store only overrides. |
107
+ | Outcomes | Raw training/validation curves, gradient and State diagnostics, checkpoints, runtime/resource data, and the primary plus guardrail metrics. |
108
+ | Decision | `CONTINUE`, `WAIT`, `STOP_INVALID`, `STOP_RULE`, `STOP_BUDGET`, or `COMPLETE`, with the evidence and locked rule that justified it. |
109
+
110
+ Do not compare a tuned run only with another tuned run. Preserve run 0 even
111
+ when it fails, because its failure constrains the next hypothesis.
112
+
113
+ ## Monitor process health and training quality
114
+
115
+ Check process liveness, device activity, checkpoint/log freshness, loss,
116
+ validation metric, learning rate, and gradient norm at the declared cadence. A
117
+ live process can train invalidly; unavailable metrics mean unknown, not failed.
118
+
119
+ | Evidence over the declared window | Decision | Action |
120
+ |---|---|---|
121
+ | Metrics are temporarily unreachable but the process is observable | `WAIT` | Retry observation; preserve the last evidence and make no quality claim. |
122
+ | Process exit, unexpected idle device, stale outputs, storage failure, or no checkpoint progress is confirmed | `STOP_INVALID` | Preserve logs and the last valid checkpoint; retry only the identical compatible run. |
123
+ | NaN/Inf, invalid gradients, State leakage, or target/reset misalignment appears | `STOP_INVALID` | Preserve the first failing step and diagnostics; return to implementation. |
124
+ | Training loss and the locked validation metric improve | `CONTINUE` | Continue; widen the check interval only after repeated healthy checks. |
125
+ | Metrics are flat, noisy, or slightly worse before minimum evidence or patience | `WAIT` | Keep or shorten the interval and gather the next planned checkpoint. |
126
+ | Loss diverges across the window, validation degradation exceeds patience, or gradients repeatedly explode or vanish | `STOP_RULE` | Stop under the locked rule and preserve the metric window and reason. |
127
+ | Maximum epochs or target criterion is reached with valid artifacts | `COMPLETE` | Close the run and compare it through the locked selection rule. |
128
+ | The tuning budget is exhausted | `STOP_BUDGET` | Launch no new configuration; compare every completed or invalidated run. |
129
+
130
+ Do not stop on one noisy point. For every stop, record the run ID, metric window,
131
+ checkpoint and log paths, exact rule, and reason. Monitoring ends or invalidates
132
+ a run; it never validates a scientific claim.
133
+
134
+ ## Tune hyperparameters with bounded evidence
135
+
136
+ Use this bounded hyperparameter-tuning loop: `run -> analyze -> record ->
137
+ choose`. Do not launch tuning until run 0 and the mechanical gates establish
138
+ what needs improvement.
139
+
140
+ 1. Diagnose the limiting signal from the complete run history: optimization,
141
+ generalization, temporal credit assignment, gradient scale, State leakage,
142
+ capacity, or compute/memory.
143
+ 2. State one falsifiable tuning hypothesis and the validation result that would
144
+ support or reject it.
145
+ 3. Choose the smallest coherent parameter set that tests that hypothesis. Give
146
+ each value a type, range, scale, default, and scientific or optimization
147
+ rationale.
148
+ 4. Create a complete new run record before execution. Change no unrecorded
149
+ model, split, preprocessing, reset, metric, seed aggregation, or stop rule.
150
+ 5. Analyze the primary validation metric with its guardrails, gradient/State
151
+ diagnostics, resource cost, and variability. Append failed, stopped, and
152
+ pruned runs to the same ledger.
153
+ 6. Stop when the locked budget or patience is exhausted, the hypothesis is
154
+ rejected, gradients or data become invalid, or no remaining candidate can
155
+ answer the declared question.
156
+
157
+ Establish `Adam` or another routed canonical baseline before a specialized
158
+ optimizer. Do not change optimizer, scheduler, surrogate, temporal reduction,
159
+ reset policy, and architecture together. When parallel resources are available,
160
+ run independent configurations concurrently only if each has an allocated
161
+ budget entry, isolated BrainState/RNG/checkpoint artifacts, and the same locked
162
+ comparison contract.
163
+
164
+ ## Resume and reuse checkpoints safely
165
+
166
+ Checkpoint compatibility is a State-graph and experiment-contract decision,
167
+ not a matching filename.
168
+
169
+ | Case | Rule |
170
+ |---|---|
171
+ | Resume an interrupted run | Restore model parameters, optimizer and scheduler State, RNG State, counters, preprocessing identity, and runtime configuration only when the complete configuration and State tree are identical. |
172
+ | Compare independent hyperparameter candidates | Start every candidate from the same declared initialization or base checkpoint. Do not give one candidate inherited training progress and compare it as an independent run. |
173
+ | Warm-start a later phase | Permit only when the plan declares a dependent phase and parameter structure, shapes, dtypes, units, task, targets, preprocessing, partitions, model dynamics, and runtime-State contract remain compatible. Record the ancestor checkpoint. |
174
+ | Change optimizer or schedule | Parameter-only restore may be valid, but do not restore incompatible optimizer or scheduler State; treat the run as a warm start, not an identical resume. |
175
+ | Change architecture, parameter shapes, solver, `dt`, surrogate, target semantics, preprocessing, data partitions, or State/reset meaning | Restart from the declared initialization. Do not coerce or partially load State to preserve progress. |
176
+
177
+ Save checkpoint metadata with the full State-tree signature and resolved
178
+ configuration. Validate a restored checkpoint with one deterministic evaluation
179
+ before training continues.
180
+
181
+ ## Select without touching held-out data
182
+
183
+ Apply the locked checkpoint rule to validation evidence only. Confirm the
184
+ selected configuration across every declared seed or replication and report
185
+ seed-wise results plus the locked aggregate; never select or present the best
186
+ seed alone.
187
+
188
+ After every modeling, preprocessing, tuning, checkpoint, seed, and stop decision
189
+ is frozen, restore the selected checkpoint for each declared replica, reset
190
+ evaluation State, and evaluate the untouched held-out partition. Preserve raw
191
+ predictions, sample IDs, per-sample or per-group metrics, aggregation, and
192
+ uncertainty. Do not tune, choose another checkpoint, or suppress a seed after
193
+ seeing held-out results.
194
+
195
+ Successful optimization proves that the declared training pipeline can learn
196
+ the task under its tested conditions. It does not by itself establish
197
+ biological validity, mechanism recovery, identifiability, or generalization
198
+ beyond the locked held-out population.
199
+
200
+ ## Return training evidence to the modeling loop
201
+
202
+ Return these artifacts through steps 2-5 of `brainx-modeling-loop`:
203
+
204
+ - the locked training contract, split IDs, and fitted preprocessing state;
205
+ - axis, unit, target-alignment, State-selection, reset, gradient, and tiny-case
206
+ tests;
207
+ - run 0 and the immutable ledger for every completed, stopped, failed, or pruned
208
+ run;
209
+ - raw training and validation curves plus process, gradient, State, runtime, and
210
+ resource diagnostics;
211
+ - every checkpoint, its selection trace, State-tree signature, and compatibility
212
+ decision;
213
+ - seed-wise and aggregate validation results;
214
+ - the untouched held-out predictions, metrics, aggregation, and uncertainty;
215
+ - unresolved training limitations and every claim this evidence does not
216
+ support.
217
+
218
+ Report an out-of-contract request to change the task, target, independence unit,
219
+ data inclusion, primary metric, or accepted claim. Do not edit the locked
220
+ specification inside this coverage. Report implementation, optimizer, schedule,
221
+ reset, checkpoint, or bounded-tuning defects as exact in-contract corrections.
222
+ Step 5 still emits only `REFUSE` or `PASS` and owns the loop transition.
223
+
224
+ ## Common failures
225
+
226
+ - Random row splitting when subjects, sessions, sequences, or neighboring time
227
+ windows are the independence unit.
228
+ - Learned preprocessing fitted outside the training partition.
229
+ - BrainCell scientific-parameter estimation mislabeled as task training.
230
+ - Hidden or runtime State included in the optimizer collection.
231
+ - Dynamical State carried across independent samples or reset across a boundary
232
+ that should preserve it.
233
+ - Raw `jax.grad`, `jax.jit`, or a non-BrainX trainer wrapped around
234
+ State-mutating BrainX code.
235
+ - Target indices shifted relative to the temporal output being scored, or padded
236
+ timesteps included in the loss.
237
+ - Optimizer updates placed inside a temporal loop when the contract specifies
238
+ one update per complete sequence or minibatch.
239
+ - Tuning started before finite gradients and tiny-case overfitting pass.
240
+ - Multiple optimizer, surrogate, architecture, reset, and reduction decisions
241
+ changed in one run without a testable hypothesis.
242
+ - Checkpoint selection, early stopping, seed choice, or tuning influenced by
243
+ held-out metrics.
244
+ - A warm-started run compared as if it were an independent candidate.
245
+ - Best-seed reporting, silent failed-run exclusion, or aggregation changed after
246
+ results.
247
+ - BrainTrace activated for generic speed rather than a demonstrated temporal
248
+ memory bottleneck and an accepted estimator boundary.
249
+
250
+ ## Package and reference routing
251
+
252
+ Read every active modeling skill before implementing training, then open only
253
+ the smallest routed reference that owns the next decision. The package skills
254
+ own model construction and train-step mechanics; this reference owns the
255
+ training contract, gates, experiment discipline, and evidence.
256
+
257
+ | Need | Required route |
258
+ |---|---|
259
+ | Large temporal workloads limited by sequence-length-dependent BPTT activation memory | First open the active package's checkpointed-control-flow reference. When ordinary BPTT remains memory-limited and an online eligibility-trace estimator is scientifically acceptable, open `skills/package-skills/braintrace/SKILL.md` and use BrainTrace as the memory-efficient alternative. Its memory is constant only in sequence length and still scales with batch size, participating parameters, hidden dimensions, and estimator choice. |
260
+
261
+ ### Choose Braintools training components
262
+
263
+ | Decision | BrainPy-State route | BrainMass route |
264
+ |---|---|---|
265
+ | Loss or neuroscience metric | `skills/package-skills/brainpy-state/references/braintools/metric.md` | `skills/package-skills/brainmass/references/braintools/metric.md` |
266
+ | Optimizer, scheduler, clipping, or update lifecycle | `skills/package-skills/brainpy-state/references/braintools/optimizer.md` | `skills/package-skills/brainmass/references/braintools/optimizer.md` |
267
+ | Parameter initialization | `skills/package-skills/brainpy-state/references/braintools/parameter-initializer.md` | `skills/package-skills/brainmass/references/braintools/parameter-initializer.md` |
268
+ | Input encoding | `skills/package-skills/brainpy-state/references/braintools/data-preprocessing.md` | `skills/package-skills/brainmass/references/braintools/data-preprocessing.md` |
269
+ | Hard-spike backward derivative | `skills/package-skills/brainpy-state/references/braintools/surrogate.md` | `skills/package-skills/brainmass/references/braintools/surrogate.md` |
270
+ | Phase-structured cognitive trials | Open the shared `skills/package-skills/brainmass/references/braintools/cogtask.md`, then preserve the BrainPy-State model's time-major input contract. | `skills/package-skills/brainmass/references/braintools/cogtask.md` |
@@ -13,7 +13,7 @@ Use BrainCell for cellular biophysics at either of its two supported spatial sca
13
13
  - Use `Cell` when soma, dendrite, axon, branch geometry, spatial channel distribution, or location-specific stimulation and recording affect the result.
14
14
 
15
15
 
16
- Keep network wiring, projections, and network training outside this skill. Open `skills/brainpy-state/SKILL.md` when multiple cells must communicate.
16
+ Keep network wiring, projections, and network training outside this skill. Open `skills/package-skills/brainpy-state/SKILL.md` when multiple cells must communicate.
17
17
 
18
18
  ## Underlying principle of BrainCell
19
19
 
@@ -100,7 +100,7 @@ assert voltages.shape[:1] == times.shape
100
100
  assert spikes.shape[:1] == times.shape
101
101
  ```
102
102
 
103
- Treat `V_th` only as the spike-event threshold; it does not change the membrane equation. Keep membrane capacitance and channel conductance density-based in the canonical path. `update()` accepts current density or total current and uses `SingleCompartment.area` to normalize total input; do not manually area-scale only part of the model. Use `size=N` for `N` independent cells, never for `N` compartments.
103
+ Treat `V_th` only as the spike-event threshold; it does not change the membrane equation. Keep membrane capacitance and channel conductance density-based in the canonical path. `update()` accepts current density or total current and uses `SingleCompartment.area` to normalize total input; do not manually area-scale only part of the model. Use `size=N` for `N` independent cells, never for `N` compartments. For a multidimensional condition sweep, use the condition-grid shape as `size` and pass shape-aligned channel parameters and inputs; do not wrap identity functions in `vmap` merely to construct that grid.
104
104
 
105
105
  Open `references/area-scaled-hh-pattern.md` when changing cell geometry or explicitly converting density parameters to total quantities. Open `references/ion-library.md`, `references/channel-library.md`, or `references/mixions-for-adaptation.md` only when the classical fixed-ion HH path is insufficient.
106
106
 
@@ -176,21 +176,8 @@ Open only the smallest reference that owns the non-canonical decision.
176
176
  | `references/area-scaled-hh-pattern.md` | Changing single-compartment geometry or converting density parameters consistently to total capacitance and conductance. |
177
177
  | `references/braincell-custom-ion-channel-authoring.md` | Implementing a custom ion or channel after confirming that no built-in mechanism fits. |
178
178
  | `references/channel-library.md` | Selecting a built-in sodium, potassium, calcium, leak, HCN, or mixed-ion channel. |
179
+ | `references/scripts/fitting_hh_neuron.py` | Studying the official complete HH fitting composition: custom sodium and potassium channels, trace loading, unit-bearing bounds, independent cell initialization, time-major rollout, voltage loss, candidate `vmap`, and Nevergrad. Supply the upstream trace CSVs and reconcile its source-version APIs with the current BrainCell and BrainState skills before adapting it. |
179
180
  | `references/ion-library.md` | Choosing fixed, Nernst-initialized, or dynamic ions and their concentration behavior. |
180
181
  | `references/mixions-for-adaptation.md` | Adding calcium-dependent adaptation, AHP/KCa currents, rebound, dynamic calcium, or multi-ion channel dependencies. |
181
182
  | `references/multicompartment/multicompartment-cell-workflow.md` | Extending the canonical `Morphology -> Cell -> paint/place -> run` path and selecting the exclusive multicompartment references. |
182
183
  | `references/solver-library-with-effects.md` | Comparing registered integrators, stability, accuracy, and solver-dependent trace effects. |
183
-
184
- ## Application script examples
185
-
186
- Open one script only when its pattern matches the task; each is a complete, runnable program mirrored from the official BrainCell examples.
187
-
188
- | Script | Open when |
189
- |---|---|
190
- | `references/scripts/hh_neuron_basics.py` | Building one end-to-end `SingleCompartment` current-clamp simulation with Na/K/leak currents; this is the default full-script reference. |
191
- | `references/scripts/fi_curve.py` | Producing FI curves, current sweeps, spike counts, or firing rates, where `size=N` means N independent point neurons. |
192
- | `references/scripts/channel_ablation.py` | Comparing intact against ablated dynamics by setting a conductance such as `g_max` to zero while preserving the ion and channel structure. |
193
- | `references/scripts/calcium_channel_gating.py` | Inspecting voltage-dependent activation or inactivation curves through direct channel methods rather than simulating a membrane trace. |
194
- | `references/scripts/spike_frequency_adaptation.py` | Adding spike-frequency adaptation or calcium-dependent afterhyperpolarization with dynamic calcium and `MixIons`. |
195
- | `references/scripts/t_current_rebound.py` | Producing post-inhibitory rebound bursting from a hyperpolarizing step with T-type calcium and HCN currents. |
196
- | `references/scripts/thalamic_neurons.py` | Comparing several thalamic point-neuron phenotypes built from different ion and channel compositions in one script. |
@@ -17,7 +17,12 @@ import brainunit as u
17
17
 
18
18
 
19
19
  class AdaptingCell(braincell.SingleCompartment):
20
- def __init__(self, size, solver="ind_exp_euler"):
20
+ def __init__(
21
+ self,
22
+ size,
23
+ g_ahp=0.3 * u.mS / u.cm**2,
24
+ solver="ind_exp_euler",
25
+ ):
21
26
  super().__init__(
22
27
  size,
23
28
  V_initializer=braintools.init.Constant(-65. * u.mV),
@@ -51,7 +56,7 @@ class AdaptingCell(braincell.SingleCompartment):
51
56
  self.ca.add(ICaHT=braincell.channel.CaHT_HM1992(size, g_max=3.0 * (u.mS / u.cm ** 2)))
52
57
 
53
58
  self.kca = braincell.MixIons(self.k, self.ca)
54
- self.kca.add(IAHP=braincell.channel.AHP_De1994(size, g_max=0.3 * (u.mS / u.cm ** 2)))
59
+ self.kca.add(IAHP=braincell.channel.AHP_De1994(size, g_max=g_ahp))
55
60
 
56
61
  self.IL = braincell.channel.IL(
57
62
  size,
@@ -60,7 +65,25 @@ class AdaptingCell(braincell.SingleCompartment):
60
65
  )
61
66
  ```
62
67
 
63
- ## Rebound Input Variant
68
+ ## Test adaptation by controlled ablation
69
+
70
+ Expose only AHP `g_max`, set it to zero for the ablated condition, and keep the cell template, initialization, solver, stimulus, and every other conductance identical. Use `SingleCompartment.size` for independent conditions; it already owns the batch axis.
71
+
72
+ ```python
73
+ g_ahp = u.math.asarray([0.0, 0.3]) * u.mS / u.cm**2
74
+ cell = AdaptingCell(size=g_ahp.shape, g_ahp=g_ahp)
75
+ current = u.math.asarray([2.0, 2.0]) * u.uA / u.cm**2
76
+ ```
77
+
78
+ Treat the ISI trajectory as the primary adaptation check: the present-AHP lane should lengthen materially while the zero-AHP lane remains more tonic or fires faster late in the stimulus. Report the early/late windows beside rate summaries. Call a condition "intact" only when its complete model and parameter values come from a sourced template; otherwise call it "AHP present" and disclose any calibration.
79
+
80
+ Verify that stimulus onset starts from the intended baseline. If a calibrated hybrid spikes without applied current, use the same disclosed holding current and initialization in every lane, and assert that no spikes occur before the stimulus. Do not interpret an already-spiking baseline as onset adaptation.
81
+
82
+ Do not combine channel families or tune calcium influx, calcium removal, and AHP conductance solely to force the requested contrast. Preserve a coherent template when making biological claims, or label a hybrid explicitly as a teaching model and check that the conclusion survives a small parameter sweep.
83
+
84
+ Open `references/scripts/spike_frequency_adaptation.py` for a runnable calibrated teaching model with a quiet baseline, strength sweep, and zero-conductance comparison. Open `references/scripts/channel_ablation.py` only when the task needs the general one-parameter channel-ablation pattern without calcium-dependent adaptation.
85
+
86
+ ## Rebound input variant
64
87
 
65
88
  For post-inhibitory rebound, add or retain a low-threshold T-type calcium current such as `CaT_HM1992` and drive a time-dependent hyperpolarizing input.
66
89
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  ## Purpose and boundary
4
4
 
5
- Use this reference when a BrainCell simulation depends on geometry, axial current, regional biophysics, or location-specific stimulation and recording. Keep isopotential cells in `skills/braincell/SKILL.md` and cross-cell connections or training in `skills/brainpy-state/SKILL.md`; never model compartments with `SingleCompartment.size`.
5
+ Use this reference when a BrainCell simulation depends on geometry, axial current, regional biophysics, or location-specific stimulation and recording. Keep isopotential cells in `skills/package-skills/braincell/SKILL.md` and cross-cell connections or training in `skills/package-skills/brainpy-state/SKILL.md`; never model compartments with `SingleCompartment.size`.
6
6
 
7
7
  ## Underlying principle of BrainCell multicompartment cells
8
8
 
@@ -373,7 +373,7 @@ Use continuation, State reset, declaration reset, or a new cell according to wha
373
373
 
374
374
  ## Reference routing
375
375
 
376
- Open the smallest child for the next decision; `skills/braincell/SKILL.md` routes multicompartment work here before these children.
376
+ Open the smallest child for the next decision; `skills/package-skills/braincell/SKILL.md` routes multicompartment work here before these children.
377
377
 
378
378
  | Reference | Open when |
379
379
  |---|---|