Skip to main content

The TensorFlow for neuromorphic computing — high-level SNN framework

Project description

synaptic_ml

PyPI version License: MIT Python 3.8+

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)

Why neuromorphic?

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.


Installation

pip install synaptic-ml

Optional 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

Hardware Backends

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

BrainChip Akida — works today

# 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

Intel Loihi 2 — via Lava

# 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


Neuron Models

# 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')

Spike Encoders

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)

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 with validation
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 to SNN Conversion

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')

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}x 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 + surrogate gradients
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
│   ├── 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

Roadmap

  • LIF, Adaptive LIF, Izhikevich neuron models
  • Rate, Temporal, Population, Delta encoders
  • Surrogate gradient + STDP training
  • ANN->SNN conversion (PyTorch + Keras)
  • BrainChip Akida backend (fully working)
  • Intel Loihi 2 backend (via Lava)
  • BrainScaleS-2 backend (via PyNN)
  • 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

Contributing

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
  • Tests — pytest coverage

License

MIT License — see LICENSE.

Copyright (c) 2026 Hrishikesh Rajulu


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

synaptic_ml-0.1.3.tar.gz (40.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

synaptic_ml-0.1.3-py3-none-any.whl (47.9 kB view details)

Uploaded Python 3

File details

Details for the file synaptic_ml-0.1.3.tar.gz.

File metadata

  • Download URL: synaptic_ml-0.1.3.tar.gz
  • Upload date:
  • Size: 40.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.5

File hashes

Hashes for synaptic_ml-0.1.3.tar.gz
Algorithm Hash digest
SHA256 54a838937f5b19956c812fdf4897b73b5a0860375b349c107e750d278557422c
MD5 2bc961b82560b11d1cbaf60790ccf792
BLAKE2b-256 492675973ffc9a041d35c7191772ff0b72bae18b67ee37339c1e37856766f3af

See more details on using hashes here.

File details

Details for the file synaptic_ml-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: synaptic_ml-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 47.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.5

File hashes

Hashes for synaptic_ml-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 dbe23ea18e7c21a40c854351e98a89e77f7e8738d6824c1fe5be7da053cc4b5b
MD5 b5839eeaba8522c7c0532991f199d5d5
BLAKE2b-256 e72207664c32c154fe28caafb6662d1e704909757d3563aee91d430ea60bbffb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page