brainx-skill 1.0.6 → 1.0.9

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 (120) hide show
  1. package/README.md +10 -8
  2. package/adapters/gemini.js +7 -0
  3. package/adapters/opencode.js +7 -0
  4. package/adapters/windsurf.js +7 -0
  5. package/installation/lib/installer.js +4 -1
  6. package/manifest.json +6 -1
  7. package/package.json +8 -2
  8. package/skills/braincell/SKILL.md +182 -0
  9. package/skills/braincell/references/area-scaled-hh-pattern.md +54 -0
  10. package/skills/braincell/references/braincell-custom-ion-channel-authoring.md +273 -0
  11. package/skills/braincell/references/channel-library.md +85 -0
  12. package/skills/braincell/references/ion-library.md +87 -0
  13. package/skills/braincell/references/mixions-for-adaptation.md +81 -0
  14. package/skills/braincell/references/multicompartment/braincell-manual-morphology-construction.md +180 -0
  15. package/skills/braincell/references/multicompartment/cv-policy-reference.md +133 -0
  16. package/skills/braincell/references/multicompartment/filter-function-library.md +154 -0
  17. package/skills/braincell/references/multicompartment/morphology-io-loading-validation.md +135 -0
  18. package/skills/braincell/references/multicompartment/multicompartment-cell-workflow.md +391 -0
  19. package/skills/braincell/references/multicompartment/probe-reference.md +128 -0
  20. package/skills/braincell/references/multicompartment/topology-building-and-visualization.md +260 -0
  21. package/skills/braincell/references/scripts/calcium_channel_gating.py +66 -0
  22. package/skills/braincell/references/scripts/cell_multicompartment_reference.py +221 -0
  23. package/skills/braincell/references/scripts/channel_ablation.py +61 -0
  24. package/skills/braincell/references/scripts/fi_curve.py +68 -0
  25. package/skills/braincell/references/scripts/hh_neuron_basics.py +59 -0
  26. package/skills/braincell/references/scripts/spike_frequency_adaptation.py +75 -0
  27. package/skills/braincell/references/scripts/t_current_rebound.py +72 -0
  28. package/skills/braincell/references/scripts/thalamic_neurons.py +228 -0
  29. package/skills/braincell/references/solver-library-with-effects.md +188 -0
  30. package/skills/brainevent/SKILL.md +268 -0
  31. package/skills/brainevent/references/connectivity-variants.md +312 -0
  32. package/skills/brainevent/references/custom-operators-cpu.md +304 -0
  33. package/skills/brainevent/references/custom-operators-gpu.md +468 -0
  34. package/skills/brainevent/references/scripts/102_EI_net_1996.py +107 -0
  35. package/skills/brainevent/references/scripts/204_joglekar_2018_propagation.py +168 -0
  36. package/skills/brainevent/references/scripts/coba_ei_teaching.py +356 -0
  37. package/skills/brainevent/references/sparse-formats.md +182 -0
  38. package/skills/brainevent/references/synaptic-plasticity.md +285 -0
  39. package/skills/brainmass/SKILL.md +290 -0
  40. package/skills/brainmass/references/batch-transform-acceleration.md +136 -0
  41. package/skills/brainmass/references/brainstate/parameter-constraints-regularization.md +214 -0
  42. package/skills/brainmass/references/brainstate/parameter-transforms-regularizers-catalog.md +171 -0
  43. package/skills/brainmass/references/braintools/cogtask.md +190 -0
  44. package/skills/brainmass/references/braintools/data-preprocessing.md +83 -0
  45. package/skills/brainmass/references/braintools/metric.md +157 -0
  46. package/skills/brainmass/references/braintools/optimizer.md +187 -0
  47. package/skills/brainmass/references/braintools/parameter-initializer.md +187 -0
  48. package/skills/brainmass/references/braintools/surrogate.md +151 -0
  49. package/skills/brainmass/references/coupling-network-api.md +148 -0
  50. package/skills/brainmass/references/datasets-api.md +72 -0
  51. package/skills/brainmass/references/fitting-with-objectives-api.md +146 -0
  52. package/skills/brainmass/references/forward-observation-api.md +131 -0
  53. package/skills/brainmass/references/horn-task-training.md +199 -0
  54. package/skills/brainmass/references/modellibrary.md +104 -0
  55. package/skills/brainmass/references/noiseprocesses.md +121 -0
  56. package/skills/brainmass/references/parameter-sweeps-and-regime-analysis.md +130 -0
  57. package/skills/brainmass/references/scripts/eeg-fitting-with-gradients.py +230 -0
  58. package/skills/brainmass/references/scripts/gradient-free-fitting.py +106 -0
  59. package/skills/brainmass/references/scripts/hopf-bifurcation-single-node.py +78 -0
  60. package/skills/brainmass/references/scripts/horn-cognitive-task-training.py +211 -0
  61. package/skills/brainmass/references/scripts/jansen-rit-eeg-proxy.py +76 -0
  62. package/skills/brainmass/references/scripts/kuramoto-synchronization.py +81 -0
  63. package/skills/brainmass/references/scripts/linear-baseline-node.py +81 -0
  64. package/skills/brainmass/references/scripts/resting-state-meg-whole-brain-pipeline.py +249 -0
  65. package/skills/brainmass/references/scripts/seizure-epileptor-case-study.py +126 -0
  66. package/skills/brainmass/references/scripts/wilson-cowan-ei-dynamics.py +86 -0
  67. package/skills/brainmass/references/scripts/wong-wang-decision-making.py +167 -0
  68. package/skills/brainmass/references/scripts/wong-wang-dmf-resting-state.py +72 -0
  69. package/skills/brainmass/references/visualization-analysis-api.md +130 -0
  70. package/skills/brainpy-state/SKILL.md +232 -0
  71. package/skills/brainpy-state/references/array-creation.md +158 -0
  72. package/skills/brainpy-state/references/brain-dynamics-delay-protocol.md +96 -0
  73. package/skills/brainpy-state/references/braintools/brainstate-control-flow-patterns.md +334 -0
  74. package/skills/brainpy-state/references/braintools/data-preprocessing.md +79 -0
  75. package/skills/brainpy-state/references/braintools/metric.md +152 -0
  76. package/skills/brainpy-state/references/braintools/optimizer.md +179 -0
  77. package/skills/brainpy-state/references/braintools/parameter-initializer.md +183 -0
  78. package/skills/brainpy-state/references/braintools/surrogate.md +147 -0
  79. package/skills/brainpy-state/references/component-selection.md +273 -0
  80. package/skills/brainpy-state/references/nest-compatible/devices.md +157 -0
  81. package/skills/brainpy-state/references/nest-compatible/divergence-and-parity.md +114 -0
  82. package/skills/brainpy-state/references/nest-compatible/integration-categories.md +41 -0
  83. package/skills/brainpy-state/references/nest-compatible/model-library.md +200 -0
  84. package/skills/brainpy-state/references/nest-compatible/nest-workflow.md +156 -0
  85. package/skills/brainpy-state/references/nest-compatible/network-building.md +264 -0
  86. package/skills/brainpy-state/references/nest-compatible/scripts/brette_et_al_2007.py +320 -0
  87. package/skills/brainpy-state/references/nest-compatible/scripts/brunel_alpha.py +108 -0
  88. package/skills/brainpy-state/references/nest-compatible/scripts/brunel_delta.py +93 -0
  89. package/skills/brainpy-state/references/nest-compatible/scripts/clopath_synapse_spike_pairing.py +171 -0
  90. package/skills/brainpy-state/references/nest-compatible/scripts/evaluate_tsodyks2_synapse.py +147 -0
  91. package/skills/brainpy-state/references/nest-compatible/scripts/spatial_gaussex.py +112 -0
  92. package/skills/brainpy-state/references/nest-compatible/scripts/synapsecollection.py +198 -0
  93. package/skills/brainpy-state/references/nest-compatible/synapse-and-connectivity.md +153 -0
  94. package/skills/brainpy-state/references/projection-patterns.md +125 -0
  95. package/skills/brainpy-state/references/scripts/103_COBA_2005.py +86 -0
  96. package/skills/brainpy-state/references/scripts/106_COBA_HH_2007.py +181 -0
  97. package/skills/brainpy-state/references/scripts/107_gamma_oscillation_1996.py +156 -0
  98. package/skills/brainpy-state/references/scripts/109_fast_global_oscillation.py +111 -0
  99. package/skills/brainpy-state/references/scripts/201_surrogate_grad_lif_fashion_mnist.py +221 -0
  100. package/skills/brainpy-state/references/scripts/training-snn.py +119 -0
  101. package/skills/brainstate/SKILL.md +1 -1
  102. package/skills/brainstate/references/brainstate/brainstate-control-flow-patterns.md +250 -399
  103. package/skills/brainstate/references/brainstate/brainstate-transformed-diagnostics.md +6 -2
  104. package/skills/brainstate/references/brainstate/parameter-constraints-regularization.md +16 -2
  105. package/skills/brainstate/references/brainstate/parameter-transforms-regularizers-catalog.md +8 -3
  106. package/skills/brainstate/references/brainstate/randomness-and-reproducibility.md +64 -143
  107. package/skills/brainstate/references/brainstate/transformation-grad-expansion.md +13 -1
  108. package/skills/brainstate/references/brainstate/transformation-jit-expansion.md +11 -1
  109. package/skills/brainstate/references/brainstate/transformation-vmap-expansion.md +35 -7
  110. package/skills/brainstate/references/collective_model_operations.md +9 -9
  111. package/skills/brainstate/references/extension_mechanisms.md +12 -1
  112. package/skills/brainstate/references/libraries/prebuilt-activation-library.md +106 -97
  113. package/skills/brainstate/references/libraries/prebuilt-layer-library.md +102 -176
  114. package/skills/brainstate/references/model-interop-and-migration.md +11 -1
  115. package/skills/brainstate/references/size-inference-variations.md +11 -0
  116. package/skills/brainstate/references/state-graph-operations.md +13 -15
  117. package/skills/brainstate/references/state_collections_and_utilities.md +12 -1
  118. package/skills/brainx-general-guard/SKILL.md +68 -0
  119. package/skills/brainstate/references/braintools-optimizer-reference.md +0 -133
  120. package/skills/brainstate/references/libraries/solver-library-with-effects.md +0 -85
