brainx-skill 1.0.10 → 1.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -0
- package/adapters/antigravity.js +8 -0
- package/installation/lib/installer.js +60 -20
- package/installation/lib/paths.js +41 -3
- package/installation/lib/prompts.js +13 -7
- package/manifest.json +2 -1
- package/package.json +3 -2
- package/skills/braincell/SKILL.md +1 -1
- package/skills/braincell/references/mixions-for-adaptation.md +26 -3
- package/skills/braincell/references/scripts/spike_frequency_adaptation.py +113 -53
- package/skills/brainevent/references/synaptic-plasticity.md +74 -230
- package/skills/brainmass/SKILL.md +11 -6
- package/skills/brainmass/references/batch-transform-acceleration.md +44 -3
- package/skills/brainmass/references/modellibrary.md +11 -0
- package/skills/brainmass/references/simulator-input-monitor-api.md +98 -0
- package/skills/brainpy-state/SKILL.md +20 -6
- package/skills/brainpy-state/references/brain-dynamics-delay-protocol.md +52 -1
- package/skills/brainpy-state/references/brainPy(legacy)/analysis.md +150 -0
- package/skills/brainpy-state/references/brainPy(legacy)/brainpy legacy workflow.md +373 -0
- package/skills/brainpy-state/references/brainPy(legacy)/built-in dynamic neuron model.md +150 -0
- package/skills/brainpy-state/references/brainPy(legacy)/connecting neurons.md +175 -0
- package/skills/brainpy-state/references/brainPy(legacy)/customize neuron and synpase.md +286 -0
- package/skills/brainpy-state/references/brainPy(legacy)/infrastructure/Input generation.md +111 -0
- package/skills/brainpy-state/references/brainPy(legacy)/infrastructure/More about simulation.md +163 -0
- package/skills/brainpy-state/references/brainPy(legacy)/infrastructure/Multi-device array sharding.md +113 -0
- package/skills/brainpy-state/references/brainPy(legacy)/infrastructure/Parallel experiment execution.md +136 -0
- package/skills/brainpy-state/references/brainPy(legacy)/infrastructure/array creation and mechanics.md +222 -0
- package/skills/brainpy-state/references/brainPy(legacy)/infrastructure/brainpy math environment setting.md +123 -0
- package/skills/brainpy-state/references/brainPy(legacy)/infrastructure/delays.md +107 -0
- package/skills/brainpy-state/references/brainPy(legacy)/infrastructure/object oriented transformations and control flows.md +185 -0
- package/skills/brainpy-state/references/brainPy(legacy)/integrators.md +181 -0
- package/skills/brainpy-state/references/brainPy(legacy)/route activity through connectivity.md +102 -0
- package/skills/brainpy-state/references/brainPy(legacy)/synaptic projections.md +147 -0
- package/skills/brainpy-state/references/brainPy(legacy)/synpase properties.md +159 -0
- package/skills/brainpy-state/references/brainPy(legacy)/training/loss library.md +127 -0
- package/skills/brainpy-state/references/brainPy(legacy)/training/optimizers.md +167 -0
- package/skills/brainpy-state/references/brainPy(legacy)/training/parameter initializers.md +107 -0
- package/skills/brainpy-state/references/brainPy(legacy)/training/prebuilt neural network layers.md +186 -0
- package/skills/brainpy-state/references/brainPy(legacy)/training/surrogate gradients.md +104 -0
- package/skills/brainpy-state/references/brainPy(legacy)/training/trainer library.md +89 -0
- package/skills/brainpy-state/references/brainPy(legacy)/training/trainingworkflows.md +253 -0
- package/skills/brainpy-state/references/braintools/connectivity.md +206 -0
- package/skills/brainpy-state/references/braintools/input-current.md +199 -0
- package/skills/brainpy-state/references/component-selection.md +20 -5
- package/skills/brainpy-state/references/projection-patterns.md +2 -0
- package/skills/brainpy-state/references/scripts/sound_localization.py +240 -0
- package/skills/brainstate/SKILL.md +1 -1
- package/skills/brainstate/references/brainstate/brainstate-control-flow-patterns.md +8 -0
- package/skills/brainstate/references/brainstate/transformation-vmap-expansion.md +57 -7
- package/skills/brainstate/references/collective_model_operations.md +26 -27
- package/skills/braintrace/SKILL.md +161 -0
- package/skills/braintrace/references/Drtrl.md +179 -0
- package/skills/braintrace/references/ETP operators.md +161 -0
- package/skills/braintrace/references/algorithm selection.md +120 -0
- package/skills/braintrace/references/batching.md +150 -0
- package/skills/braintrace/references/compiler_internal.md +162 -0
- package/skills/braintrace/references/custom ETP primitives.md +200 -0
- package/skills/braintrace/references/custom algorithms.md +206 -0
- package/skills/braintrace/references/customizing_primitive_transforms.md +191 -0
- package/skills/braintrace/references/pp_pprop workflow.md +196 -0
- package/skills/braintrace/references/pre-built-braintrace-layer.md +149 -0
- package/skills/brainx-general-guard/SKILL.md +64 -21
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.12",
|
|
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",
|
|
@@ -100,7 +100,7 @@ assert voltages.shape[:1] == times.shape
|
|
|
100
100
|
assert spikes.shape[:1] == times.shape
|
|
101
101
|
```
|
|
102
102
|
|
|
103
|
-
Treat `V_th` only as the spike-event threshold; it does not change the membrane equation. Keep membrane capacitance and channel conductance density-based in the canonical path. `update()` accepts current density or total current and uses `SingleCompartment.area` to normalize total input; do not manually area-scale only part of the model. Use `size=N` for `N` independent cells, never for `N` compartments.
|
|
103
|
+
Treat `V_th` only as the spike-event threshold; it does not change the membrane equation. Keep membrane capacitance and channel conductance density-based in the canonical path. `update()` accepts current density or total current and uses `SingleCompartment.area` to normalize total input; do not manually area-scale only part of the model. Use `size=N` for `N` independent cells, never for `N` compartments. For a multidimensional condition sweep, use the condition-grid shape as `size` and pass shape-aligned channel parameters and inputs; do not wrap identity functions in `vmap` merely to construct that grid.
|
|
104
104
|
|
|
105
105
|
Open `references/area-scaled-hh-pattern.md` when changing cell geometry or explicitly converting density parameters to total quantities. Open `references/ion-library.md`, `references/channel-library.md`, or `references/mixions-for-adaptation.md` only when the classical fixed-ion HH path is insufficient.
|
|
106
106
|
|
|
@@ -17,7 +17,12 @@ import brainunit as u
|
|
|
17
17
|
|
|
18
18
|
|
|
19
19
|
class AdaptingCell(braincell.SingleCompartment):
|
|
20
|
-
def __init__(
|
|
20
|
+
def __init__(
|
|
21
|
+
self,
|
|
22
|
+
size,
|
|
23
|
+
g_ahp=0.3 * u.mS / u.cm**2,
|
|
24
|
+
solver="ind_exp_euler",
|
|
25
|
+
):
|
|
21
26
|
super().__init__(
|
|
22
27
|
size,
|
|
23
28
|
V_initializer=braintools.init.Constant(-65. * u.mV),
|
|
@@ -51,7 +56,7 @@ class AdaptingCell(braincell.SingleCompartment):
|
|
|
51
56
|
self.ca.add(ICaHT=braincell.channel.CaHT_HM1992(size, g_max=3.0 * (u.mS / u.cm ** 2)))
|
|
52
57
|
|
|
53
58
|
self.kca = braincell.MixIons(self.k, self.ca)
|
|
54
|
-
self.kca.add(IAHP=braincell.channel.AHP_De1994(size, g_max=
|
|
59
|
+
self.kca.add(IAHP=braincell.channel.AHP_De1994(size, g_max=g_ahp))
|
|
55
60
|
|
|
56
61
|
self.IL = braincell.channel.IL(
|
|
57
62
|
size,
|
|
@@ -60,7 +65,25 @@ class AdaptingCell(braincell.SingleCompartment):
|
|
|
60
65
|
)
|
|
61
66
|
```
|
|
62
67
|
|
|
63
|
-
##
|
|
68
|
+
## Test adaptation by controlled ablation
|
|
69
|
+
|
|
70
|
+
Expose only AHP `g_max`, set it to zero for the ablated condition, and keep the cell template, initialization, solver, stimulus, and every other conductance identical. Use `SingleCompartment.size` for independent conditions; it already owns the batch axis.
|
|
71
|
+
|
|
72
|
+
```python
|
|
73
|
+
g_ahp = u.math.asarray([0.0, 0.3]) * u.mS / u.cm**2
|
|
74
|
+
cell = AdaptingCell(size=g_ahp.shape, g_ahp=g_ahp)
|
|
75
|
+
current = u.math.asarray([2.0, 2.0]) * u.uA / u.cm**2
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Treat the ISI trajectory as the primary adaptation check: the present-AHP lane should lengthen materially while the zero-AHP lane remains more tonic or fires faster late in the stimulus. Report the early/late windows beside rate summaries. Call a condition "intact" only when its complete model and parameter values come from a sourced template; otherwise call it "AHP present" and disclose any calibration.
|
|
79
|
+
|
|
80
|
+
Verify that stimulus onset starts from the intended baseline. If a calibrated hybrid spikes without applied current, use the same disclosed holding current and initialization in every lane, and assert that no spikes occur before the stimulus. Do not interpret an already-spiking baseline as onset adaptation.
|
|
81
|
+
|
|
82
|
+
Do not combine channel families or tune calcium influx, calcium removal, and AHP conductance solely to force the requested contrast. Preserve a coherent template when making biological claims, or label a hybrid explicitly as a teaching model and check that the conclusion survives a small parameter sweep.
|
|
83
|
+
|
|
84
|
+
Open `references/scripts/spike_frequency_adaptation.py` for a runnable calibrated teaching model with a quiet baseline, strength sweep, and zero-conductance comparison. Open `references/scripts/channel_ablation.py` only when the task needs the general one-parameter channel-ablation pattern without calcium-dependent adaptation.
|
|
85
|
+
|
|
86
|
+
## Rebound input variant
|
|
64
87
|
|
|
65
88
|
For post-inhibitory rebound, add or retain a low-threshold T-type calcium current such as `CaT_HM1992` and drive a time-dependent hyperpolarizing input.
|
|
66
89
|
|
|
@@ -1,75 +1,135 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Reference script mirrored from:
|
|
3
|
-
https://brainx.chaobrain.com/braincell/examples/spike_frequency_adaptation.html
|
|
1
|
+
"""Controlled AHP ablation in a calibrated BrainCell teaching model.
|
|
4
2
|
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
Mechanism pattern:
|
|
4
|
+
https://brainx.chaobrain.com/braincell/examples/spike_frequency_adaptation.html
|
|
7
5
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
- The agent needs dynamic calcium plus `MixIons(self.k, self.ca)` for AHP/KCa currents.
|
|
6
|
+
Ablation pattern:
|
|
7
|
+
https://brainx.chaobrain.com/braincell/examples/channel_ablation.html
|
|
11
8
|
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
This is not a reproduction of one literature neuron. It combines classical HH
|
|
10
|
+
spiking with dynamic calcium and AHP_De1994, then sweeps AHP strength so the
|
|
11
|
+
causal effect is visible and sensitivity to the calibrated value is explicit.
|
|
14
12
|
"""
|
|
15
13
|
|
|
14
|
+
import braincell
|
|
16
15
|
import brainstate
|
|
17
16
|
import braintools
|
|
18
17
|
import brainunit as u
|
|
19
|
-
import numpy as np
|
|
20
18
|
import matplotlib.pyplot as plt
|
|
21
|
-
import
|
|
19
|
+
import numpy as np
|
|
22
20
|
|
|
23
21
|
|
|
24
22
|
class AdaptingCell(braincell.SingleCompartment):
|
|
25
|
-
"""
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
self.
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
self.
|
|
39
|
-
self.
|
|
40
|
-
|
|
41
|
-
#
|
|
23
|
+
"""Single-compartment teaching model with removable Ca-activated K current."""
|
|
24
|
+
|
|
25
|
+
def __init__(self, size, g_ahp, solver="exp_euler"):
|
|
26
|
+
super().__init__(
|
|
27
|
+
size,
|
|
28
|
+
C=1.0 * u.uF / u.cm**2,
|
|
29
|
+
V_initializer=braintools.init.Constant(-75.0 * u.mV),
|
|
30
|
+
V_th=20.0 * u.mV,
|
|
31
|
+
solver=solver,
|
|
32
|
+
)
|
|
33
|
+
self.na = braincell.ion.SodiumFixed(size, E=50.0 * u.mV)
|
|
34
|
+
self.na.add(INa=braincell.channel.Na_HH1952(size))
|
|
35
|
+
|
|
36
|
+
self.k = braincell.ion.PotassiumFixed(size, E=-77.0 * u.mV)
|
|
37
|
+
self.k.add(IK=braincell.channel.K_HH1952(size))
|
|
38
|
+
|
|
39
|
+
# These teaching values are calibrated, not a sourced cell phenotype.
|
|
40
|
+
self.ca = braincell.ion.CalciumDetailed(
|
|
41
|
+
size,
|
|
42
|
+
C_rest=5.0e-5 * u.mM,
|
|
43
|
+
tau=80.0 * u.ms,
|
|
44
|
+
d=0.5 * u.um,
|
|
45
|
+
)
|
|
46
|
+
self.ca.add(
|
|
47
|
+
ICaL=braincell.channel.CaL_IS2008(
|
|
48
|
+
size,
|
|
49
|
+
g_max=5.0 * u.mS / u.cm**2,
|
|
50
|
+
)
|
|
51
|
+
)
|
|
52
|
+
|
|
42
53
|
self.kca = braincell.MixIons(self.k, self.ca)
|
|
43
|
-
self.kca.add(
|
|
44
|
-
|
|
54
|
+
self.kca.add(
|
|
55
|
+
IAHP=braincell.channel.AHP_De1994(size, g_max=g_ahp)
|
|
56
|
+
)
|
|
57
|
+
self.IL = braincell.channel.IL(
|
|
58
|
+
size,
|
|
59
|
+
E=-54.387 * u.mV,
|
|
60
|
+
g_max=0.03 * u.mS / u.cm**2,
|
|
61
|
+
)
|
|
62
|
+
|
|
45
63
|
|
|
64
|
+
dt = 0.01 * u.ms
|
|
65
|
+
stimulus_on = 50.0 * u.ms
|
|
66
|
+
stimulus_off = 550.0 * u.ms
|
|
67
|
+
holding_current = -0.5 * u.uA / u.cm**2
|
|
68
|
+
g_ahp = u.math.asarray([0.0, 0.3, 1.0]) * u.mS / u.cm**2
|
|
69
|
+
current = u.math.asarray([10.0, 10.0, 10.0]) * u.uA / u.cm**2
|
|
46
70
|
|
|
47
|
-
cell = AdaptingCell(
|
|
48
|
-
cell.init_state()
|
|
71
|
+
cell = AdaptingCell(size=g_ahp.shape, g_ahp=g_ahp)
|
|
49
72
|
|
|
50
|
-
|
|
73
|
+
with brainstate.environ.context(dt=dt):
|
|
74
|
+
cell.init_state()
|
|
75
|
+
times = u.math.arange(0.0 * u.ms, 600.0 * u.ms, dt)
|
|
51
76
|
|
|
77
|
+
def step(t):
|
|
78
|
+
injected = u.math.where(
|
|
79
|
+
(t >= stimulus_on) & (t < stimulus_off),
|
|
80
|
+
current,
|
|
81
|
+
holding_current,
|
|
82
|
+
)
|
|
83
|
+
with brainstate.environ.context(t=t):
|
|
84
|
+
spike = cell.update(injected)
|
|
85
|
+
return cell.V.value, spike
|
|
52
86
|
|
|
53
|
-
|
|
54
|
-
with brainstate.environ.context(t=t):
|
|
55
|
-
cell.update(I)
|
|
56
|
-
return cell.V.value, cell.spike.value
|
|
87
|
+
voltages, spikes = brainstate.transform.for_loop(step, times)
|
|
57
88
|
|
|
89
|
+
times_ms = np.asarray(times.to_decimal(u.ms))
|
|
90
|
+
pre_stimulus_spikes = np.asarray(spikes[times < stimulus_on]).sum()
|
|
91
|
+
assert pre_stimulus_spikes == 0
|
|
58
92
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
93
|
+
isis = []
|
|
94
|
+
for i, strength in enumerate(g_ahp.to_decimal(u.mS / u.cm**2)):
|
|
95
|
+
spike_times = times_ms[np.asarray(spikes[:, i]) > 0]
|
|
96
|
+
spike_times = spike_times[
|
|
97
|
+
(spike_times >= stimulus_on.to_decimal(u.ms))
|
|
98
|
+
& (spike_times < stimulus_off.to_decimal(u.ms))
|
|
99
|
+
]
|
|
100
|
+
isi = np.diff(spike_times)
|
|
101
|
+
isis.append(isi)
|
|
102
|
+
print(
|
|
103
|
+
f"g_AHP={strength:.1f} mS/cm^2: {spike_times.size} spikes, "
|
|
104
|
+
f"first ISI={isi[0]:.2f} ms, last ISI={isi[-1]:.2f} ms"
|
|
105
|
+
)
|
|
62
106
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
print('first ISIs (ms):', np.round(isi[:6], 2).tolist())
|
|
107
|
+
# The ablated lane is tonic; the calibrated present-AHP lane adapts strongly.
|
|
108
|
+
assert abs(isis[0][-1] - isis[0][0]) / isis[0][0] < 0.10
|
|
109
|
+
assert isis[-1][-1] / isis[-1][0] > 1.50
|
|
67
110
|
|
|
68
|
-
fig,
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
111
|
+
fig, axes = plt.subplots(2, 1, figsize=(8, 5))
|
|
112
|
+
for i, label in ((0, "AHP removed"), (-1, "AHP present (teaching value)")):
|
|
113
|
+
axes[0].plot(
|
|
114
|
+
times_ms,
|
|
115
|
+
np.asarray(voltages[:, i].to_decimal(u.mV)),
|
|
116
|
+
linewidth=0.8,
|
|
117
|
+
label=label,
|
|
118
|
+
)
|
|
119
|
+
axes[1].plot(
|
|
120
|
+
np.arange(1, isis[i].size + 1),
|
|
121
|
+
isis[i],
|
|
122
|
+
"o-",
|
|
123
|
+
markersize=3,
|
|
124
|
+
label=label,
|
|
125
|
+
)
|
|
126
|
+
axes[0].set(
|
|
127
|
+
xlabel="Time (ms)",
|
|
128
|
+
ylabel="V (mV)",
|
|
129
|
+
title="Matched steady-current conditions from a quiet baseline",
|
|
130
|
+
)
|
|
131
|
+
axes[1].set(xlabel="ISI index", ylabel="ISI (ms)", title="AHP-dependent slowing")
|
|
132
|
+
for axis in axes:
|
|
133
|
+
axis.legend(frameon=False)
|
|
134
|
+
plt.tight_layout()
|
|
135
|
+
plt.show()
|