FlyWire connectome · spiking simulation · Polish Olympiad in Informatics

Can a fruit fly brain solve an olympiad problem?

I simulated the complete wiring diagram of an adult fruit fly brain, all 138,639 neurons and 15.1 million connections traced from electron microscope images by the FlyWire project, and gave it task TES from the XVII Polish Olympiad in Informatics. This page shows how the test was built, run and graded, one step at a time.

No.

Not in this model: it answered at coin-flip level. Why it failed, and what it takes to give a fly a fair chance, is the interesting part.

Three front views of the fly brain, one dot per neuron. In round 1 the smells reach 13,519 neurons all over the brain, in the rewired control 1,725, and with short-term memory 8,399, concentrated in the smell pathway and mushroom body.
Which neurons the smells reach: front views of the fly brain with one dot per neuron. Grey shows every neuron, color the ones that fire or come within 3 mV of firing.
138,639neurons, wired exactly as in a real fly
15.1Mconnections between them
52.8%right on 600 unseen puzzles, where a coin flip gets 50%
5 of 12official test queries right; always answering TAK gets 8
89%smells recognized mid-stream once neurons can tire, up from 30%

1 · The puzzle

Can b be made by crossing numbers out of a?

Task TES, "Test na inteligencję", XVII Polish Olympiad in Informatics, stage I. Sequence a holds up to 1,000,000 numbers, and every query b must be answered TAK (yes) or NIE (no).

aquery banswerwhy
1 5 4 5 7 8 61 5 5 8 6TAKevery number found, in order
1 5 4 5 7 8 62 2 2NIEthere is no 2 in a
1 5 4 5 7 8 65 7 8TAK5, then 7, then 8
1 5 4 5 7 8 61 5 7 4NIEall numbers exist, but the 4 comes too early

The classic solution stores, for every value, the sorted positions where it appears in a. It then walks through b and binary-searches the earliest position after the previous match; if a number has none left, the answer is NIE. All queries together take O((m + total length of b) log m), and solution/tes.py passes all 25 official tests. Step through it:

Try the algorithm

examples:
b
a

positions of each value in a

