FlySim — a fruit fly that walks on its connectome and flies on a trained brain

Closed-loop Drosophila simulation: the NeuroMechFly v2 / FlyBody body (MuJoCo), three interchangeable brains — flygym's CPG, a 64-pool rate network distilled from the MaleCNS v1.0 connectome (Janelia/Google, CC-BY), and a pure-NumPy port of the FlyBody flight policy — plus a self-sustaining colony loop: food, energy, olfactory chemotaxis, courtship, eggs, eclosion, starvation.

LIVE  Feed the flies — the real simulator, interactive. Two actual MuJoCo walkers streamed live: click the arena to move their food, they re-orient with the M4-verified chemotaxis, walk over, and feed. Energy drains; starvation is real. Open the live viewer →

1.0airborne fraction — free flight, no tether (5 s run)
8.8 mmmean altitude under a virtual goal
20/20odor chemotaxis reach (vs 10/20 chance, p<1e-6)
20/20feeding reach with the oracle bearing (p<1e-6)
6/6sign-consistent flight steering, |ΔψL−ΔψR| = 45.7 rad
$2.78of $4.70 compute budget spent (38 jobs)

Flight — steered by its brain

Free flight, no tether. The FlyBody paper's trained RL policy (ported to pure NumPy, int8 weights) inside their own dm_control environment; the reference trajectory is replaced by a virtual circuit goal. Mean altitude 8.8 mm, airborne fraction 1.0.
Tethered-flight baseline (honest analog of real fly-lab rigs): hand-tuned wingbeat WPG + PD stabilizer on the composed FlyBody. Measured open-loop lift ceiling: 0.68× body weight — which is exactly why free hover needs the trained policy.

M0: the connectome steers the flight. Lateralized activation of connectome-identified descending neurons (each weighted by its measured projection asymmetry onto the left vs right wing motor pools — DNs project bilaterally, so soma-side masking would be wrong) is read out through the connectome's premotor→wing-MN mapping and drives a dead-reckoning goal integrator. Verified on HF Jobs (3 drives × 3 seeds × 5 s): the heading-change sign matches the drive in 6/6 lateralized runs, straight stays near zero by construction, |ΔψL−ΔψR| > 0.5 rad.

The colony — a self-sustaining ecosystem

Colony arena. A male walker courts a scripted female (the connectome readout steers orient → follow → contact); eggs mature and eclose from a pre-allocated body pool; starvation is the population regulator.
The full loop, verified in one run (M1–M6):
  • Multi-fly physics: explicit inter-fly collision pairs — a head-on meeting deflects (±9.9 mm y-escape), never passes through
  • Food & energy: metabolic drain 0.02/s, patch intake 0.25/s; starvation at exactly E₀/drain = 50.0 s
  • Feeding (M3): 20/20 reach vs 10/20 chance, p<10⁻⁶
  • Olfaction (M4): 20/20 with the antennal gradient alone, p<10⁻⁶ — no oracle
  • Courtship & breeding (M5–M6): mating event → egg at t=10.9 s → eclosion t=40.9 s; parents starve at t=50 s

Interactive trajectory player

Replays of real committed run logs, animated in your browser — open the player (colony 60 s · steered flight). Trails, goals, energy readouts; scrub with the speed slider.

Walking on its connectome

MaleCNS 1.0-driven walk. The 1.1 GB edge list distilled into a recurrent rate network (64 neurotransmitter-signed MN pools + 400 premotor units, NT sign rule: ACh +1, GABA/glu −1, other +0.5). Sustained ~1.4 mm/s.
CPG reference walker. Six coupled oscillators + preprogrammed step trajectories (FlyGym demo controller), +13 mm / 2 s.

Milestone board — every claim has a metric

MCapabilityVerified numberStatus
0Connectome steers flight (DN turn-bias readout → goal integrator) 3 drives × 3 seeds × 5 s on HF Jobs: sign-consistent, |ΔψL−ΔψR|>0.5 rad, RMSE ≤ 1.5× baseline PASS
1Multi-fly arena with fly-fly collision N=3 walkers 60 s finite, min separation 3.27 mm; head-on deflects PASS
1.5/7Live interactive stream MJPEG colony + click-to-feed: clicking moves the food patch (mocap body) and both flies chemotax to it (M4 sensing); verified end-to-end in-container PASS
2Food & energy substrate death at exactly E₀/drain (50.0 s); patch recovery to cap PASS
3Feeding FSM (oracle bearing) 20/20 vs 10/20 chance, one-sided binomial p<10⁻⁶ PASS
4Sensing in the loop (antennal gradient, no oracle) 20/20 vs 10/20, p<10⁻⁶; odor-zeroed ablation = chance PASS
5Courtship (male connectome × scripted female) orient→follow→contact→mated (egg); courtship-ablation = no mating PASS
6Population loop egg t=10.9 s → eclosion t=40.9 s; starvation regulates; carrying capacity by allocation PASS
8Release (CI, README, attribution, ledger) ruff clean, 5 tests passing, every artifact committed PASS

The live stream renders through a raw mujoco.Renderer (flygym's Renderer EGL path fails in job containers; the identical raw stack works).

Cost ledger — every job, success or failure

TagModeHoursEst. costNote

Rendered from data/site.json (built by flysim/site.py from the append-only ledger at output/job_ledger.jsonl) — dedup rule: one row per job tag, keeping the max estimate. Every killed launch and stale job is logged honestly.

Run it yourself

python run_sim.py --mode connectome — walk on the connectome
python -m flysim.brain_sim --ref-mode connectome --drive left — steered free flight
python -m flysim.arena --duration 60 --n 3 — multi-fly colony with collisions
python -m flysim.m3 --trials 20 — the feeding experiment
python -m flysim.population — the whole loop: courtship, egg, eclosion, starvation
python -m flysim.jobs --live --ref-mode circuit — watch the fly fly live (HF Job)

Artifacts: epoch14/fly-sim-runs · full state report in REPORT.md · every gotcha in AGENTS.md · ownership in ATTRIBUTION.md

Interactive fly, in your browser (client-side, no server)

More: pose viewer · NeuroMechFly Live slalom game

Credits