The TensorFlow for Neuromorphic Computing.
Train spiking neural networks. Deploy to neuromorphic chips. Use 1000x 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
model.train(X_train, y_train, epochs=10)
# See the energy advantage
print(sml.energy_comparison_table(model))
# Deploy to neuromorphic hardware
model.deploy(target='akida') # BrainChip Akida (works today, pip install akida)
model.deploy(target='loihi2') # Intel Loihi 2 (via Lava framework)
model.deploy(target='brainscales') # BrainScaleS-2 (via PyNN)
model.deploy(target='cpu') # CPU simulation (default, always works)| GPU (A100) | Intel Loihi 2 | BrainChip Akida | Human Brain | |
|---|---|---|---|---|
| Power | 300W | 30mW | 30mW | 20W |
| Energy/inference | ~1000 nJ | ~0.1 nJ | ~1.4 nJ | ~0.001 nJ |
| Available | Yes | Research only | Yes — buy now | No |
The brain uses 20 watts. GPT-4 uses 50 megawatts. That is a 2.5 million x gap.
Neuromorphic chips close that gap. synaptic_ml makes them programmable.
pip install synaptic-mlOptional hardware backends:
pip install akida # BrainChip Akida (recommended — works without hardware)
pip install lava-nc # Intel Loihi 2 via Lava (requires Python 3.10)
pip install pyNN # BrainScaleS-2 / SpiNNaker 2| Backend | Chip | Install | Hardware needed? |
|---|---|---|---|
cpu |
CPU simulation | built-in | No |
akida |
BrainChip AKD1000/AKD1500 | pip install akida |
No (virtual mode) |
loihi2 |
Intel Loihi 2 | pip install lava-nc |
No (CPU sim via Lava) |
brainscales |
BrainScaleS-2 | pip install pyNN |
Apply at ebrains.eu |
# No hardware needed — runs in virtual simulation
backend = model.deploy(target='akida')
# With real AKD1000/AKD1500 hardware connected
backend = model.deploy(target='akida', use_hardware=True)Buy Akida hardware: brainchipinc.com/products
# Lava is Intel's official open-source neuromorphic framework
# synaptic_ml sits on top of it as a friendly API layer
backend = model.deploy(target='loihi2')For real Loihi 2 hardware, join the INRC: neuromorphic.intel.com
# Leaky Integrate-and-Fire (default, fast)
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')import numpy as np
x = np.random.rand(784) # values in [0, 1]
# Rate coding — spike probability proportional to 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)
# Delta — spikes only on change (perfect for IoT sensors)
enc = sml.DeltaEncoder(threshold=0.05)
spikes = enc.encode_series(time_series)# Surrogate gradients (recommended) — backprop through spike nonlinearity
# Uses voltage-based soft activations + Adam optimizer for stable training.
model.train(X, y, learning_rule='surrogate', learning_rate=0.001, epochs=30)
# STDP — unsupervised, no labels needed, biologically inspired
model.train(X, y, learning_rule='stdp')
# Custom trainer with validation split
trainer = sml.Trainer(model, learning_rule='surrogate', learning_rate=0.001)
trainer.fit(X_train, y_train, epochs=50, validation_split=0.1)
trainer.evaluate(X_test, y_test)Convert your existing PyTorch or Keras models to SNNs in one line:
import torch.nn as nn
# Your trained ANN
ann = nn.Sequential(nn.Linear(784, 256), nn.ReLU(), nn.Linear(256, 10))
# Convert to SNN (threshold balancing)
snn = sml.convert_from_pytorch(ann, X_calibration, time_steps=100)
# Deploy to neuromorphic hardware
snn.deploy(target='akida')# 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}x more efficient")
# Full comparison table
print(sml.energy_comparison_table(model))model.save('my_snn.snm')
model = sml.SpikingNet.load('my_snn.snm')import numpy as np
import synaptic_ml as sml
# Generate some data
X = np.random.rand(1000, 16).astype('float32')
y = (X.mean(axis=1) > 0.5).astype('int64')
# Build and train
model = sml.SpikingNet([16, 64, 2], neuron='lif', time_steps=50)
model.train(X[:800], y[:800], epochs=30, learning_rate=0.001)
# Evaluate
preds = model.predict(X[800:])
print(f"Accuracy: {(preds == y[800:]).mean():.1%}")
# Self-test
python -m synaptic_mlsynaptic_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
│ ├── akida.py # BrainChip Akida (pip install akida)
│ ├── loihi2.py # Intel Loihi 2 (via Lava)
│ └── brainscales.py # BrainScaleS-2 (via PyNN)
├── training/
│ └── trainer.py # Training loop, surrogate + STDP
└── utils/
├── metrics.py # Energy, spike metrics, Van Rossum distance
└── visualization.py # Raster plots, membrane traces, energy bars
- LIF, Adaptive LIF, Izhikevich neuron models
- Rate, Temporal, Population, Delta encoders
- LIF, Adaptive LIF, Izhikevich neuron models
- Rate, Temporal, Population, Delta encoders
- Surrogate gradient training (BPTT with momentum, voltage-based soft activations)
- STDP + Reward-modulated STDP
- ANN->SNN conversion (threshold balancing)
- BrainChip Akida backend (CPU virtual mode + hardware mode)
- Intel Loihi 2 backend (via Lava framework)
- BrainScaleS-2 backend (via PyNN)
- 111-test suite (neurons, encoders, layers, network, backends, learning)
- GPU simulation (CuPy backend)
- SpiNNaker 2 backend
- Innatera T1 backend
- IBM NorthPole backend (when SDK releases)
- Quantization-aware training
- Online/streaming inference API
- Pretrained model hub
See CONTRIBUTING.md.
Most needed right now:
- Someone with Loihi 2 hardware to test and fix the Loihi 2 backend
- Someone with Akida AKD1000/AKD1500 hardware to test hardware mode
- GPU simulation via CuPy
- MNIST/CIFAR benchmarks — real-world accuracy numbers
MIT License — see LICENSE.
Copyright (c) 2026 Hrishikesh Rajulu
The brain uses 20 watts. GPT-4 uses 50 megawatts. synaptic_ml bridges that gap.