snnlang is the network-authoring layer for tools/snnsim. It provides a small Python API for describing populations, projections, inputs, outputs, and recordings. Compilation checks the description and writes a portable, data-only bundle. tools/snnsim loads that bundle and performs the simulation or training.
The system separates four concerns:
A saved bundle contains scientific structure rather than live Python objects. It can be inspected and replayed without importing the authoring package.
A network begins with an explicit timestep and a typed input. Components add reusable motifs. Outputs are values returned to a caller; observables are internal signals retained for inspection.
from tools import snnlang as snn
net = snn.Network("small_ping", dt=0.1 * snn.ms)
events = net.input(
"events",
shape=("time", "batch", 128),
signal_type="spikes",
unit="spike",
)
cell = snn.components.ping(
net,
name="cell",
n_e=80,
n_i=20,
source=events,
)
net.expose(cell.E.spikes, cell.I.spikes, name="raster")
bundle = snn.compile(net, target="tools/snnsim")
bundle.write("small_ping.bundle", visualise=True)Compilation produces graph.json, manifest.json, a readable report, and optional circuit diagrams.
Provide one tensor for every declared input:
import torch
from tools.snnsim.execution import ExecutionSpec, simulate
spikes = torch.zeros(2_000, 1, 128)
result = simulate(ExecutionSpec(
kind="simulate",
executor="graph",
bundle="small_ping.bundle",
inputs={"events": spikes},
seed=42,
device="cpu",
recording="observables",
))
e_spikes = result.recordings["raster_0"]
i_spikes = result.recordings["raster_1"]Graph-native forward simulation supports this example today. Input generation remains the caller’s responsibility.
Import the public authoring API with from tools import snnlang as snn. The top-level package exports Network, graph specification constructors, units, compile, load_bundle, validate_graph, and the components, ops, readouts, and training modules.
net = snn.Network(name, dt=0.1 * snn.ms)
bundle = snn.compile(net, training=None, target=None, assets=None)
root = bundle.write(path, visualise=False)
loaded = snn.load_bundle(root)Network is mutable while authoring. compile returns a Bundle containing immutable graph data, optional training data, a manifest, diagnostics, and logical asset sources. Bundle.write returns the bundle directory. load_bundle verifies digests and validates the stored graph before returning a Bundle.
Execution is deliberately separate from tools.snnlang. Import ExecutionSpec, build, simulate, train, or infer from tools.snnsim.execution. Graph execution is opt-in with executor="graph"; the legacy executor remains the default.
Read the collection in this order:
Each page begins with its own linked contents, presents the high-level developer guide, and ends with the API reference.