# flybrain — a living fruit fly brain farm Three simulated fruit flies — **F1, F2 (male)** and **F3 (female)** — each running a piece of the *real* male Drosophila connectome, flying around a 3D arena and **talking to each other through airborne odor plumes**. Built on the [complete male fruit fly connectome](https://research.google/blog/a-connectomics-milestone-mapping-the-complete-male-fruit-fly-brain/) mapped by Google Research & HHMI Janelia (~166k neurons, ~125M synapses, [Cell](https://www.cell.com/), 2026). Each brain runs the olfactory pathway + mushroom body + central complex + VNC T1–T3 subnetwork plus the neurons that feed the AL/MB most strongly (24,029 neurons, 4.03M connections, the real wiring from the public Janelia release) as a leaky integrate-and-fire network. There is no complete *female* connectome available for download, so F3 is a male-cns brain with a **sex-dimorphic parameter set** (stronger pheromone release, different response tuning) — identical wiring, dimorphic behavior. ``` Janelia male-cns:v1.0 (public GCS) body-annotations / neurotransmitters / connectome-weights │ scripts/build_subnetwork.py ▼ ┌───────── Subnetwork (24k neurons, 4M edges) ───────────┐ │ F1 (male) F2 (male) F3 ("female") │ │ LIF engine LIF engine LIF engine (Numba) │ │ odor drives ──────────────────────── motor outputs │ ▼ │ │ ┌──────────────────── 3D arena 1m box, 32³ ─────────┐ │ │ 3 odorant channels (male / female / food pheromone)│ │ │ diffusion + updraft advection + decay │ │ │ flies fly on brain motor output, emit scent │◄───────────┘ └────────────────────────────────────────────────────┘ │ snapshots 10 Hz ▼ FastAPI + WebSocket ──► Three.js web UI http://localhost:8321 ``` ## Run First-time: put these public Janelia male-cns:v1.0 files in `data/cache/male-cns/` (from `gs://flyem-male-cns/v1.0/connectome-data/flat-connectome/`; the build script reads them, it does not download): | cache file | source file | size | |---|---|---| | `body-annotations.feather` | `body-annotations-male-cns-v1.0-minconf-0.5.feather` | 14 MB | | `body-neurotransmitters.feather` | `body-neurotransmitters-male-cns-v1.0.feather` | 43 MB | | `connectome-weights.feather` | `connectome-weights-male-cns-v1.0-minconf-0.5.feather` | 1.05 GB | | `syn-partners-significant.feather` | `syn-partners-male-cns-v1.0-minconf-0.5-significant-only.feather` | 2.97 GB | The last one is optional but strongly recommended: without it every synaptic contact counts as spike-driving (no dendrite/axon split), and the engine's calibration no longer holds. ```bash uv sync uv run python scripts/build_subnetwork.py # one-time, ~30 s, builds data/subnetwork/ uv run python scripts/run_farm.py # sim + web UI (rebuilds subnetwork if missing) uv run python scripts/calibrate_engine.py # only after changing the engine or data (~6 min) ``` Then open **http://localhost:8321**. ### Controls | Control | Effect | |---|---| | pause / resume | freeze the farm | | speed slider | 0.1× to 20× real time (log scale) | | banana / place banana… | drop a banana slice on the floor at a random spot, or click the floor to place it | | odor puff | a brief puff of banana odor with no food behind it | | brain | show/hide the brain panel: the viewed fly's 24k neurons at their real positions, flashing as they fire, plus a 15 s region-activity strip. Pick a fly with the tabs or by clicking its name; a ring marks it in the arena. | | kill (per fly) / reset | a killed fly falls grey and stops emitting; reset restores everyone | ### What you should see - Three fruit flies with beating wings, banking into turns and casting soft shadows; the female's abdomen is longer, the males' have a dark tip. Motion is interpolated between the sim's 10 Hz snapshots. - Each fly trails a pheromone plume (blue male, pink female). Flies sense the other sex's scent strongly and their own sex's weakly (habituated). - Drop a banana: it scents the air (a plume rising on the updraft). Hungry flies pick up the plume, surge and dive down it, see the slice at close range, land, and eat in bouts (proboscis out) with pauses; once full they take off and ignore food until hungry again. The slice shrinks as it is eaten and disappears when finished. Fly cards show hunger (orange bar) and landing / eating / on food / taking off. - Flies near a food odor puff turn toward it (VM5/VM6/VM7/DM1 food-ORN pathway) and switch into odor search: the fly card shows **surge** (odor encounter: fast, slowing near the source, turning toward the stronger side and back if the odor fades) and then **cast** (widening zigzag for 3 s after losing the plume). - Identical wiring, different per-fly synapse draws: each fly has its own personality. ## How the brain works - **Neurons:** leaky integrate-and-fire after Shiu et al. 2024 (7 mV threshold, 20 ms membrane, 5 ms synapses, 0.275 mV per synaptic contact). Signs come from predicted neurotransmitters (ACh excitatory, GABA and glutamate inhibitory). - **Dendrites vs axons:** only contacts onto a neuron's input-enriched brain regions drive spikes (from per-synapse locations). Axo-axonal contacts, such as KC→KC in the mushroom-body lobes, act presynaptically in a real neuron, and a point model that counts them runs away. - **Stability:** APL is graded (it doesn't spike in the fly). Spike-frequency adaptation and short-term synaptic depression stop recurrent loops from locking on after an odor. - **Fitted parameters:** only 20 gains, on each cell class's excitatory and inhibitory input, fit to published firing rates across 5 simulated flies and checked on 8 held-out ones (`scripts/calibrate_engine.py`, `src/flybrain/engine/calibration.json`). - **Steering:** each antenna drives the ORNs on its nerve-root side. The brain compares evoked projection-neuron activity between the left and right antennal lobes (the wiring is ~2:1 ipsilateral) and turns toward the stronger side. - **Odor search:** an encounter (PN activity rising above its own adapting baseline for 80 ms, ignoring spontaneous AL bursts that recruit >15% of PNs) starts a surge; losing the odor starts casting. This motor program stands in for lateral-horn and descending circuits the subnetwork lacks; its trigger is the brain's own activity. - **Pheromone valence:** male scent reaches only VA1a (cVA), female scent only VA1m. Each fly's approach readout ignores PNs fed by its own sex's glomerulus (derived from wiring; for cVA it finds DA1, the known cVA glomerulus), so a male surges to female scent but not to male scent, and vice versa. ## Layout ``` src/flybrain/ types.py frozen shared contract (time, channels, regions, messages) data/ subnetwork builder + loader (feathers → CSR-ready arrays) engine/ Numba LIF network, odor drives, motor/release outputs env/ arena: odor PDE, kinematics, sensory tuning, stimulus bus server/ FastAPI + WebSocket app web/ Three.js UI (no build step) scripts/ build_subnetwork.py, run_farm.py data/cache/ downloaded Janelia feathers (gitignored) data/subnetwork/ prebuilt simulation artifact (gitignored) docs/CONTRACTS.md the interface contracts ``` ## Tests ```bash uv run pytest ``` ## Notes & limitations - Synaptic neurotransmitter signs are annotated by Janelia's per-neuron consensus; unannotated ones are modeled as excitatory. - More ORNs are side-typed on the right than the left in the annotations; ORN rates are rebalanced per side and odor group so the model fly is symmetric. - Local interneurons fire below their literature rates (raising them re-ignites antennal-lobe reverberation), and evoked PN rates peak around 30 Hz rather than 60. - Opposite-sex attraction is not demonstrated. Valence is right (males surge to female scent only, and vice versa) and pheromones last 1.5 s, but over 8 runs of 3 min male-female time within 0.2 units is 4.1% with the search program vs 3.6% without, and male-male ~5% either way. An earlier result (3.4% vs 1.7%) depended on a movement bug (idle drift applied on top of the brain's motion), fixed 2026-09-18. - Food search: flies spend 48% more time in the odor than with the search program switched off, and closest approach improves from 0.12 to 0.09 units. - Feeding is a behavioural program: the subnetwork has no taste neurons. The last few centimetres of the approach use a visual stand-in (odor-gated attraction to the food object), since there is no visual system. Brain- driven search still matters: 3.8 landings per 3 min run vs 2.2 with the brain's search switched off, first landing ~21 s vs ~40 s. - There is no path from the odor pathway to the VNC in this subnetwork, so VNC activity is ~0 and motor commands are read out from the brain directly. - The "female" fly is male wiring with female-tuned parameters — a stand-in until a female connectome becomes downloadable (the female map exists in the Janelia pipeline but is not in the public release yet). - Not a research tool: dynamics are tuned for *plausible, stable, interesting* collective behavior, not quantitative neurophysiology.