brainx-skill 1.0.15 → 1.0.17
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 +17 -1
- package/installation/lib/literature-mcp.js +7 -1
- package/manifest.json +1 -1
- package/mcp-servers/codex/README.md +46 -20
- package/mcp-servers/codex/UPSTREAM.md +20 -16
- package/mcp-servers/codex/app-server.mjs +177 -0
- package/mcp-servers/codex/cli-invocation.cjs +50 -0
- package/mcp-servers/codex/server.mjs +136 -69
- package/mcp-servers/codex/skills.json +1 -1
- package/mcp-servers/codex/test/fixtures/fake-codex.mjs +80 -3
- package/mcp-servers/codex/test/fixtures/run-server.mjs +7 -0
- package/mcp-servers/codex/test/server.test.mjs +188 -84
- package/package.json +1 -1
- package/skills/bio-neuro-lit/SKILL.md +4 -2
- package/skills/bio-neuro-lit/references/required-supplements.md +27 -0
- package/skills/brainx-acceleration/SKILL.md +30 -437
- package/skills/brainx-acceleration/references/audit-and-rewrite-patterns.md +326 -0
- package/skills/brainx-general-guard/SKILL.md +24 -8
- package/skills/brainx-install/SKILL.md +3 -3
- package/skills/brainx-install/references/compatibility-and-release-matching.md +28 -20
- package/skills/brainx-install/references/uninstall-and-cleanup.md +11 -4
- package/skills/brainx-modeling-loop/SKILL.md +117 -36
- package/skills/brainx-modeling-loop/agents/openai.yaml +2 -2
- package/skills/brainx-modeling-loop/references/mechanism-comparison.md +62 -0
- package/skills/brainx-modeling-loop/references/multiscale-coupling.md +16 -0
- package/skills/brainx-modeling-loop/references/paper-reproduction.md +42 -0
- package/skills/brainx-modeling-loop/references/parameter-fitting-workflow.md +14 -14
- package/skills/brainx-modeling-loop/references/run-experiment.md +1 -1
- package/skills/brainx-modeling-loop/references/training-workflow.md +10 -8
- package/skills/brainx-visualization/SKILL.md +6 -2
- package/skills/brainx-visualization/references/neural-data-visualization.md +1 -1
- package/skills/brainx-visualization/references/statistical-and-model-visualization.md +1 -1
- package/skills/package-skills/braincell/SKILL.md +23 -14
- package/skills/package-skills/braincell/references/braintools/input-current.md +1 -1
- package/skills/package-skills/braincell/references/braintools/metric.md +72 -46
- package/skills/package-skills/braincell/references/mixions-for-adaptation.md +1 -1
- package/skills/package-skills/braincell/references/multicompartment/braincell-manual-morphology-construction.md +1 -1
- package/skills/package-skills/braincell/references/multicompartment/cv-policy-reference.md +1 -1
- package/skills/package-skills/braincell/references/multicompartment/filter-function-library.md +3 -3
- package/skills/package-skills/braincell/references/multicompartment/morphology-io-loading-validation.md +1 -1
- package/skills/package-skills/braincell/references/multicompartment/multicompartment-cell-workflow.md +31 -43
- package/skills/package-skills/braincell/references/multicompartment/network-workflow.md +49 -0
- package/skills/package-skills/braincell/references/multicompartment/probe-reference.md +26 -114
- package/skills/package-skills/braincell/references/multicompartment/topology-building-and-visualization.md +40 -28
- package/skills/package-skills/braincell/references/scripts/cell_multicompartment_reference.py +13 -17
- package/skills/package-skills/brainevent/SKILL.md +0 -3
- package/skills/package-skills/brainevent/references/synaptic-plasticity.md +1 -1
- package/skills/package-skills/brainmass/SKILL.md +5 -3
- package/skills/package-skills/brainmass/references/brainstate/parameter-constraints-regularization.md +9 -7
- package/skills/package-skills/brainmass/references/brainstate/parameter-transforms-regularizers-catalog.md +4 -4
- package/skills/package-skills/brainmass/references/braintools/data-preprocessing.md +15 -7
- package/skills/package-skills/brainmass/references/braintools/metric.md +72 -46
- package/skills/package-skills/brainmass/references/coupling-network-api.md +3 -1
- package/skills/package-skills/brainmass/references/fitting-with-objectives-api.md +6 -6
- package/skills/package-skills/brainmass/references/horn-task-training.md +9 -9
- package/skills/package-skills/brainmass/references/modellibrary.md +12 -10
- package/skills/package-skills/brainmass/references/scripts/resting-state-meg-whole-brain-pipeline.py +5 -3
- package/skills/package-skills/brainmass/references/scripts/wilson-cowan-ei-dynamics.py +10 -6
- package/skills/package-skills/brainmass/references/simulator-input-monitor-api.md +3 -1
- package/skills/package-skills/brainmass/references/visualization-analysis-api.md +17 -9
- package/skills/package-skills/brainspike/SKILL.md +201 -0
- package/skills/package-skills/brainspike/references/braintools/connectivity.md +40 -0
- package/skills/package-skills/brainspike/references/braintools/data-preprocessing.md +39 -0
- package/skills/package-skills/brainspike/references/braintools/input-current.md +55 -0
- package/skills/package-skills/brainspike/references/braintools/metric.md +36 -0
- package/skills/package-skills/brainspike/references/braintools/optimizer.md +50 -0
- package/skills/package-skills/brainspike/references/braintools/parameter-initializer.md +43 -0
- package/skills/package-skills/brainspike/references/braintools/surrogate.md +40 -0
- package/skills/package-skills/brainspike/references/migration-boundary.md +38 -0
- package/skills/package-skills/brainspike/references/model-and-readout-selection.md +41 -0
- package/skills/package-skills/brainspike/references/multirate-coupling.md +31 -0
- package/skills/package-skills/brainspike/references/multiscale-composition.md +28 -0
- package/skills/package-skills/brainspike/references/native-composition.md +52 -0
- package/skills/package-skills/brainspike/references/native-delays.md +34 -0
- package/skills/package-skills/brainspike/references/native-projections.md +43 -0
- package/skills/package-skills/brainspike/references/native-training.md +36 -0
- package/skills/package-skills/{brainpy-state → brainspike}/references/nest-compatible/devices.md +33 -33
- package/skills/package-skills/{brainpy-state → brainspike}/references/nest-compatible/divergence-and-parity.md +15 -15
- package/skills/package-skills/{brainpy-state → brainspike}/references/nest-compatible/integration-categories.md +1 -1
- package/skills/package-skills/brainspike/references/nest-compatible/model-library.md +200 -0
- package/skills/package-skills/brainspike/references/nest-compatible/network-building.md +276 -0
- package/skills/package-skills/{brainpy-state → brainspike}/references/nest-compatible/scripts/brette_et_al_2007.py +23 -26
- package/skills/package-skills/{brainpy-state → brainspike}/references/nest-compatible/scripts/brunel_alpha.py +18 -21
- package/skills/package-skills/{brainpy-state → brainspike}/references/nest-compatible/scripts/brunel_delta.py +16 -19
- package/skills/package-skills/{brainpy-state → brainspike}/references/nest-compatible/scripts/clopath_synapse_spike_pairing.py +11 -12
- package/skills/package-skills/{brainpy-state → brainspike}/references/nest-compatible/scripts/evaluate_tsodyks2_synapse.py +10 -11
- package/skills/package-skills/{brainpy-state → brainspike}/references/nest-compatible/scripts/spatial_gaussex.py +18 -18
- package/skills/package-skills/{brainpy-state → brainspike}/references/nest-compatible/scripts/synapsecollection.py +26 -29
- package/skills/package-skills/brainspike/references/nest-compatible/synapse-and-connectivity.md +166 -0
- package/skills/package-skills/brainspike/references/nest-delay-boundaries.md +31 -0
- package/skills/package-skills/brainspike/references/nonlinear-state-sharing.md +26 -0
- package/skills/package-skills/{brainpy-state → brainspike}/references/perturbation-experiment-validity.md +2 -2
- package/skills/package-skills/brainspike/references/simulator-training.md +61 -0
- package/skills/package-skills/brainspike/references/temporal-task-training.md +36 -0
- package/skills/package-skills/brainspike/scripts/advanced_native_patterns.py +76 -0
- package/skills/package-skills/brainspike/scripts/delay_workflow.py +44 -0
- package/skills/package-skills/brainspike/scripts/delayed_cue_training.py +78 -0
- package/skills/package-skills/brainspike/scripts/lif_smoke.py +31 -0
- package/skills/package-skills/brainspike/scripts/multiscale_workflow.py +35 -0
- package/skills/package-skills/brainspike/scripts/native_ei_network.py +47 -0
- package/skills/package-skills/brainspike/scripts/native_workflows.py +77 -0
- package/skills/package-skills/brainspike/scripts/nest_boundary_workflows.py +108 -0
- package/skills/package-skills/brainspike/scripts/train_native_snn.py +65 -0
- package/skills/package-skills/brainspike/scripts/train_nest_simulator.py +69 -0
- package/skills/package-skills/brainspike/scripts/train_nest_simulator_two_weights.py +220 -0
- package/skills/package-skills/brainstate/SKILL.md +16 -21
- package/skills/package-skills/brainstate/references/brainstate/brainstate-control-flow-patterns.md +1 -138
- package/skills/package-skills/brainstate/references/brainstate/brainstate-transformed-diagnostics.md +1 -1
- package/skills/package-skills/brainstate/references/brainstate/delay-buffers.md +45 -0
- package/skills/package-skills/brainstate/references/brainstate/parameter-constraints-regularization.md +9 -7
- package/skills/package-skills/brainstate/references/brainstate/parameter-transforms-regularizers-catalog.md +4 -4
- package/skills/package-skills/brainstate/references/brainstate/randomness-and-reproducibility.md +6 -4
- package/skills/package-skills/brainstate/references/brainstate/transformation-grad-expansion.md +4 -4
- package/skills/package-skills/brainstate/references/brainstate/transformation-vmap-expansion.md +1 -1
- package/skills/package-skills/brainstate/references/braintools-optimizer-reference.md +16 -0
- package/skills/package-skills/brainstate/references/libraries/prebuilt-layer-library.md +1 -1
- package/skills/package-skills/brainstate/references/simulation-environment.md +5 -5
- package/skills/package-skills/braintrace/SKILL.md +17 -38
- package/skills/package-skills/braintrace/references/Drtrl.md +9 -26
- package/skills/package-skills/braintrace/references/algorithm selection.md +7 -12
- package/skills/package-skills/braintrace/references/batching.md +15 -35
- package/skills/package-skills/braintrace/references/compiler_internal.md +1 -1
- package/skills/package-skills/braintrace/references/custom algorithms.md +1 -2
- package/skills/package-skills/braintrace/references/customizing_primitive_transforms.md +26 -15
- package/skills/package-skills/braintrace/references/pp_pprop workflow.md +5 -139
- package/skills/package-skills/brainunit/SKILL.md +7 -2
- package/skills/package-skills/brainunit/references/array-mechanics/functional-structural-api.md +1 -1
- package/skills/package-skills/brainunit/references/math-function-library.md +2 -2
- package/skills/package-skills/brainunit/references/typing-and-runtime-validation.md +5 -2
- package/skills/package-skills/brainevent/references/scripts/102_EI_net_1996.py +0 -107
- package/skills/package-skills/brainevent/references/scripts/204_joglekar_2018_propagation.py +0 -168
- package/skills/package-skills/brainevent/references/scripts/coba_ei_teaching.py +0 -356
- package/skills/package-skills/brainpy-state/SKILL.md +0 -247
- package/skills/package-skills/brainpy-state/references/array-creation.md +0 -158
- package/skills/package-skills/brainpy-state/references/brain-dynamics-delay-protocol.md +0 -147
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/analysis.md +0 -150
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/brainpy legacy workflow.md +0 -373
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/built-in dynamic neuron model.md +0 -150
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/connecting neurons.md +0 -175
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/customize neuron and synpase.md +0 -286
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/infrastructure/Input generation.md +0 -111
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/infrastructure/More about simulation.md +0 -163
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/infrastructure/Multi-device array sharding.md +0 -113
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/infrastructure/Parallel experiment execution.md +0 -136
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/infrastructure/array creation and mechanics.md +0 -222
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/infrastructure/brainpy math environment setting.md +0 -123
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/infrastructure/delays.md +0 -107
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/infrastructure/object oriented transformations and control flows.md +0 -185
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/integrators.md +0 -181
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/route activity through connectivity.md +0 -102
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/synaptic projections.md +0 -147
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/synpase properties.md +0 -159
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/training/loss library.md +0 -127
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/training/optimizers.md +0 -167
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/training/parameter initializers.md +0 -107
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/training/prebuilt neural network layers.md +0 -186
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/training/surrogate gradients.md +0 -104
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/training/trainer library.md +0 -89
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/training/trainingworkflows.md +0 -253
- package/skills/package-skills/brainpy-state/references/braintools/brainstate-control-flow-patterns.md +0 -334
- package/skills/package-skills/brainpy-state/references/braintools/connectivity.md +0 -206
- package/skills/package-skills/brainpy-state/references/braintools/data-preprocessing.md +0 -79
- package/skills/package-skills/brainpy-state/references/braintools/input-current.md +0 -199
- package/skills/package-skills/brainpy-state/references/braintools/metric.md +0 -152
- package/skills/package-skills/brainpy-state/references/braintools/optimizer.md +0 -179
- package/skills/package-skills/brainpy-state/references/braintools/parameter-initializer.md +0 -183
- package/skills/package-skills/brainpy-state/references/braintools/surrogate.md +0 -147
- package/skills/package-skills/brainpy-state/references/component-selection.md +0 -288
- package/skills/package-skills/brainpy-state/references/nest-compatible/model-library.md +0 -200
- package/skills/package-skills/brainpy-state/references/nest-compatible/nest-workflow.md +0 -156
- package/skills/package-skills/brainpy-state/references/nest-compatible/network-building.md +0 -264
- package/skills/package-skills/brainpy-state/references/nest-compatible/synapse-and-connectivity.md +0 -153
- package/skills/package-skills/brainpy-state/references/projection-patterns.md +0 -127
- package/skills/package-skills/brainpy-state/references/scripts/103_COBA_2005.py +0 -86
- package/skills/package-skills/brainpy-state/references/scripts/106_COBA_HH_2007.py +0 -181
- package/skills/package-skills/brainpy-state/references/scripts/107_gamma_oscillation_1996.py +0 -156
- package/skills/package-skills/brainpy-state/references/scripts/109_fast_global_oscillation.py +0 -111
- package/skills/package-skills/brainpy-state/references/scripts/201_surrogate_grad_lif_fashion_mnist.py +0 -221
- package/skills/package-skills/brainpy-state/references/scripts/sound_localization.py +0 -240
- package/skills/package-skills/brainpy-state/references/scripts/training-snn.py +0 -119
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# Connect detailed cells
|
|
2
|
+
|
|
3
|
+
Use `braincell.Network` when sources must deliver events to synapses placed at explicit locations on detailed cells. The network owns registration, connection pairing, event delivery, integration time, and population-keyed outputs.
|
|
4
|
+
|
|
5
|
+
| API | Description |
|
|
6
|
+
|---|---|
|
|
7
|
+
| `cell.place(locset, braincell.mech.Synapse(...))` | Declare a named synapse on the detailed cell before network initialization. |
|
|
8
|
+
| `network.add_population(name, model)` | Register each declaring cell or event source. Keep the population handles for connections. |
|
|
9
|
+
| `network.connect(name, source=..., synapse=..., weight=..., delay=...)` | Connect a source to selected synapse endpoints. Check the resolved pairs and attach physical units appropriate to the synapse and the delay. |
|
|
10
|
+
| `network.run(dt=..., duration=...)` | Initialize the network on first use and advance all registered populations on one clock. Read regular samples and sparse events from their separate result mappings. |
|
|
11
|
+
|
|
12
|
+
```python
|
|
13
|
+
import braincell
|
|
14
|
+
import brainunit as u
|
|
15
|
+
from braincell.filter import AllRegion, RootLocation
|
|
16
|
+
|
|
17
|
+
branch = braincell.Branch.from_lengths(
|
|
18
|
+
lengths=[20.0] * u.um, radii=[5.0, 5.0] * u.um,
|
|
19
|
+
)
|
|
20
|
+
cell = braincell.Cell(braincell.Morphology.from_root(branch), pop_size=2)
|
|
21
|
+
cell.paint(
|
|
22
|
+
AllRegion(), braincell.mech.Channel("IL", g_max=0.1 * u.mS / u.cm**2, E=-65.0 * u.mV),
|
|
23
|
+
)
|
|
24
|
+
midpoint = RootLocation(0.5)
|
|
25
|
+
cell.place(midpoint, braincell.mech.Synapse("ExpSyn", name="ampa", tau=2.0 * u.ms))
|
|
26
|
+
cell.loc(midpoint).record("v", braincell.observe.state("v"))
|
|
27
|
+
|
|
28
|
+
network = braincell.Network("demo", seed=7)
|
|
29
|
+
source = network.add_population("drive", braincell.NetStim(size=2, start=0.1 * u.ms))
|
|
30
|
+
target = network.add_population("post", cell)
|
|
31
|
+
edges = network.connect(
|
|
32
|
+
"input", source=source, synapse=target.synapses["ampa"], weight=0.001 * u.uS,
|
|
33
|
+
)
|
|
34
|
+
assert len(edges) == 2
|
|
35
|
+
|
|
36
|
+
result = network.run(dt=0.025 * u.ms, duration=0.5 * u.ms)
|
|
37
|
+
assert result.samples["post"]["v"].values.shape == (20, 2)
|
|
38
|
+
assert result.events["drive"]["spike"].source_id.shape == (2,)
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
After registration, use `network.run()` to advance time and `network.init_state()` for explicit initialization. Calls to `cell.run()`, `cell.init_state()`, `cell.reset_state()`, or `cell.reset()` on a network-managed cell raise `RuntimeError`.
|
|
42
|
+
|
|
43
|
+
Check connection views before the first run. Initialization can invalidate them, so select a fresh view for later inspection. Before a large run, check the resolved source and target indices, synapse placement, delay and weight units, and one small event-delivery response.
|
|
44
|
+
|
|
45
|
+
Use `network.reset_state()` to replay from the initial State with the same scheduled input. A noisy `NetStim` replays the same event times after this reset. For independent noisy inputs, build a fresh network and source per trial with a distinct recorded `NetStim(seed=...)`. Keep the network seed and connection declarations fixed when the study varies input noise with matched wiring.
|
|
46
|
+
|
|
47
|
+
- [BrainCell 0.2.0 Network API and minimal example](https://github.com/chaobrain/braincell/blob/v0.2.0/docs/design/network/current/api.md)
|
|
48
|
+
- [BrainCell 0.2.0 event sources and seeds](https://github.com/chaobrain/braincell/blob/v0.2.0/docs/design/network/current/connections.md)
|
|
49
|
+
- [BrainCell 0.2.0 network examples](https://github.com/chaobrain/braincell/tree/v0.2.0/examples/network)
|
|
@@ -1,128 +1,40 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Record cell observables
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Open this reference when a multicompartment workflow needs a sample schedule, a mechanism or current readout, or migration from legacy probes. A recording binds a spatial selection and an observable to one named result block.
|
|
4
4
|
|
|
5
|
-
## Choose the
|
|
5
|
+
## Choose the observation
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
|
10
|
-
|
|
11
|
-
| `
|
|
12
|
-
| `
|
|
13
|
-
| `
|
|
14
|
-
| `cell.place(locset, *probes)` | Attach probes to concrete morphology locations before initialization. | A locset resolving to several points creates one resolved probe at each point. |
|
|
15
|
-
| `cell.sample_probe(name)` | Read one placed probe after `init_state()`. | It returns the current snapshot for the exact resolved probe name. |
|
|
16
|
-
| `cell.sample_probes()` | Read every placed probe after `init_state()`. | It returns `{probe_name: current_value}`. |
|
|
17
|
-
| `cell.run(dt=..., duration=...)` | Record the same probes at every integration step. | It returns `RunResult(time=..., traces=...)`, where `traces` is keyed by resolved probe name. |
|
|
18
|
-
|
|
19
|
-
Use `StateProbe` for cell voltage. Use `MechanismProbe` only for stored runtime State. Use `CurrentProbe` when the requested observable is computed current rather than stored State.
|
|
20
|
-
|
|
21
|
-
## Place and read probes
|
|
7
|
+
| API | Description |
|
|
8
|
+
|---|---|
|
|
9
|
+
| `cell.loc(locset).record(name, observable, period=...)` | Register a unique name before initialization. Use a locset for spatial sampling or call `record()` on another cell view to keep its existing population and CV selection. |
|
|
10
|
+
| `braincell.observe.state("v")` | Record membrane voltage at the selected CVs. |
|
|
11
|
+
| `braincell.observe.channel(name=...).state(field)` | Record a stored channel State such as a gate. Match the declared name and choose a view where the channel is present. |
|
|
12
|
+
| `braincell.observe.ion(species=...).current()` | Record the total current for the selected ion species. Use a named channel's `current()` for a specific contributor. |
|
|
13
|
+
| `braincell.observe.membrane_current()` | Record total membrane current density at the selected CVs. |
|
|
22
14
|
|
|
23
|
-
|
|
15
|
+
Choose `period` or `frequency`, or omit both to sample every integration step. The resolved period and `start` must align with `dt`. Use the block's own time axis for plotting and its schema to identify the result columns.
|
|
24
16
|
|
|
25
17
|
```python
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
from braincell.filter import AllRegion, at
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
morphology = braincell.Morphology.from_swc("neuron.swc")
|
|
33
|
-
cell = braincell.Cell(morphology, solver="staggered")
|
|
34
|
-
|
|
35
|
-
cell.paint(
|
|
36
|
-
AllRegion(),
|
|
37
|
-
mech.Channel(
|
|
38
|
-
"IL",
|
|
39
|
-
g_max=0.03 * u.mS / u.cm**2,
|
|
40
|
-
E=-54.387 * u.mV,
|
|
41
|
-
),
|
|
42
|
-
mech.Channel(
|
|
43
|
-
"Na_HH1952",
|
|
44
|
-
g_max=120.0 * u.mS / u.cm**2,
|
|
45
|
-
),
|
|
18
|
+
# Reuse the declaring Cell and RootLocation from the multicompartment workflow.
|
|
19
|
+
cell.loc(RootLocation(0.5)).record(
|
|
20
|
+
"voltage_2kHz", braincell.observe.state("v"), frequency=2.0 * u.kHz,
|
|
46
21
|
)
|
|
47
|
-
cell.
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
)
|
|
53
|
-
|
|
54
|
-
cell.init_state()
|
|
55
|
-
samples = cell.sample_probes()
|
|
56
|
-
|
|
57
|
-
assert "soma(0.5)_v" in samples
|
|
58
|
-
assert "soma(0.5)_Na_HH1952_p" in samples
|
|
59
|
-
assert "soma(0.5)_IL_current" in samples
|
|
60
|
-
|
|
61
|
-
result = cell.run(dt=0.05 * u.ms, duration=12.0 * u.ms)
|
|
62
|
-
assert result.traces["soma(0.5)_v"].shape[0] == result.time.shape[0]
|
|
22
|
+
result = cell.run(dt=0.1 * u.ms, duration=10.0 * u.ms)
|
|
23
|
+
block = result.samples["voltage_2kHz"]
|
|
24
|
+
assert block.values.shape == (20, 1)
|
|
25
|
+
assert block.time.shape == (20,)
|
|
26
|
+
assert len(block.schema.rows) == 1
|
|
63
27
|
```
|
|
64
28
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
## Predict probe names
|
|
68
|
-
|
|
69
|
-
When `name` is omitted, the lowerer combines the resolved location with the observed target.
|
|
70
|
-
|
|
71
|
-
| Probe declaration | Generated key pattern | Documented example |
|
|
72
|
-
|---|---|---|
|
|
73
|
-
| `StateProbe()` | `<location>_v` | `soma(0.5)_v` |
|
|
74
|
-
| `MechanismProbe(mechanism=M, field=F)` | `<location>_<M>_<F>` | `soma(0.5)_Na_HH1952_p` |
|
|
75
|
-
| `CurrentProbe(mechanism=M)` | `<location>_<M>_current` | `soma(0.5)_IL_current` |
|
|
76
|
-
| `CurrentProbe(ion=I)` | `<location>_<I>_current` | `soma(0.5)_na_current` |
|
|
77
|
-
|
|
78
|
-
Use `sorted(cell.sample_probes())` after initialization to discover the actual keys instead of reconstructing them from memory. If `name=...` is supplied, keep it globally unique; duplicate names make snapshot and run results ambiguous.
|
|
79
|
-
|
|
80
|
-
A multi-point locset expands into separate concrete names. For example, `RootLocation(0.5) | Terminals()` creates one voltage key for the root midpoint and one for each terminal selected by the morphology.
|
|
81
|
-
|
|
82
|
-
## Probe mechanism and ion State
|
|
83
|
-
|
|
84
|
-
`MechanismProbe` resolves a named runtime owner, then reads one field that is stored as `brainstate.State`.
|
|
85
|
-
|
|
86
|
-
| Request | Use | Do not use |
|
|
87
|
-
|---|---|---|
|
|
88
|
-
| Channel gate | `MechanismProbe(mechanism="Na_HH1952", field="p")` | A parameter such as `g_max`; it is not evolving State. |
|
|
89
|
-
| Dynamic ion concentration | `MechanismProbe(mechanism="ca_dyn", field="Ci")` | A derived Nernst property such as `E` when it is computed rather than stored. |
|
|
90
|
-
| Cell voltage | `StateProbe(field="v")` | `MechanismProbe` without a mechanism owner. |
|
|
91
|
-
|
|
92
|
-
The mechanism or ion must exist at the selected runtime point. A valid field on a mechanism painted elsewhere is still invalid at the probe location.
|
|
93
|
-
|
|
94
|
-
## Probe current ownership
|
|
95
|
-
|
|
96
|
-
Choose between one mechanism current and an ion owner's total current:
|
|
97
|
-
|
|
98
|
-
| Request | Probe |
|
|
99
|
-
|---|---|
|
|
100
|
-
| One ion-bound mechanism | `CurrentProbe(ion="na", mechanism="Na_HH1952")` |
|
|
101
|
-
| One mechanism that can evaluate current without an explicit ion selector | `CurrentProbe(mechanism="IL")` |
|
|
102
|
-
| Sum of currents owned by an ion | `CurrentProbe(ion="na")` |
|
|
103
|
-
|
|
104
|
-
An ion total may equal a mechanism current when that ion owns only one channel. Do not rely on that equality: adding another channel changes the ion total but not the individual mechanism trace.
|
|
105
|
-
|
|
106
|
-
For mixed-ion channels, distinguish the current owner from ions that only modulate gating. Use `CurrentProbe(mechanism=...)` for the channel's own current and `CurrentProbe(ion=...)` for the owning ion's aggregate current.
|
|
107
|
-
|
|
108
|
-
## Diagnose missing or wrong traces
|
|
29
|
+
Use `result.samples[population_name][recording_name]` for a `Network` result. Open `references/multicompartment/network-workflow.md` for population registration and sparse events.
|
|
109
30
|
|
|
110
|
-
|
|
31
|
+
## Diagnose missing or misaligned samples
|
|
111
32
|
|
|
112
|
-
|
|
113
|
-
2. Resolve the locset with `morphology.select(locset)` and inspect its `points` and `display_names`.
|
|
114
|
-
3. Inspect `sorted(cell.sample_probes())`; do not guess the trace key.
|
|
115
|
-
4. Confirm that the named mechanism or ion is painted at the resolved point.
|
|
116
|
-
5. For `MechanismProbe`, confirm that the field is stored runtime State rather than a parameter or derived property.
|
|
117
|
-
6. For `CurrentProbe`, confirm whether the request means one mechanism current or an ion-owner total.
|
|
118
|
-
7. Check explicit names for global uniqueness and multi-point locsets for automatic expansion.
|
|
119
|
-
8. Compare `result.time.shape[0]` with every requested trace length after `run()`.
|
|
33
|
+
Check the recording name and declaration phase, then inspect the selected cells and CVs, the observed mechanism at those sites, and the time window. Read the block's schema before comparing positions across CV policies. For a layout mismatch, open `references/multicompartment/topology-building-and-visualization.md`.
|
|
120
34
|
|
|
121
|
-
|
|
35
|
+
## Migrate legacy probes
|
|
122
36
|
|
|
123
|
-
|
|
37
|
+
BrainCell 0.2.0 retains `StateProbe`, `MechanismProbe`, and `CurrentProbe` for existing declarations. Read their values by resolved key from `sample_probes()` after initialization or `RunResult.traces` after a run. For new recordings, give each view and observable an explicit name. Compare resolved sample locations, units, and time axes before treating a legacy point probe and a CV recording as equivalent.
|
|
124
38
|
|
|
125
|
-
- [
|
|
126
|
-
- [
|
|
127
|
-
- [MechanismProbe API](https://brainx.chaobrain.com/braincell/apis/generated/braincell.mech.MechanismProbe.html)
|
|
128
|
-
- [CurrentProbe API](https://brainx.chaobrain.com/braincell/apis/generated/braincell.mech.CurrentProbe.html)
|
|
39
|
+
- [BrainCell 0.2.0 recording API](https://github.com/chaobrain/braincell/blob/v0.2.0/docs/design/network/current/recording.md)
|
|
40
|
+
- [BrainCell 0.2.0 recording examples](https://github.com/chaobrain/braincell/blob/v0.2.0/examples/cell/recording.ipynb)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Topology building and visualization
|
|
2
2
|
|
|
3
|
-
Use this reference after `references/multicompartment/multicompartment-cell-workflow.md` when branch topology, CV coverage, runtime nodes, selector placement, or spatial values must be visualized. Keep morphology construction and validation, selector design, CV-policy choice,
|
|
3
|
+
Use this reference after `references/multicompartment/multicompartment-cell-workflow.md` when branch topology, CV coverage, runtime nodes, selector placement, or spatial values must be visualized. Keep morphology construction and validation, selector design, CV-policy choice, recording behavior, and simulation in their owning references.
|
|
4
4
|
|
|
5
5
|
## Choose the view
|
|
6
6
|
|
|
@@ -10,21 +10,21 @@ Morphology branches, CVs, and runtime nodes are different layers of one cell; vi
|
|
|
10
10
|
|---|---|---|
|
|
11
11
|
| `morphology.topo()` | Check the named parent-child branch tree before discretization. | It does not show CVs or runtime nodes. |
|
|
12
12
|
| `morphology.select(expr)` | Confirm region intervals or locset points before plotting. | Use the filter reference when the selection itself is wrong. |
|
|
13
|
-
| `
|
|
14
|
-
| `
|
|
15
|
-
| `
|
|
16
|
-
| `cell.vis_topology(level=...)` | Dispatch dynamically among `"branch"`, `"cv"`, and `"node"`. | Branch level rejects locset and value arguments. |
|
|
13
|
+
| `braincell.vis.plot_cell_topology(cell, level="branch", ...)` | Inspect compact branch topology or region coverage. | Supports region highlights. |
|
|
14
|
+
| `braincell.vis.plot_cell_topology(cell, level="cv", ...)` | Inspect discretization, region coverage, locset ownership, or CV values. | Initialize before reading runtime values. |
|
|
15
|
+
| `braincell.vis.plot_cell_topology(cell, level="node", ...)` | Inspect the runtime point graph, lowered placement, or point values. | Initialize before rendering runtime nodes. |
|
|
17
16
|
| `braincell.vis.plot2d()` / `plot3d()` | Inspect physical morphology geometry. | Use these instead of topology layouts when length, radius, or 3D position matters. |
|
|
18
17
|
|
|
19
18
|
The morphology defines continuous cable, the CV policy defines isopotential intervals, and `init_state()` lowers them into the execution-oriented `NodeTree`. Do not equate morphology points, branches, CVs, and runtime nodes.
|
|
20
19
|
|
|
21
20
|
## Prepare the visualization context
|
|
22
21
|
|
|
23
|
-
|
|
22
|
+
Supply a validated `neuron.swc` with a soma and dendrite and use an environment with Matplotlib and NetworkX, available with the BrainCell `vis` extra. Graphviz layouts require PyGraphviz. When a Graphviz layout is unavailable, the plot warns and falls back to `kamada_kawai`. Choose `layout="kamada_kawai"` directly when only NetworkX is available.
|
|
24
23
|
|
|
25
24
|
```python
|
|
26
25
|
import braincell
|
|
27
26
|
import braincell.mech as mech
|
|
27
|
+
import braincell.vis as vis
|
|
28
28
|
import brainunit as u
|
|
29
29
|
import matplotlib.pyplot as plt
|
|
30
30
|
from braincell.filter import AllRegion, RootLocation, Terminals, branch_in
|
|
@@ -67,39 +67,43 @@ Render one selection across structural levels, then show a locset at runtime lev
|
|
|
67
67
|
```python
|
|
68
68
|
fig, axes = plt.subplots(2, 2, figsize=(10, 9), dpi=140)
|
|
69
69
|
|
|
70
|
-
|
|
70
|
+
vis.plot_cell_topology(
|
|
71
|
+
cell,
|
|
72
|
+
level="branch",
|
|
71
73
|
region=target_region,
|
|
72
74
|
coverage_mode="fraction",
|
|
73
75
|
layout="dot",
|
|
74
76
|
ax=axes[0, 0],
|
|
75
|
-
show=False,
|
|
76
77
|
)
|
|
77
78
|
axes[0, 0].set_title("Branch region")
|
|
78
79
|
|
|
79
|
-
|
|
80
|
+
vis.plot_cell_topology(
|
|
81
|
+
cell,
|
|
82
|
+
level="cv",
|
|
80
83
|
region=target_region,
|
|
81
84
|
coverage_mode="fraction",
|
|
82
85
|
layout="dot",
|
|
83
86
|
ax=axes[0, 1],
|
|
84
|
-
show=False,
|
|
85
87
|
)
|
|
86
88
|
axes[0, 1].set_title(f"CV region: n={cell.n_cv}")
|
|
87
89
|
|
|
88
|
-
|
|
90
|
+
vis.plot_cell_topology(
|
|
91
|
+
cell,
|
|
92
|
+
level="node",
|
|
89
93
|
region=target_region,
|
|
90
94
|
coverage_mode="fraction",
|
|
91
95
|
layout="dot",
|
|
92
96
|
ax=axes[1, 0],
|
|
93
|
-
show=False,
|
|
94
97
|
)
|
|
95
98
|
axes[1, 0].set_title("Runtime region")
|
|
96
99
|
|
|
97
|
-
|
|
100
|
+
vis.plot_cell_topology(
|
|
101
|
+
cell,
|
|
102
|
+
level="node",
|
|
98
103
|
locset=target_sites,
|
|
99
104
|
highlight_color="#f97316",
|
|
100
105
|
layout="dot",
|
|
101
106
|
ax=axes[1, 1],
|
|
102
|
-
show=False,
|
|
103
107
|
)
|
|
104
108
|
axes[1, 1].set_title("Runtime locset")
|
|
105
109
|
|
|
@@ -116,25 +120,28 @@ Hold the initialized cell and data fixed while choosing the layout that makes to
|
|
|
116
120
|
```python
|
|
117
121
|
fig, axes = plt.subplots(1, 3, figsize=(13, 4), dpi=140)
|
|
118
122
|
|
|
119
|
-
|
|
123
|
+
vis.plot_cell_topology(
|
|
124
|
+
cell,
|
|
125
|
+
level="node",
|
|
120
126
|
preset="dendrotweaks",
|
|
121
127
|
ax=axes[0],
|
|
122
|
-
show=False,
|
|
123
128
|
)
|
|
124
129
|
axes[0].set_title("dendrotweaks")
|
|
125
130
|
|
|
126
|
-
|
|
131
|
+
vis.plot_cell_topology(
|
|
132
|
+
cell,
|
|
133
|
+
level="node",
|
|
127
134
|
layout="dot",
|
|
128
135
|
ax=axes[1],
|
|
129
|
-
show=False,
|
|
130
136
|
)
|
|
131
137
|
axes[1].set_title("dot")
|
|
132
138
|
|
|
133
|
-
|
|
139
|
+
vis.plot_cell_topology(
|
|
140
|
+
cell,
|
|
141
|
+
level="node",
|
|
134
142
|
layout="kamada_kawai",
|
|
135
143
|
layout_scale=1.5,
|
|
136
144
|
ax=axes[2],
|
|
137
|
-
show=False,
|
|
138
145
|
)
|
|
139
146
|
axes[2].set_title("kamada_kawai")
|
|
140
147
|
|
|
@@ -153,23 +160,25 @@ Use value mode on an initialized or already simulated cell. Named selectors avoi
|
|
|
153
160
|
```python
|
|
154
161
|
fig, axes = plt.subplots(1, 2, figsize=(10, 4), dpi=140)
|
|
155
162
|
|
|
156
|
-
|
|
163
|
+
vis.plot_cell_topology(
|
|
164
|
+
cell,
|
|
165
|
+
level="node",
|
|
157
166
|
value="V",
|
|
158
167
|
cmap="viridis",
|
|
159
168
|
vmin=-80.0,
|
|
160
169
|
vmax=-40.0,
|
|
161
170
|
value_label="Voltage",
|
|
162
171
|
ax=axes[0],
|
|
163
|
-
show=False,
|
|
164
172
|
)
|
|
165
173
|
axes[0].set_title("Membrane voltage")
|
|
166
174
|
|
|
167
|
-
|
|
175
|
+
vis.plot_cell_topology(
|
|
176
|
+
cell,
|
|
177
|
+
level="node",
|
|
168
178
|
value=("channel", "IL", "g_max"),
|
|
169
179
|
cmap="magma",
|
|
170
180
|
value_label="IL g_max",
|
|
171
181
|
ax=axes[1],
|
|
172
|
-
show=False,
|
|
173
182
|
)
|
|
174
183
|
axes[1].set_title("Leak conductance")
|
|
175
184
|
|
|
@@ -212,18 +221,19 @@ assert depth.shape == (len(cell.node_tree.nodes),)
|
|
|
212
221
|
assert not np.isnan(depth).any()
|
|
213
222
|
|
|
214
223
|
fig, ax = plt.subplots(figsize=(7, 7), dpi=140)
|
|
215
|
-
|
|
224
|
+
vis.plot_cell_topology(
|
|
225
|
+
cell,
|
|
226
|
+
level="node",
|
|
216
227
|
value=depth,
|
|
217
228
|
cmap="magma",
|
|
218
229
|
value_label="Runtime graph depth",
|
|
219
230
|
ax=ax,
|
|
220
|
-
show=False,
|
|
221
231
|
)
|
|
222
232
|
fig.tight_layout()
|
|
223
233
|
plt.show()
|
|
224
234
|
```
|
|
225
235
|
|
|
226
|
-
|
|
236
|
+
Pass one population member as a one-dimensional array of length `n_point` or `n_cv`. In node mode the function scatters CV values into point space. Named runtime selectors handle a singleton population directly.
|
|
227
237
|
|
|
228
238
|
## Lookup
|
|
229
239
|
|
|
@@ -248,12 +258,14 @@ A point-space array must have length `n_point`. A CV-space array must have lengt
|
|
|
248
258
|
| `cmap`, `vmin`, `vmax`, `norm` | Control value normalization. |
|
|
249
259
|
| `value_label`, `show_colorbar` | Control the colorbar. |
|
|
250
260
|
| `node_color`, `edge_color`, `root_color` | Style topology without entering value mode. |
|
|
251
|
-
| `ax
|
|
261
|
+
| `ax=...` | Compose subplots; call `plt.show()` or `fig.savefig(...)` once afterward. |
|
|
252
262
|
|
|
253
263
|
Highlight mode and value mode are mutually exclusive. Fix selectors in `filter-function-library.md`, discretization in `cv-policy-reference.md`, morphology geometry in the IO or manual-construction reference, and recorded-trace mismatches in `probe-reference.md`.
|
|
254
264
|
|
|
255
265
|
## Sources
|
|
256
266
|
|
|
267
|
+
- [Cell topology API](https://brainx.chaobrain.com/braincell/apis/vis.html#cell-topology-plots)
|
|
268
|
+
- [BrainCell 0.2.0 migration](https://github.com/chaobrain/braincell/releases/tag/v0.2.0)
|
|
257
269
|
- [Point tree visualization](https://brainx.chaobrain.com/braincell/tutorials/vis.html)
|
|
258
270
|
- [Region and locset filters](https://brainx.chaobrain.com/braincell/tutorials/filter.html)
|
|
259
271
|
- [Morphology](https://brainx.chaobrain.com/braincell/concepts/morphology.html)
|
package/skills/package-skills/braincell/references/scripts/cell_multicompartment_reference.py
CHANGED
|
@@ -8,6 +8,7 @@ All BrainCell reference scripts live in this directory.
|
|
|
8
8
|
|
|
9
9
|
# 1. Imports and CPU/JAX setup.
|
|
10
10
|
# Set the platform before importing JAX-backed BrainCell/BrainState packages.
|
|
11
|
+
import argparse
|
|
11
12
|
import os
|
|
12
13
|
|
|
13
14
|
os.environ.setdefault("JAX_PLATFORMS", "cpu")
|
|
@@ -20,13 +21,13 @@ import matplotlib.pyplot as plt
|
|
|
20
21
|
from braincell import Cell, Morphology
|
|
21
22
|
from braincell import CVPerBranch, MaxCVLen
|
|
22
23
|
from braincell.filter import BranchSlice, RootLocation, at
|
|
23
|
-
from braincell.mech import CableProperty, Channel, CurrentClamp
|
|
24
|
+
from braincell.mech import CableProperty, Channel, CurrentClamp
|
|
24
25
|
|
|
25
26
|
|
|
26
27
|
# 2. Load morphology from SWC.
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
morpho = Morphology.from_swc(
|
|
28
|
+
parser = argparse.ArgumentParser(description="Run the multicompartment cell example.")
|
|
29
|
+
parser.add_argument("swc", help="Path to an SWC containing a soma and at least one dendrite")
|
|
30
|
+
morpho = Morphology.from_swc(parser.parse_args().swc)
|
|
30
31
|
|
|
31
32
|
print("Morphology topology:")
|
|
32
33
|
print(morpho.topo())
|
|
@@ -142,20 +143,18 @@ channel_cell.paint(
|
|
|
142
143
|
|
|
143
144
|
channel_cell.init_state()
|
|
144
145
|
layout = channel_cell.layouts[0]
|
|
145
|
-
point_id = int(layout.point_index[0])
|
|
146
146
|
|
|
147
147
|
print("\nDensity mechanism layout:")
|
|
148
148
|
print("layout.kind:", layout.kind)
|
|
149
149
|
print("layout.target:", layout.target)
|
|
150
150
|
print("layout.n_active:", layout.n_active)
|
|
151
151
|
print("layout.source_cv_ids:", layout.source_cv_ids)
|
|
152
|
-
print("layout
|
|
153
|
-
print("
|
|
154
|
-
print("sample E at one active point:", channel_cell.get_point_state(point_id)[layout.id]["E"])
|
|
152
|
+
print("g_max on the density layout:", channel_cell.get_state(layout.id, "g_max"))
|
|
153
|
+
print("E on the density layout:", channel_cell.get_state(layout.id, "E"))
|
|
155
154
|
|
|
156
155
|
|
|
157
156
|
# 10. place(...): point mechanisms.
|
|
158
|
-
# place(locset, mechanism) attaches point mechanisms such as clamps
|
|
157
|
+
# place(locset, mechanism) attaches point mechanisms such as clamps.
|
|
159
158
|
place_cell = Cell(morpho, cv_policy=CVPerBranch(2))
|
|
160
159
|
place_cell.place(
|
|
161
160
|
RootLocation(x=0.5),
|
|
@@ -173,12 +172,11 @@ print("layout.n_active:", layout.n_active)
|
|
|
173
172
|
print("layout.point_index:", layout.point_index.tolist())
|
|
174
173
|
print("amplitudes:", place_cell.get_state(layout.id, "amplitudes"))
|
|
175
174
|
print("durations:", place_cell.get_state(layout.id, "durations"))
|
|
176
|
-
print("start:", place_cell.get_state(layout.id, "start"))
|
|
177
175
|
|
|
178
176
|
|
|
179
177
|
# 11. Minimal runnable multicompartment simulation.
|
|
180
178
|
# This is the canonical Cell(morpho) simulation shape: choose CV policy and solver,
|
|
181
|
-
# paint density mechanisms, place
|
|
179
|
+
# paint density mechanisms, place the clamp, register voltage, initialize, and run.
|
|
182
180
|
sim_cell = Cell(
|
|
183
181
|
morpho,
|
|
184
182
|
cv_policy=CVPerBranch(cv_per_branch=2),
|
|
@@ -197,10 +195,7 @@ sim_cell.place(
|
|
|
197
195
|
CurrentClamp(delay=20.0 * u.ms, durations=60.0 * u.ms, amplitudes=0.2 * u.nA),
|
|
198
196
|
)
|
|
199
197
|
|
|
200
|
-
sim_cell.
|
|
201
|
-
at("soma", 0.5),
|
|
202
|
-
StateProbe(),
|
|
203
|
-
)
|
|
198
|
+
sim_cell.loc(at("soma", 0.5)).record("soma_v", braincell.observe.state("v"))
|
|
204
199
|
|
|
205
200
|
sim_cell.init_state()
|
|
206
201
|
sim_cell.reset_state()
|
|
@@ -209,8 +204,9 @@ dt = 0.1 * u.ms
|
|
|
209
204
|
duration = 100.0 * u.ms
|
|
210
205
|
result = sim_cell.run(dt=dt, duration=duration)
|
|
211
206
|
|
|
212
|
-
|
|
213
|
-
|
|
207
|
+
voltage = result.samples["soma_v"]
|
|
208
|
+
times_ms = voltage.time.to_decimal(u.ms)
|
|
209
|
+
soma_v_mV = voltage.values[:, 0].to_decimal(u.mV)
|
|
214
210
|
|
|
215
211
|
plt.figure(figsize=(6, 4))
|
|
216
212
|
plt.plot(times_ms, soma_v_mV, label="soma(0.5)_v")
|
|
@@ -263,6 +263,3 @@ Verify `postsynaptic_input.shape == connectivity.shape[1:]` for vector input and
|
|
|
263
263
|
## Application script examples
|
|
264
264
|
| Reference | Open when |
|
|
265
265
|
|---|---|
|
|
266
|
-
| `references/scripts/coba_ei_teaching.py` | Open for the shared BrainEvent and BrainPy teaching example; it uses `BinaryArray` with interchangeable `FixedNumPerPre`, `CSR`, and dense connectivity for efficient event-driven communication into BrainPy `LIFRef`, `Expon`, and `COBA` dynamics inside one compiled BrainState loop. |
|
|
267
|
-
| `references/scripts/102_EI_net_1996.py` | Open for a complete high-level E/I network already using `brainpy.state.AlignPostProj` and `brainstate.nn.EventFixedProb`; it preserves unit-aware weights, initialization, compiled time loops, and visualization. |
|
|
268
|
-
| `references/scripts/204_joglekar_2018_propagation.py` | Open for delayed spikes, area mapping, and vmapped `JITCScalarC` communication; it preserves delays, seeds, external-data assumptions, and BrainPy compatibility details. |
|
|
@@ -125,5 +125,5 @@ Open the official Synaptic Plasticity tutorial when choosing trace equations, up
|
|
|
125
125
|
|
|
126
126
|
## Sources
|
|
127
127
|
|
|
128
|
-
-
|
|
128
|
+
- [Event-driven synaptic plasticity tutorial](https://brainx.chaobrain.com/brainevent/tutorials/events/synaptic-plasticity.html)
|
|
129
129
|
- Apply event-driven synaptic plasticity: https://brainx.chaobrain.com/brainevent/how-to/data-structures/synaptic-plasticity.html
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: brainmass
|
|
3
|
-
description: Use for neural-mass modeling of aggregate population activity at the local-circuit, brain-region, multi-region, or whole-brain scale. Use alone for mass-model studies or together with
|
|
3
|
+
description: Use for neural-mass modeling of aggregate population activity at the local-circuit, brain-region, multi-region, or whole-brain scale. Use alone for mass-model studies or together with BrainSpike and/or BrainCell when aggregate dynamics participate in a multiscale model.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# BrainMass
|
|
@@ -40,11 +40,13 @@ A noise process represents unresolved fluctuations or stochastic drive. It is at
|
|
|
40
40
|
|
|
41
41
|
Every public regional model follows the same `*Step` contract, so choose by scientific observable and dynamical regime, then let `Simulator` own initialization and the transformed time loop.
|
|
42
42
|
|
|
43
|
+
Separate the catalog's scientific abstraction from the runner's compatibility. For a custom continuous-rate `brainstate.nn.Module`, evaluate `Simulator` against its initialization/update contract before choosing a manual rollout; using the runner does not pool individual units or replace their equations. Reject it for a concrete contract limitation, not merely because the custom model differs from the population-model catalog.
|
|
44
|
+
|
|
43
45
|
| API | Description |
|
|
44
46
|
|---|---|
|
|
45
47
|
| `brainmass.list_models()` | Use before choosing a model; it returns `ModelInfo` records with name, category, state-variable count, and use case. |
|
|
46
48
|
| `brainmass.<Model>Step(in_size, **params)` | Use after selecting a model family; `in_size` sets the number of regions or parallel units and parameters broadcast to that shape. |
|
|
47
|
-
| `brainmass.Simulator(model, dt=...)` | Use for the default run path; it stores the model and integration step without changing the model equations. |
|
|
49
|
+
| `brainmass.Simulator(model, dt=...)` | Use for the default run path, including compatible custom Modules; it stores the model and integration step without changing the model equations. |
|
|
48
50
|
| `Simulator.run(duration, *, inputs=None, monitors=None, transient=None, sample_every=None, batch_size=None, init_states=True, jit=True)` | Use to drive and observe the model through the standard runner; it initializes State by default, executes the complete State-aware loop with JIT by default, applies transient removal and post-update sampling, and returns time-major trajectories plus unit-aware `ts`. |
|
|
49
51
|
|
|
50
52
|
```python
|
|
@@ -265,7 +267,7 @@ Choose the workflow category first, then open only the smallest reference that o
|
|
|
265
267
|
| `references/datasets-api.md` | Loading, inspecting, generating, or registering BrainMass data containers. |
|
|
266
268
|
| `references/coupling-network-api.md` | Selecting or configuring coupling, delays, connectivity conventions, direct coupling objects, or trainable network parameters. |
|
|
267
269
|
| `references/forward-observation-api.md` | Selecting BOLD, HRF kernels, temporal averaging, EEG/MEG lead fields, or trainable readouts. |
|
|
268
|
-
| `references/visualization-analysis-api.md` | Plotting or computing time-series, FC, FCD, and spectral summaries. |
|
|
270
|
+
| `references/visualization-analysis-api.md` | Plotting or computing sample-by-signal Pearson similarity, time-series, FC, FCD, and spectral summaries. |
|
|
269
271
|
|
|
270
272
|
### Fitting and regime exploration
|
|
271
273
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# BrainState constrained and regularized parameters
|
|
2
2
|
|
|
3
|
-
Use this reference after `
|
|
3
|
+
Use this reference after `brainmass` → `SKILL.md` has selected
|
|
4
4
|
`brainstate.nn.Param` for a fitted or directly trained BrainMass value that
|
|
5
5
|
needs a valid-domain transform, a regularization penalty, a modeling prior, or
|
|
6
6
|
fixed parameter-like storage. It owns the operational workflow and common
|
|
@@ -21,7 +21,7 @@ Keep `brainstate.nn` parameter transforms separate from execution transforms suc
|
|
|
21
21
|
|
|
22
22
|
## Parameter contract
|
|
23
23
|
|
|
24
|
-
A `ParamState`
|
|
24
|
+
A `ParamState` holds a trainable array or PyTree. `brainstate.nn.Param` layers two orthogonal concerns on top of it: a constraint transform and a regularization term.
|
|
25
25
|
|
|
26
26
|
- `param.val` is the underlying `ParamState`; optimizers update its unconstrained array.
|
|
27
27
|
- `param.value()` applies the forward transform and returns the constrained model-space value. With the default `IdentityT`, constrained and unconstrained values coincide.
|
|
@@ -45,6 +45,7 @@ This workflow keeps optimizer targets in unconstrained `ParamState`s, reads tran
|
|
|
45
45
|
import brainstate
|
|
46
46
|
from brainstate import nn
|
|
47
47
|
import brainunit as u
|
|
48
|
+
import braintools
|
|
48
49
|
import jax.numpy as jnp
|
|
49
50
|
|
|
50
51
|
|
|
@@ -69,6 +70,8 @@ class ConstrainedLinear(nn.Module):
|
|
|
69
70
|
|
|
70
71
|
model = ConstrainedLinear(4, 2)
|
|
71
72
|
params = model.states(brainstate.ParamState)
|
|
73
|
+
optimizer = braintools.optim.SGD(lr=0.1)
|
|
74
|
+
optimizer.register_trainable_weights(params)
|
|
72
75
|
x = brainstate.random.randn(16, 4)
|
|
73
76
|
y = brainstate.random.randn(16, 2)
|
|
74
77
|
|
|
@@ -82,11 +85,10 @@ def loss_fn():
|
|
|
82
85
|
def train_step():
|
|
83
86
|
grads, loss = brainstate.transform.grad(
|
|
84
87
|
loss_fn,
|
|
85
|
-
params,
|
|
88
|
+
grad_states=params,
|
|
86
89
|
return_value=True,
|
|
87
90
|
)()
|
|
88
|
-
|
|
89
|
-
params[key].value -= 0.1 * grads[key]
|
|
91
|
+
optimizer.update(grads)
|
|
90
92
|
return loss
|
|
91
93
|
```
|
|
92
94
|
|
|
@@ -161,7 +163,7 @@ Open `parameter-transforms-regularizers-catalog.md` to select classical, structu
|
|
|
161
163
|
Official sources:
|
|
162
164
|
|
|
163
165
|
- https://brainx.chaobrain.com/brainstate/tutorials/core/05_parameters_transforms_regularization.html
|
|
164
|
-
- https://brainx.chaobrain.com/brainstate/apis/nn/
|
|
166
|
+
- https://brainx.chaobrain.com/brainstate/apis/nn/parameters.html#standard-regularizations
|
|
165
167
|
- https://brainx.chaobrain.com/brainstate/apis/generated/brainstate.nn.ChainedReg.html
|
|
166
168
|
|
|
167
169
|
## Fixed values with `nn.Const`
|
|
@@ -209,6 +211,6 @@ Official sources:
|
|
|
209
211
|
- https://brainx.chaobrain.com/brainstate/tutorials/core/05_parameters_transforms_regularization.html
|
|
210
212
|
- https://brainx.chaobrain.com/brainstate/how_to/constrain_and_regularize_parameters.html
|
|
211
213
|
- https://brainx.chaobrain.com/brainstate/apis/nn/parameters.html
|
|
212
|
-
- https://brainx.chaobrain.com/brainstate/apis/nn/
|
|
214
|
+
- https://brainx.chaobrain.com/brainstate/apis/nn/parameters.html#standard-regularizations
|
|
213
215
|
- https://brainx.chaobrain.com/brainstate/apis/generated/brainstate.nn.Param.html
|
|
214
216
|
- https://brainx.chaobrain.com/brainstate/apis/generated/brainstate.nn.Const.html
|
|
@@ -100,7 +100,7 @@ Official sources:
|
|
|
100
100
|
|
|
101
101
|
Official sources:
|
|
102
102
|
|
|
103
|
-
- https://brainx.chaobrain.com/brainstate/apis/nn/
|
|
103
|
+
- https://brainx.chaobrain.com/brainstate/apis/nn/parameters.html#standard-regularizations
|
|
104
104
|
- https://brainx.chaobrain.com/brainstate/apis/generated/brainstate.nn.Regularization.html
|
|
105
105
|
- https://brainx.chaobrain.com/brainstate/apis/generated/brainstate.nn.ChainedReg.html
|
|
106
106
|
- https://github.com/chaobrain/brainstate/blob/main/brainstate/nn/_regularization.py
|
|
@@ -124,7 +124,7 @@ Official sources:
|
|
|
124
124
|
|
|
125
125
|
Use the generated class page for exact axes, reduction behavior, weights, and initialization arguments; these differ by regularizer and should not be inferred from neighboring classes.
|
|
126
126
|
|
|
127
|
-
Official source: https://brainx.chaobrain.com/brainstate/apis/nn/
|
|
127
|
+
Official source: https://brainx.chaobrain.com/brainstate/apis/nn/parameters.html#standard-regularizations
|
|
128
128
|
|
|
129
129
|
## Prior-distribution regularizer selection
|
|
130
130
|
|
|
@@ -146,7 +146,7 @@ Prior regularizers encode distributional assumptions for Bayesian-inspired param
|
|
|
146
146
|
| Variable selection | `SpikeAndSlabReg` |
|
|
147
147
|
| Probability simplex | `DirichletReg` |
|
|
148
148
|
|
|
149
|
-
Official source: https://brainx.chaobrain.com/brainstate/apis/nn/
|
|
149
|
+
Official source: https://brainx.chaobrain.com/brainstate/apis/nn/parameters.html#prior-distribution-based-regularizations
|
|
150
150
|
|
|
151
151
|
## Interaction safeguards
|
|
152
152
|
|
|
@@ -163,7 +163,7 @@ Official source: https://brainx.chaobrain.com/brainstate/apis/nn/regularization.
|
|
|
163
163
|
## Mirror source urls
|
|
164
164
|
|
|
165
165
|
- https://brainx.chaobrain.com/brainstate/apis/nn/parameters.html
|
|
166
|
-
- https://brainx.chaobrain.com/brainstate/apis/nn/
|
|
166
|
+
- https://brainx.chaobrain.com/brainstate/apis/nn/parameters.html#standard-regularizations
|
|
167
167
|
- https://brainx.chaobrain.com/brainstate/tutorials/core/05_parameters_transforms_regularization.html
|
|
168
168
|
- https://brainx.chaobrain.com/brainstate/how_to/constrain_and_regularize_parameters.html
|
|
169
169
|
- https://github.com/chaobrain/brainstate/blob/main/brainstate/nn/_param.py
|