The TensorFlow for neuromorphic computing — high-level SNN framework
Project description
synaptic_ml
The TensorFlow for Neuromorphic Computing.
Train spiking neural networks. Deploy to neuromorphic chips. Use 1000× less energy than GPU.
import synaptic_ml as sml
# Build a spiking network
model = sml.SpikingNet([784, 256, 10])
model.summary()
# Train with surrogate gradients (like backprop, but for spikes)
model.train(X_train, y_train, epochs=10)
# Evaluate
predictions = model.predict(X_test)
# See the energy advantage
print(sml.energy_comparison_table(model))
# Deploy to neuromorphic hardware
model.deploy(target='loihi2') # Intel Loihi 2
model.deploy(target='brainscales') # BrainScaleS-2
model.deploy(target='cpu') # CPU simulation (default, always works)
Why neuromorphic?
| GPU (A100) | Intel Loihi 2 | Human Brain | |
|---|---|---|---|
| Power | 300W | 30mW | 20W |
| Energy/inference | ~1000 nJ | ~0.1 nJ | ~0.001 nJ |
| Efficiency | baseline | 10,000× better | 1,000,000× better |
The brain uses 20 watts. GPT-4 uses 50 megawatts. That's a 2.5 million× gap.
Neuromorphic chips close that gap — and synaptic_ml makes them programmable.
Installation
pip install synaptic-ml
# or from source:
git clone https://github.com/yourusername/synaptic-ml
pip install -e .
Optional extras:
pip install synaptic-ml[torch] # PyTorch ANN→SNN conversion
pip install synaptic-ml[sklearn] # MNIST examples
pip install synaptic-ml[all] # Everything
Core Concepts
Neuron Models
# Leaky Integrate-and-Fire (default, fast, efficient)
model = sml.SpikingNet([784, 256, 10], neuron='lif')
# Adaptive LIF (spike-frequency adaptation)
model = sml.SpikingNet([784, 256, 10], neuron='adaptive_lif')
# Izhikevich (biologically rich: bursting, chattering, fast-spiking)
model = sml.SpikingNet([784, 256, 10], neuron='izhikevich')
Spike Encoders
import synaptic_ml as sml
import numpy as np
x = np.random.rand(784) # your data, values in [0, 1]
# Rate coding: spike probability ∝ value (most common)
enc = sml.RateEncoder(time_steps=100, max_rate=100)
spikes = enc.encode(x) # shape: (100, 784)
# Temporal: earlier spike = stronger signal (most energy efficient)
enc = sml.TemporalEncoder(time_steps=100)
spikes = enc.encode(x) # at most 1 spike per neuron
# Population: Gaussian tuning curves (most biologically realistic)
enc = sml.PopulationEncoder(n_neurons=10, sigma=0.5)
spikes = enc.encode(x) # shape: (100, 7840)
# Delta: spikes only on change — perfect for IoT/sensors
enc = sml.DeltaEncoder(threshold=0.05)
spikes = enc.encode_series(time_series) # event-driven
Learning Rules
# Surrogate gradients (recommended) — backprop through spikes
model.train(X, y, learning_rule='surrogate', learning_rate=0.001)
# STDP — unsupervised, no labels needed, biologically inspired
model.train(X, y, learning_rule='stdp')
# Custom trainer
trainer = sml.Trainer(model, learning_rule='surrogate', learning_rate=0.001)
trainer.fit(X_train, y_train, epochs=10, validation_split=0.1)
trainer.evaluate(X_test, y_test)
ANN → SNN Conversion
Convert your existing PyTorch/Keras models to SNNs in one line:
import torch.nn as nn
import synaptic_ml as sml
# Your existing trained ANN
ann = nn.Sequential(nn.Linear(784, 256), nn.ReLU(), nn.Linear(256, 10))
# Convert to SNN (threshold balancing method)
snn = sml.convert_from_pytorch(ann, X_calibration, time_steps=100)
# Deploy to neuromorphic hardware
snn.deploy(target='loihi2')
Hardware Backends
# CPU simulation — always works, no hardware needed
backend = model.deploy(target='cpu')
# Intel Loihi 2 — requires NxSDK (Intel Research Program)
# Apply at: intel.com/loihi
backend = model.deploy(target='loihi2')
# BrainScaleS-2 — requires EBRAINS access (Human Brain Project)
# Apply at: ebrains.eu
backend = model.deploy(target='brainscales')
Energy Analysis
# After running predictions:
model.predict(X_test)
# Detailed energy breakdown
energy = model.estimate_energy()
print(f"Ops/inference: {energy['synaptic_ops_per_inference']:,.0f}")
print(f"Energy/inference: {energy['energy_per_inference_nJ']:.4f} nJ")
print(f"vs GPU: {energy['efficiency_gain']:.0f}× more efficient")
# Full comparison table
print(sml.energy_comparison_table(model))
Save / Load
model.save('my_snn.snm')
model = sml.SpikingNet.load('my_snn.snm')
Examples
# MNIST classification with LIF neurons
python examples/mnist_lif.py
# Unsupervised pattern learning with STDP
python examples/pattern_recognition.py
# IoT anomaly detection with delta encoding
python examples/edge_sensor.py
# Quick self-test
python -m synaptic_ml
Architecture
synaptic_ml/
├── core/
│ ├── neurons.py # LIF, Adaptive LIF, Izhikevich
│ ├── synapses.py # Dense, Sparse, Delayed
│ ├── layers.py # LIFLayer, OutputLayer, etc.
│ └── network.py # SpikingNet (main model class)
├── encoding/
│ ├── rate.py # Poisson rate coding
│ ├── temporal.py # Time-to-first-spike, phase coding
│ └── population.py # Gaussian tuning, delta/event coding
├── learning/
│ ├── stdp.py # STDP, reward-modulated STDP
│ ├── surrogate.py # Surrogate gradient functions
│ └── conversion.py # ANN→SNN threshold balancing
├── backends/
│ ├── cpu.py # Pure numpy simulation
│ ├── loihi2.py # Intel Loihi 2 (NxSDK)
│ └── brainscales.py # BrainScaleS-2 (PyNN)
├── training/
│ └── trainer.py # Training loop, loss functions
└── utils/
├── metrics.py # Energy, spike metrics, Van Rossum distance
└── visualization.py # Raster plots, membrane traces, energy bars
Hardware Access
Neither Loihi 2 nor BrainScaleS requires purchase — they're available through research programs:
- Intel Loihi 2: Intel Neuromorphic Research Community
- BrainScaleS-2: EBRAINS / Human Brain Project
Until you get hardware access, the CPU backend gives exact simulation results.
Roadmap
- GPU-accelerated simulation (CuPy backend)
- Innatera T1 chip support
- Online/streaming inference API
- Quantization-aware training
- Multi-chip deployment
- Web dashboard for spike visualization
License
MIT License. See LICENSE.
The brain uses 20 watts. GPT-4 uses 50 megawatts. synaptic_ml bridges that gap.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file synaptic_ml-0.1.0.tar.gz.
File metadata
- Download URL: synaptic_ml-0.1.0.tar.gz
- Upload date:
- Size: 37.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dcd9e9d98b3f771a547073fcb84598150e097401d47f5fdde89756930cfca463
|
|
| MD5 |
6a4413df03b65cfe21eef7a04176ca38
|
|
| BLAKE2b-256 |
7c3c950a62ecb7609ac664a8b1f097e745f2537c2bf2248b8f140d3703f72f33
|
File details
Details for the file synaptic_ml-0.1.0-py3-none-any.whl.
File metadata
- Download URL: synaptic_ml-0.1.0-py3-none-any.whl
- Upload date:
- Size: 43.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5d3444cefdbbf2a7365367b4a2cda08cf0d3e5652390da514f0577893a81eba5
|
|
| MD5 |
8f165b1facb01d3e89b685e59c5c174e
|
|
| BLAKE2b-256 |
c849b06ddd8e3f1e4d6ad9180461402d12fc679bb9244333198acf305d0e84d9
|