Talk to 138,000 neurons. Ask a fly to walk, taste sugar, or run for its life.
A whole-brain computational model of the adult Drosophila melanogaster (fruit fly), built on the FlyWire connectome (~138k neurons, ~5M synapses). Translates natural language into neural stimulations, runs a leaky integrate-and-fire (LIF) simulation across the entire brain, and describes what the fly would do.
Based on Shiu et al. (2023) โ "A leaky integrate-and-fire computational model based on the connectome of the entire adult Drosophila brain reveals insights into sensorimotor processing".
| Stimulus | What Happens |
|---|---|
| ๐ฌ Sweet taste | Fly extends proboscis โ feeding |
| ๐ Bitter taste | Fly retracts โ rejection |
| ๐ฆถ Walk forward | Coordinated leg movement |
| ๐ Walk backward | Moonwalker retreat |
| ๐ Escape | Giant fiber activation โ emergency takeoff |
| ๐งน Groom | Antenna cleaning with front legs |
| ๐ Looming shadow | Visual threat โ triggers escape |
| ๐ Sound | Auditory processing via Johnston's organ |
| ๐ Danger smell | Olfactory avoidance (geosmin detection) |
Combine them: Walk + looming shadow, sweet + bitter (watch the fly get confused)
Learning: The fly has a mushroom body with dopamine-modulated plasticity. Punish it (โก electric shock) or reward it (๐ฐ) and it remembers!
git clone https://github.com/lixiang1076/fly-brain.git
cd fly-brain๐ก Large data files (~200 MB) are stored with Git LFS. Make sure you have
git-lfsinstalled. If data files appear as small pointer files, rungit lfs pull.
conda env create -f environment.yml
conda activate brain-flyInteractive mode (recommended):
python fly_chat.pyThen type in Chinese or English:
๐ชฐ > ็ปๆ่ๅฐ็็
๐ฌ ็่งฃ: ็ปๆ่ๅฐ็็
ๅผๅงไปฟ็ 13.8ไธไธช็ฅ็ปๅ
...
==================================================
๐ชฐ ๆ่ๅคง่ไปฟ็ๅฎๆ๏ผ
ไปฟ็ๆถ้ฟ: 0.1็ง
ๆดป่ท็ฅ็ปๅ
: 324/138639
ๆป่ๅฒๆฐ: 1571
==================================================
๐ง ๆ่็ๅๅบ:
๐
ๆ่ไผธๅบไบๅฃๅจ๏ผproboscis๏ผ๏ผๅฎๅจ็งฏๆ่ฟ้ฃ๏ผ็่ตทๆฅๅพไบซๅใ
๐ ๅ
ณ้ฎ่พๅบ็ฅ็ปๅ
ๆดปๅจ:
MN9_left 80.0 Hz โโโโโโโโโโโโโโโโ (ๅฃๅจ่ฟๅจ (่ฟ้ฃ))
MN9_right 60.0 Hz โโโโโโโโโโโโ (ๅฃๅจ่ฟๅจ (่ฟ้ฃ))
Command-line mode (JSON output):
# Single stimulus
python chat_with_fly.py --stim taste_sweet --duration 0.1 --pretty
# Combo: walking + visual threat
python chat_with_fly.py --stim walk_forward,vision_looming --freq 100,200 --duration 0.1 --pretty
# Silence a sense (blind the fly, then make it walk)
python chat_with_fly.py --stim walk_forward --silence vision_looming --duration 0.1 --pretty
# Stimulate by neuron ID directly
python chat_with_fly.py --neuron-ids 720575940622838154,720575940632499757 --freq 200 --duration 0.1 --prettyThe fly has a mushroom body โ the insect equivalent of associative memory. It supports dopamine-modulated learning:
๐ชฐ > ็ปๆ่ๅฐ็็ โ present a stimulus
๐ชฐ > ็ตๅป โ punish! (PPL1 dopamine neurons fire)
โก ๆ่ๅญฆไผไบ๏ผไธๆฌก็ๅบๆฟ = ๅฑ้ฉ๏ผ
๐ชฐ > ็ปๆ่ๅฐ็็ โ same stimulus again
๐ง ๆ่่ฎฐๅพ่ฟไธชๆฐๅณๆฏๅฑ้ฉ็๏ผๅผบ็ๅ้ฟๅๅบ โ learned avoidance!
๐ชฐ > ่ฎฐๅฟ โ check what the fly has learned
๐ชฐ > ๅคฑๅฟ โ wipe its memory (amnesia)
This mirrors real fly learning: Kenyon Cells (KC) encode stimulus identity, Dopamine Neurons (DAN) carry reward/punishment signals, and KCโMBON synaptic weights are modified accordingly.
- 4,133 Kenyon Cells (KCฮณ + KCฮฑฮฒ)
- 96 Mushroom Body Output Neurons (MBON)
- 307 PAM dopamine neurons (reward)
- 24 PPL1 dopamine neurons (punishment)
fly-brain/
โโโ fly_chat.py # ๐ฎ Interactive chat interface (start here!)
โโโ chat_with_fly.py # ๐ง CLI simulation wrapper (JSON output)
โโโ dopamine_learning.py # ๐ง Mushroom body learning (KCโMBON plasticity)
โโโ fast_learning.py # โก Fast post-hoc learning (no recompile needed)
โโโ neuron_atlas.json # ๐บ๏ธ Stimulusโneuron mappings & output definitions
โโโ main.py # ๐ Multi-framework benchmark runner
โโโ environment.yml # ๐ฆ Conda environment
โโโ code/
โ โโโ benchmark.py # Benchmark orchestrator
โ โโโ paper-phil-drosophila/
โ โ โโโ model.py # Core LIF model (Brian2)
โ โ โโโ utils.py # Analysis utilities
โ โ โโโ example.ipynb # Tutorial notebook
โ โ โโโ figures.ipynb # Reproduce paper figures
โ โโโ run_brian2_cuda.py # Brian2/Brian2CUDA runner
โ โโโ run_pytorch.py # PyTorch runner
โ โโโ run_nestgpu.py # NEST GPU runner
โโโ data/
โ โโโ 2025_Completeness_783.csv # Neuron list (FlyWire v783, LFS)
โ โโโ 2025_Connectivity_783.parquet # Synapse connectivity (LFS)
โ โโโ mushroom_body_neurons.json # MB neuron IDs
โ โโโ flywire_annotations.tsv # Neuron annotations (LFS)
โ โโโ archive/ # Legacy v630 data (LFS)
โโโ scripts/
โโโ download_data.py # Verify data files
โโโ setup_WSL_CUDA.sh # WSL2 + CUDA setup guide
The same LIF model runs on four simulation backends:
| Framework | Backend | Notes |
|---|---|---|
| Brian2 | C++ standalone (CPU) | Reference implementation |
| Brian2CUDA | CUDA (GPU) | GPU-accelerated Brian2 |
| PyTorch | CUDA (GPU) | Sparse tensor operations |
| NEST GPU | CUDA (custom kernel) | Requires separate build |
python main.py --pytorch --t_run 1 --n_run 1 # single backend
python main.py # all backends, all durationsFlyWire connectome v783 (public release). Stored via Git LFS.
| File | Description | Size |
|---|---|---|
2025_Completeness_783.csv |
138,639 neuron IDs + metadata | 3.3 MB |
2025_Connectivity_783.parquet |
~5M synaptic connections + weights | 96 MB |
mushroom_body_neurons.json |
4,133 KC + 96 MBON + 331 DAN neuron IDs | 120 KB |
flywire_annotations.tsv |
Neuron type annotations | 31 MB |
archive/ |
Legacy v630 data (for paper figure reproduction) | 86 MB |
- Minimum: Python 3.10+, 8 GB RAM (Brian2 CPU backend)
- Recommended: NVIDIA GPU with CUDA 12.x (for PyTorch / Brian2CUDA backends)
- First simulation takes ~60โ90s (Brian2 C++ compilation); subsequent runs reuse the compiled model
- Input โ specify neurons to stimulate (natural language, stimulus keys, or FlyWire IDs)
- Mapping โ
neuron_atlas.jsonresolves stimuli to specific FlyWire neuron IDs - Simulation โ Brian2 runs a LIF simulation across all 138,639 neurons with 0.1ms timestep
- Analysis โ output neuron firing rates โ behavioral predictions
- Learning โ mushroom body KCโMBON weights modified by dopamine signals
Neuron model parameters from Kakaria & de Bivort (2017):
| Parameter | Value |
|---|---|
| Resting potential | โ52 mV |
| Spike threshold | โ45 mV |
| Membrane time constant | 20 ms |
| Synaptic time constant | 5 ms |
| Refractory period | 2.2 ms |
| Synaptic delay | 1.8 ms |
If you use this code, please cite:
@article{shiu2023lif,
title={A leaky integrate-and-fire computational model based on the connectome
of the entire adult Drosophila brain reveals insights into sensorimotor processing},
author={Shiu, Philip K and others},
journal={bioRxiv},
year={2023},
doi={10.1101/2023.05.02.539144}
}MIT License. See LICENSE for details.
The FlyWire connectome data is subject to the FlyWire Terms of Use.