@@ -1,4 +1,4 @@
1
- # Brainstate state-graph operations
1
+ # BrainState state-graph operations
2
2
 
3
3
  Use this reference after the core `State`, `Module`, and transform rules in
4
4
  `SKILL.md`. It covers the less-frequent graph operations needed to find,
@@ -13,6 +13,18 @@ cycles are encoded by integer index rather than duplicated.
13
13
  Source URL:
14
14
  https://brainx.chaobrain.com/brainstate/apis/graph.html
15
15
 
16
+ ## Selection map
17
+
18
+ | Need | Use | Key constraint |
19
+ |---|---|---|
20
+ | Inspect graph paths and live objects | `iter_node()`, `iter_leaf()`, `nodes()`, or `states()` | Filters select by path and value without changing graph structure. |
21
+ | Extract State as a PyTree | `treefy_states()` | No `GraphDef` is returned, so this path alone cannot reconstruct the graph. |
22
+ | Partition State and reconstruct later | `treefy_split()` plus `treefy_merge()` | Preserve the returned `GraphDef` and every matching partition. |
23
+ | Produce the low-level graph representation | `flatten()` plus `unflatten()` | The pair preserves sharing and cycles through graph indices. |
24
+ | Update State values in an existing graph | `update_states()` | This replaces values, not graph nodes. |
25
+ | Remove matching State objects | `pop_states()` | This is destructive. |
26
+ | Move graph nodes through a larger PyTree | `graph_to_tree()` plus `tree_to_graph()` | Preserve each `NodeStates` wrapper. |
27
+
16
28
  ## Find nodes, leaves, and states
