synaptic-ml 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- synaptic_ml-0.1.0/LICENSE +21 -0
- synaptic_ml-0.1.0/PKG-INFO +307 -0
- synaptic_ml-0.1.0/README.md +251 -0
- synaptic_ml-0.1.0/setup.cfg +4 -0
- synaptic_ml-0.1.0/setup.py +63 -0
- synaptic_ml-0.1.0/synaptic_ml/__init__.py +103 -0
- synaptic_ml-0.1.0/synaptic_ml/__main__.py +46 -0
- synaptic_ml-0.1.0/synaptic_ml/backends/__init__.py +37 -0
- synaptic_ml-0.1.0/synaptic_ml/backends/base.py +61 -0
- synaptic_ml-0.1.0/synaptic_ml/backends/brainscales.py +164 -0
- synaptic_ml-0.1.0/synaptic_ml/backends/cpu.py +99 -0
- synaptic_ml-0.1.0/synaptic_ml/backends/loihi2.py +163 -0
- synaptic_ml-0.1.0/synaptic_ml/core/__init__.py +11 -0
- synaptic_ml-0.1.0/synaptic_ml/core/layers.py +292 -0
- synaptic_ml-0.1.0/synaptic_ml/core/network.py +294 -0
- synaptic_ml-0.1.0/synaptic_ml/core/neurons.py +245 -0
- synaptic_ml-0.1.0/synaptic_ml/core/synapses.py +175 -0
- synaptic_ml-0.1.0/synaptic_ml/encoding/__init__.py +36 -0
- synaptic_ml-0.1.0/synaptic_ml/encoding/population.py +157 -0
- synaptic_ml-0.1.0/synaptic_ml/encoding/rate.py +77 -0
- synaptic_ml-0.1.0/synaptic_ml/encoding/temporal.py +115 -0
- synaptic_ml-0.1.0/synaptic_ml/learning/__init__.py +13 -0
- synaptic_ml-0.1.0/synaptic_ml/learning/conversion.py +173 -0
- synaptic_ml-0.1.0/synaptic_ml/learning/stdp.py +164 -0
- synaptic_ml-0.1.0/synaptic_ml/learning/surrogate.py +123 -0
- synaptic_ml-0.1.0/synaptic_ml/training/__init__.py +3 -0
- synaptic_ml-0.1.0/synaptic_ml/training/trainer.py +312 -0
- synaptic_ml-0.1.0/synaptic_ml/utils/__init__.py +15 -0
- synaptic_ml-0.1.0/synaptic_ml/utils/metrics.py +189 -0
- synaptic_ml-0.1.0/synaptic_ml/utils/visualization.py +215 -0
- synaptic_ml-0.1.0/synaptic_ml.egg-info/PKG-INFO +307 -0
- synaptic_ml-0.1.0/synaptic_ml.egg-info/SOURCES.txt +34 -0
- synaptic_ml-0.1.0/synaptic_ml.egg-info/dependency_links.txt +1 -0
- synaptic_ml-0.1.0/synaptic_ml.egg-info/entry_points.txt +2 -0
- synaptic_ml-0.1.0/synaptic_ml.egg-info/requires.txt +29 -0
- synaptic_ml-0.1.0/synaptic_ml.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Hrishikesh Rajulu
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: synaptic-ml
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: The TensorFlow for neuromorphic computing — high-level SNN framework
|
|
5
|
+
Home-page: https://github.com/HrishikeshRajulu/synaptic-ml
|
|
6
|
+
Author: synaptic_ml contributors
|
|
7
|
+
Keywords: neuromorphic,spiking neural network,SNN,deep learning,Loihi,BrainScaleS,energy efficient AI,edge computing
|
|
8
|
+
Classifier: Development Status :: 3 - Alpha
|
|
9
|
+
Classifier: Intended Audience :: Science/Research
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
18
|
+
Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
|
|
19
|
+
Requires-Python: >=3.8
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Requires-Dist: numpy>=1.21
|
|
23
|
+
Requires-Dist: scipy>=1.7
|
|
24
|
+
Requires-Dist: matplotlib>=3.4
|
|
25
|
+
Requires-Dist: tqdm>=4.62
|
|
26
|
+
Provides-Extra: torch
|
|
27
|
+
Requires-Dist: torch>=1.9; extra == "torch"
|
|
28
|
+
Provides-Extra: loihi
|
|
29
|
+
Requires-Dist: nxsdk; extra == "loihi"
|
|
30
|
+
Provides-Extra: brainscales
|
|
31
|
+
Requires-Dist: pynn_brainscales; extra == "brainscales"
|
|
32
|
+
Requires-Dist: hxtorch; extra == "brainscales"
|
|
33
|
+
Provides-Extra: sklearn
|
|
34
|
+
Requires-Dist: scikit-learn>=0.24; extra == "sklearn"
|
|
35
|
+
Provides-Extra: dev
|
|
36
|
+
Requires-Dist: pytest>=6.0; extra == "dev"
|
|
37
|
+
Requires-Dist: pytest-cov; extra == "dev"
|
|
38
|
+
Requires-Dist: black; extra == "dev"
|
|
39
|
+
Requires-Dist: isort; extra == "dev"
|
|
40
|
+
Requires-Dist: scikit-learn>=0.24; extra == "dev"
|
|
41
|
+
Provides-Extra: all
|
|
42
|
+
Requires-Dist: torch>=1.9; extra == "all"
|
|
43
|
+
Requires-Dist: scikit-learn>=0.24; extra == "all"
|
|
44
|
+
Requires-Dist: tqdm>=4.62; extra == "all"
|
|
45
|
+
Dynamic: author
|
|
46
|
+
Dynamic: classifier
|
|
47
|
+
Dynamic: description
|
|
48
|
+
Dynamic: description-content-type
|
|
49
|
+
Dynamic: home-page
|
|
50
|
+
Dynamic: keywords
|
|
51
|
+
Dynamic: license-file
|
|
52
|
+
Dynamic: provides-extra
|
|
53
|
+
Dynamic: requires-dist
|
|
54
|
+
Dynamic: requires-python
|
|
55
|
+
Dynamic: summary
|
|
56
|
+
|
|
57
|
+
# synaptic_ml
|
|
58
|
+
|
|
59
|
+
**The TensorFlow for Neuromorphic Computing.**
|
|
60
|
+
|
|
61
|
+
Train spiking neural networks. Deploy to neuromorphic chips. Use 1000× less energy than GPU.
|
|
62
|
+
|
|
63
|
+
```python
|
|
64
|
+
import synaptic_ml as sml
|
|
65
|
+
|
|
66
|
+
# Build a spiking network
|
|
67
|
+
model = sml.SpikingNet([784, 256, 10])
|
|
68
|
+
model.summary()
|
|
69
|
+
|
|
70
|
+
# Train with surrogate gradients (like backprop, but for spikes)
|
|
71
|
+
model.train(X_train, y_train, epochs=10)
|
|
72
|
+
|
|
73
|
+
# Evaluate
|
|
74
|
+
predictions = model.predict(X_test)
|
|
75
|
+
|
|
76
|
+
# See the energy advantage
|
|
77
|
+
print(sml.energy_comparison_table(model))
|
|
78
|
+
|
|
79
|
+
# Deploy to neuromorphic hardware
|
|
80
|
+
model.deploy(target='loihi2') # Intel Loihi 2
|
|
81
|
+
model.deploy(target='brainscales') # BrainScaleS-2
|
|
82
|
+
model.deploy(target='cpu') # CPU simulation (default, always works)
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
## Why neuromorphic?
|
|
88
|
+
|
|
89
|
+
| | GPU (A100) | Intel Loihi 2 | Human Brain |
|
|
90
|
+
|--|--|--|--|
|
|
91
|
+
| Power | 300W | 30mW | 20W |
|
|
92
|
+
| Energy/inference | ~1000 nJ | ~0.1 nJ | ~0.001 nJ |
|
|
93
|
+
| Efficiency | baseline | **10,000× better** | **1,000,000× better** |
|
|
94
|
+
|
|
95
|
+
The brain uses 20 watts. GPT-4 uses 50 megawatts. That's a 2.5 million× gap.
|
|
96
|
+
Neuromorphic chips close that gap — and `synaptic_ml` makes them programmable.
|
|
97
|
+
|
|
98
|
+
---
|
|
99
|
+
|
|
100
|
+
## Installation
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
pip install synaptic-ml
|
|
104
|
+
# or from source:
|
|
105
|
+
git clone https://github.com/yourusername/synaptic-ml
|
|
106
|
+
pip install -e .
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
**Optional extras:**
|
|
110
|
+
```bash
|
|
111
|
+
pip install synaptic-ml[torch] # PyTorch ANN→SNN conversion
|
|
112
|
+
pip install synaptic-ml[sklearn] # MNIST examples
|
|
113
|
+
pip install synaptic-ml[all] # Everything
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
---
|
|
117
|
+
|
|
118
|
+
## Core Concepts
|
|
119
|
+
|
|
120
|
+
### Neuron Models
|
|
121
|
+
|
|
122
|
+
```python
|
|
123
|
+
# Leaky Integrate-and-Fire (default, fast, efficient)
|
|
124
|
+
model = sml.SpikingNet([784, 256, 10], neuron='lif')
|
|
125
|
+
|
|
126
|
+
# Adaptive LIF (spike-frequency adaptation)
|
|
127
|
+
model = sml.SpikingNet([784, 256, 10], neuron='adaptive_lif')
|
|
128
|
+
|
|
129
|
+
# Izhikevich (biologically rich: bursting, chattering, fast-spiking)
|
|
130
|
+
model = sml.SpikingNet([784, 256, 10], neuron='izhikevich')
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### Spike Encoders
|
|
134
|
+
|
|
135
|
+
```python
|
|
136
|
+
import synaptic_ml as sml
|
|
137
|
+
import numpy as np
|
|
138
|
+
|
|
139
|
+
x = np.random.rand(784) # your data, values in [0, 1]
|
|
140
|
+
|
|
141
|
+
# Rate coding: spike probability ∝ value (most common)
|
|
142
|
+
enc = sml.RateEncoder(time_steps=100, max_rate=100)
|
|
143
|
+
spikes = enc.encode(x) # shape: (100, 784)
|
|
144
|
+
|
|
145
|
+
# Temporal: earlier spike = stronger signal (most energy efficient)
|
|
146
|
+
enc = sml.TemporalEncoder(time_steps=100)
|
|
147
|
+
spikes = enc.encode(x) # at most 1 spike per neuron
|
|
148
|
+
|
|
149
|
+
# Population: Gaussian tuning curves (most biologically realistic)
|
|
150
|
+
enc = sml.PopulationEncoder(n_neurons=10, sigma=0.5)
|
|
151
|
+
spikes = enc.encode(x) # shape: (100, 7840)
|
|
152
|
+
|
|
153
|
+
# Delta: spikes only on change — perfect for IoT/sensors
|
|
154
|
+
enc = sml.DeltaEncoder(threshold=0.05)
|
|
155
|
+
spikes = enc.encode_series(time_series) # event-driven
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### Learning Rules
|
|
159
|
+
|
|
160
|
+
```python
|
|
161
|
+
# Surrogate gradients (recommended) — backprop through spikes
|
|
162
|
+
model.train(X, y, learning_rule='surrogate', learning_rate=0.001)
|
|
163
|
+
|
|
164
|
+
# STDP — unsupervised, no labels needed, biologically inspired
|
|
165
|
+
model.train(X, y, learning_rule='stdp')
|
|
166
|
+
|
|
167
|
+
# Custom trainer
|
|
168
|
+
trainer = sml.Trainer(model, learning_rule='surrogate', learning_rate=0.001)
|
|
169
|
+
trainer.fit(X_train, y_train, epochs=10, validation_split=0.1)
|
|
170
|
+
trainer.evaluate(X_test, y_test)
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
### ANN → SNN Conversion
|
|
174
|
+
|
|
175
|
+
Convert your existing PyTorch/Keras models to SNNs in one line:
|
|
176
|
+
|
|
177
|
+
```python
|
|
178
|
+
import torch.nn as nn
|
|
179
|
+
import synaptic_ml as sml
|
|
180
|
+
|
|
181
|
+
# Your existing trained ANN
|
|
182
|
+
ann = nn.Sequential(nn.Linear(784, 256), nn.ReLU(), nn.Linear(256, 10))
|
|
183
|
+
|
|
184
|
+
# Convert to SNN (threshold balancing method)
|
|
185
|
+
snn = sml.convert_from_pytorch(ann, X_calibration, time_steps=100)
|
|
186
|
+
|
|
187
|
+
# Deploy to neuromorphic hardware
|
|
188
|
+
snn.deploy(target='loihi2')
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
### Hardware Backends
|
|
192
|
+
|
|
193
|
+
```python
|
|
194
|
+
# CPU simulation — always works, no hardware needed
|
|
195
|
+
backend = model.deploy(target='cpu')
|
|
196
|
+
|
|
197
|
+
# Intel Loihi 2 — requires NxSDK (Intel Research Program)
|
|
198
|
+
# Apply at: intel.com/loihi
|
|
199
|
+
backend = model.deploy(target='loihi2')
|
|
200
|
+
|
|
201
|
+
# BrainScaleS-2 — requires EBRAINS access (Human Brain Project)
|
|
202
|
+
# Apply at: ebrains.eu
|
|
203
|
+
backend = model.deploy(target='brainscales')
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
### Energy Analysis
|
|
207
|
+
|
|
208
|
+
```python
|
|
209
|
+
# After running predictions:
|
|
210
|
+
model.predict(X_test)
|
|
211
|
+
|
|
212
|
+
# Detailed energy breakdown
|
|
213
|
+
energy = model.estimate_energy()
|
|
214
|
+
print(f"Ops/inference: {energy['synaptic_ops_per_inference']:,.0f}")
|
|
215
|
+
print(f"Energy/inference: {energy['energy_per_inference_nJ']:.4f} nJ")
|
|
216
|
+
print(f"vs GPU: {energy['efficiency_gain']:.0f}× more efficient")
|
|
217
|
+
|
|
218
|
+
# Full comparison table
|
|
219
|
+
print(sml.energy_comparison_table(model))
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
### Save / Load
|
|
223
|
+
|
|
224
|
+
```python
|
|
225
|
+
model.save('my_snn.snm')
|
|
226
|
+
model = sml.SpikingNet.load('my_snn.snm')
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
---
|
|
230
|
+
|
|
231
|
+
## Examples
|
|
232
|
+
|
|
233
|
+
```bash
|
|
234
|
+
# MNIST classification with LIF neurons
|
|
235
|
+
python examples/mnist_lif.py
|
|
236
|
+
|
|
237
|
+
# Unsupervised pattern learning with STDP
|
|
238
|
+
python examples/pattern_recognition.py
|
|
239
|
+
|
|
240
|
+
# IoT anomaly detection with delta encoding
|
|
241
|
+
python examples/edge_sensor.py
|
|
242
|
+
|
|
243
|
+
# Quick self-test
|
|
244
|
+
python -m synaptic_ml
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
---
|
|
248
|
+
|
|
249
|
+
## Architecture
|
|
250
|
+
|
|
251
|
+
```
|
|
252
|
+
synaptic_ml/
|
|
253
|
+
├── core/
|
|
254
|
+
│ ├── neurons.py # LIF, Adaptive LIF, Izhikevich
|
|
255
|
+
│ ├── synapses.py # Dense, Sparse, Delayed
|
|
256
|
+
│ ├── layers.py # LIFLayer, OutputLayer, etc.
|
|
257
|
+
│ └── network.py # SpikingNet (main model class)
|
|
258
|
+
├── encoding/
|
|
259
|
+
│ ├── rate.py # Poisson rate coding
|
|
260
|
+
│ ├── temporal.py # Time-to-first-spike, phase coding
|
|
261
|
+
│ └── population.py # Gaussian tuning, delta/event coding
|
|
262
|
+
├── learning/
|
|
263
|
+
│ ├── stdp.py # STDP, reward-modulated STDP
|
|
264
|
+
│ ├── surrogate.py # Surrogate gradient functions
|
|
265
|
+
│ └── conversion.py # ANN→SNN threshold balancing
|
|
266
|
+
├── backends/
|
|
267
|
+
│ ├── cpu.py # Pure numpy simulation
|
|
268
|
+
│ ├── loihi2.py # Intel Loihi 2 (NxSDK)
|
|
269
|
+
│ └── brainscales.py # BrainScaleS-2 (PyNN)
|
|
270
|
+
├── training/
|
|
271
|
+
│ └── trainer.py # Training loop, loss functions
|
|
272
|
+
└── utils/
|
|
273
|
+
├── metrics.py # Energy, spike metrics, Van Rossum distance
|
|
274
|
+
└── visualization.py # Raster plots, membrane traces, energy bars
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
---
|
|
278
|
+
|
|
279
|
+
## Hardware Access
|
|
280
|
+
|
|
281
|
+
Neither Loihi 2 nor BrainScaleS requires purchase — they're available through research programs:
|
|
282
|
+
|
|
283
|
+
- **Intel Loihi 2**: [Intel Neuromorphic Research Community](https://www.intel.com/content/www/us/en/research/neuromorphic-computing.html)
|
|
284
|
+
- **BrainScaleS-2**: [EBRAINS / Human Brain Project](https://www.ebrains.eu/)
|
|
285
|
+
|
|
286
|
+
Until you get hardware access, the CPU backend gives exact simulation results.
|
|
287
|
+
|
|
288
|
+
---
|
|
289
|
+
|
|
290
|
+
## Roadmap
|
|
291
|
+
|
|
292
|
+
- [ ] GPU-accelerated simulation (CuPy backend)
|
|
293
|
+
- [ ] Innatera T1 chip support
|
|
294
|
+
- [ ] Online/streaming inference API
|
|
295
|
+
- [ ] Quantization-aware training
|
|
296
|
+
- [ ] Multi-chip deployment
|
|
297
|
+
- [ ] Web dashboard for spike visualization
|
|
298
|
+
|
|
299
|
+
---
|
|
300
|
+
|
|
301
|
+
## License
|
|
302
|
+
|
|
303
|
+
MIT License. See LICENSE.
|
|
304
|
+
|
|
305
|
+
---
|
|
306
|
+
|
|
307
|
+
*The brain uses 20 watts. GPT-4 uses 50 megawatts. synaptic_ml bridges that gap.*
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
# synaptic_ml
|
|
2
|
+
|
|
3
|
+
**The TensorFlow for Neuromorphic Computing.**
|
|
4
|
+
|
|
5
|
+
Train spiking neural networks. Deploy to neuromorphic chips. Use 1000× less energy than GPU.
|
|
6
|
+
|
|
7
|
+
```python
|
|
8
|
+
import synaptic_ml as sml
|
|
9
|
+
|
|
10
|
+
# Build a spiking network
|
|
11
|
+
model = sml.SpikingNet([784, 256, 10])
|
|
12
|
+
model.summary()
|
|
13
|
+
|
|
14
|
+
# Train with surrogate gradients (like backprop, but for spikes)
|
|
15
|
+
model.train(X_train, y_train, epochs=10)
|
|
16
|
+
|
|
17
|
+
# Evaluate
|
|
18
|
+
predictions = model.predict(X_test)
|
|
19
|
+
|
|
20
|
+
# See the energy advantage
|
|
21
|
+
print(sml.energy_comparison_table(model))
|
|
22
|
+
|
|
23
|
+
# Deploy to neuromorphic hardware
|
|
24
|
+
model.deploy(target='loihi2') # Intel Loihi 2
|
|
25
|
+
model.deploy(target='brainscales') # BrainScaleS-2
|
|
26
|
+
model.deploy(target='cpu') # CPU simulation (default, always works)
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## Why neuromorphic?
|
|
32
|
+
|
|
33
|
+
| | GPU (A100) | Intel Loihi 2 | Human Brain |
|
|
34
|
+
|--|--|--|--|
|
|
35
|
+
| Power | 300W | 30mW | 20W |
|
|
36
|
+
| Energy/inference | ~1000 nJ | ~0.1 nJ | ~0.001 nJ |
|
|
37
|
+
| Efficiency | baseline | **10,000× better** | **1,000,000× better** |
|
|
38
|
+
|
|
39
|
+
The brain uses 20 watts. GPT-4 uses 50 megawatts. That's a 2.5 million× gap.
|
|
40
|
+
Neuromorphic chips close that gap — and `synaptic_ml` makes them programmable.
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
## Installation
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
pip install synaptic-ml
|
|
48
|
+
# or from source:
|
|
49
|
+
git clone https://github.com/yourusername/synaptic-ml
|
|
50
|
+
pip install -e .
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
**Optional extras:**
|
|
54
|
+
```bash
|
|
55
|
+
pip install synaptic-ml[torch] # PyTorch ANN→SNN conversion
|
|
56
|
+
pip install synaptic-ml[sklearn] # MNIST examples
|
|
57
|
+
pip install synaptic-ml[all] # Everything
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
## Core Concepts
|
|
63
|
+
|
|
64
|
+
### Neuron Models
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
# Leaky Integrate-and-Fire (default, fast, efficient)
|
|
68
|
+
model = sml.SpikingNet([784, 256, 10], neuron='lif')
|
|
69
|
+
|
|
70
|
+
# Adaptive LIF (spike-frequency adaptation)
|
|
71
|
+
model = sml.SpikingNet([784, 256, 10], neuron='adaptive_lif')
|
|
72
|
+
|
|
73
|
+
# Izhikevich (biologically rich: bursting, chattering, fast-spiking)
|
|
74
|
+
model = sml.SpikingNet([784, 256, 10], neuron='izhikevich')
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Spike Encoders
|
|
78
|
+
|
|
79
|
+
```python
|
|
80
|
+
import synaptic_ml as sml
|
|
81
|
+
import numpy as np
|
|
82
|
+
|
|
83
|
+
x = np.random.rand(784) # your data, values in [0, 1]
|
|
84
|
+
|
|
85
|
+
# Rate coding: spike probability ∝ value (most common)
|
|
86
|
+
enc = sml.RateEncoder(time_steps=100, max_rate=100)
|
|
87
|
+
spikes = enc.encode(x) # shape: (100, 784)
|
|
88
|
+
|
|
89
|
+
# Temporal: earlier spike = stronger signal (most energy efficient)
|
|
90
|
+
enc = sml.TemporalEncoder(time_steps=100)
|
|
91
|
+
spikes = enc.encode(x) # at most 1 spike per neuron
|
|
92
|
+
|
|
93
|
+
# Population: Gaussian tuning curves (most biologically realistic)
|
|
94
|
+
enc = sml.PopulationEncoder(n_neurons=10, sigma=0.5)
|
|
95
|
+
spikes = enc.encode(x) # shape: (100, 7840)
|
|
96
|
+
|
|
97
|
+
# Delta: spikes only on change — perfect for IoT/sensors
|
|
98
|
+
enc = sml.DeltaEncoder(threshold=0.05)
|
|
99
|
+
spikes = enc.encode_series(time_series) # event-driven
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### Learning Rules
|
|
103
|
+
|
|
104
|
+
```python
|
|
105
|
+
# Surrogate gradients (recommended) — backprop through spikes
|
|
106
|
+
model.train(X, y, learning_rule='surrogate', learning_rate=0.001)
|
|
107
|
+
|
|
108
|
+
# STDP — unsupervised, no labels needed, biologically inspired
|
|
109
|
+
model.train(X, y, learning_rule='stdp')
|
|
110
|
+
|
|
111
|
+
# Custom trainer
|
|
112
|
+
trainer = sml.Trainer(model, learning_rule='surrogate', learning_rate=0.001)
|
|
113
|
+
trainer.fit(X_train, y_train, epochs=10, validation_split=0.1)
|
|
114
|
+
trainer.evaluate(X_test, y_test)
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### ANN → SNN Conversion
|
|
118
|
+
|
|
119
|
+
Convert your existing PyTorch/Keras models to SNNs in one line:
|
|
120
|
+
|
|
121
|
+
```python
|
|
122
|
+
import torch.nn as nn
|
|
123
|
+
import synaptic_ml as sml
|
|
124
|
+
|
|
125
|
+
# Your existing trained ANN
|
|
126
|
+
ann = nn.Sequential(nn.Linear(784, 256), nn.ReLU(), nn.Linear(256, 10))
|
|
127
|
+
|
|
128
|
+
# Convert to SNN (threshold balancing method)
|
|
129
|
+
snn = sml.convert_from_pytorch(ann, X_calibration, time_steps=100)
|
|
130
|
+
|
|
131
|
+
# Deploy to neuromorphic hardware
|
|
132
|
+
snn.deploy(target='loihi2')
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### Hardware Backends
|
|
136
|
+
|
|
137
|
+
```python
|
|
138
|
+
# CPU simulation — always works, no hardware needed
|
|
139
|
+
backend = model.deploy(target='cpu')
|
|
140
|
+
|
|
141
|
+
# Intel Loihi 2 — requires NxSDK (Intel Research Program)
|
|
142
|
+
# Apply at: intel.com/loihi
|
|
143
|
+
backend = model.deploy(target='loihi2')
|
|
144
|
+
|
|
145
|
+
# BrainScaleS-2 — requires EBRAINS access (Human Brain Project)
|
|
146
|
+
# Apply at: ebrains.eu
|
|
147
|
+
backend = model.deploy(target='brainscales')
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### Energy Analysis
|
|
151
|
+
|
|
152
|
+
```python
|
|
153
|
+
# After running predictions:
|
|
154
|
+
model.predict(X_test)
|
|
155
|
+
|
|
156
|
+
# Detailed energy breakdown
|
|
157
|
+
energy = model.estimate_energy()
|
|
158
|
+
print(f"Ops/inference: {energy['synaptic_ops_per_inference']:,.0f}")
|
|
159
|
+
print(f"Energy/inference: {energy['energy_per_inference_nJ']:.4f} nJ")
|
|
160
|
+
print(f"vs GPU: {energy['efficiency_gain']:.0f}× more efficient")
|
|
161
|
+
|
|
162
|
+
# Full comparison table
|
|
163
|
+
print(sml.energy_comparison_table(model))
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### Save / Load
|
|
167
|
+
|
|
168
|
+
```python
|
|
169
|
+
model.save('my_snn.snm')
|
|
170
|
+
model = sml.SpikingNet.load('my_snn.snm')
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
---
|
|
174
|
+
|
|
175
|
+
## Examples
|
|
176
|
+
|
|
177
|
+
```bash
|
|
178
|
+
# MNIST classification with LIF neurons
|
|
179
|
+
python examples/mnist_lif.py
|
|
180
|
+
|
|
181
|
+
# Unsupervised pattern learning with STDP
|
|
182
|
+
python examples/pattern_recognition.py
|
|
183
|
+
|
|
184
|
+
# IoT anomaly detection with delta encoding
|
|
185
|
+
python examples/edge_sensor.py
|
|
186
|
+
|
|
187
|
+
# Quick self-test
|
|
188
|
+
python -m synaptic_ml
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
---
|
|
192
|
+
|
|
193
|
+
## Architecture
|
|
194
|
+
|
|
195
|
+
```
|
|
196
|
+
synaptic_ml/
|
|
197
|
+
├── core/
|
|
198
|
+
│ ├── neurons.py # LIF, Adaptive LIF, Izhikevich
|
|
199
|
+
│ ├── synapses.py # Dense, Sparse, Delayed
|
|
200
|
+
│ ├── layers.py # LIFLayer, OutputLayer, etc.
|
|
201
|
+
│ └── network.py # SpikingNet (main model class)
|
|
202
|
+
├── encoding/
|
|
203
|
+
│ ├── rate.py # Poisson rate coding
|
|
204
|
+
│ ├── temporal.py # Time-to-first-spike, phase coding
|
|
205
|
+
│ └── population.py # Gaussian tuning, delta/event coding
|
|
206
|
+
├── learning/
|
|
207
|
+
│ ├── stdp.py # STDP, reward-modulated STDP
|
|
208
|
+
│ ├── surrogate.py # Surrogate gradient functions
|
|
209
|
+
│ └── conversion.py # ANN→SNN threshold balancing
|
|
210
|
+
├── backends/
|
|
211
|
+
│ ├── cpu.py # Pure numpy simulation
|
|
212
|
+
│ ├── loihi2.py # Intel Loihi 2 (NxSDK)
|
|
213
|
+
│ └── brainscales.py # BrainScaleS-2 (PyNN)
|
|
214
|
+
├── training/
|
|
215
|
+
│ └── trainer.py # Training loop, loss functions
|
|
216
|
+
└── utils/
|
|
217
|
+
├── metrics.py # Energy, spike metrics, Van Rossum distance
|
|
218
|
+
└── visualization.py # Raster plots, membrane traces, energy bars
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
---
|
|
222
|
+
|
|
223
|
+
## Hardware Access
|
|
224
|
+
|
|
225
|
+
Neither Loihi 2 nor BrainScaleS requires purchase — they're available through research programs:
|
|
226
|
+
|
|
227
|
+
- **Intel Loihi 2**: [Intel Neuromorphic Research Community](https://www.intel.com/content/www/us/en/research/neuromorphic-computing.html)
|
|
228
|
+
- **BrainScaleS-2**: [EBRAINS / Human Brain Project](https://www.ebrains.eu/)
|
|
229
|
+
|
|
230
|
+
Until you get hardware access, the CPU backend gives exact simulation results.
|
|
231
|
+
|
|
232
|
+
---
|
|
233
|
+
|
|
234
|
+
## Roadmap
|
|
235
|
+
|
|
236
|
+
- [ ] GPU-accelerated simulation (CuPy backend)
|
|
237
|
+
- [ ] Innatera T1 chip support
|
|
238
|
+
- [ ] Online/streaming inference API
|
|
239
|
+
- [ ] Quantization-aware training
|
|
240
|
+
- [ ] Multi-chip deployment
|
|
241
|
+
- [ ] Web dashboard for spike visualization
|
|
242
|
+
|
|
243
|
+
---
|
|
244
|
+
|
|
245
|
+
## License
|
|
246
|
+
|
|
247
|
+
MIT License. See LICENSE.
|
|
248
|
+
|
|
249
|
+
---
|
|
250
|
+
|
|
251
|
+
*The brain uses 20 watts. GPT-4 uses 50 megawatts. synaptic_ml bridges that gap.*
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
from setuptools import setup, find_packages
|
|
2
|
+
|
|
3
|
+
with open("README.md", "r", encoding="utf-8") as f:
|
|
4
|
+
long_description = f.read()
|
|
5
|
+
|
|
6
|
+
setup(
|
|
7
|
+
name="synaptic-ml",
|
|
8
|
+
version="0.1.0",
|
|
9
|
+
author="synaptic_ml contributors",
|
|
10
|
+
description="The TensorFlow for neuromorphic computing — high-level SNN framework",
|
|
11
|
+
long_description=long_description,
|
|
12
|
+
long_description_content_type="text/markdown",
|
|
13
|
+
url="https://github.com/HrishikeshRajulu/synaptic-ml",
|
|
14
|
+
packages=find_packages(),
|
|
15
|
+
python_requires=">=3.8",
|
|
16
|
+
install_requires=[
|
|
17
|
+
"numpy>=1.21",
|
|
18
|
+
"scipy>=1.7",
|
|
19
|
+
"matplotlib>=3.4",
|
|
20
|
+
"tqdm>=4.62",
|
|
21
|
+
],
|
|
22
|
+
extras_require={
|
|
23
|
+
"torch": ["torch>=1.9"],
|
|
24
|
+
"loihi": ["nxsdk"],
|
|
25
|
+
"brainscales": ["pynn_brainscales", "hxtorch"],
|
|
26
|
+
"sklearn": ["scikit-learn>=0.24"],
|
|
27
|
+
"dev": [
|
|
28
|
+
"pytest>=6.0",
|
|
29
|
+
"pytest-cov",
|
|
30
|
+
"black",
|
|
31
|
+
"isort",
|
|
32
|
+
"scikit-learn>=0.24",
|
|
33
|
+
],
|
|
34
|
+
"all": [
|
|
35
|
+
"torch>=1.9",
|
|
36
|
+
"scikit-learn>=0.24",
|
|
37
|
+
"tqdm>=4.62",
|
|
38
|
+
],
|
|
39
|
+
},
|
|
40
|
+
classifiers=[
|
|
41
|
+
"Development Status :: 3 - Alpha",
|
|
42
|
+
"Intended Audience :: Science/Research",
|
|
43
|
+
"Intended Audience :: Developers",
|
|
44
|
+
"License :: OSI Approved :: MIT License",
|
|
45
|
+
"Programming Language :: Python :: 3",
|
|
46
|
+
"Programming Language :: Python :: 3.8",
|
|
47
|
+
"Programming Language :: Python :: 3.9",
|
|
48
|
+
"Programming Language :: Python :: 3.10",
|
|
49
|
+
"Programming Language :: Python :: 3.11",
|
|
50
|
+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
51
|
+
"Topic :: Scientific/Engineering :: Bio-Informatics",
|
|
52
|
+
],
|
|
53
|
+
keywords=[
|
|
54
|
+
"neuromorphic", "spiking neural network", "SNN",
|
|
55
|
+
"deep learning", "Loihi", "BrainScaleS",
|
|
56
|
+
"energy efficient AI", "edge computing",
|
|
57
|
+
],
|
|
58
|
+
entry_points={
|
|
59
|
+
"console_scripts": [
|
|
60
|
+
"synaptic-info=synaptic_ml.__main__:main",
|
|
61
|
+
],
|
|
62
|
+
},
|
|
63
|
+
)
|