steps

    2 · Method

    How a fly takes the test, step by step

    A whole-brain simulation cannot read digits, so the puzzle is played to it as smells, and a readout is trained to pull the answer out of its spikes. The brain itself is never trained.

    1. Puzzlea = 1 5 4 5 7 8 6
      b = 5 7 8
    2. Smellsone 50 ms smell per number
    3. Receptorsrandom spikes in the matching smell neurons
    4. Fly brain138,639 spiking neurons, FlyWire wiring
    5. Spike countsper neuron, per 75 ms
    6. Readoutlinear, the only trained part
    7. TAK / NIE
    1. Load the wiring

      FlyWire release 783 lists which neuron connects to which, through how many synapses, and whether the sender excites or inhibits (predicted from its neurotransmitter). I use the processed connectivity of Shiu et al. 2024 and FlyWire's cell annotations to find smell receptors, mushroom body cells and the neurons that drive the body.

      138,639neurons
      15,091,983connections
      53smell receptor types
      5,177Kenyon cells, the learning centre
    2. Make every neuron a leaky integrate-and-fire unit

      The same equations and constants as the published whole-brain model. A neuron spikes when its voltage passes -45 mV, resets to -52 mV and rests for 2.2 ms. Each spike of neuron \(j\) adds \(w_{ij} = 0.275\,\text{mV} \times n_{ij} \times s_j\) to neuron \(i\) after 1.8 ms, for \(n_{ij}\) synapses with sign \(s_j = \pm 1\).

      \[ \tau_m \frac{dv}{dt} = v_0 - v + g, \qquad \tau_s \frac{dg}{dt} = -g, \qquad \tau_m = 20\text{ ms},\; \tau_s = 5\text{ ms} \]

      The linear part is integrated exactly over each 0.1 ms step, so there is no numerical drift:

      \[ u(t+\Delta t) = u(t)\,e^{-\Delta t/\tau_m} + g(t)\,\frac{\tau_s}{\tau_s - \tau_m}\left(e^{-\Delta t/\tau_s} - e^{-\Delta t/\tau_m}\right), \qquad u = v - v_0 \]
      Checked against the published model

      Its headline result is that sugar-sensing neurons drive MN9, the motor neuron that extends the proboscis to feed. This implementation reproduces it: MN9 fires at 71.5 Hz with sugar input and stays silent without.

    3. Turn numbers into smells

      Each number drives one type of olfactory receptor neuron with random (Poisson) spikes for 50 ms, one number per 75 ms slot: first b, a pause, then a, then a silent slot.

      Timeline of one puzzle: the numbers of b as three teal smell pulses, a pause, the seven numbers of a as red pulses, then a readout slot.
    4. Simulate only what can fire, and prove nothing changes

      A neuron that never spikes cannot influence anything. A pilot on the full brain finds every neuron that spikes or comes within 3 mV of threshold; the experiment runs on that subnetwork. Fresh trials on the full and trimmed brain, with identical random input, must give identical spikes. Trials run side by side as (neurons x trials) arrays, and every condition gets the same random seeds, so the brain and its controls smell exactly the same thing.

      Bar chart: the whole brain has 138,639 neurons; round 1 simulates 13,519 with identical spikes, the rewired control 1,725, round 2 8,399 with identical spikes.
    5. Read the answer out

      A linear classifier reads the log spike count of every neuron in every 75 ms slot, about 140,000 features, and says TAK or NIE. That is the most generous question you can ask: is the answer present in the activity at all? The response matrix had 450 million nonzero entries, so the classifier is fitted exactly on the trial-by-trial kernel instead:

      \[ \hat t(x) = k(x)^\top \left(K + \lambda I\right)^{-1} t, \qquad K_{ij} = x_i^\top x_j \;\;(3{,}180 \times 3{,}180) \]
    6. Grade it without fooling yourself

      Generated puzzlesrandom TES instances, official queries excluded
      • train fits the readout
      • validation picks settings
      • test gives the reported number
      Official examthe 12 official test queries small enough to smell, never used for training
      • each played 15 times, since the brain is noisy
      • the majority vote is the answer
      • Always answer TAKno computation at all
      • Raw smells, no brainthe same readout on a perfect record of the smells
      • Randomly rewired brainsame neurons, connection counts and signs, wiring shuffled
      • Trained artificial networkan upper reference that is not a fly

    3 · Round 1 results

    At coin-flip level, and worse than its own input

    Correct answers on 600 held-out puzzles. Hover a bar for its score on the hardest kind of puzzle, where every number is present but the order is wrong, and on the official exam.

    Grouped bars by kind of puzzle. On wrong-order puzzles the fly brain scores 52% whole and 60% mushroom body, the raw smells with no brain 62%, the trained network 81%.
    By kind of puzzle: on wrong-order puzzles the fly brain does no better than the raw smells with no brain at all.
    5/12real fly brain
    8/12always answer TAK
    6/12raw smells, no brain
    10/12trained artificial network

    The brain loses information

    Its activity is harder to read (52.8%) than the smell signal going into it (61.8%). Processing made the answer less visible, not more.

    The real wiring didn't help

    The same brain with its connections randomly shuffled scored 55.0%. The fly's actual wiring gave no advantage on this task.

    Nothing reaches the body

    The descending neurons, which carry commands to the body, are at chance (48.3%).

    It keeps nothing

    75 ms after the last smell the activity is uninformative (49.7%), yet the task needs a whole sequence held in mind.

    4 · Inside the brain

    Why it failed: the brain floods, and forgets

    The same puzzle played to two brains. In round 1 almost every sampled neuron fires almost all the time, whichever number is smelled: 874,511 spikes in one puzzle. With short-term memory (round 2) activity is sparse and tied to the smells: 12,503 spikes.

    Spike rasters for the same puzzle. Round 1: dense spiking in every neuron group for the whole trial. Round 2 with memory: brief, sparse bursts after individual smells.
    Every dot is one spike of one neuron; 40 neurons are sampled from each group. Red and teal bars above each panel are the smells of a and b.
    Line chart: from 20 Hz of receptor drive, 73% of Kenyon cells fire and the overlap between the cells of different numbers reaches 100%.
    Measured on the plain model: from 20 Hz up, every number activates the identical set of Kenyon cells, so the learning centre cannot tell 1 from 9.
    Two problems, both fixable

    No memory. In the published model activity fades within tens of milliseconds. TES needs all of a remembered while b is checked.

    Flooding. The uniform synaptic strength that makes the model's taste pathway work saturates the smell pathway. At round 1's 150 Hz, about 70% of all neuron-and-time-slot pairs contain spikes.

    5 · Round 2

    A fairer rerun: let neurons tire, calibrate the smells, climb a ladder of tasks

    Every setting below was fixed before any task was run, and every rule that was tried and dropped is recorded in the repository.

    1. Short-term memory

      Two textbook mechanisms real neurons have, added on top of the published model: spike-frequency adaptation (a neuron that fires a lot fires less for a while) and short-term synaptic depression (a synapse used a lot delivers less for a while).

      \[ \tau_m \frac{dv}{dt} = v_0 - v + g - a, \qquad \tau_a \frac{da}{dt} = -a, \qquad a \leftarrow a + b \;\text{ at every spike} \]
      \[ \text{a spike of } j \text{ delivers } w_{ij}\,x_j,\;\text{ then } x_j \leftarrow (1-U)\,x_j, \qquad \tau_{rec}\frac{dx_j}{dt} = 1 - x_j \]
      presetadaptation bτadepression Uτrec
      mild0.1 mV200 ms0.05300 ms
      strong0.5 mV800 ms0.21000 ms
    2. Realistic smells at a calibrated strength

      Every number now activates a blend of three receptor types, like a real odor. The strength is chosen per memory setting by what every task needs first: naming the number being smelled right now, in the middle of a stream of smells.

      Line chart of smells named correctly versus smell strength: strong memory rises to 89%, mild memory to 56%, no memory peaks at 30% and falls toward chance.
      memorystrengthsmells namedKenyon cells active
      none3 Hz30%38.5%
      mild40 Hz56%14.1%
      strong40 Hz89%3.0%
    3. A ladder of tasks instead of one pass or fail

      Same or different? Was it in the list? Which came first? Then full TES, each with train, validation and test sets and 95% confidence intervals. A trained network learns the first three almost perfectly; simply adding up the smells cannot.

      Grouped bars for the four ladder tasks: the trained network scores 100, 99, 98 and 82 percent; a linear readout of the raw smells scores 60, 51, 49 and 59 percent.
      Status

      Calibration, trimming for strong memory (identical spikes: 44,540 on both brains) and every baseline are done and committed. The full ladder under every condition is an unattended, resumable pipeline estimated at about 12 hours of CPU, and has not been run to completion.

    6 · Engineering

    Built to be checked

    Batched simulator

    Vectorised NumPy and SciPy integrate-and-fire engine with exact exponential integration, a ring buffer for synaptic delays and many trials per process. Reproduces the published MN9 result.

    Exact trimming

    Only 9.8% of the brain is simulated in round 1, with identical spike trains on held-out trials: 5,284,179 spikes on both brains.

    Memory-safe readout

    A 5.4 GB response matrix becomes an exact 3,180 x 3,180 kernel, built in chunks, reproducing the direct fit's scores exactly.

    Measured, not assumed

    A C sparse-matrix propagation matched np.add.at (per-neuron correlation 0.9995) but ran at 0.9x the speed, so it was dropped.

    Honest evaluation

    Official queries excluded from training data, untouched test sets, a control for every claim, and every dropped calibration rule recorded.

    Tested

    18 unit tests: the greedy check against brute force, the official solution, the simulator on hand-built networks including trimming exactness, and the readout kernel.

    7 · Limitations

    What this does not show

    Data and credits