17
29
 
18
30
  Use traversal when the path is part of the decision. `iter_node()` yields
@@ -202,17 +214,3 @@ shared index across the related operations. For a deep copy of one graph,
202
214
 
203
215
  Source URL:
204
216
  https://brainx.chaobrain.com/brainstate/apis/graph.html
205
-
206
- ## Selection rules
207
-
208
- - Need paths plus graph objects: `iter_node()`, `iter_leaf()`, `nodes()`, or
209
- `states()`.
210
- - Need only a parameter/state PyTree: `treefy_states()`.
211
- - Need filtered state PyTrees and later reconstruction: `treefy_split()` plus
212
- `treefy_merge()`.
213
- - Need one low-level graph IR and nested state mapping: `flatten()` plus
214
- `unflatten()`.
215
- - Need to update an existing graph: `update_states()`.
216
- - Need destructive removal: `pop_states()`.
217
- - Need graph nodes to cross a larger pytree boundary: `graph_to_tree()` plus
218
- `tree_to_graph()`.
@@ -1,9 +1,20 @@
1
- # Brainstate state collections and utility toolkit
1
+ # BrainState state collections and utility toolkit
2
2
 
3
3
  Use this reference for the collection-focused parts of BrainState's Utility Toolkit: managing mappings, nested configuration, dictionary conversion, immutable structured PyTrees, declarative filters, and readable PyTree containers. These utilities organize data; the core `State` and `Module` programming model remains in the parent `SKILL.md`.
