Skip to main content

biosnn-bus

BioSNN-Plug 的模态插件骨架库。

它只负责一件事:让新增模态不需要修改已有架构。

这是骨架,不是认知核心。 本库不包含任何学习规则(e-prop / R-STDP / 核化 IB-Hebbian)、不包含脉冲神经元模型、不依赖 GPU、不依赖 PyTorch。它提供 的是插件的接口契约、注册与发现机制、以及脉冲总线的接缝。

安装

pip install biosnn-bus

# 需要 torch 桥接时(SpikeTrain.to_torch / from_torch)
pip install "biosnn-bus[torch]"

要从 main 分支装尚未发布的改动(例如正在评审的修复),可以走 Git:

pip install "biosnn-bus @ git+https://github.com/lzmd-arch/BioSNN-Plug.git#subdirectory=packages/biosnn-bus"

只依赖 numpy。

快速开始

import numpy as np
from biosnn_bus import ModalityPlugin, PassThroughMembrane, SpikeBus, SpikeTrain


class MyPlugin(ModalityPlugin):
    @property
    def modality_name(self) -> str:
        return "my_modality"

    @property
    def spike_dim(self) -> int:
        return 64

    def encode(self, raw_input):
        return SpikeTrain(data=np.asarray(raw_input) > 0.5, channel=self.channel)

    def get_membrane(self):
        return PassThroughMembrane()

    def decode(self, spike_output):
        return spike_output.rates


bus = SpikeBus(bus_dim=128, seed=0)
bus.register(MyPlugin())
out = bus.step({"my_modality": np.random.default_rng(0).random((10, 64))})
print(out)

完整可跑的版本见 examples/quickstart_register_plugin.py, 以及 Colab notebook(无 GPU 可跑)。

它跑出来就是下面这张图——一维正弦信号走时间通道(32 个单元的水平编码),8×8 的亮度变化序列走 语义通道(128 通道 ON/OFF),最下面那条是融合、投影之后真正送进认知核心的输入:

三面板脉冲栅格图:时间通道 sine_wave / 语义通道 image_diff / SpikeBus 融合输出

图内的标签是英文:默认字体没有中文字形,中文标签会渲染成方块。图只有这一份真相源—— scripts/make_figures.py 重跑上面那个示例、由示例自己把 PNG 落盘, 绘图代码不另抄一份。这是论文用图 F1。

核心概念

概念 说明
ModalityPlugin 模态插件的抽象基类:encode / decode / get_membrane 三方法,modality_name / spike_dim 两属性
SpikeTrain 形状 (T, N) 的脉冲序列容器,布尔(脉冲)或浮点(发放率)皆可
FusionChannel temporal / semantic 两条融合通道,对应计划书 §2.2 的"双通道融合"
SpikeBus 脉冲总线:编码 → 时间对齐 → 按通道融合 → 稀疏随机投影到认知核心维度
register_plugin 进程内注册装饰器
discover_plugins 扫描第三方分发包声明的 entry points

第三方插件怎么接入

在你的包里声明 entry point,不需要修改 BioSNN-Plug 任何一行代码:

# 你的包的 pyproject.toml
[project.entry-points."biosnn_bus.plugins"]
audio = "my_pkg.plugins.audio:AudioPlugin"

用户侧扫描并接入。下面这段可以直接跑——即使一个第三方插件都没装:

from biosnn_bus import SpikeBus, discover_plugins, get_plugin, list_plugins
from biosnn_bus.plugins import DiffImagePlugin

discover_plugins()  # 扫描第三方分发包声明的插件;一个都没装也不会报错
print(list_plugins())  # 内置示例插件在 import 时已注册进注册表

bus = SpikeBus(bus_dim=128, seed=0)
bus.register(get_plugin("image_diff")())  # 等价于 bus.register(DiffImagePlugin())
print(bus)

骨架的边界

脉冲总线当前的默认融合策略是平凡的拼接(ConcatenateFusion),不是计划书 §2.2 描述的 TAAF 时间注意力引导融合——后者是第二阶段的研究任务。总线已经把 FusionStrategy 协议和双通道路由留好,替换策略不会改动调用方代码。

理由见 ADR-0001。

许可证

Apache-2.0。文档采用 CC-BY 4.0。

Metadata

Release files for biosnn-bus 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for biosnn-bus 0.2.0
File Size Uploaded
biosnn_bus-0.2.0.tar.gz 50.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for biosnn-bus 0.2.0
File Interpreter ABI Platform
biosnn_bus-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 89.5 kB

Release files / biosnn_bus-0.2.0.tar.gz

Download URL biosnn_bus-0.2.0.tar.gz
Size 50.6 kB
Tags Source
SHA-256 checksum
How to use checksums
c8f998c31dea66545c8185e2c9fb494edb0a59b9d4ce68bd12f55edbbc6d55cc
BLAKE2b-256 checksum
How to use checksums
1981df7d24874cb920f7516ebfba78d3d0771edc80053673f5da49f695a10ed8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 14, 2026.

Transparency log

Release files / biosnn_bus-0.2.0-py3-none-any.whl

Download URL biosnn_bus-0.2.0-py3-none-any.whl
Size 38.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9194f1edf758849668328b3c6199a7384620ee884f6e67be07cad1447d4f7c7e
BLAKE2b-256 checksum
How to use checksums
86a04263da8f937c1b78f9faafdc608db9bb10fc2ddb27ce01cd87fff371c872
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 14, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page