brainx-skill 1.0.10 → 1.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -0
- package/adapters/antigravity.js +8 -0
- package/installation/lib/installer.js +60 -20
- package/installation/lib/paths.js +41 -3
- package/installation/lib/prompts.js +13 -7
- package/manifest.json +2 -1
- package/package.json +3 -2
- package/skills/braincell/SKILL.md +14 -0
- package/skills/brainevent/SKILL.md +1 -0
- package/skills/brainmass/SKILL.md +1 -1
- package/skills/brainpy-state/SKILL.md +7 -1
- package/skills/brainpy-state/references/array-creation.md +2 -2
- package/skills/brainpy-state/references/brainPy(legacy)/analysis.md +150 -0
- package/skills/brainpy-state/references/brainPy(legacy)/brainpy legacy workflow.md +373 -0
- package/skills/brainpy-state/references/brainPy(legacy)/built-in dynamic neuron model.md +150 -0
- package/skills/brainpy-state/references/brainPy(legacy)/connecting neurons.md +175 -0
- package/skills/brainpy-state/references/brainPy(legacy)/customize neuron and synpase.md +286 -0
- package/skills/brainpy-state/references/brainPy(legacy)/infrastructure/Input generation.md +111 -0
- package/skills/brainpy-state/references/brainPy(legacy)/infrastructure/More about simulation.md +163 -0
- package/skills/brainpy-state/references/brainPy(legacy)/infrastructure/Multi-device array sharding.md +113 -0
- package/skills/brainpy-state/references/brainPy(legacy)/infrastructure/Parallel experiment execution.md +136 -0
- package/skills/brainpy-state/references/brainPy(legacy)/infrastructure/array creation and mechanics.md +222 -0
- package/skills/brainpy-state/references/brainPy(legacy)/infrastructure/brainpy math environment setting.md +123 -0
- package/skills/brainpy-state/references/brainPy(legacy)/infrastructure/delays.md +107 -0
- package/skills/brainpy-state/references/brainPy(legacy)/infrastructure/object oriented transformations and control flows.md +185 -0
- package/skills/brainpy-state/references/brainPy(legacy)/integrators.md +181 -0
- package/skills/brainpy-state/references/brainPy(legacy)/route activity through connectivity.md +102 -0
- package/skills/brainpy-state/references/brainPy(legacy)/synaptic projections.md +147 -0
- package/skills/brainpy-state/references/brainPy(legacy)/synpase properties.md +159 -0
- package/skills/brainpy-state/references/brainPy(legacy)/training/loss library.md +127 -0
- package/skills/brainpy-state/references/brainPy(legacy)/training/optimizers.md +167 -0
- package/skills/brainpy-state/references/brainPy(legacy)/training/parameter initializers.md +107 -0
- package/skills/brainpy-state/references/brainPy(legacy)/training/prebuilt neural network layers.md +186 -0
- package/skills/brainpy-state/references/brainPy(legacy)/training/surrogate gradients.md +104 -0
- package/skills/brainpy-state/references/brainPy(legacy)/training/trainer library.md +89 -0
- package/skills/brainpy-state/references/brainPy(legacy)/training/trainingworkflows.md +253 -0
- package/skills/brainstate/SKILL.md +14 -10
- package/skills/brainstate/references/brainstate/transformation-grad-expansion.md +1 -1
- package/skills/brainstate/references/braintools/optimizer.md +179 -0
- package/skills/braintrace/SKILL.md +161 -0
- package/skills/braintrace/references/Drtrl.md +179 -0
- package/skills/braintrace/references/ETP operators.md +161 -0
- package/skills/braintrace/references/algorithm selection.md +120 -0
- package/skills/braintrace/references/batching.md +150 -0
- package/skills/braintrace/references/compiler_internal.md +162 -0
- package/skills/braintrace/references/custom ETP primitives.md +200 -0
- package/skills/braintrace/references/custom algorithms.md +206 -0
- package/skills/braintrace/references/customizing_primitive_transforms.md +191 -0
- package/skills/braintrace/references/pp_pprop workflow.md +196 -0
- package/skills/braintrace/references/pre-built-braintrace-layer.md +149 -0
- package/skills/brainx-general-guard/SKILL.md +20 -2
- package/skills/brainx-install/SKILL.md +24 -21
- package/skills/brainstate/agents/openai.yaml +0 -4
package/README.md
CHANGED
|
@@ -58,7 +58,13 @@ Codex: ~/.agents/skills/<skill-name> or <cwd>/.agents/skills/<skill-name>
|
|
|
58
58
|
Cursor: ~/.cursor/skills/<skill-name> or <cwd>/.cursor/skills/<skill-name>
|
|
59
59
|
Windsurf: ~/.codeium/windsurf/skills/<skill-name> or <cwd>/.codeium/windsurf/skills/<skill-name>
|
|
60
60
|
Gemini CLI: ~/.gemini/skills/<skill-name> or <cwd>/.gemini/skills/<skill-name>
|
|
61
|
+
Antigravity: ~/.gemini/config/skills/<skill-name> or <cwd>/.agents/skills/<skill-name>
|
|
61
62
|
OpenCode: ~/.config/opencode/skills/<skill-name> or <cwd>/.config/opencode/skills/<skill-name>
|
|
62
63
|
```
|
|
63
64
|
|
|
65
|
+
Antigravity reads global skills from `~/.gemini/config/skills` and workspace skills
|
|
66
|
+
from `<cwd>/.agents/skills`. In project scope that workspace directory is the same one
|
|
67
|
+
Codex uses, so selecting both harnesses installs the skills once and records them for
|
|
68
|
+
both.
|
|
69
|
+
|
|
64
70
|
Installation ownership is recorded in `~/.brainx/receipt.json`.
|
|
@@ -9,13 +9,19 @@ const cursor = require('../../adapters/cursor');
|
|
|
9
9
|
const windsurf = require('../../adapters/windsurf');
|
|
10
10
|
const gemini = require('../../adapters/gemini');
|
|
11
11
|
const opencode = require('../../adapters/opencode');
|
|
12
|
+
const antigravity = require('../../adapters/antigravity');
|
|
12
13
|
const { prepareAdapter, AdapterOperationError } = require('./adapter-transaction');
|
|
13
14
|
const { validateBundle } = require('./bundle');
|
|
14
15
|
const { PACKAGE_NAME, RECEIPT_SCHEMA_VERSION } = require('./constants');
|
|
15
|
-
const {
|
|
16
|
+
const {
|
|
17
|
+
groupAdaptersByDestination,
|
|
18
|
+
resolveDestinationRoot,
|
|
19
|
+
resolveLocations,
|
|
20
|
+
samePath,
|
|
21
|
+
} = require('./paths');
|
|
16
22
|
const { readReceipt, writeReceiptAtomic } = require('./receipt');
|
|
17
23
|
|
|
18
|
-
const DEFAULT_ADAPTERS = [claude, codex, cursor, windsurf, gemini, opencode];
|
|
24
|
+
const DEFAULT_ADAPTERS = [claude, codex, cursor, windsurf, gemini, antigravity, opencode];
|
|
19
25
|
|
|
20
26
|
function writeLine(stream, text = '') {
|
|
21
27
|
stream.write(`${text}\n`);
|
|
@@ -26,7 +32,7 @@ function adapterLabel(adapter) {
|
|
|
26
32
|
}
|
|
27
33
|
|
|
28
34
|
function formatAdapterFailure(error, stderr) {
|
|
29
|
-
writeLine(stderr, `x ${adapterLabel(error.adapter)} installation failed`);
|
|
35
|
+
writeLine(stderr, `x ${error.affectedLabels || adapterLabel(error.adapter)} installation failed`);
|
|
30
36
|
writeLine(stderr, ` Path: ${error.affectedPath}`);
|
|
31
37
|
writeLine(stderr, ` Action not performed: ${error.action}`);
|
|
32
38
|
writeLine(stderr, ` Resolve: ${error.resolution}`);
|
|
@@ -35,6 +41,23 @@ function formatAdapterFailure(error, stderr) {
|
|
|
35
41
|
}
|
|
36
42
|
}
|
|
37
43
|
|
|
44
|
+
// Ownership is a property of the destination directory, not of one harness, so a
|
|
45
|
+
// directory installed for Codex is also BrainX-owned when Antigravity is added later.
|
|
46
|
+
function findPreviousRecord(receipt, group, pathApi) {
|
|
47
|
+
if (!receipt) {
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
const ownRecord = group.adapters
|
|
51
|
+
.map((adapter) => receipt.adapters[adapter.id])
|
|
52
|
+
.find(Boolean);
|
|
53
|
+
if (ownRecord) {
|
|
54
|
+
return ownRecord;
|
|
55
|
+
}
|
|
56
|
+
return Object.values(receipt.adapters).find((record) => (
|
|
57
|
+
record && samePath(record.destination, group.destination, pathApi)
|
|
58
|
+
));
|
|
59
|
+
}
|
|
60
|
+
|
|
38
61
|
function asAdapterError(adapter, destination, error) {
|
|
39
62
|
if (error instanceof AdapterOperationError) {
|
|
40
63
|
return error;
|
|
@@ -125,12 +148,16 @@ async function runInstaller(command, options = {}) {
|
|
|
125
148
|
const committedTransactions = [];
|
|
126
149
|
const failures = [];
|
|
127
150
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
151
|
+
// Harnesses may share one skill directory (Codex and Antigravity both use
|
|
152
|
+
// <cwd>/.agents/skills). Install once per destination and record the same
|
|
153
|
+
// ownership for every harness that resolves there.
|
|
154
|
+
for (const group of groupAdaptersByDestination(adapters, destinations, pathApi)) {
|
|
155
|
+
const { destination } = group;
|
|
156
|
+
const [leadAdapter] = group.adapters;
|
|
157
|
+
const previousRecord = findPreviousRecord(receipt, group, pathApi);
|
|
131
158
|
try {
|
|
132
159
|
const transaction = await prepareAdapter(
|
|
133
|
-
|
|
160
|
+
leadAdapter,
|
|
134
161
|
destination,
|
|
135
162
|
bundle,
|
|
136
163
|
previousRecord,
|
|
@@ -140,26 +167,39 @@ async function runInstaller(command, options = {}) {
|
|
|
140
167
|
uuid: options.uuid,
|
|
141
168
|
timestamp,
|
|
142
169
|
copySkill: options.copySkill,
|
|
143
|
-
homeDir: resolveDestinationRoot(destination,
|
|
170
|
+
homeDir: resolveDestinationRoot(destination, leadAdapter, pathApi),
|
|
144
171
|
},
|
|
145
172
|
);
|
|
146
|
-
if (transaction.status
|
|
147
|
-
|
|
148
|
-
|
|
173
|
+
if (transaction.status !== 'current') {
|
|
174
|
+
await transaction.commit();
|
|
175
|
+
committedTransactions.push(transaction);
|
|
176
|
+
}
|
|
177
|
+
const status = transaction.status === 'current' ? 'current' : 'installed';
|
|
178
|
+
for (const adapter of group.adapters) {
|
|
179
|
+
results.push({
|
|
180
|
+
status,
|
|
181
|
+
adapter,
|
|
182
|
+
destination,
|
|
183
|
+
record: { ...transaction.record, label: adapter.label },
|
|
184
|
+
});
|
|
149
185
|
}
|
|
150
|
-
await transaction.commit();
|
|
151
|
-
committedTransactions.push(transaction);
|
|
152
|
-
results.push({ ...transaction, status: 'installed' });
|
|
153
186
|
} catch (error) {
|
|
154
|
-
|
|
187
|
+
const failure = asAdapterError(leadAdapter, destination, error);
|
|
188
|
+
failure.affectedLabels = group.adapters.map(adapterLabel).join(', ');
|
|
189
|
+
failures.push(failure);
|
|
155
190
|
}
|
|
156
191
|
}
|
|
157
192
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
193
|
+
const nextAdapters = receipt ? { ...receipt.adapters } : {};
|
|
194
|
+
for (const result of results) {
|
|
195
|
+
nextAdapters[result.adapter.id] = result.record;
|
|
196
|
+
}
|
|
197
|
+
const receiptChanged = results.length > 0
|
|
198
|
+
&& (committedTransactions.length > 0
|
|
199
|
+
|| !receipt
|
|
200
|
+
|| JSON.stringify(receipt.adapters) !== JSON.stringify(nextAdapters));
|
|
201
|
+
|
|
202
|
+
if (receiptChanged) {
|
|
163
203
|
const nextReceipt = {
|
|
164
204
|
schemaVersion: RECEIPT_SCHEMA_VERSION,
|
|
165
205
|
packageName: PACKAGE_NAME,
|
|
@@ -2,6 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
const path = require('node:path');
|
|
4
4
|
|
|
5
|
+
function adapterSkillPath(adapter, scope = 'global') {
|
|
6
|
+
if (scope === 'project' && adapter.projectPath) {
|
|
7
|
+
return adapter.projectPath;
|
|
8
|
+
}
|
|
9
|
+
return adapter.homePath;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function adapterSkillPaths(adapter) {
|
|
13
|
+
return adapter.projectPath ? [adapter.homePath, adapter.projectPath] : [adapter.homePath];
|
|
14
|
+
}
|
|
15
|
+
|
|
5
16
|
function resolveLocations(homeDir, adapters, pathApi = path, options = {}) {
|
|
6
17
|
if (typeof homeDir !== 'string' || !pathApi.isAbsolute(homeDir)) {
|
|
7
18
|
throw new Error(`Home directory must be an absolute path: ${homeDir}`);
|
|
@@ -18,7 +29,7 @@ function resolveLocations(homeDir, adapters, pathApi = path, options = {}) {
|
|
|
18
29
|
|
|
19
30
|
const destinations = {};
|
|
20
31
|
for (const adapter of adapters) {
|
|
21
|
-
destinations[adapter.id] = pathApi.resolve(baseDir, ...adapter
|
|
32
|
+
destinations[adapter.id] = pathApi.resolve(baseDir, ...adapterSkillPath(adapter, scope));
|
|
22
33
|
}
|
|
23
34
|
|
|
24
35
|
return {
|
|
@@ -30,9 +41,9 @@ function resolveLocations(homeDir, adapters, pathApi = path, options = {}) {
|
|
|
30
41
|
};
|
|
31
42
|
}
|
|
32
43
|
|
|
33
|
-
function
|
|
44
|
+
function stripSkillPath(destination, skillPath, pathApi) {
|
|
34
45
|
let current = pathApi.resolve(destination);
|
|
35
|
-
for (const part of [...
|
|
46
|
+
for (const part of [...skillPath].reverse()) {
|
|
36
47
|
const name = pathApi.basename(current);
|
|
37
48
|
const matches = pathApi === path.win32
|
|
38
49
|
? name.toLowerCase() === part.toLowerCase()
|
|
@@ -45,6 +56,16 @@ function resolveDestinationRoot(destination, adapter, pathApi = path) {
|
|
|
45
56
|
return current;
|
|
46
57
|
}
|
|
47
58
|
|
|
59
|
+
function resolveDestinationRoot(destination, adapter, pathApi = path) {
|
|
60
|
+
for (const skillPath of adapterSkillPaths(adapter)) {
|
|
61
|
+
const root = stripSkillPath(destination, skillPath, pathApi);
|
|
62
|
+
if (root) {
|
|
63
|
+
return root;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
|
|
48
69
|
function samePath(left, right, pathApi = path) {
|
|
49
70
|
const normalizedLeft = pathApi.normalize(pathApi.resolve(left));
|
|
50
71
|
const normalizedRight = pathApi.normalize(pathApi.resolve(right));
|
|
@@ -54,7 +75,24 @@ function samePath(left, right, pathApi = path) {
|
|
|
54
75
|
return normalizedLeft === normalizedRight;
|
|
55
76
|
}
|
|
56
77
|
|
|
78
|
+
function groupAdaptersByDestination(adapters, destinations, pathApi = path) {
|
|
79
|
+
const groups = [];
|
|
80
|
+
for (const adapter of adapters) {
|
|
81
|
+
const destination = destinations[adapter.id];
|
|
82
|
+
const existing = groups.find((group) => samePath(group.destination, destination, pathApi));
|
|
83
|
+
if (existing) {
|
|
84
|
+
existing.adapters.push(adapter);
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
groups.push({ destination, adapters: [adapter] });
|
|
88
|
+
}
|
|
89
|
+
return groups;
|
|
90
|
+
}
|
|
91
|
+
|
|
57
92
|
module.exports = {
|
|
93
|
+
adapterSkillPath,
|
|
94
|
+
adapterSkillPaths,
|
|
95
|
+
groupAdaptersByDestination,
|
|
58
96
|
resolveDestinationRoot,
|
|
59
97
|
resolveLocations,
|
|
60
98
|
samePath,
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const fs = require('node:fs/promises');
|
|
4
4
|
const path = require('node:path');
|
|
5
|
+
const { adapterSkillPath, adapterSkillPaths } = require('./paths');
|
|
5
6
|
|
|
6
7
|
class NonInteractiveInstallError extends Error {
|
|
7
8
|
constructor() {
|
|
@@ -21,8 +22,13 @@ function harnessLabel(adapter) {
|
|
|
21
22
|
return adapter.promptLabel || adapter.label;
|
|
22
23
|
}
|
|
23
24
|
|
|
24
|
-
function harnessRoot(adapter) {
|
|
25
|
-
return adapter.
|
|
25
|
+
function harnessRoot(adapter, scope) {
|
|
26
|
+
return adapterSkillPath(adapter, scope).slice(0, -1);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function harnessHint(adapter) {
|
|
30
|
+
const variants = adapterSkillPaths(adapter).map((skillPath) => skillPath.join('/'));
|
|
31
|
+
return `(${[...new Set(variants)].join(' or ')})`;
|
|
26
32
|
}
|
|
27
33
|
|
|
28
34
|
async function isDirectory(directory, fsApi) {
|
|
@@ -47,9 +53,9 @@ async function detectHarnesses(options) {
|
|
|
47
53
|
continue;
|
|
48
54
|
}
|
|
49
55
|
seen.add(adapter.id);
|
|
50
|
-
const
|
|
51
|
-
const globalRoot = pathApi.resolve(options.homeDir, ...
|
|
52
|
-
const projectRoot = pathApi.resolve(options.cwd, ...
|
|
56
|
+
const globalPath = harnessRoot(adapter, 'global');
|
|
57
|
+
const globalRoot = pathApi.resolve(options.homeDir, ...globalPath);
|
|
58
|
+
const projectRoot = pathApi.resolve(options.cwd, ...harnessRoot(adapter, 'project'));
|
|
53
59
|
const globalDetected = await isDirectory(globalRoot, fsApi);
|
|
54
60
|
const projectDetected = globalRoot === projectRoot
|
|
55
61
|
? globalDetected
|
|
@@ -59,7 +65,7 @@ async function detectHarnesses(options) {
|
|
|
59
65
|
detected.push({
|
|
60
66
|
id: adapter.id,
|
|
61
67
|
label: harnessLabel(adapter),
|
|
62
|
-
displayPath: globalDetected ? `~/${
|
|
68
|
+
displayPath: globalDetected ? `~/${globalPath.join('/')}` : projectRoot,
|
|
63
69
|
});
|
|
64
70
|
}
|
|
65
71
|
}
|
|
@@ -172,7 +178,7 @@ async function promptForInstall(options) {
|
|
|
172
178
|
choices: options.adapters.map((adapter) => ({
|
|
173
179
|
name: adapter.id,
|
|
174
180
|
message: harnessLabel(adapter),
|
|
175
|
-
hint:
|
|
181
|
+
hint: harnessHint(adapter),
|
|
176
182
|
})),
|
|
177
183
|
validate(value) {
|
|
178
184
|
return value.length > 0 || 'Select at least one harness.';
|
package/manifest.json
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "brainx-skill",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "Portable BrainX Agent Skills for Claude Code, Codex, Cursor, Windsurf, Gemini CLI, and OpenCode",
|
|
3
|
+
"version": "1.0.11",
|
|
4
|
+
"description": "Portable BrainX Agent Skills for Claude Code, Codex, Cursor, Windsurf, Gemini CLI, Antigravity, and OpenCode",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "commonjs",
|
|
7
7
|
"scripts": {
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
"skills/brainstate/",
|
|
22
22
|
"skills/brainevent/",
|
|
23
23
|
"skills/brainpy-state/",
|
|
24
|
+
"skills/braintrace/",
|
|
24
25
|
"skills/brainx-general-guard/",
|
|
25
26
|
"manifest.json",
|
|
26
27
|
"README.md",
|
|
@@ -180,3 +180,17 @@ Open only the smallest reference that owns the non-canonical decision.
|
|
|
180
180
|
| `references/mixions-for-adaptation.md` | Adding calcium-dependent adaptation, AHP/KCa currents, rebound, dynamic calcium, or multi-ion channel dependencies. |
|
|
181
181
|
| `references/multicompartment/multicompartment-cell-workflow.md` | Extending the canonical `Morphology -> Cell -> paint/place -> run` path and selecting the exclusive multicompartment references. |
|
|
182
182
|
| `references/solver-library-with-effects.md` | Comparing registered integrators, stability, accuracy, and solver-dependent trace effects. |
|
|
183
|
+
|
|
184
|
+
## Application script examples
|
|
185
|
+
|
|
186
|
+
Open one script only when its pattern matches the task; each is a complete, runnable program mirrored from the official BrainCell examples.
|
|
187
|
+
|
|
188
|
+
| Script | Open when |
|
|
189
|
+
|---|---|
|
|
190
|
+
| `references/scripts/hh_neuron_basics.py` | Building one end-to-end `SingleCompartment` current-clamp simulation with Na/K/leak currents; this is the default full-script reference. |
|
|
191
|
+
| `references/scripts/fi_curve.py` | Producing FI curves, current sweeps, spike counts, or firing rates, where `size=N` means N independent point neurons. |
|
|
192
|
+
| `references/scripts/channel_ablation.py` | Comparing intact against ablated dynamics by setting a conductance such as `g_max` to zero while preserving the ion and channel structure. |
|
|
193
|
+
| `references/scripts/calcium_channel_gating.py` | Inspecting voltage-dependent activation or inactivation curves through direct channel methods rather than simulating a membrane trace. |
|
|
194
|
+
| `references/scripts/spike_frequency_adaptation.py` | Adding spike-frequency adaptation or calcium-dependent afterhyperpolarization with dynamic calcium and `MixIons`. |
|
|
195
|
+
| `references/scripts/t_current_rebound.py` | Producing post-inhibitory rebound bursting from a hyperpolarizing step with T-type calcium and HCN currents. |
|
|
196
|
+
| `references/scripts/thalamic_neurons.py` | Comparing several thalamic point-neuron phenotypes built from different ion and channel compositions in one script. |
|
|
@@ -261,6 +261,7 @@ Verify `postsynaptic_input.shape == connectivity.shape[1:]` for vector input and
|
|
|
261
261
|
| `references/custom-operators-gpu.md` | Open when a custom operation targets GPU; it contains Numba CUDA, Warp, raw CUDA, GPU and multi-backend registration, stream and ABI rules, compiler controls, caching, diagnostics, and verification workflows. |
|
|
262
262
|
|
|
263
263
|
## Application script examples
|
|
264
|
+
|
|
264
265
|
| Reference | Open when |
|
|
265
266
|
|---|---|
|
|
266
267
|
| `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. |
|
|
@@ -69,7 +69,7 @@ assert result["ts"].shape == (1800,)
|
|
|
69
69
|
|
|
70
70
|
Open `references/modellibrary.md` when choosing among model families, distinguishing similarly named Wong-Wang variants, comparing state cost, or locating a model's observable. Open `references/datasets-api.md` when the workflow needs bundled or registered input data.
|
|
71
71
|
|
|
72
|
-
##
|
|
72
|
+
## Noise and stochastic run
|
|
73
73
|
|
|
74
74
|
Noise belongs to the model, while `batch_size` asks `Simulator` to initialize and run independent State realizations in one time-major result.
|
|
75
75
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: brainpy-state
|
|
3
|
-
description: Use for point-neuron modeling, from individual neurons to spiking networks with synapses and projections. Use alone for point-neuron studies or together with BrainCell and/or BrainMass when point-neuron dynamics participate in a multiscale model.
|
|
3
|
+
description: Use for point-neuron modeling, from individual neurons to spiking networks with synapses and projections. Use alone for point-neuron studies or together with BrainCell and/or BrainMass when point-neuron dynamics participate in a multiscale model. Use as the legacy BrainPy routing entry only when an existing codebase uses legacy `brainpy`, uses neither units nor BrainTrace, and the user explicitly asks to preserve it.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# BrainPy-State
|
|
@@ -11,6 +11,10 @@ Use this skill for the native `brainpy.state` modeling path: compose point neuro
|
|
|
11
11
|
|
|
12
12
|
Route NEST-compatible work to `references/nest-compatible/nest-workflow.md`, and online-learning execution to BrainTrace.
|
|
13
13
|
|
|
14
|
+
Open `references/brainPy(legacy)/brainpy legacy workflow.md` only when the workspace already contains legacy `brainpy` code, contains no BrainUnit quantities, unit-aware APIs, and when the user explicitly asks to preserve old BrainPy. Use native BrainPy-State for new project is HIGHLY RECOMMENDED; use BrainPy-State with BrainCell for all cellular modeling.
|
|
15
|
+
|
|
16
|
+
Treat that workflow as the only first-level legacy reference. Do not open or route directly to any other Markdown under `references/brainPy(legacy)/`; let the workflow select those second-level references.
|
|
17
|
+
|
|
14
18
|
## Underlying principle of BrainPy-State
|
|
15
19
|
|
|
16
20
|
BrainPy-State composes unit-aware, stateful neuron and synapse `Dynamics` into projections that separate `comm`, `syn`, `out`, and `post`; BrainState transforms run the same Module graph for simulation or surrogate-gradient training.
|
|
@@ -217,11 +221,13 @@ Open only the smallest reference that owns the decision.
|
|
|
217
221
|
| `references/component-selection.md` | Choosing a neuron, synapse, synaptic output, plasticity model, input generator, or readout from the documented native API families |
|
|
218
222
|
| `references/projection-patterns.md` | Choosing projection alignment or API form, adding delays or short-term plasticity, using direct/delta projections, or adding gap junctions |
|
|
219
223
|
| `references/nest-compatible/nest-workflow.md` | Using NEST/PyNEST model names, `Simulator`, devices, connection rules, spatial networks, parity, porting, or the bundled NEST-compatible full scripts |
|
|
224
|
+
| `references/brainPy(legacy)/brainpy legacy workflow.md` | Use as the only first-level legacy entry when existing legacy `brainpy` has no BrainUnit, unit-aware, or BrainTrace code and the user explicitly requests it; this workflow routes all second-level legacy references |
|
|
220
225
|
| `skills/brainevent/SKILL.md` | Selecting sparse event representations, connectivity formats, event operators, plasticity kernels, or custom kernels |
|
|
221
226
|
| `skills/brainevent/references/scripts/coba_ei_teaching.py` | Learning how to incorporate efficient BrainEvent communication into a complete BrainPy COBA E/I network while preserving BrainPy dynamics and BrainState execution |
|
|
222
227
|
|
|
223
228
|
|
|
224
229
|
## Application script examples
|
|
230
|
+
|
|
225
231
|
| Reference | Open when |
|
|
226
232
|
|---|---|
|
|
227
233
|
| `references/scripts/103_COBA_2005.py` | Needing a complete canonical E/I COBA network built from native BrainPy-State projections |
|
|
@@ -143,9 +143,9 @@ import jax.numpy as jnp
|
|
|
143
143
|
|
|
144
144
|
## Routing
|
|
145
145
|
|
|
146
|
-
`array_split()` appears on the tutorial page, but it is a structural operation; route it to `array-mechanics.md`.
|
|
146
|
+
`array_split()` appears on the tutorial page, but it is a structural operation; route it to `skills/brainunit/references/array-mechanics.md`.
|
|
147
147
|
|
|
148
|
-
Backend extraction and `as_numpy()` belong in `array-mechanics.md` because they cross an existing array boundary rather than create a scientific quantity from source values.
|
|
148
|
+
Backend extraction and `as_numpy()` belong in `skills/brainunit/references/array-mechanics.md` because they cross an existing array boundary rather than create a scientific quantity from source values.
|
|
149
149
|
|
|
150
150
|
## Cross-family gotchas
|
|
151
151
|
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
# Legacy BrainPy analysis
|
|
2
|
+
|
|
3
|
+
Use this reference when a legacy BrainPy 2.x model needs low-dimensional phase-plane or bifurcation analysis, fast-slow analysis, or numerical fixed-point discovery in a high-dimensional state space. Keep model construction and simulation in `brainpy legacy workflow.md`.
|
|
4
|
+
|
|
5
|
+
## Choose the analyzer
|
|
6
|
+
|
|
7
|
+
Low-dimensional analyzers work from named model variables and parameters. `SlowPointFinder` instead optimizes candidate states and is the normal choice once plotting the full state space is no longer meaningful.
|
|
8
|
+
|
|
9
|
+
| API | Use when |
|
|
10
|
+
|---|---|
|
|
11
|
+
| `bp.analysis.PhasePlane1D(model, target_vars, ...)` | Inspect the vector field and fixed points of one state variable. |
|
|
12
|
+
| `bp.analysis.PhasePlane2D(model, target_vars, ...)` | Inspect nullclines, vector fields, fixed points, and trajectories of two state variables. |
|
|
13
|
+
| `bp.analysis.Bifurcation1D(model, target_pars, target_vars, ...)` | Continue equilibria of a one-variable system while sweeping one or two parameters. |
|
|
14
|
+
| `bp.analysis.Bifurcation2D(model, target_pars, target_vars, ...)` | Continue equilibria of a two-variable system and classify local stability while parameters change. |
|
|
15
|
+
| `bp.analysis.FastSlow1D(model, fast_vars, slow_vars, ...)` | Treat one variable as fast and one or more variables as slowly varying bifurcation parameters. |
|
|
16
|
+
| `bp.analysis.FastSlow2D(model, fast_vars, slow_vars, ...)` | Analyze a two-variable fast subsystem across one or more slow variables. |
|
|
17
|
+
| `bp.analysis.SlowPointFinder(f_cell, ...)` | Find fixed or slow points in a high-dimensional callable or `DynamicalSystem` from supplied candidate states. |
|
|
18
|
+
|
|
19
|
+
Enable 64-bit computation before constructing an analyzer when numerical root finding or stability classification is sensitive to precision:
|
|
20
|
+
|
|
21
|
+
```python
|
|
22
|
+
import brainpy as bp
|
|
23
|
+
import brainpy.math as bm
|
|
24
|
+
|
|
25
|
+
bm.enable_x64()
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Define variables, parameters, and resolution
|
|
29
|
+
|
|
30
|
+
The analyzer separates coordinates being solved, parameters being swept, and values held fixed; preserve that distinction so the resulting diagram represents the intended system.
|
|
31
|
+
|
|
32
|
+
| Argument | Description |
|
|
33
|
+
|---|---|
|
|
34
|
+
| `target_vars={'name': [low, high]}` | Give each analyzed state variable and its search interval. Names must match model or integrator arguments. |
|
|
35
|
+
| `target_pars={'name': [low, high]}` | Give each parameter to sweep in a bifurcation analysis. |
|
|
36
|
+
| `pars_update={'name': value}` | Hold model parameters or external inputs at fixed values during analysis. |
|
|
37
|
+
| `fixed_vars={'name': value}` | Hold non-target state variables fixed when reducing a larger system. |
|
|
38
|
+
| `resolutions=step` | Use one grid step for all target dimensions. |
|
|
39
|
+
| `resolutions={'name': step}` | Control grid density per variable or parameter; refine only regions that need it. |
|
|
40
|
+
|
|
41
|
+
Do not place a swept value in `pars_update`; a value is either varied through `target_pars` or fixed through `pars_update` for one analysis.
|
|
42
|
+
|
|
43
|
+
## Analyze a two-variable phase plane
|
|
44
|
+
|
|
45
|
+
Use `PhasePlane2D` when the decision depends on nullcline intersections, flow direction, stability, or trajectories in a two-state system.
|
|
46
|
+
|
|
47
|
+
| API | Description |
|
|
48
|
+
|---|---|
|
|
49
|
+
| `plot_nullcline(...)` | Compute and optionally plot the two zero-derivative curves. |
|
|
50
|
+
| `plot_vector_field(plot_method='streamplot', ...)` | Plot the local flow; use `plot_method='quiver'` for arrows instead of streamlines. |
|
|
51
|
+
| `plot_fixed_point(...)` | Find and classify fixed points from the analysis grid. |
|
|
52
|
+
| `plot_trajectory(initials, duration, ...)` | Integrate trajectories from explicit initial states on the phase plane. |
|
|
53
|
+
| `show_figure()` | Display accumulated analysis plots when individual plot calls use `show=False`. |
|
|
54
|
+
|
|
55
|
+
```python
|
|
56
|
+
import brainpy as bp
|
|
57
|
+
import brainpy.math as bm
|
|
58
|
+
|
|
59
|
+
bm.enable_x64()
|
|
60
|
+
|
|
61
|
+
model = bp.neurons.FHN(1)
|
|
62
|
+
plane = bp.analysis.PhasePlane2D(
|
|
63
|
+
model=model,
|
|
64
|
+
target_vars={'V': [-3.0, 3.0], 'w': [-3.0, 3.0]},
|
|
65
|
+
pars_update={'I_ext': 0.8},
|
|
66
|
+
resolutions={'V': 0.01, 'w': 0.01},
|
|
67
|
+
)
|
|
68
|
+
plane.plot_nullcline(x_style={'fmt': '-'}, y_style={'fmt': '-'})
|
|
69
|
+
plane.plot_vector_field()
|
|
70
|
+
plane.plot_fixed_point()
|
|
71
|
+
plane.plot_trajectory(
|
|
72
|
+
initials={'V': [-2.0], 'w': [0.0]},
|
|
73
|
+
duration=100.0,
|
|
74
|
+
show=True,
|
|
75
|
+
)
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
**Invariant:** `target_vars` keys must identify the variables whose derivatives define the phase plane. A visually plausible plot with the wrong variable or parameter names analyzes a different system.
|
|
79
|
+
|
|
80
|
+
## Continue equilibria across parameters
|
|
81
|
+
|
|
82
|
+
Use a bifurcation analyzer when the question is how equilibria or their stability change as a parameter varies.
|
|
83
|
+
|
|
84
|
+
```python
|
|
85
|
+
import brainpy as bp
|
|
86
|
+
import brainpy.math as bm
|
|
87
|
+
|
|
88
|
+
bm.enable_x64()
|
|
89
|
+
|
|
90
|
+
model = bp.dyn.ExpIF(1, delta_T=1.0)
|
|
91
|
+
bifurcation = bp.analysis.Bifurcation1D(
|
|
92
|
+
model=model,
|
|
93
|
+
target_vars={'V': [-70.0, -55.0]},
|
|
94
|
+
target_pars={'I': [0.0, 6.0]},
|
|
95
|
+
resolutions={'I': 0.01},
|
|
96
|
+
)
|
|
97
|
+
bifurcation.plot_bifurcation(show=True)
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Use a dictionary of per-parameter resolutions when a narrow transition region needs a finer grid. Use `num_rank` on two-dimensional bifurcation plots to increase the number of initial candidates only after verifying the variable and parameter ranges.
|
|
101
|
+
|
|
102
|
+
## Find high-dimensional fixed or slow points
|
|
103
|
+
|
|
104
|
+
`SlowPointFinder` minimizes state change rather than drawing a state-space grid; candidate coverage therefore determines which fixed points can be found.
|
|
105
|
+
|
|
106
|
+
| API | Description |
|
|
107
|
+
|---|---|
|
|
108
|
+
| `SlowPointFinder(f_cell, f_type=..., target_vars=..., inputs=...)` | Bind a callable or model, optionally restrict the optimized variables, and hold explicit model inputs fixed. |
|
|
109
|
+
| `find_fps_with_gd_method(candidates, tolerance=..., num_batch=..., num_opt=...)` | Optimize batches of candidate states with gradient descent. |
|
|
110
|
+
| `find_fps_with_opt_solver(candidates, opt_solver='BFGS')` | Use a named optimization solver instead of the gradient-descent path. |
|
|
111
|
+
| `filter_loss(tolerance)` | Remove candidates whose fixed-point loss remains above the threshold. |
|
|
112
|
+
| `keep_unique(tolerance)` | Remove fixed points closer than the uniqueness tolerance. |
|
|
113
|
+
| `compute_jacobians(points, plot=False, ...)` | Linearize the dynamics at retained points and return their Jacobians. |
|
|
114
|
+
|
|
115
|
+
```python
|
|
116
|
+
# Given a constructed legacy BrainPy model with Variables V and w:
|
|
117
|
+
finder = bp.analysis.SlowPointFinder(
|
|
118
|
+
f_cell=model,
|
|
119
|
+
target_vars={'V': model.V, 'w': model.w},
|
|
120
|
+
inputs=[model.Iext, fixed_input],
|
|
121
|
+
)
|
|
122
|
+
finder.find_fps_with_gd_method(
|
|
123
|
+
candidates={
|
|
124
|
+
'V': bm.random.normal(0.0, 2.0, (1000, model.num)),
|
|
125
|
+
'w': bm.random.normal(0.0, 1.0, (1000, model.num)),
|
|
126
|
+
},
|
|
127
|
+
tolerance=1e-5,
|
|
128
|
+
num_batch=200,
|
|
129
|
+
)
|
|
130
|
+
finder.filter_loss(1e-5)
|
|
131
|
+
finder.keep_unique(1e-3)
|
|
132
|
+
jacobians = finder.compute_jacobians(finder.fixed_points)
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
Treat the last example as a composition pattern: `model`, `model.Iext`, and `fixed_input` must come from the actual model. Sample candidates around states reached in simulation when random candidates do not cover the relevant attractor basin.
|
|
136
|
+
|
|
137
|
+
## Common failures
|
|
138
|
+
|
|
139
|
+
- Enable x64 before creating analyzers, not after an analysis has already been traced.
|
|
140
|
+
- Do not infer exhaustive fixed-point coverage from one candidate distribution.
|
|
141
|
+
- Filter by loss before interpreting or deduplicating optimized points.
|
|
142
|
+
- Use `f_type='continuous'` when a raw callable returns continuous-time derivatives; verify the callable convention before optimization.
|
|
143
|
+
- Compare analysis predictions with a `DSRunner` trajectory before treating a fixed point or bifurcation branch as scientifically meaningful.
|
|
144
|
+
|
|
145
|
+
## Sources mirrored
|
|
146
|
+
|
|
147
|
+
- https://brainpy.readthedocs.io/apis/analysis.html
|
|
148
|
+
- https://brainpy.readthedocs.io/tutorial_analysis/lowdim_analysis.html
|
|
149
|
+
- https://brainpy.readthedocs.io/tutorial_analysis/highdim_analysis.html
|
|
150
|
+
- https://brainpy.readthedocs.io/tutorial_analysis/decision_making_model.html
|