4
4
 
5
5
  Official page: https://brainx.chaobrain.com/brainstate/how_to/filter_and_organize_states.html
6
6
 
7
+ ## Selection map
8
+
9
+ | Need | Use | Key constraint |
10
+ |---|---|---|
11
+ | Filter, split, or transform a mapping | `DictManager` | Operates on collection values; it does not preserve Module graph identity. |
12
+ | Access nested configuration by attribute | `DotDict` | Convert back with `to_dict()` at plain-dictionary boundaries. |
13
+ | Merge or convert dotted-key dictionaries | `merge_dicts`, `flatten_dict`, `unflatten_dict` | Dotted-string keys differ from tuple graph paths. |
14
+ | Keep an immutable structured mapping | `FrozenDict` and related PyTree utilities | Replace values functionally rather than mutating in place. |
15
+ | Build a reusable path/value predicate | `to_predicate`, `OfType`, `WithTag`, `Any`, or `All` | Filters receive both path and value. |
16
+ | Preserve readable nested or flat PyTree containers | `NestedDict`, `FlattedDict`, `PrettyList`, `flat_mapping`, `nest_mapping` | `flat_mapping` uses tuple paths, not dotted strings. |
17
+
7
18
  ## Managing collections with `DictManager`
8
19
 
9
20
  Source URL: https://brainx.chaobrain.com/brainstate/how_to/filter_and_organize_states.html
