brainx-skill 1.0.11 → 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/package.json +1 -1
- package/skills/braincell/SKILL.md +1 -15
- package/skills/braincell/references/mixions-for-adaptation.md +26 -3
- package/skills/braincell/references/scripts/spike_frequency_adaptation.py +113 -53
- package/skills/brainevent/SKILL.md +0 -1
- package/skills/brainevent/references/synaptic-plasticity.md +74 -230
- package/skills/brainmass/SKILL.md +10 -5
- 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 +14 -6
- package/skills/brainpy-state/references/array-creation.md +2 -2
- package/skills/brainpy-state/references/brain-dynamics-delay-protocol.md +52 -1
- 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 +11 -15
- package/skills/brainstate/agents/openai.yaml +4 -0
- package/skills/brainstate/references/brainstate/brainstate-control-flow-patterns.md +8 -0
- package/skills/brainstate/references/brainstate/transformation-grad-expansion.md +1 -1
- package/skills/brainstate/references/brainstate/transformation-vmap-expansion.md +57 -7
- package/skills/brainstate/references/collective_model_operations.md +26 -27
- package/skills/brainx-general-guard/SKILL.md +62 -37
- package/skills/brainx-install/SKILL.md +21 -24
- package/skills/brainstate/references/braintools/optimizer.md +0 -179
|
@@ -9,10 +9,7 @@ This reference covers only behavior demonstrated by these routed official tutori
|
|
|
9
9
|
- Vectorization: https://brainx.chaobrain.com/brainstate/tutorials/transformations/03_vectorization.html
|
|
10
10
|
- Random Number Generation: https://brainx.chaobrain.com/brainstate/tutorials/core/08_randomness.html
|
|
11
11
|
|
|
12
|
-
The Vectorization tutorial
|
|
13
|
-
state-aware wrapper around `jax.vmap`, but its detailed executable examples use
|
|
14
|
-
`brainstate.transform.vmap2`. Preserve that distinction; do not silently
|
|
15
|
-
substitute one API for the other.
|
|
12
|
+
The Vectorization tutorial demonstrates filter-based `vmap2`; the current generated API pages define both mapping contracts. Use `vmap` when specific State instances must be declared with `in_states` and `out_states`. Use `vmap2` when State filters, automatic output-axis inference, or `unexpected_out_state_mapping` are required. Do not silently substitute one contract for the other.
|
|
16
13
|
|
|
17
14
|
## Selection map
|
|
18
15
|
|
|
@@ -22,6 +19,7 @@ substitute one API for the other.
|
|
|
22
19
|
| Place the mapped output axis | `out_axes` | Match the downstream layout explicitly. |
|
|
23
20
|
| Map with no mapped input argument | `axis_size` | Supply the size because it cannot be inferred. |
|
|
24
21
|
| Use collectives over the mapped axis | `axis_name` | The collective must use the same name. |
|
|
22
|
+
| Map explicitly named State instances | `vmap(..., in_states=..., out_states=...)` | Declare every mapped input State and written output State; undeclared batched writes raise `BatchAxisError`. |
|
|
25
23
|
| Map mutable State but share parameters | `vmap2(..., state_in_axes=..., state_out_axes=...)` with State filters | Define both input mapping and write-back for per-instance State. |
|
|
26
24
|
| Handle a written State omitted from `state_out_axes` | `vmap2(..., unexpected_out_state_mapping=...)` | The default `'auto'` infers and scatters the mapped axis; declare State axes when a coincidental leading-size match would be ambiguous. |
|
|
27
25
|
| Choose independent or shared random draws | BrainState automatic splitting or one broadcast JAX key | Shared keys intentionally correlate mapped results. |
|
|
@@ -138,11 +136,59 @@ assert model.param.value == 1.0
|
|
|
138
136
|
|
|
139
137
|
This bundles the State-axis decision with the executable pattern: each mapped element owns one `temp` value, while every element reads the same scalar parameter. For an ordinary `nn.Module` with no State-axis filters, the tutorial says Module states are typically shared, or broadcast, across the batch by default.
|
|
140
138
|
|
|
141
|
-
|
|
139
|
+
A shared State remains unbatched and is omitted from the mapped State axis. Keep it read-only during the mapped call. Broadcasting identical values to shape `(batch, ...)` and then mapping axis 0 creates independent copies with batch-scaled storage; it does not share one State. Map a State that each lane may write, but keep an unbatched State shared only when concurrent lanes do not update it.
|
|
142
140
|
|
|
143
|
-
|
|
141
|
+
### Map a complete step inside one time loop
|
|
144
142
|
|
|
145
|
-
|
|
143
|
+
Use `vmap_init_all_states` to allocate one dynamical State lane per independent rollout, map the complete per-step transition with semantic State-role filters, then call that mapped step from one `for_loop`. The mapping owns the condition axis and the loop owns time.
|
|
144
|
+
|
|
145
|
+
```python
|
|
146
|
+
from brainstate.util import filter as util_filter
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
class Accumulator(brainstate.nn.Module):
|
|
150
|
+
def init_state(self):
|
|
151
|
+
self.total = brainstate.ShortTermState(jnp.asarray(0.0))
|
|
152
|
+
|
|
153
|
+
def update(self, value):
|
|
154
|
+
self.total.value = self.total.value + value
|
|
155
|
+
return self.total.value
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
model = Accumulator()
|
|
159
|
+
inputs = jnp.ones((5, 8)) # [time, independent condition]
|
|
160
|
+
brainstate.nn.vmap_init_all_states(model, axis_size=inputs.shape[1])
|
|
161
|
+
|
|
162
|
+
dynamical_state = util_filter.Any(
|
|
163
|
+
util_filter.OfType(brainstate.HiddenState),
|
|
164
|
+
util_filter.OfType(brainstate.ShortTermState),
|
|
165
|
+
)
|
|
166
|
+
mapped_step = vmap2(
|
|
167
|
+
model.update,
|
|
168
|
+
in_axes=0,
|
|
169
|
+
out_axes=0,
|
|
170
|
+
state_in_axes={0: dynamical_state},
|
|
171
|
+
state_out_axes={0: dynamical_state},
|
|
172
|
+
unexpected_out_state_mapping="raise",
|
|
173
|
+
)
|
|
174
|
+
outputs = brainstate.transform.for_loop(mapped_step, inputs)
|
|
175
|
+
|
|
176
|
+
assert outputs.shape == (5, 8)
|
|
177
|
+
assert jnp.allclose(outputs[-1], 5.0)
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
Do not select writable State with `.ndim`, shape, or path coincidences; those properties do not identify State ownership and can map a future parameter accidentally. Every State written by `mapped_step` needs a compatible per-lane axis. In particular, a delay buffer with per-lane history cannot share a mutable scalar write pointer merely because all lanes advance in lockstep; map the complete delay State or choose a delay representation whose writable State follows one axis policy.
|
|
181
|
+
|
|
182
|
+
### Choose the State declaration contract
|
|
183
|
+
|
|
184
|
+
The generated APIs use distinct, non-alias parameter names:
|
|
185
|
+
|
|
186
|
+
| API | State input mapping | State output mapping | Undeclared batched write |
|
|
187
|
+
|---|---|---|---|
|
|
188
|
+
| `brainstate.transform.vmap` | `in_states` by State instance | `out_states` by State instance | Raises `BatchAxisError`. |
|
|
189
|
+
| `brainstate.transform.vmap2` | `state_in_axes` by State filter | `state_out_axes` by State filter | Controlled by `unexpected_out_state_mapping`; default `'auto'` infers and scatters. |
|
|
190
|
+
|
|
191
|
+
Sources: https://brainx.chaobrain.com/brainstate/apis/generated/brainstate.transform.vmap.html and https://brainx.chaobrain.com/brainstate/apis/generated/brainstate.transform.vmap2.html.
|
|
146
192
|
|
|
147
193
|
## Handle state writes outside `state_out_axes`
|
|
148
194
|
|
|
@@ -307,7 +353,11 @@ Do not infer semantics for `vmap_new_states`, `vmap2_new_states`, `map`, `pmap2`
|
|
|
307
353
|
## High-impact checks
|
|
308
354
|
|
|
309
355
|
- Match every non-`None` `in_axes` entry to an actual mapped dimension of the corresponding argument.
|
|
356
|
+
- Use `vmap` for State-instance declarations and `vmap2` for filter-based State-axis policies; do not mix their parameter names.
|
|
357
|
+
- Prefer an owning package's native batch or `size` axis when it already represents the independent conditions.
|
|
310
358
|
- Decide whether mutable State is shared or mapped; use `state_in_axes` and `state_out_axes` together for per-instance State write-back.
|
|
359
|
+
- Map a complete per-step transition inside one `for_loop` when the mapping owns independent conditions and the loop owns time.
|
|
360
|
+
- Select mapped State by semantic role rather than array rank, shape, or leading-size coincidence.
|
|
311
361
|
- Set `axis_size` when all inputs are static.
|
|
312
362
|
- Declare State axes or set an explicit policy when automatic output-axis inference would be ambiguous.
|
|
313
363
|
- Expect automatic independent `RandomState` keys; use the documented broadcast-key pattern only when shared randomness is intentional.
|
|
@@ -13,7 +13,7 @@ The official guide presents `brainstate.nn._collective_ops` through these public
|
|
|
13
13
|
| Fix the execution order of methods | `brainstate.nn.call_order` | Lower order values run first. |
|
|
14
14
|
| Call the same method on each model node | `brainstate.nn.call_all_fns`, `brainstate.nn.vmap_call_all_fns` | Filter nodes deliberately and verify the installed call signature. |
|
|
15
15
|
| Initialise state variables everywhere | `brainstate.nn.init_all_states`, `brainstate.nn.vmap_init_all_states` | Run after construction and before the first rollout. |
|
|
16
|
-
| Reset existing states everywhere | `brainstate.nn.reset_all_states`, `brainstate.nn.vmap_reset_all_states` | Reset at the intended sequence boundary,
|
|
16
|
+
| Reset existing states everywhere | `brainstate.nn.reset_all_states`, `brainstate.nn.vmap_reset_all_states` | Reset at the intended sequence boundary; after vmapped reset, verify that every mapped dynamical State retains its leading lane axis. |
|
|
17
17
|
| Restore values keyed by absolute state paths | `brainstate.nn.assign_state_values` | Inspect both returned mismatch collections. |
|
|
18
18
|
|
|
19
19
|
## Ordering calls with `call_order`
|
|
@@ -84,27 +84,28 @@ brainstate.nn.reset_all_states(rnn)
|
|
|
84
84
|
|
|
85
85
|
As with `init_all_states`, reset can exclude nodes or receive additional arguments. `call_order` still governs the pass, allowing buffers to reset before hidden states when required.
|
|
86
86
|
|
|
87
|
-
## Batched
|
|
87
|
+
## Batched lifecycle operations with `vmap_*`
|
|
88
88
|
|
|
89
89
|
Source: https://brainx.chaobrain.com/brainstate/how_to/collective_operations.html
|
|
90
90
|
|
|
91
|
-
|
|
91
|
+
API contract: https://brainx.chaobrain.com/brainstate/apis/generated/brainstate.nn.vmap_reset_all_states.html
|
|
92
92
|
|
|
93
|
-
|
|
94
|
-
policy = brainstate.nn.Sequential(
|
|
95
|
-
brainstate.nn.Linear((4,), (64,)),
|
|
96
|
-
brainstate.nn.GELU(),
|
|
97
|
-
brainstate.nn.Linear((64,), (2,)),
|
|
98
|
-
)
|
|
93
|
+
For independent ensemble or Monte-Carlo instances, `vmap_init_all_states` inserts a leading axis and manages a separate random key for each copy. Pass a `state_to_exclude` filter when selected States, such as statistics buffers, must remain shared; excluded States retain their original shape.
|
|
99
94
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
95
|
+
```python
|
|
96
|
+
rnn = brainstate.nn.ValinaRNNCell(num_in=4, num_out=8)
|
|
97
|
+
axis_size = 8
|
|
98
|
+
brainstate.nn.vmap_init_all_states(rnn, axis_size=axis_size)
|
|
99
|
+
|
|
100
|
+
hidden_shapes = {
|
|
101
|
+
path: state.value.shape
|
|
102
|
+
for path, state in rnn.states(brainstate.HiddenState).items()
|
|
103
|
+
}
|
|
104
|
+
assert hidden_shapes
|
|
105
|
+
assert all(shape[0] == axis_size for shape in hidden_shapes.values())
|
|
105
106
|
```
|
|
106
107
|
|
|
107
|
-
|
|
108
|
+
The official `vmap_reset_all_states` contract intends to reset each lane independently, but the selected Module's `reset_state` implementation must still preserve the mapped State shape. Before selecting it for repeated rollouts, capture a direct-path snapshot, run one reset outside the transformed and timed path, and compare every mapped dynamical shape before and after. If any leading lane axis changes, restore the snapshot and use `assign_state_values` for subsequent exact resets instead of `vmap_reset_all_states`.
|
|
108
109
|
|
|
109
110
|
## Calling arbitrary methods collectively
|
|
110
111
|
|
|
@@ -146,7 +147,7 @@ The page identifies `brainstate.nn.vmap_call_all_fns` as the corresponding opera
|
|
|
146
147
|
|
|
147
148
|
Source: https://brainx.chaobrain.com/brainstate/how_to/collective_operations.html
|
|
148
149
|
|
|
149
|
-
`assign_state_values` maps
|
|
150
|
+
`assign_state_values` maps values back to State objects by absolute State path and returns mismatched keys as `(unexpected, missing)`. Keep a dictionary-valued State intact under its State path; do not append its inner keys as if they were separate States.
|
|
150
151
|
|
|
151
152
|
```python
|
|
152
153
|
autoencoder = brainstate.nn.Sequential(
|
|
@@ -156,13 +157,10 @@ autoencoder = brainstate.nn.Sequential(
|
|
|
156
157
|
)
|
|
157
158
|
brainstate.nn.init_all_states(autoencoder)
|
|
158
159
|
|
|
159
|
-
state_snapshot = {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
state_snapshot[path + (key,)] = value
|
|
164
|
-
else:
|
|
165
|
-
state_snapshot[path] = state.value
|
|
160
|
+
state_snapshot = {
|
|
161
|
+
path: state.value
|
|
162
|
+
for path, state in autoencoder.states().items()
|
|
163
|
+
}
|
|
166
164
|
|
|
167
165
|
# ... modify weights or states ...
|
|
168
166
|
|
|
@@ -172,17 +170,17 @@ unexpected, missing = brainstate.nn.assign_state_values(
|
|
|
172
170
|
)
|
|
173
171
|
if unexpected or missing:
|
|
174
172
|
raise ValueError(
|
|
175
|
-
f
|
|
173
|
+
f"checkpoint mismatch: unexpected={unexpected}, missing={missing}"
|
|
176
174
|
)
|
|
177
175
|
```
|
|
178
176
|
|
|
179
|
-
|
|
177
|
+
Capture all States when exact whole-model restoration is required. A deliberately partial snapshot reports every omitted model State in `missing`; handle that result as an explicit partial-restore policy rather than ignoring it.
|
|
180
178
|
|
|
181
179
|
## Putting it all together
|
|
182
180
|
|
|
183
181
|
Source: https://brainx.chaobrain.com/brainstate/how_to/collective_operations.html
|
|
184
182
|
|
|
185
|
-
|
|
183
|
+
Use this order for a batched recurrent workflow: construct the model, call `vmap_init_all_states(..., axis_size=...)`, verify mapped dynamical shapes, capture all values under their existing State paths, run the transformed rollout, then either use a shape-verified `vmap_reset_all_states` or restore the exact snapshot with `assign_state_values`. Reject unexpected or missing paths before the next rollout.
|
|
186
184
|
|
|
187
185
|
## Best practices
|
|
188
186
|
|
|
@@ -192,4 +190,5 @@ Source: https://brainx.chaobrain.com/brainstate/how_to/collective_operations.htm
|
|
|
192
190
|
- Decorate stateful methods with `call_order` when their interaction matters.
|
|
193
191
|
- Use `node_to_exclude` and `state_to_exclude` filters to fine-tune traversal.
|
|
194
192
|
- Inspect both return values from `assign_state_values` to catch mismatched checkpoints.
|
|
195
|
-
-
|
|
193
|
+
- Preserve dictionary-valued State under its existing absolute State path when taking a snapshot.
|
|
194
|
+
- Use vmapped helpers for ensembles while accounting for the added leading axis, and verify that reset preserves that axis for the selected Modules.
|
|
@@ -7,32 +7,24 @@ description: Use first for every BrainX modeling, simulation, training, review,
|
|
|
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
|
-
|
|
14
|
-
## Never inspect BrainX packages in the venv for knowledge
|
|
15
|
-
|
|
16
|
-
Treat BrainX packages in the active virtual environment only as execution dependencies, never as sources of modeling knowledge.
|
|
17
|
-
|
|
18
|
-
- **ONLY check presence.** Determine whether each required BrainX package is present, then stop inspecting the environment.
|
|
19
|
-
- **NEVER investigate installed content.** Do not enumerate package files, modules, symbols, signatures, docstrings, runtime definitions, or object internals.
|
|
20
|
-
- **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
|
|
21
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.
|
|
22
15
|
|
|
23
16
|
## Study modeling skills and task-relevant scripts
|
|
24
17
|
|
|
25
|
-
1. Treat the selected modeling skills as the authoritative
|
|
26
|
-
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.
|
|
27
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.
|
|
28
21
|
4. Trace each relevant script end to end.
|
|
29
|
-
5.
|
|
30
|
-
|
|
31
|
-
|
|
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.
|
|
32
24
|
|
|
33
25
|
## Select modeling skills by represented scale
|
|
34
26
|
|
|
35
|
-
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
|
|
27
|
+
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.
|
|
36
28
|
|
|
37
29
|
| The task explicitly represents | Open |
|
|
38
30
|
|---|---|
|
|
@@ -44,21 +36,23 @@ Select every row supported by the user's task. A single-scale task opens one mod
|
|
|
44
36
|
| Cellular mechanisms coupled to aggregate neural-mass dynamics | BrainCell + BrainMass |
|
|
45
37
|
| Cellular biophysics, point-neuron networks, and aggregate population dynamics interacting in one workflow | BrainCell + BrainPy-State + BrainMass |
|
|
46
38
|
|
|
47
|
-
|
|
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.
|
|
48
40
|
|
|
49
|
-
|
|
41
|
+
## Write BrainX-native code
|
|
50
42
|
|
|
51
|
-
|
|
52
|
-
|---|---|
|
|
53
|
-
| Physical quantities, units, dimensional mismatches, unit-aware math, or suspicious bare numbers | BrainUnit |
|
|
54
|
-
| Mutable State and `.value`, Module graphs, state initialization, environment scoping, or state-aware `jit`/`grad`/`vmap` | BrainState |
|
|
55
|
-
| Binary firing events, sparse or probabilistic connectivity, spike-driven postsynaptic input, or activity-dependent weight changes | BrainEvent |
|
|
56
|
-
| Eligibility-trace online learning, D-RTRL or pp-prop selection, or training a recurrent or spiking model without BPTT | BrainTrace |
|
|
57
|
-
| Installing, upgrading, pinning, migrating, or removing BrainX packages | BrainX-Install |
|
|
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.
|
|
58
44
|
|
|
59
|
-
##
|
|
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.
|
|
60
52
|
|
|
61
|
-
|
|
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.
|
|
62
56
|
|
|
63
57
|
## Prefer high-level BrainX APIs
|
|
64
58
|
|
|
@@ -66,40 +60,71 @@ Use high-level APIs as the abstraction boundary: simulation code should state th
|
|
|
66
60
|
|
|
67
61
|
| Need | Prefer |
|
|
68
62
|
|---|---|
|
|
69
|
-
|
|
|
70
|
-
|
|
|
71
|
-
|
|
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` |
|
|
72
67
|
|
|
73
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.
|
|
74
69
|
|
|
75
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.
|
|
76
71
|
|
|
77
|
-
|
|
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.
|
|
73
|
+
|
|
74
|
+
## Validate scientific claims
|
|
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.
|
|
77
|
+
|
|
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.
|
|
84
|
+
|
|
85
|
+
Run independent controls and mechanism checks in the same mapped or batched path as the intervention.
|
|
78
86
|
|
|
79
|
-
|
|
87
|
+
## Keep visualization simple without lowering figure quality
|
|
80
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`.
|
|
81
90
|
|
|
82
|
-
|
|
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.
|
|
83
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.
|
|
84
94
|
|
|
85
95
|
## Transform stateful execution
|
|
86
96
|
|
|
87
|
-
|
|
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`.
|
|
88
98
|
|
|
89
99
|
| API | Use |
|
|
90
100
|
|---|---|
|
|
91
|
-
| `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. |
|
|
92
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. |
|
|
93
105
|
| `brainstate.transform.scan` | Run a sequence when an ordinary explicit carry must pass between iterations. |
|
|
94
106
|
|
|
95
|
-
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.
|
|
96
118
|
|
|
97
119
|
Use raw JAX transformations only for pure array or PyTree functions that do not close over BrainState `State`.
|
|
98
120
|
|
|
99
121
|
## Boundaries and common failures
|
|
100
122
|
|
|
101
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.
|
|
102
126
|
- Manual array or mathematical machinery that duplicates BrainUnit or BrainTools.
|
|
103
|
-
- Python loops
|
|
127
|
+
- Python timestep loops or host loops inside a stable logical rollout.
|
|
104
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.
|
|
105
130
|
- Fabricated APIs or signatures accepted without checking the owning documentation.
|
|
@@ -1,23 +1,21 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: brainx-install
|
|
3
|
-
description: Gently check whether the BrainX meta-package is installed in the intended Python environment; if it is absent, open this skill.
|
|
3
|
+
description: " Gently check whether the BrainX meta-package is installed in the intended Python environment; if it is absent, open this skill. use this skill to install, set up, upgrade, downgrade, pin, migrate, uninstall, or clean up BrainX."
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
# BrainX
|
|
6
|
+
# BrainX Install
|
|
7
7
|
|
|
8
|
-
##
|
|
8
|
+
## Objective
|
|
9
9
|
|
|
10
10
|
Install or remove BrainX in one confirmed Python virtual environment, verify, then report the result. For installation, treat each published BrainX release as an indivisible compatibility set; never assemble independently selected subpackage versions.
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
## Request routing
|
|
12
|
+
## Request Routing
|
|
15
13
|
|
|
16
14
|
For an uninstall, removal, or BrainX package-cleanup request, open [references/uninstall-and-cleanup.md](references/uninstall-and-cleanup.md) and stop here. Follow that reference in full; do not apply the installation workflow's device or release selection.
|
|
17
15
|
|
|
18
16
|
For installation, upgrade, downgrade, migration, device-target, or compatibility requests, continue with the workflow below.
|
|
19
17
|
|
|
20
|
-
## Core
|
|
18
|
+
## Core Rules
|
|
21
19
|
|
|
22
20
|
1. BrainX package must use a Python interpreter at version `>=3.11`.
|
|
23
21
|
2. For a clean environment with no requested version, prefer to use the unpinned BrainX install matching the confirmed device, but resolve and name the current latest Python-compatible BrainX date-style release before confirmation. Critically, if a BrainX component already exists in the environment, or a requested version is specified, you must open [compatibility-and-release-matching.md](references/compatibility-and-release-matching.md), use it as the primary release source, and select one non-separated release. Never mix component versions from different rows.
|
|
@@ -43,7 +41,7 @@ read-only inspection
|
|
|
43
41
|
-> final report
|
|
44
42
|
```
|
|
45
43
|
|
|
46
|
-
## 1. Read-
|
|
44
|
+
## 1. Read-Only Inspection
|
|
47
45
|
|
|
48
46
|
Record the intended run location first. Perform no package installation, or environment creation during inspection.
|
|
49
47
|
|
|
@@ -60,7 +58,7 @@ Collect enough evidence to identify:
|
|
|
60
58
|
|
|
61
59
|
Prefer package metadata and platform-native tools over imports or newly installed helpers. Record missing evidence explicitly as `unknown`, `not_detected`, or a command error rather than guessing. Organize the result in whatever concise structured form best fits the task.
|
|
62
60
|
|
|
63
|
-
## 2. Confirm the
|
|
61
|
+
## 2. Confirm the Device Target
|
|
64
62
|
|
|
65
63
|
Determine whether the intended installation is for:
|
|
66
64
|
|
|
@@ -77,7 +75,7 @@ Reflect the understood requirement back to the user before release selection. Us
|
|
|
77
75
|
|
|
78
76
|
Replace the example values with the user's actual target. If evidence is uncertain, explain the ambiguity and ask a focused question instead of filling in a likely answer. Recommend `cpu` when accelerator support is absent or uncertain, but still require explicit confirmation. Do not proceed until the user confirms or corrects the reflected device target.
|
|
79
77
|
|
|
80
|
-
## 3. Select
|
|
78
|
+
## 3. Select One Release
|
|
81
79
|
|
|
82
80
|
First case, When no BrainX meta-package or ecosystem component is installed and the user has not requested a specific version, do not open the compatibility reference. Use read-only official package-index metadata with the proposed interpreter to identify the exact latest Python-compatible BrainX release, then report it in the form `latest (vYYYY.M.D)`. For example, report `latest (v2026.7.9)` when `2026.7.9` is the verified current release.
|
|
83
81
|
|
|
@@ -89,7 +87,7 @@ Critically, for the second case, when BrainX packages are already installed or t
|
|
|
89
87
|
- Treat an installed `BrainX` meta-package version as the release anchor, but surface any component drift from its row.
|
|
90
88
|
- Do not use JAX or Optax alone as a legacy release anchor unless the user explicitly asks to preserve it.
|
|
91
89
|
|
|
92
|
-
## 4. Choose the
|
|
90
|
+
## 4. Choose the Venv
|
|
93
91
|
|
|
94
92
|
Prefer reusing an existing relevant Python virtual environment whose interpreter is Python `>=3.11`. This includes environments managed by `venv`, Conda, or another environment manager; inspect the environment before proposing reuse.
|
|
95
93
|
|
|
@@ -99,7 +97,7 @@ Prefer reusing an existing relevant Python virtual environment whose interpreter
|
|
|
99
97
|
|
|
100
98
|
Resolve the exact interpreter inside the proposed environment using the conventions of the confirmed platform and environment manager. Do not rely on shell activation or assume that a bare `python` or `pip` command targets the intended environment.
|
|
101
99
|
|
|
102
|
-
## 5. Present the
|
|
100
|
+
## 5. Present the Complete Specification
|
|
103
101
|
|
|
104
102
|
The agent must report the complete proposed setup before any mutation. This is a mandatory reporting contract, not a rigid implementation script. Use concrete values and preserve the following visible structure:
|
|
105
103
|
|
|
@@ -135,7 +133,7 @@ End by asking the user to confirm the entire setup or correct it, and state expl
|
|
|
135
133
|
|
|
136
134
|
Do not combine specification and installation in one turn unless the user has already confirmed this exact environment, release, and device extra.
|
|
137
135
|
|
|
138
|
-
## 6. Install and
|
|
136
|
+
## 6. Install and Verify
|
|
139
137
|
|
|
140
138
|
Use exactly the confirmed venv, interpreter, device extra, and unpinned or pinned release method.
|
|
141
139
|
|
|
@@ -163,7 +161,7 @@ Verification passes only when:
|
|
|
163
161
|
|
|
164
162
|
Do not modify manifests, lockfiles, requirements files, or unrelated environments.
|
|
165
163
|
|
|
166
|
-
## 7. Report and
|
|
164
|
+
## 7. Report and Post-install handoff
|
|
167
165
|
|
|
168
166
|
Report:
|
|
169
167
|
|
|
@@ -178,11 +176,11 @@ After reporting a `PASS`, explicitly tell the user:
|
|
|
178
176
|
> This session is for installation of the BrainX package. Installation is complete; Please open another codex chat so that the context is clean
|
|
179
177
|
|
|
180
178
|
|
|
181
|
-
## Official
|
|
179
|
+
## Official Commands to use
|
|
182
180
|
|
|
183
181
|
Use these official BrainX documentation examples to understand the supported syntax. They are educational patterns, not a rigid workflow or permission to bypass the confirmed interpreter, venv, release behavior, or device choice.
|
|
184
182
|
|
|
185
|
-
### Quick
|
|
183
|
+
### Quick Install and Dependency Resolution
|
|
186
184
|
|
|
187
185
|
When no BrainX meta-package or ecosystem component is already installed, prefer the official unpinned quick-install family:
|
|
188
186
|
|
|
@@ -198,7 +196,7 @@ For a new BrainX environment when user has no existing brainX packages, the bare
|
|
|
198
196
|
| `pip install -U 'BrainX[cuda12]'` | Same as above | Same, plus CUDA 12 JAX dependencies |
|
|
199
197
|
| `pip install 'BrainX==2025.9.15'` | Upgraded or downgraded to exactly `2025.9.15` if another version is installed | Replaced only when their installed versions do not satisfy `2025.9.15`'s requirements |
|
|
200
198
|
|
|
201
|
-
### Hardware-
|
|
199
|
+
### Hardware-Specific Installs
|
|
202
200
|
|
|
203
201
|
For a clean environment, each unpinned command below is the default for its corresponding confirmed target. Choose the extra that matches the platform and CUDA toolchain:
|
|
204
202
|
|
|
@@ -216,7 +214,7 @@ pip install -U BrainX[cuda13]
|
|
|
216
214
|
pip install -U BrainX[tpu]
|
|
217
215
|
```
|
|
218
216
|
|
|
219
|
-
### Pin a
|
|
217
|
+
### Pin a Specific BrainX Release
|
|
220
218
|
|
|
221
219
|
BrainX releases use date-style versions:
|
|
222
220
|
|
|
@@ -226,11 +224,10 @@ pip install BrainX==2025.9.15
|
|
|
226
224
|
|
|
227
225
|
When an exact release is requested, preserve the confirmed hardware extra while applying the selected BrainX release pin.
|
|
228
226
|
|
|
229
|
-
## Reference
|
|
227
|
+
## Reference Routing
|
|
228
|
+
|
|
229
|
+
Open [references/uninstall-and-cleanup.md](references/uninstall-and-cleanup.md) for any request to uninstall, remove, or clean up BrainX packages. Use its exact package scopes and mandatory uninstall specification; do not use the compatibility matrix to narrow the cleanup set.
|
|
230
230
|
|
|
231
|
-
|
|
232
|
-
|---|---|
|
|
233
|
-
| `references/uninstall-and-cleanup.md` | Uninstalling, removing, or cleaning up BrainX packages; it contains the exact package scopes and the mandatory uninstall specification. Do not narrow the cleanup set with the compatibility matrix. |
|
|
234
|
-
| `references/compatibility-and-release-matching.md` | The target environment already contains BrainX or BrainX ecosystem packages, or the user requests a specific pinned BrainX version. Mandatory in the pinned case and read before release selection; it contains the release matrix used to match existing packages, reconcile version drift, evaluate pinned-version compatibility, and select one coherent release with its declared component versions. |
|
|
231
|
+
Open [references/compatibility-and-release-matching.md](references/compatibility-and-release-matching.md) when the target environment already contains BrainX or BrainX ecosystem packages, or when the user requests a specific pinned BrainX version. This reference is mandatory for that second case and must be read before release selection. Use its matrix to match existing packages, reconcile version drift, evaluate pinned-version compatibility, and select one coherent BrainX release with its declared component versions.
|
|
235
232
|
|
|
236
|
-
Do not open
|
|
233
|
+
Do not open this reference for a clean installation when no BrainX packages are present and no specific version is requested; use the unpinned quick-install path instead.
|