Log inGet started
World

Small Brain. Big Trades.

Branchmain
Branchesmain
Commit423cc3942e

README.md

fruitFly

A whole fruit fly nervous system running as a spiking network on the GPU, a fly body it drives, and a bench for experiments on it. Install this package and a world holds the complete adult male Drosophila central nervous system (MaleCNS v1.0: 164,587 neurons, 25.6 million connections, CC-BY 4.0) as a leaky integrate-and-fire network you can stimulate, silence, read out and watch, plus a fly whose taste, looming, walking, turning, feeding, flight and escape run through that wiring.

Contents

  • maleCNS.connectome/ — MaleCNS v1.0 packed for the GPU (109 MB, the edge table in two parts). It is an instance of the connectome asset type, which lives at the world root (/zero/source/connectome.assetType/) and travels with the package as a dependency: any nervous system's wiring as one asset (manifest.json, neurons.bin, offsets.bin, edges.bin or its parts). guides { path = "types/connectome" } is the reference.
  • lif_integrate, lif_propagate, lif_clear, lif_reset (.computeShader) — the four kernels of the network: membrane step, event-driven spike propagation over the CSR edge table, step close, reset.
  • brain.module/ — Brain.load(connectomeRef, params) binds a connectome to the kernels and returns the network: step, update, select, stimulate, silence, watch, rates, activity, showCloud.
  • neuron.shader/ + neuron.material/ — the instanced neuron cloud, each neuron lit by its own activity.
  • FruitFlyBrain.component/ — puts a network on an entity: loads the connectome the connectome field names, steps it every frame, draws the cloud, and exposes stimulate / silence / watch / rates / reset (the first three are synced, so every peer's copy receives the same inputs).
  • flyBody.module/ — the fly's body as an entity tree with a tripod gait, wings, proboscis and a hop.
  • FruitFly.component/ — the embodied fly: reads the world into the brain's sensory neurons and reads motor commands back out of named cell types.
  • FoodPatch.component/ — a disc of food on the ground the fly can taste.
  • FruitFlyLab.component/ — the bench window: network state and knobs, live readouts with traces, and a selection line to stimulate, silence, restore or watch any set of neurons.
  • experiments.guide/ — the experiments the bench was built for, and how to run them.

Usage

-- The brain: one entity, one network. The default connectome is maleCNS.
local brainEnt = entity.spawn("Brain")
brainEnt.position = { 0, 6, -8 }
brainEnt.component.add("FruitFlyBrain", { gain = 0.6, timeScale = 1 })

-- An embodied fly driven by it, and something for it to taste.
local fly = entity.spawn("Fly")
fly.component.add("FruitFly", { brain = brainEnt, bodyLength = 0.6 })
local food = entity.spawn("Food")
food.position = { 3, 0, 0 }
food.component.add("FoodPatch", { radius = 0.6, sugar = 1 })

-- The bench.
entity.spawn("Lab").component.add("FruitFlyLab", { brain = brainEnt, fly = fly })

-- Or from code:
local comp = brainEnt.component.get("FruitFlyBrain")
comp:watch("MN9", { types = { "MN9" } })                 -- proboscis motor neurons
comp:stimulate({ types = { "claw_tpGRN" } }, 100)        -- tarsal taste pegs at 100 Hz
print(comp:rates().MN9)                                   -- Hz per neuron, updated every frame

A selection names neurons by the dataset's own vocabulary: types (exact cell-type names), typePrefix, pattern (a Lua pattern over the type name), classes, superclasses, sides (L/R/M), excitatory, indices, limit. brain:info(i) answers what any neuron is.

The model

Every neuron is a leaky integrate-and-fire unit with the constants Shiu et al. 2024 (Nature) fitted to the FlyWire brain: rest and reset at -52 mV, threshold -45 mV, membrane time constant 20 ms, synaptic time constant 5 ms, refractory period 2.2 ms, transmission delay 1.8 ms, 0.275 mV per synapse. A presynaptic neuron whose consensus transmitter is GABA, glutamate or histamine inhibits; every other transmitter excites. A connection carries its synapse count; connections under minSynapses (default 5) carry nothing.

gain scales every synapse. MaleCNS traces about 2.5 times the synapses per connection FlyWire does, so at gain 1 the network runs away under any drive; at 0.6 (the default) driving the 50 tarsal taste-peg neurons at 100 Hz fires the proboscis motor neurons MN9 at about 120 Hz while the Kenyon cells stay under 0.1 Hz, and driving the 595 Johnston's organ neurons instead leaves MN9 silent. At 0.5 the taste drive reaches nothing. The bench's gain slider is the experiment.

Everything runs on the GPU: the state, the input ring, the spike list and the edge table. The CPU sees the per-group spike counters each frame and, on request, the per-neuron activity lane. Integer atomics make a step order-independent, so two peers stepping the same inputs read the same network.

The fly

FruitFly reads named cell types out of the brain and writes the world into others; every name is in FruitFly.component/init.luau:

commandcell types
walkthe leg motor neurons (vnc_motor types ending in MN)
turnDNa01, DNa02 left minus right
proboscisMN9
flightthe wing power-muscle motor neurons (DLMn, DVMn)
jumpa DNp01 (giant fibre) burst
sensecell typesdriven by
tarsal tasteclaw_tpGRN, dorsal_tpGRNa front foot on a FoodPatch
labellar tasteLB* labellar bristle GRNsthe extended proboscis on a FoodPatch
loomingLPLC2, LC4any player's avatar growing fast in the fly's view

The body moves kinematically at walkSpeed body lengths per second; the fly faces its entity's -Z. On a shared world the entity's owner writes the senses into the brain (a synced call) and every peer poses its own copy from its own network.

Data and license

MaleCNS v1.0: HHMI Janelia FlyEM, Google Research and the Cambridge connectomics group, released 8 June 2026 (Berg et al. 2026, Cell, doi:10.1016/j.cell.2026.08.015), CC-BY 4.0. The pack was written by a script that reads the public flat-connectome export (connectome-weights ... traced-only, body annotations, consensus neurotransmitters), assigns dense indices, sorts edges by presynaptic neuron and writes the four files types/connectome describes; the manifest carries each source file's SHA-256.

Notes

  • Loading the network reads the 102 MB edge table into a GPU buffer once per FruitFlyBrain; the VFS copy is released afterwards.
  • The neuron cloud is one instanced draw of every neuron with a soma (139,741). Its transforms are static; the activity lanes are written by the integrate kernel.
  • maxStepsPerFrame bounds GPU time per frame; at 32 steps of 1 ms a 60 fps engine keeps up with real time.