@@ -0,0 +1,68 @@
1
+ ---
2
+ name: brainx-general-guard
3
+ description: Use first for every BrainX modeling, simulation, training, review, debugging, or optimization task. Identify every modeling scale explicitly represented, open only the BrainX package skills that own those scales, and keep the implementation BrainX-native.
4
+ ---
5
+
6
+ # BrainX general guard
7
+
8
+ ## Purpose and boundary
9
+
10
+ Open this guard before any package skill for every BrainX modeling task. First identify every modeling scale explicitly represented, then open the package skills that own those scales and keep this guard active as the cross-cutting implementation layer.
11
+
12
+ ## Select modeling skills by represented scale
13
+
14
+ Select every row supported by the user's task. A single-scale task opens one modeling skill; a multiscale task may open two or all three.
15
+
16
+ | The task explicitly represents | Open |
17
+ |---|---|
18
+ | Point neurons, synapses, or point-neuron spiking networks | BrainPy-State |
19
+ | Ions, channels, compartments, or cellular morphology | BrainCell |
20
+ | Aggregate neural populations, local circuits, brain regions, or whole-brain dynamics | BrainMass |
21
+ | Detailed cells connected into a spiking network | BrainCell + BrainPy-State |
22
+ | Point-neuron spiking networks coupled to aggregate regional dynamics | BrainPy-State + BrainMass |
23
+ | Cellular mechanisms coupled to aggregate neural-mass dynamics | BrainCell + BrainMass |
24
+ | Cellular biophysics, point-neuron networks, and aggregate population dynamics interacting in one workflow | BrainCell + BrainPy-State + BrainMass |
25
+
26
+ Use the finest explicitly modeled unit to distinguish adjacent scales: point neurons select BrainPy-State, explicit cellular mechanisms select BrainCell, and aggregate population variables select BrainMass.
27
+
28
+ ## Write BrainX-native code
29
+
30
+ Start from the scientific concept and use the selected BrainX skills to construct the workflow. Avoid raw NumPy or JAX unless at an explicit interoperability boundary or after verifying an API gap.
31
+
32
+ ## Prefer high-level BrainX APIs
33
+
34
+ Use high-level APIs as the abstraction boundary: simulation code should state the scientific operation while BrainX handles array manipulation, unit propagation, State threading, numerical steps, and infrastructure.
35
+
36
+ | Need | Prefer |
37
+ |---|---|
38
+ | Physical values, array creation or structure, mathematical operations | BrainUnit quantities and `brainunit.math` |
39
+ | Connectivity, encoding, inputs, initialization, integration, metrics, optimization, surrogate gradients, training, visualization | `braintools.conn`, `input`, `init`, `quad`, `metric`, `optim`, `surrogate`, `trainer`, or `visualize` |
40
+ | Mutable model state, compilation, differentiation, batching, control flow, randomness | `brainstate.State`, `brainstate.nn.Module`, `brainstate.transform`, and `brainstate.random` |
41
+ | Cells, events, networks, mass models, or traces | The corresponding BrainCell, BrainEvent, BrainPy-State, BrainMass, or BrainTrace abstraction |
42
+
43
+ Do not let code grow around manual indexing, reshaping, reductions, equations, loops, or bookkeeping. Prefer one named BrainX operation or Module over a chain of generic primitives.
44
+
45
+ Write custom logic only when it expresses model behavior that the ecosystem does not already provide. Verify the owning skill, reference, or official API page before using an unfamiliar name or signature.
46
+
47
+
48
+ ## Transform stateful execution
49
+
50
+ Transform the complete stateful operation with `brainstate.transform` whenever practical.
51
+
52
+ | API | Use |
53
+ |---|---|
54
+ | `brainstate.transform.jit`, `grad`, `vmap` | Compile, differentiate, or batch a complete stateful forward, simulation, or training operation. |
55
+ | `brainstate.transform.for_loop` | Run a fixed time or data sequence when iteration-to-iteration effects live in `State`; it slices leading input axes and stacks per-step outputs. |
56
+ | `brainstate.transform.scan` | Run a sequence when an ordinary explicit carry must pass between iterations. |
57
+
58
+ Do not use a Python loop for simulation timesteps, recurrent sequences, or other repeated State updates that should execute as one compiled operation. Keep Python loops for static Module construction, configuration, host-side orchestration, and debugging outside the transformed execution path.
59
+
60
+ Use raw JAX transformations only for pure array or PyTree functions that do not close over BrainState `State`.
61
+
62
+ ## Boundaries and common failures
63
+
64
+ - Generic NumPy or JAX used as the starting architecture for a BrainX simulation.
65
+ - Manual array or mathematical machinery that duplicates BrainUnit or BrainTools.
66
+ - Python loops around stateful simulation or training steps.
67
+ - Raw `jax.jit`, `jax.grad`, or `jax.vmap` applied to State-aware code.
68
+ - Fabricated APIs or signatures accepted without checking the owning documentation.
@@ -1,133 +0,0 @@
1
- # Braintools optimizer selection reference
2
-
3
- Use this reference to select a `braintools.optim` optimizer, learning-rate scheduler, Optax bridge, or external optimizer wrapper. It is a selection adapter, not a BrainState training-loop guide: return to `skills/brainstate/SKILL.md` for the canonical State-aware training structure. Advanced full-training workflows are outside the supplied router.
4
-
5
- **Source URL:** https://brainx.chaobrain.com/braintools/optim/index.html
6
-
7
- ## Route from the official optimization index
8
-
9
- The index states: "Optimization guides highlight practical solvers for tuning models and experiments. Compare gradient-free Nevergrad strategies with SciPy-based routines and learn when to apply each."
10
-
11
- Use its five routes as follows, without importing their unshown details into this reference:
12
-
13
- | Official index route | Selection cue available on the index |
14
- |---|---|
15
- | Tutorial 1: `NevergradOptimizer` Tutorial | Gradient-free Nevergrad strategy |
16
- | Tutorial 2: `ScipyOptimizer` Tutorial | SciPy-based routine |
17
- | Tutorial 3: Getting Started with `optax` Optimizers | Optax optimizer route |
18
- | Tutorial 4: Learning Rate Scheduling Strategies | Learning-rate scheduler selection |
19
- | Tutorial 5: Advanced Optimizers and Techniques | Optimizer choices beyond the basic route |
20
-
21
- **Source URL:** https://brainx.chaobrain.com/braintools/optim/index.html
22
-
23
- ## Optimizer and state types
24
-
25
- The index exposes the `braintools.optim` module and lists `Optimizer`, `OptaxOptimizer`, and `OptimState` before its concrete optimizer classes. For class selection, preserve the module and symbol names exactly:
26
-
27
- ```python
28
- import braintools.optim
29
-
30
- optimizer_type = braintools.optim.Adam
31
- ```
32
-
33
- Concrete optimizer classes, in index order:
34
-
35
- - `SGD`
36
- - `Momentum`
37
- - `MomentumNesterov`
38
- - `Adam`
39
- - `AdamW`
40
- - `Adagrad`
41
- - `Adadelta`
42
- - `RMSprop`
43
- - `Adamax`
44
- - `Nadam`
45
- - `RAdam`
46
- - `Lamb`
47
- - `Lars`
48
- - `Lookahead`
49
- - `Yogi`
50
- - `LBFGS`
51
- - `Rprop`
52
- - `Adafactor`
53
- - `AdaBelief`
54
- - `Lion`
55
- - `SM3`
56
- - `Novograd`
57
- - `Fromage`
58
- - `SOFO`
59
- - `SOFOScan`
60
-
61
- The index does not provide constructor signatures, update semantics, or comparative algorithm guidance. Select the requested class here; do not infer arguments or substitute a training workflow from this catalog.
62
-
63
- **Source URL:** https://brainx.chaobrain.com/braintools/optim/index.html
64
-
65
- ## Learning-rate schedulers
66
-
67
- The scheduler base and concrete scheduler symbols are listed together. Select the exact class first, then return to the main BrainState skill for the surrounding canonical training structure.
68
-
69
- ```python
70
- import braintools.optim
71
-
72
- scheduler_type = braintools.optim.ExponentialDecayLR
73
- ```
74
-
75
- Scheduler classes, in index order:
76
-
77
- - `LRScheduler`
78
- - `StepLR`
79
- - `MultiStepLR`
80
- - `ConstantLR`
81
- - `LinearLR`
82
- - `ExponentialLR`
83
- - `PolynomialLR`
84
- - `ExponentialDecayLR`
85
- - `CosineAnnealingLR`
86
- - `CosineAnnealingWarmRestarts`
87
- - `WarmupCosineSchedule`
88
- - `CyclicLR`
89
- - `OneCycleLR`
90
- - `ReduceLROnPlateau`
91
- - `WarmupScheduler`
92
- - `PiecewiseConstantSchedule`
93
- - `ChainedScheduler`
94
- - `SequentialLR`
95
-
96
- **Source URL:** https://brainx.chaobrain.com/braintools/optim/index.html
97
-
98
- ## Optax bridge
99
-
100
- The index pairs a "Getting Started with `optax` Optimizers" route with the exported `OptaxOptimizer` symbol. Select that bridge only when the task explicitly calls for the Optax route through Braintools:
101
-
102
- ```python
103
- import braintools.optim
104
-
105
- optax_bridge_type = braintools.optim.OptaxOptimizer
106
- ```
107
-
108
- The index gives no adapter constructor or Optax transformation example, so this reference does not invent one.
109
-
110
- **Source URL:** https://brainx.chaobrain.com/braintools/optim/index.html
111
-
112
- ## Scipy and nevergrad wrappers
113
-
114
- The index distinguishes "gradient-free Nevergrad strategies" from "SciPy-based routines" and lists the wrapper symbols `NevergradOptimizer` and `ScipyOptimizer`.
115
-
116
- ```python
117
- import braintools.optim
118
-
119
- gradient_free_wrapper_type = braintools.optim.NevergradOptimizer
120
- scipy_wrapper_type = braintools.optim.ScipyOptimizer
121
- ```
122
-
123
- - Select `NevergradOptimizer` for the index's gradient-free Nevergrad route.
124
- - Select `ScipyOptimizer` for the index's SciPy-based route.
125
- - Do not assume that either wrapper follows the ordinary BrainState gradient-step interface; the index does not state their call contracts.
126
-
127
- **Source URL:** https://brainx.chaobrain.com/braintools/optim/index.html
128
-
129
- ## Integration boundary
130
-
131
- After choosing a symbol, route back to the main BrainState skill for its canonical State-aware training structure. Advanced full-training workflows remain outside this supplied router. Training operations are deliberately not repeated here because the optimization index supplies names and routes, not the BrainState training structure.
132
-
133
- **Source URL:** https://brainx.chaobrain.com/braintools/optim/index.html
@@ -1,85 +0,0 @@
1
- # Braincell solver library with effects
2
-
3
- ## Purpose
4
-
5
- Catalog BrainCell integration and solver choices with their expected modeling consequences.
6
-
7
- ## Source pages
8
-
9
- * https://brainx.chaobrain.com/braincell/concepts/integration.html
10
- * https://brainx.chaobrain.com/braincell/apis/integration.html
11
- * https://brainx.chaobrain.com/braincell/examples/integration_methods.html
12
-
13
- ## Core model
14
-
15
- * `DiffEqState` is a state variable that carries its derivative.
16
- * `DiffEqModule` exposes a right-hand side over integrable states.
17
- * Cells implement this protocol, so solvers can advance them without user code touching the protocol in ordinary modeling.
18
- * `braincell.quad` holds a registry of solvers selectable by name.
19
- * `get_integrator` resolves an integrator from a string or callable; `register_integrator` adds a function to the global registry; `all_integrators` exposes registered names.
20
-
21
- ## Solver families
22
-
23
- | Family | Names / APIs | Use |
24
- | --- | --- | --- |
25
- | Exponential Euler | `exp_euler`, `ind_exp_euler`, `exp_exp_euler` | Good default family for HH-style gating; stable at practical point-neuron step sizes. |
26
- | Explicit Runge-Kutta | `euler`, `midpoint`, `rk2`, `rk3`, `rk4`, `heun2`, `heun3`, `ssprk3`, `ralston2`, `ralston3`, `ralston4` | Useful for comparisons and non-stiff problems; may need tiny time steps for stiff HH dynamics. |
27
- | Implicit | `backward_euler`, `implicit_euler`, `implicit_exp_euler`, `implicit_rk4` | Use when implicit stepping is required; inspect official API and examples first. |
28
- | Composite / cable | `cn_exp_euler`, `cn_rk4`, `splitting`, `staggered`, `dhs_voltage` | Designed for multicompartment/cable coupling; delegate geometry tasks to `skills/braincell/SKILL.md`, which selects its multicompartment parent. |
29
-
30
- List available names at runtime:
31
-
32
- ```python
33
- import braincell.quad as quad
34
-
35
- sorted(quad.all_integrators)
36
- ```
37
-
38
- ## Single-compartment defaults
39
-
40
- * Use `exp_euler` for high-precision single-cell HH traces and electrophysiology-style examples.
41
- * Use `ind_exp_euler` for large vectorized point-neuron or network simulations when speed matters.
42
- * Use `rk4` when the user asks for classical Runge-Kutta comparison or explicitly requests it.
43
- * Treat method-dependent waveform changes as numerical artifacts until proven otherwise.
44
-
45
- ## Solver effects from official hh comparison
46
-
47
- The official integration-methods example compares `exp_euler` and `ind_exp_euler` on HH dynamics:
48
-
49
- * `exp_euler` produces smoother curves and more accurately fits tightly coupled gating variables and membrane potential.
50
- * `ind_exp_euler` updates state variables independently, can deviate slightly during rapid changes, and is faster for large-scale simulations.
51
- * For high-precision single-cell simulations, prefer `exp_euler`.
52
- * For large-scale network simulations with thousands of neurons, prefer `ind_exp_euler` when the approximation is acceptable.
53
-
54
- ## Usage pattern
55
-
56
- ```python
57
- class HH(braincell.SingleCompartment):
58
- def __init__(self, size, solver="exp_euler"):
59
- super().__init__(size, V_th=20. * u.mV, solver=solver)
60
- self.na = braincell.ion.SodiumFixed(size, E=50. * u.mV)
61
- self.na.add(INa=braincell.channel.Na_HH1952(size))
62
- self.k = braincell.ion.PotassiumFixed(size, E=-77. * u.mV)
63
- self.k.add(IK=braincell.channel.K_HH1952(size))
64
- self.IL = braincell.channel.IL(size, E=-54.387 * u.mV, g_max=0.03 * (u.mS / u.cm ** 2))
65
-
66
- hh_exp = HH(1, solver="exp_euler")
67
- hh_ind = HH(1, solver="ind_exp_euler")
68
- ```
69
-
70
- Always keep `dt` explicit in a BrainState environment context:
71
-
72
- ```python
73
- with brainstate.environ.context(dt=0.01 * u.ms):
74
- times = u.math.arange(0. * u.ms, 100. * u.ms, brainstate.environ.get_dt())
75
- vs, spikes = brainstate.transform.for_loop(step, times)
76
- ```
77
-
78
- ## Common mistakes -> fix
79
-
80
- * Choosing solver blindly -> name the solver and why it fits the task.
81
- * Using too-large `dt` -> reduce `dt` before blaming model biology.
82
- * Treating solver differences as biological findings -> compare methods and report as numerical effects.
83
- * Using `rk4` as the default for stiff HH gating -> prefer exponential-Euler variants unless comparison requires RK.
84
- * Using cable/composite solvers in a point-neuron task -> only use them when morphology/cable coupling exists.
85
- * Forgetting units on `dt` -> use `0.01 * u.ms`, not `0.01`.