brainx-skill 1.0.10 → 1.0.12
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.
- package/README.md +6 -0
- package/adapters/antigravity.js +8 -0
- package/installation/lib/installer.js +60 -20
- package/installation/lib/paths.js +41 -3
- package/installation/lib/prompts.js +13 -7
- package/manifest.json +2 -1
- package/package.json +3 -2
- package/skills/braincell/SKILL.md +1 -1
- package/skills/braincell/references/mixions-for-adaptation.md +26 -3
- package/skills/braincell/references/scripts/spike_frequency_adaptation.py +113 -53
- package/skills/brainevent/references/synaptic-plasticity.md +74 -230
- package/skills/brainmass/SKILL.md +11 -6
- package/skills/brainmass/references/batch-transform-acceleration.md +44 -3
- package/skills/brainmass/references/modellibrary.md +11 -0
- package/skills/brainmass/references/simulator-input-monitor-api.md +98 -0
- package/skills/brainpy-state/SKILL.md +20 -6
- package/skills/brainpy-state/references/brain-dynamics-delay-protocol.md +52 -1
- package/skills/brainpy-state/references/brainPy(legacy)/analysis.md +150 -0
- package/skills/brainpy-state/references/brainPy(legacy)/brainpy legacy workflow.md +373 -0
- package/skills/brainpy-state/references/brainPy(legacy)/built-in dynamic neuron model.md +150 -0
- package/skills/brainpy-state/references/brainPy(legacy)/connecting neurons.md +175 -0
- package/skills/brainpy-state/references/brainPy(legacy)/customize neuron and synpase.md +286 -0
- package/skills/brainpy-state/references/brainPy(legacy)/infrastructure/Input generation.md +111 -0
- package/skills/brainpy-state/references/brainPy(legacy)/infrastructure/More about simulation.md +163 -0
- package/skills/brainpy-state/references/brainPy(legacy)/infrastructure/Multi-device array sharding.md +113 -0
- package/skills/brainpy-state/references/brainPy(legacy)/infrastructure/Parallel experiment execution.md +136 -0
- package/skills/brainpy-state/references/brainPy(legacy)/infrastructure/array creation and mechanics.md +222 -0
- package/skills/brainpy-state/references/brainPy(legacy)/infrastructure/brainpy math environment setting.md +123 -0
- package/skills/brainpy-state/references/brainPy(legacy)/infrastructure/delays.md +107 -0
- package/skills/brainpy-state/references/brainPy(legacy)/infrastructure/object oriented transformations and control flows.md +185 -0
- package/skills/brainpy-state/references/brainPy(legacy)/integrators.md +181 -0
- package/skills/brainpy-state/references/brainPy(legacy)/route activity through connectivity.md +102 -0
- package/skills/brainpy-state/references/brainPy(legacy)/synaptic projections.md +147 -0
- package/skills/brainpy-state/references/brainPy(legacy)/synpase properties.md +159 -0
- package/skills/brainpy-state/references/brainPy(legacy)/training/loss library.md +127 -0
- package/skills/brainpy-state/references/brainPy(legacy)/training/optimizers.md +167 -0
- package/skills/brainpy-state/references/brainPy(legacy)/training/parameter initializers.md +107 -0
- package/skills/brainpy-state/references/brainPy(legacy)/training/prebuilt neural network layers.md +186 -0
- package/skills/brainpy-state/references/brainPy(legacy)/training/surrogate gradients.md +104 -0
- package/skills/brainpy-state/references/brainPy(legacy)/training/trainer library.md +89 -0
- package/skills/brainpy-state/references/brainPy(legacy)/training/trainingworkflows.md +253 -0
- package/skills/brainpy-state/references/braintools/connectivity.md +206 -0
- package/skills/brainpy-state/references/braintools/input-current.md +199 -0
- package/skills/brainpy-state/references/component-selection.md +20 -5
- package/skills/brainpy-state/references/projection-patterns.md +2 -0
- package/skills/brainpy-state/references/scripts/sound_localization.py +240 -0
- package/skills/brainstate/SKILL.md +1 -1
- package/skills/brainstate/references/brainstate/brainstate-control-flow-patterns.md +8 -0
- package/skills/brainstate/references/brainstate/transformation-vmap-expansion.md +57 -7
- package/skills/brainstate/references/collective_model_operations.md +26 -27
- package/skills/braintrace/SKILL.md +161 -0
- package/skills/braintrace/references/Drtrl.md +179 -0
- package/skills/braintrace/references/ETP operators.md +161 -0
- package/skills/braintrace/references/algorithm selection.md +120 -0
- package/skills/braintrace/references/batching.md +150 -0
- package/skills/braintrace/references/compiler_internal.md +162 -0
- package/skills/braintrace/references/custom ETP primitives.md +200 -0
- package/skills/braintrace/references/custom algorithms.md +206 -0
- package/skills/braintrace/references/customizing_primitive_transforms.md +191 -0
- package/skills/braintrace/references/pp_pprop workflow.md +196 -0
- package/skills/braintrace/references/pre-built-braintrace-layer.md +149 -0
- package/skills/brainx-general-guard/SKILL.md +64 -21
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
# Prebuilt BrainTrace layers
|
|
2
|
+
|
|
3
|
+
Use this reference when selecting and composing the default ETP-aware
|
|
4
|
+
`braintrace.nn` layers. Prefer these layers before built-in ETP operators or a
|
|
5
|
+
custom primitive; import activation, normalization, and pooling layers from
|
|
6
|
+
their owning package instead.
|
|
7
|
+
|
|
8
|
+
## Select by parameterized operation
|
|
9
|
+
|
|
10
|
+
`braintrace.nn` mirrors the BrainState layer pattern but routes each trainable
|
|
11
|
+
forward operation through an ETP primitive, so parameters participate without
|
|
12
|
+
manual trace wiring.
|
|
13
|
+
|
|
14
|
+
| Family | Use when | ETP behavior |
|
|
15
|
+
|---|---|---|
|
|
16
|
+
| Linear maps | The layer applies dense, grouped, signed, sparse, or low-rank weights. | Uses the matching ETP matrix operation. |
|
|
17
|
+
| Embeddings | Integer indices select trainable rows. | Uses ETP-aware indexed weight access. |
|
|
18
|
+
| Convolutions | Data has one, two, or three spatial dimensions. | Uses `braintrace.conv()`. |
|
|
19
|
+
| Recurrent cells | Hidden State must update once per input step. | Uses ETP dense and element-wise operations inside the recurrence. |
|
|
20
|
+
| Readouts | Recurrent activity needs leaky continuous output dynamics. | Uses an ETP-aware projection. |
|
|
21
|
+
|
|
22
|
+
The class namespace is convenient, but the operation in the traced graph is
|
|
23
|
+
what the compiler recognizes.
|
|
24
|
+
|
|
25
|
+
## Choose a linear map
|
|
26
|
+
|
|
27
|
+
Use the representation that matches the weight structure; do not emulate a
|
|
28
|
+
specialized structure with an unrelated dense layer.
|
|
29
|
+
|
|
30
|
+
| API | Description |
|
|
31
|
+
|---|---|
|
|
32
|
+
| `braintrace.nn.Linear` | Use for a standard dense linear transformation; its weight passes through `braintrace.matmul()`. |
|
|
33
|
+
| `braintrace.nn.GroupedLinear` | Use for a block-diagonal grouped transformation backed by `braintrace.grouped_matmul()`. |
|
|
34
|
+
| `braintrace.nn.SignedWLinear` | Use for a linear layer with signed absolute weights. |
|
|
35
|
+
| `braintrace.nn.SparseLinear` | Use for a sparse weight matrix. |
|
|
36
|
+
| `braintrace.nn.LoRA` | Use for a standalone low-rank adaptation layer. |
|
|
37
|
+
|
|
38
|
+
## Choose an embedding or convolution
|
|
39
|
+
|
|
40
|
+
Use embeddings for trainable indexed lookup and choose convolution dimensionality
|
|
41
|
+
from the number of spatial axes.
|
|
42
|
+
|
|
43
|
+
| API | Description |
|
|
44
|
+
|---|---|
|
|
45
|
+
| `braintrace.nn.Embedding` | Use for a fixed-size trainable embedding table. |
|
|
46
|
+
| `braintrace.nn.Conv1d` | Use for one-dimensional convolution. |
|
|
47
|
+
| `braintrace.nn.Conv2d` | Use for two-dimensional convolution. |
|
|
48
|
+
| `braintrace.nn.Conv3d` | Use for three-dimensional convolution. |
|
|
49
|
+
|
|
50
|
+
## Choose a recurrent cell
|
|
51
|
+
|
|
52
|
+
Recurrent layers consume one time step, update hidden State in place, and
|
|
53
|
+
return the new hidden State; `LRUCell` instead returns its projected output.
|
|
54
|
+
|
|
55
|
+
| API | Description |
|
|
56
|
+
|---|---|
|
|
57
|
+
| `braintrace.nn.ValinaRNNCell` | Use for the package's vanilla RNN cell. Preserve the exported identifier spelling. |
|
|
58
|
+
| `braintrace.nn.GRUCell` | Use for a standard gated recurrent unit. |
|
|
59
|
+
| `braintrace.nn.MGUCell` | Use for a minimal gated recurrent unit. |
|
|
60
|
+
| `braintrace.nn.LSTMCell` | Use for a long short-term memory core. |
|
|
61
|
+
| `braintrace.nn.URLSTMCell` | Use for an update-reset LSTM core. |
|
|
62
|
+
| `braintrace.nn.MinimalRNNCell` | Use for the minimal RNN cell. |
|
|
63
|
+
| `braintrace.nn.MiniGRU` | Use for the package's minimal GRU cell. |
|
|
64
|
+
| `braintrace.nn.MiniLSTM` | Use for the package's minimal LSTM cell. |
|
|
65
|
+
| `braintrace.nn.LRUCell` | Use for a linear recurrent unit; it returns the projected output rather than the hidden State itself. |
|
|
66
|
+
|
|
67
|
+
## Choose a readout
|
|
68
|
+
|
|
69
|
+
Use the BrainTrace readout when an online recurrent model needs leaky output
|
|
70
|
+
dynamics.
|
|
71
|
+
|
|
72
|
+
| API | Description |
|
|
73
|
+
|---|---|
|
|
74
|
+
| `braintrace.nn.LeakyRateReadout` | Use for leaky readout dynamics in Real-Time Recurrent Learning. |
|
|
75
|
+
|
|
76
|
+
## Import supporting layers from their owner
|
|
77
|
+
|
|
78
|
+
Activation, normalization, and pooling layers are intentionally not
|
|
79
|
+
re-implemented in `braintrace.nn`.
|
|
80
|
+
|
|
81
|
+
| Need | Import from |
|
|
82
|
+
|---|---|
|
|
83
|
+
| Activation | `brainstate.nn` |
|
|
84
|
+
| Normalization | `brainstate.nn` |
|
|
85
|
+
| Pooling | `brainstate.nn` |
|
|
86
|
+
|
|
87
|
+
Do not import these through `braintrace.nn`. Compatibility forwarding, such as
|
|
88
|
+
`braintrace.nn.LayerNorm`, emits `DeprecationWarning` and forwards to the owning
|
|
89
|
+
package.
|
|
90
|
+
|
|
91
|
+
## Compose and compile a recurrent model
|
|
92
|
+
|
|
93
|
+
Put the recurrent cell and observable readout in one Module, compile from a
|
|
94
|
+
representative step, then use the learner's sequence driver for repeated
|
|
95
|
+
execution.
|
|
96
|
+
|
|
97
|
+
```python
|
|
98
|
+
import jax.numpy as jnp
|
|
99
|
+
import brainstate
|
|
100
|
+
import braintrace
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
class TinySequenceModel(brainstate.nn.Module):
|
|
104
|
+
def __init__(self):
|
|
105
|
+
super().__init__()
|
|
106
|
+
self.rnn = braintrace.nn.MiniGRU(in_size=1, out_size=4)
|
|
107
|
+
self.readout = braintrace.nn.Linear(4, 1)
|
|
108
|
+
|
|
109
|
+
def update(self, x):
|
|
110
|
+
return self.readout(self.rnn(x))
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
model = TinySequenceModel()
|
|
114
|
+
learner = braintrace.compile(
|
|
115
|
+
model,
|
|
116
|
+
braintrace.D_RTRL,
|
|
117
|
+
jnp.ones(1),
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
sequence = jnp.linspace(-1.0, 1.0, 6).reshape(6, 1)
|
|
121
|
+
brainstate.nn.reset_all_states(model)
|
|
122
|
+
learner.reset_state()
|
|
123
|
+
outputs = learner.etrace_evolve(sequence, return_outputs=True)
|
|
124
|
+
|
|
125
|
+
assert outputs.shape == (6, 1)
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
The recurrent weights influence hidden State and therefore need eligibility
|
|
129
|
+
traces. The final `Linear` weight remains trainable, but because its output does
|
|
130
|
+
not feed hidden State, the compiler classifies it as non-temporal and computes
|
|
131
|
+
its instantaneous gradient directly.
|
|
132
|
+
|
|
133
|
+
**Relation invariant:** A `weight -> weight -> hidden` path crosses two
|
|
134
|
+
trainable ETP operations. The compiler stops at the downstream operation and
|
|
135
|
+
does not record the upstream weight as an independent ETP relation, which
|
|
136
|
+
prevents double counting.
|
|
137
|
+
|
|
138
|
+
Open `ETP operators.md` when no prebuilt layer matches the required custom
|
|
139
|
+
block. Escalate to `custom ETP primitives.md` only when built-in ETP operations
|
|
140
|
+
cannot express it.
|
|
141
|
+
|
|
142
|
+
## Sources
|
|
143
|
+
|
|
144
|
+
- [Neural-Network Layers](https://brainx.chaobrain.com/braintrace/apis/nn.html)
|
|
145
|
+
- [Neural Network Layers for Online Learning](https://brainx.chaobrain.com/braintrace/tutorials/neural_network_layers.html)
|
|
146
|
+
|
|
147
|
+
The layer catalogue, ownership boundary, composition, and compiler relations
|
|
148
|
+
above are trimmed and reorganized from the official pages without changing
|
|
149
|
+
their API names.
|
|
@@ -5,24 +5,22 @@ description: Use first for every BrainX modeling, simulation, training, review,
|
|
|
5
5
|
|
|
6
6
|
# BrainX general guard
|
|
7
7
|
|
|
8
|
-
##
|
|
8
|
+
## Purpose and boundary
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
Use this guard first to identify the represented modeling scales, open their owning package skills, and keep package orchestration ahead of lower-level infrastructure. Keep it active for cross-cutting API selection, execution, interoperability, and validation decisions.
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
- **NEVER investigate installed content.** Do not enumerate package files, modules, symbols, signatures, docstrings, runtime definitions, or object internals.
|
|
14
|
-
- **NEVER read installed source code.** Do not open or read any BrainX source code in the virtual environment.
|
|
12
|
+
## Check package presence without inspecting installed BrainX
|
|
15
13
|
|
|
14
|
+
Treat installed BrainX packages only as execution dependencies: check whether each required package is importable, then move to the owning skills or route an absent package to BrainX-install. Never inspect installed versions, metadata, files, modules, symbols, signatures, docstrings, runtime definitions, source code, or object internals for modeling knowledge.
|
|
16
15
|
|
|
17
16
|
## Study modeling skills and task-relevant scripts
|
|
18
17
|
|
|
19
|
-
1. Treat the selected modeling skills as the authoritative
|
|
20
|
-
2. Follow
|
|
18
|
+
1. Treat the selected modeling skills as the authoritative guides to BrainX modeling. Read each selected skill completely.
|
|
19
|
+
2. Follow each skill's exact routing instructions. Open every reference likely to affect the user's task.
|
|
21
20
|
3. Identify the example scripts referenced by the skill or its routed references. Open and study every script that is highly related to the user's task.
|
|
22
21
|
4. Trace each relevant script end to end.
|
|
23
|
-
5.
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
5. Reconcile each script with the current root skill before copying infrastructure. Keep its scientific pattern, but replace superseded low-level execution with the owning package's current canonical API.
|
|
23
|
+
6. Derive the implementation from the reconciled patterns, then adapt only the parts required by the user's scientific model.
|
|
26
24
|
|
|
27
25
|
## Select modeling skills by represented scale
|
|
28
26
|
|
|
@@ -38,9 +36,23 @@ Select every row supported by the user's task. A single-scale task opens one mod
|
|
|
38
36
|
| Cellular mechanisms coupled to aggregate neural-mass dynamics | BrainCell + BrainMass |
|
|
39
37
|
| Cellular biophysics, point-neuron networks, and aggregate population dynamics interacting in one workflow | BrainCell + BrainPy-State + BrainMass |
|
|
40
38
|
|
|
39
|
+
Keep the implementation at the selected scale. Do not introduce aggregate population-rate State into a point-neuron model, or point neurons into an aggregate model, merely to simplify execution. When both mechanisms are scientifically represented, treat the task as multiscale and open both owning skills.
|
|
40
|
+
|
|
41
41
|
## Write BrainX-native code
|
|
42
42
|
|
|
43
|
-
Start from the scientific concept and use the selected BrainX skills to construct the workflow.
|
|
43
|
+
Start from the scientific concept and use the selected BrainX skills to construct the workflow. Keep ordinary Python, NumPy, or JAX at explicit boundaries for documented dimensionless model inputs, host-side statistics, serialization, timing, device reporting, or custom presentation logic. Preserve units and State until that boundary, and verify an API gap before writing generic numerical infrastructure.
|
|
44
|
+
|
|
45
|
+
## Enforce absolute coding simplicity
|
|
46
|
+
|
|
47
|
+
Invest substantial effort before coding. Study every routed skill, relevant example and reference, and authoritative BrainX API needed to understand the task and discover which BrainX operations remove custom logic. Then deliver absolutely simple code. Simplicity is an output criterion, not permission to skip study or guess an API.
|
|
48
|
+
|
|
49
|
+
Use the smallest clear composition that completely satisfies the scientific contract. Minimize concepts, layers, functions, classes, State objects, transforms, branches, conversions, dependencies, files, monitors, and outputs.
|
|
50
|
+
|
|
51
|
+
Keep an element only when removing it would change scientific meaning, correctness, required performance, verification of a costly failure, or requested output quality. Remove pass-through wrappers, duplicate representations, speculative configuration, redundant transforms, repeated calculations, defensive branches for impossible inputs, and unrequested artifacts. Prefer one direct data flow, one owner for each State, one stable transform boundary, and one canonical execution path.
|
|
52
|
+
|
|
53
|
+
Keep a one-off scientific demonstration concrete. Add a configuration object, result class, helper layer, command-line option, or extra artifact only when the request requires variation or reuse, or when that structure removes more complexity than it adds.
|
|
54
|
+
|
|
55
|
+
Do not simplify away units, explicit State lifecycles, numerical validity, scientifically necessary mechanisms, performance-critical compilation or batching, focused checks, or requested output quality. These are requirements, not optional complexity.
|
|
44
56
|
|
|
45
57
|
## Prefer high-level BrainX APIs
|
|
46
58
|
|
|
@@ -48,40 +60,71 @@ Use high-level APIs as the abstraction boundary: simulation code should state th
|
|
|
48
60
|
|
|
49
61
|
| Need | Prefer |
|
|
50
62
|
|---|---|
|
|
51
|
-
|
|
|
52
|
-
|
|
|
53
|
-
|
|
63
|
+
| Package-owned simulation, fitting, training, or analysis | The selected modeling package's named orchestrator or Module, such as `brainmass.Simulator`, `Network`, `Fitter`, or `brainmass.viz` |
|
|
64
|
+
| Physical quantities, unit-aware arrays, or mathematical operations | BrainUnit quantities and `brainunit.math` |
|
|
65
|
+
| State, randomness, initialization, environments, or State-aware transforms | BrainState, after checking whether the selected package orchestrator already owns the operation |
|
|
66
|
+
| Connectivity, encoding, inputs, integration, metrics, optimization, surrogate gradients, training, or visualization | `braintools` |
|
|
54
67
|
|
|
55
68
|
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.
|
|
56
69
|
|
|
57
70
|
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.
|
|
58
71
|
|
|
59
|
-
|
|
72
|
+
Use the highest-level API in the selected owning package that preserves the scientific operation. Open lower-level BrainState control flow only when the package orchestrator cannot express the required inputs, monitors, State effects, or stable compilation boundary.
|
|
60
73
|
|
|
61
|
-
|
|
74
|
+
## Validate scientific claims
|
|
62
75
|
|
|
76
|
+
Derive claims from observables that distinguish the claimed mechanism; validate the baseline and mechanism before calibration, and mark unsourced calibrated regimes as phenomenological.
|
|
63
77
|
|
|
64
|
-
|
|
78
|
+
- Freeze parameters, evaluation seeds, metrics or scores, thresholds or windows, and displayed cases before viewing intervention outcomes; otherwise calibrate separately and report held-out or nearby sensitivity.
|
|
79
|
+
- Validate each matched control independently, then compare and save control and intervention evidence at every nuisance setting and aligned physical time or event landmark; a normalized summary is not a substitute for those paired observables.
|
|
80
|
+
- At each causal branch, verify and save every relevant State and protocol input, vary only the declared intervention, and preserve per-condition evidence plus its aggregation. State causality at the intervention level; claim event mediation only when a mediator-specific manipulation and per-condition event dose agree with the outcome.
|
|
81
|
+
- Apply each claim's full temporal predicate: require time-resolved source-to-route-to-target order for propagation and exact element order for sequence direction rather than a regression sign or proxy. Identify supplied drive or retained boundary State as an external seed even when stochastic.
|
|
82
|
+
- For categorical maps, retain every continuous boundary observable, plot and save the exact reduction tested at each threshold, and verify each label's full predicate. Require measured departure before sustained recovery, and never force a requested category to appear.
|
|
83
|
+
- Claim an interval or region only when sampling resolves its extent across multiple points; otherwise report a sampled point or optimum and refine the sampling.
|
|
65
84
|
|
|
85
|
+
Run independent controls and mechanism checks in the same mapped or batched path as the intervention.
|
|
86
|
+
|
|
87
|
+
## Keep visualization simple without lowering figure quality
|
|
88
|
+
|
|
89
|
+
Use the simplest highest-level API that expresses the required scientific figure. Prefer the selected BrainX package's visualization API, such as `brainmass.viz`, then BrainTools visualization APIs, then high-level `matplotlib.pyplot`.
|
|
90
|
+
|
|
91
|
+
Write absolutely simple Matplotlib code: compose every figure with exactly one `plt.subplots(...)` call and only basic high-level plotting methods. Use `plt.figure`, `GridSpec`, `add_subplot`, projection-specific axes, custom artists, manual axes placement, style systems, or layout scaffolding only when the user explicitly requests a result that `subplots()` cannot express.
|
|
92
|
+
|
|
93
|
+
Simplicity applies to implementation, not scientific content or figure quality. Preserve intentional size, units, readable labels, title, comparison styles, legend, unclipped layout, and sufficient output resolution.
|
|
66
94
|
|
|
67
95
|
## Transform stateful execution
|
|
68
96
|
|
|
69
|
-
|
|
97
|
+
Use the owning package's orchestrator for workflows it already implements. When a custom stateful operation is necessary, transform the complete operation with `brainstate.transform`.
|
|
70
98
|
|
|
71
99
|
| API | Use |
|
|
72
100
|
|---|---|
|
|
73
|
-
| `brainstate.transform.jit
|
|
101
|
+
| `brainstate.transform.jit` | Compile a complete custom stateful operation. Construct one stable callable outside warm-up and timed repetitions when measuring compilation or steady execution. |
|
|
102
|
+
| `brainstate.transform.grad` | Differentiate a complete custom stateful forward, simulation, or training operation. |
|
|
103
|
+
| `brainstate.transform.vmap` | Batch a complete custom stateful operation when the owning package does not already expose the required batch axis. |
|
|
74
104
|
| `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. |
|
|
75
105
|
| `brainstate.transform.scan` | Run a sequence when an ordinary explicit carry must pass between iterations. |
|
|
76
106
|
|
|
77
|
-
Do not
|
|
107
|
+
Do not add a transform only to construct parameter axes or satisfy a named-API checklist. When the owning package already represents independent conditions through a native batch or `size` axis, use that path and reserve `vmap` for a callable the owning package does not already batch.
|
|
108
|
+
|
|
109
|
+
Map only independent operations. If trial N mutates weights or other State that trial N+1 consumes, keep those trials sequential; batch only independent evaluation trials or ensembles, with separate dynamical State and deliberately shared read-only State. Mapping input construction or offline scoring does not batch the stateful simulation itself. Open `skills/brainstate/references/brainstate/transformation-vmap-expansion.md` when a complete mapped operation reads or writes State, for the State-axis contracts and independent-lane pattern.
|
|
110
|
+
|
|
111
|
+
A mapped complete per-step transition called inside one `for_loop` is a stateful simulation batch: the mapping owns independent conditions and the loop owns time. Select mapped State by semantic role, such as `Any(OfType(HiddenState), OfType(ShortTermState))`; do not infer State ownership from array rank, shape, or a coincidental leading size. Open `skills/brainstate/references/brainstate/transformation-vmap-expansion.md` for the canonical initialization, mapping, and loop composition.
|
|
112
|
+
|
|
113
|
+
Describe the transform that actually runs. Native batched State, vmapped input construction, and vmapped host scoring are not stateful `vmap`. When the user explicitly requires `vmap`, map the complete independent operation or report why the requirement cannot be met.
|
|
114
|
+
|
|
115
|
+
Separate dependency order from State lifetime. When only learned or long-term State must carry from trial N to trial N+1, preserve that State but reset membrane, refractory, delay, trace, and other per-trial State at the logical boundary unless continuous carryover is part of the model. A silent interval advances State; it does not reset it.
|
|
116
|
+
|
|
117
|
+
Do not use a Python loop for simulation timesteps, recurrent sequences, or repeated State updates inside one logical rollout. A small host loop is valid across causally sequential trials when each iteration calls one compiled trial rollout and the boundary must reset selected State while preserving learned State.
|
|
78
118
|
|
|
79
119
|
Use raw JAX transformations only for pure array or PyTree functions that do not close over BrainState `State`.
|
|
80
120
|
|
|
81
121
|
## Boundaries and common failures
|
|
82
122
|
|
|
83
123
|
- Generic NumPy or JAX used as the starting architecture for a BrainX simulation.
|
|
124
|
+
- Point-neuron and aggregate population mechanisms mixed without selecting both owning skills or declaring the multiscale boundary.
|
|
125
|
+
- A custom BrainState loop that duplicates the selected package's runner, inputs, monitoring, initialization, or sampling.
|
|
84
126
|
- Manual array or mathematical machinery that duplicates BrainUnit or BrainTools.
|
|
85
|
-
- Python loops
|
|
127
|
+
- Python timestep loops or host loops inside a stable logical rollout.
|
|
86
128
|
- Raw `jax.jit`, `jax.grad`, or `jax.vmap` applied to State-aware code.
|
|
129
|
+
- Host-side statistics, serialization, timing, device reporting, or custom presentation forced into BrainX without an owning API.
|
|
87
130
|
- Fabricated APIs or signatures accepted without checking the owning documentation.
|