fly-api · demo fly-connectome-demo · 2026-09-08

Waking the Fly Brain

A fruit fly's complete wiring diagram — all 139,255 neurons and 50 million synapses of the FlyWire connectome — now runs as a working nervous system on one CPU box. This page is the record of getting it to taste, walk, and see — standing on published models we reproduced and integrated (what's ours vs. prior art) — and the opening move of fly-api: an SDK for deploying and training the fly architecture in realistic simulation.

139,255
neurons, all of them
50M+
mapped synapses
0
training steps needed
93%
bitter veto of the feeding command
100%
visual target kept in view
99%
learned suppression of the rewarded odor

The brain, tasting

We ran the entire connectome as leaky integrate-and-fire neurons (Shiu et al. 2024's model): each connection's weight is its synapse count, its sign the predicted neurotransmitter. Then we stimulated the fly's sugar-sensing gustatory neurons and read out MN9 — the motor neuron that extends the proboscis to eat.

Line chart: MN9 firing rate rises monotonically from 0 to 92 Hz as sugar GRN stimulation increases from 25 to 200 Hz
The wiring alone computes a dose–response. MN9 output rises monotonically — 0, 18, 68, 82, 92 Hz — as sugar-neuron drive climbs from 25 to 200 Hz. Ten trials per point, no parameter tuning, no training.
Bar chart: at 150 Hz drive, sugar yields 82 Hz MN9 firing, water 5.6, bitter 0, sugar plus bitter 5.8
And it knows what it's tasting. At matched 150 Hz drive: sugar 82 Hz, water 5.6, bitter 0 — and bitter layered on sugar collapses the feeding command to 5.8 Hz. The veto circuit is anatomy, not learning.
input (150 Hz)MN9 "eat" commandreading
sugar neurons82.0 Hzfeed
water neurons5.6 Hzfaint interest
bitter neurons0.0 Hzrefuse
sugar + bitter5.8 Hz93% veto

The body, walking

Anatomically detailed motor control. NeuroMechFly's MuJoCo fly — real limb geometry, 42 actuated leg degrees of freedom, tarsal adhesion — driven by a CPG-plus-reflexes controller: straight walking, then a commanded left and right turn. 16.1 mm covered in 1.5 s of simulated time; shown at 0.1× speed.

The fly, seeing

Closed-loop vision, fly's-eye view. The fly chases a moving sphere steering only from its 721-ommatidia retina readings — the hexagonal insets are what each eye actually sees, and the dark blob is the target. Azimuthal position on each retina maps to descending steering drives; the object stays in view for 100% of decision steps, mean deviation 0.25. Shown at 0.5× speed.

The brain, learning

Can it learn? We added the fly's actual learning rule — dopamine-gated depression at Kenyon-cell→MBON synapses — to the connectome's olfactory pathway and ran classical conditioning: odor A paired with a reward signal, odor B unpaired. Getting a stable substrate first required a real finding: the published whole-brain model is bistable — almost any central input ignites a permanent ~8,400-neuron storm — and four structural edits (each biologically argued, no parameter tuning) kill it.

Wondering how a static wiring diagram can learn at all — where the memory lives, how the weights update, and which parts are established biology vs. our modeling assumptions? That deserves its own page: How the fly learns, the mechanism explainer with circuit schematics and the evidence trail.

Line chart: MBON response to the paired odor falls from about 4000 spikes to near zero across five training pairings in three seeds, while the unpaired control odor stays flat
The brain learns the association. Across five odor–reward pairings the paired odor's MBON output collapses 99–100% (three seeds shown); the unpaired control odor is untouched. Post-training discrimination is ~100:1.
Line chart: synaptic memory trace decays smoothly as probe odors share fewer input channels with the trained odor, in both gained and parameter-free readouts
And the memory generalizes. Probe odors sharing 67/50/33/0% of the trained odor's receptor channels inherit proportionally graded suppression — the signature of real fly generalization — measured here as the synaptic memory trace, which needs no readout tuning (green). Full method, caveats, and the bistability audit trail in the learning report.

The loop, closed: navigating to the learned odor

The finale ties everything together: the conditioned spiking brain is put in the loop with the body. Two odor sources sit in the arena — amber A (paired with reward during conditioning) and grey B (control). Every decision step, each antenna's local odor mixture is fed to the live 8,991-neuron brain, and its MBON output steers the walk. Same fly, same arena, same controller — only the KC→MBON synapses differ:

Left: naive brain — no preference, walks between and past both sources. Right: trained brain — turns toward and reaches the rewarded odor (1.3 mm final distance, 8 decisions). 0.5× speed. Note: this is pure chemotaxis — the fly's vision is off, and the spheres are markers for the viewer, not stimuli the fly can sense.
Top-down trajectories: naive path goes straight past both sources; trained path curves directly to the rewarded source
Trajectories of the two rollouts. Steering polarity and gain are engineered glue; the learned valence signal comes from the conditioned brain, live, every sniff — details and honest caveats in the navigation report.

How the demo worked

Two open stacks, one afternoon of glue. The brain is Shiu et al.'s Brian2 model over FlyWire v630 — 8 stimulation conditions × 10 trials ran in ~19 minutes on 8 cores at ~2.5 GB per worker. The body is flygym 1.2.1 in MuJoCo, rendered headlessly on a GPU-less box by extracting libosmesa6 from the Ubuntu package into a local prefix (no sudo required). Every number and video regenerates from demo/ in the repo.

Upstream findings. Two flygym 1.2.1 bugs surfaced and are patched in this repo's vendored copies: the vision examples package hard-imports torch+flyvis that the simple taxis demo never uses, and VisualTaxis accepts an arena argument it silently fails to hand to the simulation (the camera then binds to an arena that was never compiled).

Read of the result

The claim these demos support is narrow but real: both foundation layers — whole-brain connectome dynamics and embodied simulation — run cheaply on commodity CPU, and the connectome's graph alone already computes correct sensorimotor behavior at the circuit level. What they don't yet show is the loop closed between them: the LIF brain emits motor commands and the body consumes descending drives, but nothing wires one to the other yet. Honest caveats: synapse counts are a crude weight proxy, neurotransmitter signs are predictions, and gap junctions and neuromodulation aren't in the wiring diagram at all.

Next

Explore