snnlab

Authoring networks

Build explicit graph contracts with snnlab.lang.

snnlab.lang builds and validates graphs. Compilation produces data; it does not run the simulation or train a model.

Declare inputs and populations

A spike input declares its axis order, signal type, and unit:

from snnlab import lang as snn

net = snn.Network("circuit")
events = net.input(
    "events", shape=("time", "batch", 128), signal_type="spikes", unit="spike"
)
cell = snn.components.ping(net, name="cell", n_e=256, n_i=64, source=events)

components.ping expands into explicit excitatory and inhibitory COBA-LIF populations and their connections. It is an authoring convenience, not an opaque runtime block. The default source drives E; use source_e and source_i for separate afferents.

Expose outputs and recordings

scores = snn.readouts.MeanVoltage(
    source=cell.E.spikes, classes=10, name="classifier"
)
net.output("scores", scores)
net.expose(cell.E.spikes, cell.I.spikes, name="activity")
bundle = snn.compile(net, target="tools/snnsim")
bundle.write("circuit.bundle", visualise=True)

Diagram export requires Graphviz. Omit visualise=True for a data-only bundle. Standard readouts include mean voltage, final voltage, spike count, spike rate, and cumulative potential.

Connect explicitly

Network.connect declares a source, destination port, synapse, weight initializer, connection kind, and delay. Use AMPA for an excitatory conductance port and GABA for an inhibitory port. Weights use uS; inhibitory polarity belongs to the synapse and destination, rather than a negative GABA weight.

A projection with enabled=False stays in the graph with its parameter identity and shape, but contributes zero conductance at runtime. This supports controlled structural comparisons while preserving later initializer draws.

Graph validity and backend capability are distinct checks. The authoring vocabulary includes structures, such as modulatory connections, beyond the graph executor's documented AMPA/GABA scope.

Representative examples

uv run python -m snnlab.lang.examples.build_examples

The builder writes bundles to examples/generated/ relative to the working directory and renders diagrams. Examples include a PING classifier, a three-layer hierarchy, and coupled feedback. They illustrate authoring; do not assume every example is executable on every backend.

API reference

See the complete snnlab.lang API reference for signatures, defaults, fields, methods and validation.

On this page