Project 01PlayPython · panda3d · PyTorch (MPS)

FlyWorld: a garden arena where the flies have real wiring

Six small flies, each running a sub-circuit of the MaleCNS connectome as a spiking network. One big fly you drive with the arrow keys. A timer, four fruit patches, and a single rule: get them to eat. Their escape and feeding are the circuit's own behaviour, measured in calibration, not scripted.

Neurons per small fly

10,203 (sub-circuit) or 165,122 (whole CNS, press W)

Synaptic edges

401,680 with ≥ 5 synapses

Model

Leaky integrate-and-fire, 1 ms steps, event-driven

Speed

≈ 2,500 steps/s for six brains on Apple MPS
The FlyWorld garden: a lawn with flowers, a picket fence, fruit patches, six named small flies, the big white fly Nick in front, and a live neuron panel on each side

3D chase camera. Left: every neuron group of the selected fly with its firing rate. Right: one LED row per fly, and a 200 ms spike raster of the selected fly.

The brain, in your browser

This is the same circuit the small flies run on, ported from the game's brain.py and decoder.py to JavaScript and stepped on one thread of your browser. Stimulate a group and watch what reaches the descending neurons; silence one and watch a behaviour disappear. The little fly on the right moves according to the decoded descending-neuron output, exactly as the game decodes it.

loading 2.5 MB of synapses…
sensoryinterneuronsdescending → motor
stilldecoded body
v 0.00 u/s · ω 0°/s
…

neuron groupsn · Hz · stim / silence

    spikesper group, last 200 ms

    Things to try

    • Loom left. An object approaches from the front-left over 0.6 s. LC4/LPLC2/LC16/LC6 fire, the giant fiber DNp01 spikes within about 9 ms, and the decoder calls a jump away from the threat.
    • Stimulate DNp09. Forward walking at about 100 Hz. Notice DNa02_L fires too: a walk-coupled asymmetry the circuit produces, which calibration measures and the decoder removes.
    • Stimulate DNp09, then silence DNa02. The fly still walks but can no longer steer.
    • Food odour, then On food. Odour (ORN_DM1) drives the proboscis motor neuron MN9 and suppresses walking; standing on food (LB3c) adds taste. In the game this is why a fly stops on a patch and eats.
    • MDN. Backward walking. DNg11. Grooming, with hysteresis.

    Playing the desktop game

    Shepherd mode: get the six flies to eat all four fruit patches (20 units of food) before the three-minute timer runs out. You have two tools, both of which go through the flies' real circuits.

    1. Loom at them. Walk the big fly at a small fly. Its looming detectors fire the giant fiber and it jumps away. Approach from the side opposite the food to push it there.
    2. Drive their brains. Select a fly, put the cursor on DNp09 and press S: it walks forward. DNa02 left or right makes it turn. MDN backs it up.

    Within about two units of food, odour shuts down walking and drives MN9, so the fly stops on the patch and eats. That stop-when-you-smell-food behaviour is the circuit's own.

    ←→↑↓drive the big fly Tabselect the next small fly [ ]move the cursor through the neuron groups S / Xstimulate / silence the group under the cursor + -change the stimulation amplitude Wswitch the selected fly to the whole CNS (165,122 neurons) and back R / H / Escrestart / hide help / quit

    How it works

    Stimulus (calibration)DNp01 L / RDNp09MDNMN9active cells
    rest0 / 00000.00%
    loom (both sides)325 / 310 Hz0000.83%
    LC4 right only175 / 310 Hz0000.30%
    stimulate DNp090 / 097.5 Hz000.03%
    stimulate MDN0 / 00106 Hz00.03%
    food odour (ORN_DM1)0 / 00092.5 Hz1.85%
    taste (LB3c)0 / 00032.5 Hz0.14%

    From processed/calibration.json. Rates are mean per-neuron firing over a 50 ms window; "active" is the fraction of the 10,203 cells spiking per step.

    Limits

    Odour does not steer the flies toward food through this circuit (it drives MN9 and suppresses walking instead), which is why the player has to bring them there. The brains run at 0.3× biological speed relative to the wall clock in the game (10 ms of brain per 33 ms frame); the browser port above runs at 1× by default. There is no plasticity. Synapse counts are used as weights with a predicted transmitter sign; that is a structural proxy, not measured physiology. "Wander" is the one scripted behaviour: after two seconds of brain silence a fly drifts slowly so it does not look dead.

    Run it locally

    Needs the MaleCNS v1.0 flat files (about 1.1 GB, from Janelia) in data/flat-connectome/, Python 3.12 and a GPU-capable torch (MPS or CUDA; CPU works but slower).

    cd projects/flyworld-game
    python -m venv .venv && .venv/bin/pip install torch numpy pyarrow panda3d==1.10.16 pygame-ce pytest
    .venv/bin/python scripts/extract_circuits.py --verify   # builds processed/circuit_npc.npz (shipped)
    .venv/bin/python scripts/calibrate.py                   # writes processed/calibration.json (shipped)
    .venv/bin/python -m flyworld.game                       # 3D chase camera
    .venv/bin/python -m flyworld.game --renderer pygame     # top-down view
    .venv/bin/python -m flyworld.game --headless --script "focus 2; isolate; stim DNp09; run 150; assert rate DNp09 >= 50; report"

    The extracted circuit, calibration and group tables are included in the repository, so the game runs without the raw download; only re-extraction needs it. The verification ledger is in GATES.md: eight gates from environment to scripted behaviour, each with its check command and recorded evidence.