BatchSNN is a Python library inspired by BindsNET but designed for biological realism, batch simulation, and pharmacological modeling.
It enables efficient simulation of multiple spiking networks in parallel, sharing the same synaptic weights while evolving independently in time, allowing stable and accelerated training of spiking neural networks (SNNs).
-
Biologically grounded neurons and synapses
Time constants, conductances, and dynamics consistent with cortical physiology. -
Batch evolution of parallel SNNs
Multiple independent networks evolve simultaneously, sharing one global set of synaptic weights.
STDP updates are combined across batches using configurable reduction functions. -
Flexible connectivity schemes
Supports spatial organization, distance-dependent delays, and probabilistic connections. -
Neuromodulation and pharmacology
Dopamine-modulated STDP at Exc→Motor synapses, enabling reward-based learning and pharmacological exploration (e.g. lesions, coma, zolpidem). -
Optimized performance
GPU-accelerated computation and biologically inspired weight normalization optimizers.
Each simulation contains:
- A Global Neuronal Workspace (GNW) composed of excitatory and inhibitory populations.
- Excitatory neurons (Exc): undergo plasticity and may project to motor units.
- Inhibitory neurons (Int): regulate Exc dynamics via lateral and local inhibition.
The parameter ratio defines the fraction of excitatory neurons:
N_exc = N * ratio, N_inh = N * (1 - ratio).
For experiments involving modular architectures (e.g., digit-like columns), you can specify:
n_digits: number of cortical columns (or modules).column_size: number of neurons per column.
The total number of neurons is thenN = n_digits × column_size.
The image below is extracted from the example_09.ipynb notebook, and shows the distribution of neurones when n_digits = 4, N = 120, ratio = 0.8.
When batch_size > 1, BatchSNN simulates several identical networks in parallel:
- Each network receives independent inputs and has independent membrane potentials.
- All networks share the same synaptic weights.
- STDP updates from each network are combined using a reduction function (e.g.
sum_reduction_fn,mean_reduction_fn, etc.). - The flag
unique_samples=Trueensures that each batch network receives a distinct input pattern.
This approach allows faster, more stable and more reproducible learning.
| Type | Description |
|---|---|
"all_to_all" |
Fully connected across all populations. |
"all_to_all_except_Exc" |
All-to-all except between Exc1 and Exc2 groups. |
"all_to_all_sparse" |
Randomly pruned connections preserving type ratios. |
"all_to_all_sparse_dist" |
Sparse connections with distance-dependent probabilities: (p = exp(-dist_scale * dist / dist.max())). |
Additional parameters:
connection_ratio: fraction of existing connections (for sparse topologies).connection_dist_scale: scales the exponential distance-dependence of connectivity.implement_delay: enables biologically realistic synaptic transmission delays.
The image below is extracted from the example_07.ipynb notebook and shows the connectivity graph in the network when the parameters are the following: connection = "all_to_all_sparse_dist", connection_ratio = 0.2, connection_ratio, connection_dist_scale = 10.

| Optimizer | Description |
|---|---|
"connectivity_normalization" |
Normalizes total connectivity strength to maintain homeostasis. |
"connectivity_distance_normalization" |
Same as above, but scaled by inter-neuron distance (using optim_lambda_distance and optim_scale_factor). |
The distance-based optimizer uses:
optim_lambda_distance: controls how strongly distance affects normalization.optim_scale_factor: scales the global normalization effect.
Below is a simple example that shows the stability and convergence speed brought by the optimizer. The first image was extracted from example_01.ipynb, in which no optimizer was used. The network's learning remains pretty stable because the batch size is equal to 1. The second image shows the results from the same simulation with the only difference being the use of the optimizer "connectivity_normalization".
2- optimizer = "connectivity_normalization":

BatchSNN can simulate focal or global lesions during runtime:
lesion_parameters = {
"lesion_time": 4000, # time (ms) when lesion occurs
"lesion_population": ["Int"], # affected populations
"lesion_nr_neurons": [10], # number of neurons to silence
"local_lesion": False # True = spatially localized lesion
}With the parameters above, the resulting lesion appears as:
When learn_dopa=True, dopamine-modulated STDP is enabled for Exc→Motor connections.
This allows reward-based learning or pharmacological simulation (e.g., zolpidem effects).
The GNW connections remain standard STDP (no dopamine).
An experimental exploration mechanism allows dormant synapses to explore higher weights when no dopamine activity has been detected for long periods.
Defined in utils/reductions.py.
sum_reduction_fn is the most stable and is used by default.
plot_batch_indices: list of batch indices to visualize (e.g.[0, 2]) for the final raster plot.save_pickles=True: saves simulation data (spikes,weights, etc.) as.picklefiles insave_path.show_figures,save_figures, andsave_pathcontrol output visualization and storage.
Here is an example of a raster plot, extracted from example_10_2.ipynb.

Several example notebooks are included in the example_notebooks directory to demonstrate how network epigenesis evolves depending on key parameters such as:
- Simulation duration (
time) - Timestep (
dt) - Batch size (
batch_size) - Connectivity pattern (
connection) - Optimizer type (
optimizer) - Lesion conditions (
lesion_parameters) - etc.
You can design experiments in the main.py module. Some default experiments are provided. They generate the necessary data to run the notebooks analyze_results_Exp<i>.ipynb in the result_analysis_notebooks directory. If you want to run these experiments, uncomment them at the end of the main.py module. To run the simulation, type:
python main.py
Typical parameters include time, dt, batch_size, and network configuration (N, ratio, connection, optimizer, etc.).
All simulation parameters can be adjusted in the run_network() call inside main.py.
For running on the Narval supercomputer, do not forget to set
--accountand--mail-userwhen callingrun_narval.sh.
Follow these steps to set up the project:
- Clone the repository in your local working repository:
git clone https://github.com/antoinecautru/Epigenesis_pytorch_miniBinsnet.git
-
Download Python 3.9.2 from the official Python website.
-
Open Git PowerShell in the project directory (
Epigenesis_pytorch_miniBinsnet/folder) -
Create a virtual environment called
venv:
<path_to_python3.9.2>/python.exe -m venv venv
Note: The name of the virtual environment is important, as it is included in the
.gitignorefile and in .bash files you will run later.
- Activate the virtual environment:
- On Windows:
.\venv\Scripts\Activate- On Linux/macOS:
source venv/bin/activate- Install the project dependencies:
pip install -r requirements.txt
If issues arise during installation, please manually install the following libraries:
- numpy
- pytorch
- matplotlib
- notebook
- tqdm
- Brian2
- Add neuromodulators beyond dopamine (e.g. serotonin, acetylcholine).
- Integrate exploratory plasticity mechanisms.



