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,232 @@
1
+ # BrainX parameter-fitting workflow
2
+
3
+ ## Purpose and boundary
4
+
5
+ Use this reference after `brainx-general-guard` selects the represented biological scales and their owning model skills. Keep model construction, simulation, physical units, dynamical State, observation, and biological meaning inside the active BrainX route while estimating unknown parameters from observed data.
6
+
7
+ Use this reference for the `parameter-fitting` part of `brainx-modeling-loop` steps 2-5. Keep task-training objectives, data splits, and State lifecycles separate during a `hybrid` workflow. Route parameter sweeps without observed targets to the active model skill instead.
8
+
9
+ ## Underlying mental model
10
+
11
+ A parameter map represents the scientific unknowns. It binds every optimizer coordinate to one named BrainX value, physical unit, valid domain, transform, and reporting meaning.
12
+
13
+ The BrainX simulator represents the generative model. Fitted parameter State persists while membrane, channel, synaptic, delay, noise, monitor, and other runtime State follow an explicit reset policy for every independent candidate and protocol.
14
+
15
+ The observation model represents measurement. It maps latent BrainX output into the same signal, axes, time base, preprocessing, missingness, and units as the observed data before the objective is evaluated.
16
+
17
+ The objective represents the fitting claim. It defines which discrepancy is minimized, how components are weighted and reduced, and which observations are reserved for validation.
18
+
19
+ Parameter recovery represents the interpretation gate. A fitted value may support a mechanistic claim only when the exact fitting pipeline can recover that parameter under the actual observation protocol.
20
+
21
+ ## API structure overview
22
+
23
+ | Need | Required route |
24
+ |---|---|
25
+ | Ion, channel, compartment, morphology, or conductance fitting | Open `braincell` for the model and `brainstate` for custom State-aware differentiation. Recreate or reset all cell runtime State for every independent candidate. |
26
+ | Point-neuron, synapse, or spiking-network fitting | Open `brainpy-state`. Route custom gradients through `brainstate`; open the BrainPy-State surrogate reference only when gradients must cross a discrete spike operation. |
27
+ | Aggregate population, region, or whole-brain fitting | Open `brainmass`. Prefer `brainmass.Fitter` and its routed fitting reference before building a custom optimizer loop. |
28
+ | Physical parameters or observations | Open `brainunit`. Preserve quantities through parameter application, simulation, observation, and unit-compatible comparison. |
29
+ | Constrained parameters or regularization | Open the active package's BrainState parameter reference. Record both the unconstrained optimizer value and constrained physical value. |
30
+ | Objective or optimizer selection | Open the active package's Braintools metric or optimizer reference. Prefer package-owned BrainMass objectives when they express the scientific comparison. |
31
+
32
+ Study the selected package skills and their fitting-related examples before implementing. Trace construction, initialization, parameter application, runtime State reset, protocol execution, observation, and reduction end to end.
33
+
34
+ ## Lock the fitting contract
35
+
36
+ Lock these decisions before inspecting observed-data fit results.
37
+
38
+ | Contract field | Required decision |
39
+ |---|---|
40
+ | Scientific target | Classify fitted, fixed, nuisance, observation, hierarchical, and initial-state parameters. State which fitted values require mechanistic interpretation. |
41
+ | Parameter domain | Record name, BrainX destination, unit, valid bounds, transform, initialization, and provenance. Do not invent biological precision. |
42
+ | Data contract | Record independence unit, axes, sampling or time base, physical units, missingness, and immutable fit, validation, and held-out partitions. |
43
+ | Protocol | Match input currents, stimuli, duration, trial count, conditions, noise, initial conditions, and reset boundaries to the observed experiment. |
44
+ | Observation model | Define filtering, mixing, forward modeling, delays, downsampling, feature extraction, normalization, and measurement noise from latent State to data. |
45
+ | Objective | Define every component, direction, weight, reduction axis, normalization, regularizer, and invalid-domain result. |
46
+ | Estimator | Lock backend, starts, seeds, budget, convergence or stopping rule, and candidate-selection rule. |
47
+ | Validation | Lock domain tests, gradient or candidate-batch checks, recovery design, predictive checks, and parameter-specific interpretation criteria. |
48
+
49
+ Use one explicit map whenever parameters cross a flat-array or optimizer boundary:
50
+
51
+ | Position | Name | BrainX destination | Role | Unit | Transform | Bounds | Reported value |
52
+ |---:|---|---|---|---|---|---|---|
53
+
54
+ Never rely on dictionary order or an unlabeled vector to preserve scientific meaning. Test encode -> decode -> encode round trips at nominal and boundary values.
55
+
56
+ ## Select the fitting backend
57
+
58
+ Choose the simplest backend supported by the simulator and objective.
59
+
60
+ | Condition | Use | Required checks |
61
+ |---|---|---|
62
+ | The complete simulator-to-objective path is differentiable and numerically stable | `brainmass.Fitter(..., backend="grad")` or `brainstate.transform.grad` with a Braintools gradient optimizer | Finite and nonzero gradients, a small finite-difference comparison, multiple starts, exact-pipeline recovery, and held-out prediction. |
63
+ | A required branch, observation, or objective is discontinuous, discrete, black-box, or has unreliable gradients | Bounded `brainmass.Fitter` gradient-free backend or the routed Braintools `NevergradOptimizer` or `ScipyOptimizer` | Finite bounds, correct candidate-batch semantics, full evaluation budget, multiple starts, landscape or sensitivity evidence, recovery, and held-out prediction. |
64
+
65
+ Prefer gradients when they are valid. Do not select derivative-free fitting merely because the BrainCell example uses Nevergrad; that example establishes a custom candidate-evaluation pattern, not a universal backend choice.
66
+
67
+ ## Apply the scale-specific pattern
68
+
69
+ | Route | Pattern to preserve |
70
+ |---|---|
71
+ | BrainCell | The HH fitting example constructs and initializes one cell rollout for each unit-bearing conductance and capacitance candidate, evaluates time-major current protocols, and batches derivative-free candidates. Preserve candidate independence and unit-bounded search; reconcile exact channel and State APIs with the current BrainCell skill. |
72
+ | BrainPy-State | The training examples initialize runtime State at each independent sequence, differentiate only the selected `ParamState` collection, transform the complete loss step, and update parameters outside the temporal loop. Reuse that lifecycle for an inverse objective; task loss itself is not parameter fitting. |
73
+ | BrainMass | The fitting examples prefer `Fitter`, mark fitted values with `brainstate.nn.Param(..., fit=True)`, and fit phase-appropriate observations such as settled amplitude rather than an unaligned oscillatory waveform. Use gradient fitting first and change backends only when the objective requires it. |
74
+ | Braintools | Gradient optimizers register trainable State and consume matching gradient trees. `ScipyOptimizer` and `NevergradOptimizer` instead own a complete objective and do not use the register/update lifecycle; Nevergrad requires one loss per candidate. |
75
+
76
+ ## Construct one candidate evaluation
77
+
78
+ One candidate evaluation must apply parameters, reset independent runtime State, execute the exact protocol, build the declared observation, and return one declared scalar loss.
79
+
80
+ | API | Description |
81
+ |---|---|
82
+ | `brainstate.nn.Param(..., fit=True)` | Use for a fitted model value that needs BrainState discovery, a valid-domain transform, or regularization. Read its constrained physical value in the model. |
83
+ | `brainstate.nn.init_all_states(model, ...)` | Use at an independent rollout boundary when the selected model route requires model-wide runtime State initialization. Do not reset fitted parameter State. |
84
+ | `brainstate.transform.grad(loss_fn, grad_states=..., return_value=True)` | Use for a custom stateful differentiable objective. Select only intended parameter State and transform the complete loss evaluation. |
85
+ | `brainmass.Fitter(...)` | Use when BrainMass owns the simulator and its loss, prediction, objective, and backend interfaces express the inverse problem. |
86
+ | `braintools.optim.NevergradOptimizer(...)` | Use for a custom black-box objective that accepts candidate-stacked parameters and returns one loss per candidate. Preserve unit-bearing bounds and independent runtime State. |
87
+ | `braintools.metric.*` | Use when the selected model package has no owning objective. Declare orientation and reduction because many metrics return arrays. |
88
+
89
+ Use the BrainMass path as the canonical high-level workflow:
90
+
91
+ ```python
92
+ import brainmass
93
+ import brainstate
94
+ import braintools
95
+ import brainunit as u
96
+
97
+
98
+ def settled_amplitude(model):
99
+ result = brainmass.Simulator(model, dt=0.1 * u.ms).run(
100
+ 300.0 * u.ms,
101
+ monitors=["x"],
102
+ transient=150.0 * u.ms,
103
+ )
104
+ x = u.get_magnitude(result["x"])
105
+ x = x - u.math.mean(x)
106
+ return u.math.sqrt(u.math.mean(x ** 2))
107
+
108
+
109
+ target = settled_amplitude(
110
+ brainmass.HopfStep(
111
+ in_size=1,
112
+ a=1.5,
113
+ w=0.3,
114
+ beta=1.0,
115
+ init_x=braintools.init.Constant(0.5),
116
+ init_y=braintools.init.Constant(0.0),
117
+ )
118
+ )
119
+ model = brainmass.HopfStep(
120
+ in_size=1,
121
+ a=brainstate.nn.Param(
122
+ 0.1,
123
+ t=brainstate.nn.SigmoidT(0.05, 3.0),
124
+ fit=True,
125
+ ),
126
+ w=0.3,
127
+ beta=1.0,
128
+ init_x=braintools.init.Constant(0.5),
129
+ init_y=braintools.init.Constant(0.0),
130
+ )
131
+
132
+
133
+ def loss_fn(candidate):
134
+ prediction = settled_amplitude(candidate)
135
+ return (prediction - target) ** 2, prediction
136
+
137
+
138
+ fit = brainmass.Fitter(
139
+ model,
140
+ braintools.optim.Adam(lr=0.05),
141
+ loss_fn=loss_fn,
142
+ backend="grad",
143
+ ).fit(n_steps=100)
144
+
145
+ assert fit.best_loss <= fit.history[0]
146
+ assert u.math.isfinite(fit.best_params["a"])
147
+ assert u.math.abs(fit.best_params["a"] - 1.5) < 0.1
148
+ ```
149
+
150
+ This proves only that one synthetic target is mechanically recoverable. It does not establish identifiability across the parameter domain or under the observed protocol.
151
+
152
+ ## Validate fitting mechanics
153
+
154
+ 1. Evaluate nominal, boundary, and invalid parameter values. Verify shapes, units, finite outputs, expected failures, and constraint behavior.
155
+ 2. Verify deterministic replay or characterize stochastic variation under declared seeds. Reset every State whose carryover is not part of the protocol.
156
+ 3. Inspect every objective component before reduction. Confirm its direction, unit behavior, weight, and contribution at nominal values.
157
+ 4. For oscillatory data, use scientifically justified phase-insensitive observations such as amplitude, spectrum, FC, or FCD when waveform phase is not aligned.
158
+ 5. For gradient fitting, compare autodiff with finite differences on a small stable case and inspect zero, exploding, `NaN`, or parameter-missing gradients.
159
+ 6. For derivative-free fitting, verify candidate-axis shape, one loss per candidate, unit reconstruction, bounds, invalid-candidate behavior, and total evaluation count.
160
+ 7. Inspect sensitivity, tradeoffs, flat directions, discontinuities, and numerical boundaries before running the full fit.
161
+
162
+ ## Run exact-pipeline parameter recovery
163
+
164
+ Recovery must use the same simulator, protocol, observation model, preprocessing, bounds, starts, seeds, objective, backend, budget, stopping rule, and candidate-selection rule as the observed-data fit.
165
+
166
+ | Step | Action | Required evidence |
167
+ |---|---|---|
168
+ | 1. Draw truth | Sample labeled physical parameter sets across the full plausible joint domain, including nuisance variation. | Generating table with names, units, provenance, and seeds. |
169
+ | 2. Generate observations | Run the BrainX model with the real duration, stimuli, sampling, noise, missingness, and State reset policy. | Latent and observed outputs plus simulation diagnostics. |
170
+ | 3. Fit blindly | Run the unchanged fitting pipeline without exposing truth to initialization, stopping, or selection. | Every start, trace, failure, boundary hit, and selected candidate. |
171
+ | 4. Compare | Join recovered and generating values by parameter name and unit. | Bias, MAE or RMSE, recovered-versus-true association, boundary rate, and fit-failure rate. |
172
+ | 5. Inspect tradeoffs | Examine paired errors, sensitivity, profile losses, or objective contours. | Ridges, compensating parameters, flat regions, and failure regions. |
173
+ | 6. Gate interpretation | Apply criteria locked before observed fitting to each parameter separately. | `interpretable`, `weakly-identified`, or `non-identifiable-under-this-protocol`. |
174
+
175
+ Do not copy universal sample counts or correlation thresholds from another model. Choose enough generating datasets to resolve the error, tradeoff, and failure behavior required by the scientific claim, then justify and lock that count.
176
+
177
+ High recovered-versus-true correlation can coexist with large bias. Low aggregate loss can coexist with parameter tradeoffs. Report multiple diagnostics and preserve failed fits rather than dropping them.
178
+
179
+ Poor parameter recovery may still permit a predictive result. In that case, report prediction under the tested protocol and explicitly withhold parameter-level interpretation.
180
+
181
+ ## Fit observed data and check predictions
182
+
183
+ Fit observed data only after recovery passes the locked parameter-specific criteria or the researcher approves a narrower predictive claim.
184
+
185
+ - Preserve every start, seed, trace, failed evaluation, boundary hit, and candidate-selection decision.
186
+ - Select candidates with the locked rule; do not report only the most favorable start or seed.
187
+ - Evaluate held-out data or protocols through the same observation and reset path used during fitting.
188
+ - Report raw predictions, residuals, parameter uncertainty or start-to-start variability, and protocol-wise metrics.
189
+ - Treat good prediction as evidence about prediction under the tested protocol, not parameter identifiability or biological validity.
190
+
191
+ ## Return fitting evidence
192
+
193
+ | Artifact | Required contents |
194
+ |---|---|
195
+ | Fitting contract | Parameter map, data partitions, protocol, observation model, objective, estimator, budgets, seeds, and locked criteria. |
196
+ | Mechanics checks | Parameter round trips, State reset, unit and shape tests, nominal and boundary runs, gradient or candidate-batch checks. |
197
+ | Recovery evidence | Generating parameters, every recovered estimate, bias and error summaries, tradeoffs, boundary and failure rates, and parameter classifications. |
198
+ | Observed fit | Every run, trace, failure, selected result, constrained physical parameters, and reproducibility metadata. |
199
+ | Predictive evidence | Held-out simulations, raw observations, residuals, variability or uncertainty, and protocol-wise metrics. |
200
+ | Claim boundary | Supported parameter interpretations, prediction-only results, non-identifiable targets, model limitations, and unresolved alternatives. |
201
+
202
+ ## Package routing
203
+
204
+ | Route | Open when |
205
+ |---|---|
206
+ | `parameter-fitting-workflow/scripts/fitting_hh_neuron.py` | Studying the official complete BrainCell HH derivative-free fitting composition: custom channels, unit-bearing bounds, per-candidate cell initialization, time-major rollout, voltage loss, candidate `vmap`, and Nevergrad. Supply the upstream `input_traces_hh.csv` and `output_traces_hh.csv` files, and reconcile its source-version BrainCell and BrainState APIs with the current package skills before adapting it. |
207
+ | `brainmass` -> `references/fitting-with-objectives-api.md` | Selecting `Fitter` interfaces, objectives, callbacks, `FitResult` fields, or gradient versus gradient-free backends. |
208
+ | `brainmass` -> `references/scripts/eeg-fitting-with-gradients.py` | Studying a complete phase-insensitive EEG fitting and synthetic-recovery example. |
209
+ | `brainmass` -> `references/scripts/gradient-free-fitting.py` | A bounded non-differentiable or black-box BrainMass objective requires Nevergrad or SciPy. |
210
+ | `brainstate` -> gradient and parameter references | Differentiating custom BrainCell or BrainPy-State rollouts, selecting parameter State, or applying constraints and regularization. |
211
+ | Active model package -> Braintools optimizer reference | Selecting gradient optimizers, schedules, SciPy, Nevergrad, or their distinct lifecycle and unit contracts. |
212
+ | Active model package -> Braintools metric reference | Selecting regression, spike-train, spectral, synchronization, FC, or other observation-space metrics. |
213
+
214
+ ## Boundaries and common failures
215
+
216
+ - Fitting latent State directly to measured data without the declared observation model.
217
+ - Flattening unit-bearing parameters without a tested name, order, unit, and transform map.
218
+ - Resetting fitted parameters between candidates or carrying runtime State across independent candidates.
219
+ - Treating a surrogate gradient as evidence that a fitted spiking parameter is identifiable.
220
+ - Fitting raw oscillatory waveforms when phase is not experimentally aligned.
221
+ - Selecting derivative-free fitting before checking whether gradients are valid.
222
+ - Changing bounds, summaries, exclusions, weights, or recovery criteria after inspecting observed-data results.
223
+ - Running recovery with longer, cleaner, denser, or easier data than the real protocol.
224
+ - Interpreting aggregate fit quality as parameter recovery.
225
+ - Hiding failed starts, invalid simulations, or boundary solutions.
226
+
227
+ ## BrainX source patterns
228
+
229
+ - BrainCell HH fitting: `parameter-fitting-workflow/scripts/fitting_hh_neuron.py`, mirrored from `https://github.com/chaobrain/braincell/blob/main/examples/single_compartment/SC01_fitting_a_hh_neuron.py`
230
+ - BrainPy-State SNN training lifecycle: `https://brainx.chaobrain.com/brainpy-state/brainpy-style/tutorials/04-train-an-snn.html`
231
+ - BrainMass gradient fitting: `https://brainx.chaobrain.com/brainmass/tutorials/06_fitting_with_gradients.html`
232
+ - BrainMass gradient-free fitting: `https://brainx.chaobrain.com/brainmass/tutorials/07_gradient_free_fitting.html`
@@ -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.