Minimal Python tutorial for perturbation testing using RNN and spiking RNN. to predict the effect of optogenetic stimulation of PV inhibitory neurons. It is a minimal reproduction of the results from Sourmpis et al., eLife 2026 (https://elifesciences.org/articles/106827).
We use data from the Allen institute Neuropixels dataset (see Siegle et al. 2021: https://www.nature.com/articles/s41586-020-03171-x). We use session 829720705 (Pvalb-Cre × Ai32, functional_connectivity) which includes optogenetic stimulation of PV neurons with simultaneous Neuropixels recordings.
Install uv, then sync the environment:
uv syncThis works everywhere (macOS, CPU-only PCs, etc.) and runs on CPU — or the Metal GPU on Apple Silicon. If you have an NVIDIA GPU, add the CUDA wheel:
uv sync --extra cu126uv run python train_rnn.pyWe recommend trying the sign-constrained leaky integrate-and-fire model:
uv run python train_rnn.py
uv run python train_rnn.py --model lif
uv run python train_rnn.py --sign-constrained
uv run python train_rnn.py --sign-constrained --model lifExample test-set rasters after training (data vs. model, excitatory units only):
Without optogenetic perturbation:
With PV-opto perturbation (the model's inhibitory units are driven by the same
i(t) as the recordings):

