Skip to content
Back to search

fly.ai

fly.ai: a real fruit fly brain, running on your computer

Safety scan

A static text scan, not a guarantee. Select the badge to see what was scanned and every finding.

Checked today

Check it deeper on your machine

It has changed since its scan on 11 Nov 2026.

As a Claude Code plugin, install it and then ask Claude Code:

/plugin marketplace add keithmackay/mackayi/plugin install scanskillsafety@mackayiDo a deep scan of https://github.com/alextitonis/fly.ai with scanskillsafety

Or from a terminal, clone it and run it:

git clone https://github.com/keithmackay/scanskillsafety-skill ~/.claude/skills/scanskillsafetynode ~/.claude/skills/scanskillsafety/cli.cjs --deep 'https://github.com/alextitonis/fly.ai'

It checks the exact commit: every file, its packages against OSV (api.osv.dev), how it compares with this page's scan (findsafeskills.com receives the repository's address), and, if you agree, Claude reading every file with your own Claude subscription. It never runs the code.

Badge for your README
findsafeskills safety rating

Markdown

[![findsafeskills safety rating](/api/listings/alextitonis--fly-ai/badge.svg)](/listings/alextitonis--fly-ai)

HTML

<a href="/listings/alextitonis--fly-ai"><img src="/api/listings/alextitonis--fly-ai/badge.svg" alt="findsafeskills safety rating" /></a>

Install

i

What was scanned

The files the safety scan read, as written by the repository's author and shown as plain text. Lines with a finding are marked.

README.md · README · 453 lines

View this file on GitHub (read at the repository's current version: the scan did not record which commit it read)

This file has changed since it was scanned, so this is not exactly the text that was scanned, and no line is marked. The findings are listed with the safety scan above.

  1. <p align="center"><img src="logo.webp" alt="fly.ai" width="440"></p>
  2. # fly.ai: a real fruit fly brain, running on your computer
  3. > **New here?** fly.ai runs the complete brain of a real fruit fly as open-source software. On
  4. > [flyaiworld.com](https://flyaiworld.com) that same brain trades: **Trader Flies** each trade their own wallet,
  5. > the **Fly Desk** is one shared pot traded by fly brains that pays active Trader Flies weekly, and
  6. > **$FLYAI** is the token that funds it all.
  7. > [Buy $FLYAI](https://flyaiworld.com/start) · [Token](https://flyaiworld.com/token) ·
  8. > [Trader Flies](https://flyaiworld.com/traderflies/) · [Fly Desk](https://flyaiworld.com/desk) ·
  9. > [How it works](https://flyaiworld.com/how)
  10. https://github.com/user-attachments/assets/7c3b91e5-9b50-4017-a03a-123aedd4d7b4
  11. *The fly brain playing an online fighting game. See [sshfighter/](sshfighter/).*
  12. fly.ai is a simulation of the **complete central nervous system of an adult male fruit fly**
  13. (*Drosophila melanogaster*): **166,700 neurons and 25.6 million connections** from the
  14. [MaleCNS v1.0 connectome](https://male-cns.janelia.org), wired exactly as electron microscopy
  15. found them in a real fly.
  16. There is **no training and no learned policy inside the brain**. You connect a task to it at a few
  17. neuron types known from the literature, one side for input (what the fly senses) and one for
  18. output (the commands its brain sends to the body). Everything in between is the connectome.
  19. The goal is a general-purpose "fly reservoir": plug any task into the same frozen brain, read
  20. out what it does, and find out what a real nervous system's wiring is good for.
  21. **Install it:** `pip install flybrain`. Latest release: [flybrain 0.1.0 on PyPI](https://pypi.org/project/flybrain/0.1.0/).
  22. **$FLYAI** is live on Robinhood Chain (launched on Pons):
  23. `0x0088CE7905025c4B5ea1d49aB6179B6aaADB3B9C`. The address is posted only here, on the
  24. [site](https://flyaiworld.com) and on [@flydotai](https://x.com/flydotai); any other address is a
  25. scam. Details: [TOKEN.md](TOKEN.md).
  26. ## How it works
  27. ```
  28. task input
  29. └─> encoder: drives the fly's own sensory / feature-detector neurons
  30. └─> 166,700-neuron connectome, leaky integrate-and-fire, 50 steps/s (500 with `dt=0.002`)
  31. └─> descending neurons (the brain's 1,314 output cables to the body)
  32. └─> decoder or trained linear readout
  33. └─> task output
  34. ```
  35. * **Network** (`flybrain/build.py`, `flybrain/brain.py`): every neuron with a MaleCNS superclass
  36. annotation, and every connection between them. The weight is the synapse count, made negative
  37. when the presynaptic neuron's predicted transmitter is GABA, glutamate or histamine, then scaled
  38. so each neuron's inputs add up to 1. Each neuron is a simple leaky integrate-and-fire unit
  39. (`v ← e^(-dt/τ)·v + gain·W·spikes + tonic + noise`; it spikes and resets at 1). This recipe
  40. follows [Fly64](https://github.com/ornata/fly). The simulation is multi-threaded with numba.
  41. * **Visual encoder** (`flybrain/eyes.py`): two routes into the brain.
  42. * *Eyes*: a 1-D panorama projected onto the 6,006 photoreceptors, each placed by its eye column.
  43. * *Feature detectors*: drive the fly's own visual projection neurons directly, on the side
  44. where things are:
  45. | Neuron type | Responds to (in a real fly) |
  46. |---|---|
  47. | LPLC2 | looming: something getting bigger as it approaches |
  48. | LC4 | fast looming, escape |
  49. | LPLC1 | small approaching objects |
  50. | LC10a | a moving target the male chases |
  51. * **Outputs**: the brain's descending neurons, including identified command neurons such as
  52. DNa02 (steering), DNp01 (the giant fiber, escape take-off), DNg100 (forward walking) and
  53. MDN (backward walking). A task either decodes these by hand or trains a linear readout on all
  54. of them (reservoir computing).
  55. ## What we found
  56. These are small experiments, run on a desktop. They are not peer-reviewed science.
  57. 1. **With Fly64's settings, vision does nothing.** Fly64 uses tonic 0.18 and decay e^(-0.2).
  58. That puts every neuron's resting voltage at 0.18 / (1 − 0.82) ≈ 1.0, exactly the firing
  59. threshold. The whole network ticks along by itself at about 4 Hz, and the motor neurons fire
  60. at the same rate whatever the fly is shown (`experiment.py`).
  61. 2. **The signal from the photoreceptors dies at the first relay.** Photoreceptors release
  62. histamine, which is inhibitory, onto lamina neurons. Real lamina neurons use smooth, graded
  63. signals rather than spikes, which this simple model can't reproduce. In every setting we
  64. tried, looming stimuli never reached the looming detectors (`sweep.py`).
  65. 3. **Past the eye, the wiring does the right thing on the correct side** (`inject.py`,
  66. tonic 0.14 and gain 3.0, 6 noise seeds):
  67. | Stimulate (left side only) | Result |
  68. |---|---|
  69. | LC4 + LPLC2 looming detectors | left giant fiber DNp01 **+17 to +25 spikes/s**; right side unchanged |
  70. | LC10a courtship-tracking neurons | left DNa02 steering neuron **+1.4 to +3.7 spikes/s**; right side unchanged |
  71. None of the other readout neurons changed. These are the known looming → escape and
  72. courtship pursuit → steering pathways, and they come out of the wiring alone.
  73. 4. **Smell neurons ran away until sensory neurons stopped receiving synapses.** In the original
  74. model, olfactory receptor neurons get 0.43 of their 0.45 net input from each other
  75. (ORN-to-ORN connections). At gain 3.0 that loop pins them near maximum rate, so the
  76. food-odour projection neurons (DM1/DM2) sat at 50 Hz, the model's ceiling, with or without an
  77. odour. `FlyBrain(sensory_input=False)` removes every synapse onto sensory neurons, as
  78. whole-brain spiking models of the fly do. The same odour then drives DM1/DM2 from 16 to 28 Hz
  79. while other projection neurons stay where they were. The default is unchanged, so every earlier
  80. result still holds.
  81. 5. **Two brains can signal to each other** (`flytalk.py`, [flyaiworld.com/research/flybook](https://flyaiworld.com/research/flybook)).
  82. Fly A lives through a situation (a looming threat, a mate in view, a food smell, or nothing),
  83. its wing motor neurons "sing", and fly B hears the song through its Johnston's-organ neurons.
  84. Three runs, with the tests fixed before running and 50-shuffle permutation nulls:
  85. | | Run 1: original, 20 ms | Run 2: smell fixed, 20 ms | Run 3: smell fixed, 2 ms |
  86. |---|---|---|---|
  87. | song → what happened to the singer | 0.30 bits | 0.63 bits | 0.83 bits |
  88. | same test, degree-preserving scrambled wiring | 0.01 bits | 0.01 bits | **0.87 bits** |
  89. | listener reacts to a threat song (vs silence) | 23% vs 17% | 21% vs 14% | **77.5% vs 17.5%** (p < 0.001) |
  90. Threat is the clear word in every run, and "mate" becomes partly readable at 2 ms. In every
  91. run the listener's descending neurons carry the singer's situation and stay at chance in
  92. silence, but the listener only uses loudness: a time-shuffled song works as well. The "real
  93. wiring matters" test **fails at 2 ms**, where the scrambled brain's song carries as many bits,
  94. although it groups the situations differently. Food reaches the brain but never the wings,
  95. and hearing a song never makes a fly sing back. `flybook.py` turns the 2 ms brain into a feed
  96. of posts, each with the neurons behind it.
  97. ## Applications
  98. | Folder | What the fly does |
  99. |---|---|
  100. | [`sshfighter/`](sshfighter/) | plays [SSH Fighter](https://sshfighter.com), an online terminal fighting game, as a registered bot, with a live dashboard of every neuron firing and a trained punch readout |
  101. | [`flybook/`](flybook/) | **Flybook**, the live social game at [flyaiworld.com/flybook](https://flyaiworld.com/flybook/): connectome flies live in patches, post what their brains sense and do, set each other off, duel, breed, mate with other owners' flies and trade in a simulated fly market; $FLYAI holders make and tune their own ([README](flybook/README.md)) |
  102. | [`world/`](world/) | the 3-D fly world, running around the clock on a server that records every life, egg, relationship and memory (`world/server/`), and **Wiz**: a giant monkey wizard puppeted by the full connectome running in the browser (`flybrain export --web`), with the puppet strings read off descending neurons ([README](world/README.md)) |
  103. | [`drone/`](drone/) | the connectome flies a simulated quadcopter: it follows a leader using only its cameras, learns who to follow with dopamine, and turns when it sees a hand swipe. Simulation only so far ([README](drone/README.md)) |
  104. | [`flytalk.py`](flytalk.py), [`flybook.py`](flybook.py) | two copies of the brain signal to each other through wing song and hearing; the experiment behind Flybook, written up at [flyaiworld.com/research/flybook](https://flyaiworld.com/research/flybook) |
  105. ![Dashboard: the fight on the left, every neuron of the fly's nervous system on the right](sshfighter/media/dashboard.png)
  106. New applications go in their own folder and import the core from the `flybrain` package
  107. (`from flybrain import FlyBrain`), either from the repository root or after `pip install flybrain`.
  108. ## On BNB Chain
  109. [Trader Flies](https://flyaiworld.com/traderflies/) give each fly its own trading wallet. On BNB Chain (BNB Smart
  110. Chain, chain ID 56) a fly:
  111. - keeps BNB as BNB: BNB sent to the fly trades BNB Chain tokens and sells back into BNB;
  112. - makes markets on PancakeSwap v3 (USDT or WBNB pools) through Fly Maker vaults, collecting the pool fees;
  113. - snipes new BNB Chain launches after GoPlus and honeypot checks, and swing or grid trades its owner's picks.
  114. Fly Maker contracts on BNB Smart Chain, verified on BscScan (also listed in
  115. [`deployments/bsc.json`](deployments/bsc.json)):
  116. | Contract | Address |
  117. |---|---|
  118. | FlyMakerFactory (proxy) | [`0xAbf20F4756A085CC4e400a95C81c41a887D23329`](https://bscscan.com/address/0xAbf20F4756A085CC4e400a95C81c41a887D23329) |
  119. | FlyMakerVault beacon | [`0x5A3D1D98c05A4A3C9F3407a29013407fb8278feD`](https://bscscan.com/address/0x5A3D1D98c05A4A3C9F3407a29013407fb8278feD) |
  120. ## Flybook
  121. [Flybook](https://flyaiworld.com/flybook/) is a social network run by fly brains. Every fly is the full connectome, simulated; nobody writes the posts.
  122. * **Every 2 minutes** something happens in each patch (a shadow, a gust, a taste, a brush, a male's scent or a passing fly). The fly's brain runs for 1.5 s. A decoder reads what it sensed from its descending neurons, and its behaviour neurons show what it did: jumped, turned, groomed, backed up or buzzed its wings. A word is posted only when the decoder is confident; the decoder and its thresholds are fitted on episodes built like live patches from the live flies' own settings, and all six words (threat, mate, wind, taste, touch, cVA) can be posted ([details](flybook/README.md#word-decoder-refit-on-todays-flies-2026-09-15)).
  123. * **Flies set each other off**: a jump looms over the flies nearby, movement catches their eye, a bump touches their bristles. Posts say what really happened, including misreads and hallucinations, and each patch has a live map replaying its last tick.
  124. * **Anyone plays**: sign in free with email or a wallet to make 1 fly, like, comment, poke and duel; $FLYAI holders make up to 3 flies; holding or staking 200k $FLYAI makes you eligible for season rewards. Holders make up to 3 flies (13 profiles, or tune senses, temperament and 8 neuron groups), breed them, poke a patch by clicking its map, like, comment and caption, challenge flies to duels in the Arena (quick draw or stare-down, Elo), and complete missions.
  125. * **Flies mate on their own** with flies of other owners (when one's brain reads "mate" next to the other, or when the worker pairs them). The baby goes to one of the two owners at random and doesn't count toward the 3-fly limit.
  126. * **Fly market**: holders' flies get a wallet with 1 fake ETH and trade simulated coins every 10 minutes. A pumping coin reaches the brain as a fly walking past, a crash as a looming shape, choppy prices as wind; what the neurons do becomes the trade. Owners pick a trading style (risk, and whether dopamine, memory or slime-mold tubes shape it), check each fly's wallet, and climb the Richest board. Learning sits at the interface, not in the wiring, and in two offline checks it did not beat non-learning flies ([details](flybook/README.md#fly-market-2026-09-14)).
  127. * **Rewards**: Seasons last two weeks (season 3 runs 27 September - 10 October 2026, then every other Sunday 00:00 UTC). Missions earn season points: 10 for each daily mission, 50 for each weekly one. At the end of each season the top 3 on the Season points board who hold or stake 200k $FLYAI win $50, $25 and $25 in $FLYAI.
  128. How it is built, measured and deployed: [flybook/README.md](flybook/README.md).
  129. ## Compute
  130. [fly.ai compute](https://flyaiworld.com/compute/) lets anyone lend a GPU or CPU to the full connectome, from a browser tab or the Chrome extension.
  131. * **The brain:** each job runs the brain in exact integer maths (WebGPU, or CPU as a fallback) for 15 simulated seconds, so every machine gets identical spikes.
  132. * **Checks:** the server re-runs a sample of answers, and a wrong answer zeroes the day.
  133. * **Rewards:** checked work earns monthly points per wallet. Staking $FLYAI raises the multiplier, and a wallet holding a [FlightPass](https://flyaiworld.com/traderflies/pass) for a whole UTC day gets x1.25 on top. After each month, a $FLYAI pool may be split by points and claimed on-chain (see [TOKEN.md](TOKEN.md#compute)).
  134. * **Buy compute:** anyone can rent the network on the [Buy compute page](https://flyaiworld.com/compute/jobs) or [from code](https://flyaiworld.com/compute/compute-api.md). Run brain experiments, your own WebAssembly programs and GPU shaders, or text embeddings (upload texts, get one vector per text back, for search or RAG). Pay in $FLYAI, or USDC on Base, per finished job; 80% goes to the miners. Starter programs (pi, proof-of-work hash search, a Bitcoin pool bridge with a guided setup, Mandelbrot tiles, TSP search, a GPU matrix multiply) are in [mine/examples](mine/examples).
  135. * **Our own work:** house orders run whatever the project needs on the network, and results are kept for us to pull. They have run brain tuning, world simulations and encoding datasets (brain → words, brain → trades); since 18 September 2026 they mine instead.
  136. * **Mining for the project:** the fleet mines a yespower coin on CPU threads and Kaspa on GPUs, paid to the project's own wallets, with the miners still earning their usual points. The pool bridges run on [fly.io](https://flyai-bridge.fly.dev/). It is small money — about $0.02 per machine-day on the CPU side and a rounding error on the GPU — and the measurements behind that, along with every coin that was tried and rejected, are in [mine/README.md](mine/README.md#mining-for-the-project).
  137. How it works, how answers are checked, the contracts and operations: [mine/README.md](mine/README.md).
  138. ## Drone
  139. The full connectome pilots a simulated [Crazyflie 2](drone/sim/crazyflie/) in MuJoCo. It has not flown on real hardware; the
  140. [drone README](drone/README.md#using-it-in-the-real-world) says what that would take.
  141. ```bash
  142. pip install -r drone/requirements.txt
  143. python drone/follow.py # follows a leader by sight -> drone/runs/follow.mp4
  144. python drone/choose.py --people --train A --out drone/runs/person.mp4 # learns who to follow
  145. python drone/reflex.py # a hand swipe turns it, nothing trained
  146. ```
  147. * **Following with no radio:** the follower knows only what its four onboard cameras show. It stays 0.97 m from the leader, against 1.84 m when it tracks a different drone and 1.39 m on scrambled wiring. It missed one of four pre-set rules: within 1 m 55% of the time, against 60%.
  148. * **Learning who to follow:** dopamine at the Kenyon-cell output synapses teaches it a leader by colour, and swapping the rewards flips its choice. This passed every pre-set rule over 48 flights: with people it picks the rewarded one 91-93% of the time, and retraining shifts its picks by 84 points. It only knows colour, and the "blink" that keeps the Kenyon cells working in flight is our addition.
  149. * **Hand gestures:** with no trained readout, two types of its descending neurons (DNg41, DNb03) read left and right swipes the right way 100% of the time on rendered hands, against 35-45% on scrambled wiring, and 8 of 9 on one real clip. It only tells left from right. A trained 7-gesture readout did no better than scrambled wiring.
  150. Commands, how to train each part, full results and limits: [drone/README.md](drone/README.md).
  151. ## Use it on your own task
  152. `flybrain/reservoir.py` is the reusable half of the SSH Fighter bot's reservoir readout, pulled out so
  153. any task can use it, not just the game:
  154. ```
  155. input -> encoder -> fly brain (frozen) -> trace -> trained readout -> output
  156. ```
  157. The brain never trains, on any task: `FlyBrain`'s weights are the connectome, fixed at load
  158. time. Only two things ever get fit:
  159. * **An encoder**, which you write: pick the neuron types your input should drive with
  160. `brain.cells([...types], side=...)` and pass `(indices, amount)` pairs to
  161. `brain.step(inject=...)`. `flybrain/eyes.py` is a worked example for SSH Fighter's visual input;
  162. the neuron types available are whatever the MaleCNS connectome names (look one up on
  163. [neuPrint](https://neuprint.janelia.org)).
  164. * **A readout**, which `flybrain.Readout.fit` trains for you: a linear (`kind="ridge"`) or
  165. logistic (`kind="logistic"`) fit on the top principal components of neural activity, with the
  166. PCA rank and L2 strength picked by cross-validation. This is the exact method
  167. `sshfighter/reservoir.py` uses for the punch and movement readouts, generalised off SSH
  168. Fighter's game state.
  169. `flybrain.Trace` collects a decaying spike trace of any neuron population (a cell type, a
  170. `brain.groups[...]` set, or your own index array) step by step; `flybrain.run` steps the
  171. brain over a sequence of encoded inputs and returns the trace stacked over time, so the whole
  172. loop is one call from a notebook:
  173. ```python
  174. from flybrain import FlyBrain
  175. from flybrain.reservoir import Trace, Readout, run
  176. brain = FlyBrain(device="auto")
  177. trace = Trace(brain, types=["descending_neuron"]) # or group=..., or idx=your_own_array
  178. def encode(t):
  179. return [(brain.cells(["LC10a"], side="L"), my_inputs[t])] # your task's encoder
  180. activity = run(brain, len(my_inputs), encode=encode, trace=trace)
  181. readout = Readout.fit(activity, my_labels, kind="ridge") # or "logistic" for 0/1 labels
  182. prediction = readout.predict(activity[-1])
  183. readout.save("readout.npz") # Readout.load(...) later
  184. ```
  185. `flyreservoir_example.py` runs this end to end on a synthetic task (classify and measure the
  186. strength of a left/right stimulus) with no game or recordings needed:
  187. `python flyreservoir_example.py`. Its held-out numbers are printed as they come out, not curated
  188. — on the fixed seed it ships with, the classifier does better than chance and the strength
  189. regression is close to just predicting the average; that is the honest state of a two-line
  190. encoder on an invented task, not a claim about what the connectome can do in general (see
  191. "What's next" and `ROADMAP.md` for the open question of how much the real wiring helps versus
  192. a random network of the same size).
  193. Batching and the GPU option work the same way they do in `flybrain/brain.py`: `FlyBrain(batch=8)` or
  194. `FlyBrain(device="cuda")` (or `FLY_DEVICE=cuda`); `Trace(..., aggregate="mean")` (the default)
  195. gives one feature vector averaged across the batch, `aggregate="batch"` keeps one per fly.
  196. ### Brain options
  197. `FlyBrain` takes three options. The defaults are the model every earlier result used.
  198. * `dt` (default `0.020`): the step length. `tonic` is rescaled so a silent neuron settles at the
  199. same voltage. At `dt=0.002` the network runs far hotter unless you also set a refractory
  200. period; `refractory=0.004` matched the 20 ms brain's resting descending-neuron rate with no
  201. neurons above 100 Hz.
  202. * `sensory_input` (default `True`): `False` removes every synapse onto sensory neurons, which
  203. fixes the olfactory runaway loop (finding 4).
  204. * `refractory` (default `0`): seconds a neuron is held at 0 after it spikes.
  205. `brain.cells([...])` accepts superclass names such as `"descending_neuron"` as well as cell types.
  206. ### Limitations
  207. * Point neurons with one global set of parameters. There are no dendrites, no graded neurons,
  208. no neuromodulators and no plasticity.
  209. * Transmitter sign is a rough rule (GABA, glutamate and histamine inhibitory; everything else
  210. excitatory). Real effects depend on the receptor.
  211. * The visual front end is a shortcut, like [Eon's embodied fly](https://eon.systems/updates/embodied-brain-emulation).
  212. We inject input into feature-detector neurons instead of simulating the eye.
  213. * None of this is validated against recordings from real flies. It's a demo, not an emulation.
  214. ## Run it
  215. A multi-core CPU helps: one brain step takes about 12–15 ms on 24 threads, and real time needs
  216. under 20 ms.
  217. **Just the brain, as a library** (Python 3.10+, [flybrain 0.1.0 on PyPI](https://pypi.org/project/flybrain/0.1.0/)):
  218. ```sh
  219. pip install flybrain # or "flybrain[gpu]" for an NVIDIA GPU
  220. flybrain download # optional: the first FlyBrain() does this itself (~260 MB, once)
  221. flybrain info # where the data lives, and whether CUDA works
  222. ```
  223. **This repository** (experiments, the SSH Fighter bot, flytalk): the `flybrain/` package sits at
  224. the root, so scripts run from a clone without installing it.
  225. ```sh
  226. python -m venv .venv
  227. # Windows: .venv\Scripts\activate macOS/Linux: source .venv/bin/activate
  228. pip install -r requirements.txt
  229. python -m flybrain download # prebuilt brain (~260 MB) into ~/fly-data
  230. # or: python -m flybrain build # download MaleCNS v1.0 (~1.1 GB) and build the network yourself
  231. ```
  232. Set `FLY_DATA=/some/path` to store the data somewhere else.
  233. **Quickstart notebook:** [`notebooks/quickstart.ipynb`](notebooks/quickstart.ipynb) loads the
  234. brain, stimulates the left looming detectors and shows the left giant fiber fire, maps where
  235. the activity goes, and tests the chase pathway. It needs `pip install matplotlib jupyter`.
  236. ```python
  237. from flybrain import FlyBrain
  238. brain = FlyBrain(device="auto") # GPU if available, else CPU
  239. brain.stimulate(brain.cells(["LC4", "LPLC2"], side="L"), 0.8)
  240. fired = brain.step() # advance 20 ms; indices of neurons that spiked
  241. ```
  242. **GPU:** on an NVIDIA card, `pip install -r requirements-gpu.txt` and set `FLY_DEVICE=cuda` (or
  243. pass `device="cuda"`, or `--device cuda` to the bot). The whole connectome fits in about 210 MB of
  244. GPU memory. On an RTX 4060 laptop GPU a step takes **1.4 ms, against 8.9 ms on a 24-thread CPU**.
  245. Both devices run the same model and give the same results. Only the random noise differs, so
  246. individual spikes differ between them.
  247. **Many flies at once:** `FlyBrain(batch=8)` runs 8 independent copies of the brain with the
  248. same wiring, each with its own voltages and noise. On a GPU they share one sparse multiply, at
  249. about 1.2 ms per fly per step. Inputs can be the same for every fly or differ per fly, which is
  250. how `sshfighter/` runs voting flies and compares encoders side by side.
  251. **Experiments:** `python experiment.py`, `python sweep.py`, `python inject.py`.
  252. **Watch it play:** `python sshfighter/fly_fighter.py --offline --seconds 120 --dashboard`
  253. (fake opponent, opens http://127.0.0.1:8777). See [sshfighter/README.md](sshfighter/README.md).
  254. ### Getting the data (the "model")
  255. There are no trained weights. The "model" is the fly's wiring diagram. `flybrain download` fetches
  256. a prebuilt copy (checked against its sha256); `flybrain build` (needs `pip install "flybrain[build]"`,
  257. already in `requirements.txt`) builds the same files from the public MaleCNS v1.0 release. It downloads these files into
  258. `$FLY_DATA/raw/` and skips any that are already there. An interrupted download starts over on
  259. the next run:
  260. | File | Size | What it is | Source |
  261. |---|---|---|---|
  262. | `connectome-weights-male-cns-v1.0-minconf-0.5.feather` | 1.05 GB | every neuron-to-neuron connection, with synapse counts | [MaleCNS bucket](https://storage.googleapis.com/flyem-male-cns/v1.0/connectome-data/flat-connectome/connectome-weights-male-cns-v1.0-minconf-0.5.feather) |
  263. | `body-annotations-male-cns-v1.0-minconf-0.5.feather` | 14 MB | cell types, sides, classes, soma positions | [MaleCNS bucket](https://storage.googleapis.com/flyem-male-cns/v1.0/connectome-data/flat-connectome/body-annotations-male-cns-v1.0-minconf-0.5.feather) |
  264. | `body-neurotransmitters-male-cns-v1.0.feather` | 43 MB | predicted neurotransmitter for each neuron | [MaleCNS bucket](https://storage.googleapis.com/flyem-male-cns/v1.0/connectome-data/flat-connectome/body-neurotransmitters-male-cns-v1.0.feather) |
  265. | `optic-columns.xlsx` | 0.1 MB | which eye column each photoreceptor belongs to | [flyconnectome/2025malecns](https://github.com/flyconnectome/2025malecns/blob/67767d2233657983993ff6c2be48e836a935863c/supplemental_data/optic-column-type-assignments-v1.0.xlsx) |
  266. To download by hand instead (for example on a slow connection, or with `curl -C -` to resume):
  267. ```sh
  268. mkdir -p ~/fly-data/raw && cd ~/fly-data/raw
  269. B=https://storage.googleapis.com/flyem-male-cns/v1.0/connectome-data/flat-connectome
  270. curl -LO -C - $B/connectome-weights-male-cns-v1.0-minconf-0.5.feather
  271. curl -LO -C - $B/body-annotations-male-cns-v1.0-minconf-0.5.feather
  272. curl -LO -C - $B/body-neurotransmitters-male-cns-v1.0.feather
  273. curl -L -o optic-columns.xlsx https://raw.githubusercontent.com/flyconnectome/2025malecns/67767d2233657983993ff6c2be48e836a935863c/supplemental_data/optic-column-type-assignments-v1.0.xlsx
  274. ```
  275. Then `python -m flybrain build` builds the network in about a minute. It writes
  276. `weights.npz` (205 MB, the signed and normalized connection matrix) and `brain.npz` (neuron
  277. types, sides, positions, readout groups, eye layout) into `$FLY_DATA`. Expect exactly
  278. **166,700 neurons and 25,582,938 connections**. If you get different numbers, the data changed.
  279. **Other ways to explore the same data**, without downloading anything:
  280. * [neuPrint](https://neuprint.janelia.org) (dataset `male-cns:v1.0`): look up any neuron's inputs and
  281. outputs in the browser, for example `DNp01`, the giant fiber. Its top inputs are LC4 and LPLC2.
  282. For code, use `pip install neuprint-python` with an API token from your neuPrint account page.
  283. * The [MaleCNS site](https://male-cns.janelia.org): cell type and dimorphism explorers, 3D viewers,
  284. and the full download list (synapse positions, skeletons, EM images; far larger and not needed
  285. here).
  286. ## Files
  287. | File | What it does |
  288. |---|---|
  289. | `flybrain/` | the pip package (`pyproject.toml`); `flybrain download/build/info` is its command line, plus `flybrain export --web DIR` in the repository (not in 0.1.0) |
  290. | `flybrain/web.py` | exports the connectome for a browser: compact gzipped CSC weights in parts under 40 MB, labels, `brain.json` |
  291. | `wiz/` | the experiments behind Wiz: `probe.py` (which motor groups answer which stimulus), `dnscreen.py` (all descending neurons vs his senses), `vnc.py`, `vnc2.py`, `vnc3.py` (can the VNC relay commands; all failed their pre-set criteria) |
  292. | `flybrain/data.py` | where the brain files live (`$FLY_DATA`), and downloading the prebuilt copy |
  293. | `flybrain/build.py` | downloads MaleCNS v1.0 and builds the weight matrix, readout groups, eye layout and neuron positions |
  294. | `flybrain/brain.py` | integrate-and-fire simulation: CPU (numba) or NVIDIA GPU (CuPy), one fly or a batch |
  295. | `flybrain/eyes.py` | photoreceptor rendering plus the looming/chase feature-detector input, with tunable encoder parameters (`ENCODER`) |
  296. | `flybrain/reservoir.py` | generic reservoir readout: spike trace of any neuron population, PCA + linear/logistic readout, cross-validated |
  297. | `flyreservoir_example.py` | the module above, end to end, on a synthetic task |
  298. | `experiment.py`, `sweep.py`, `inject.py` | the experiments above |
  299. | `flytalk.py` | the talking-flies experiment: two brains coupled through wing song and hearing, a scrambled-wiring control, permutation tests (`pilot`, `run`, `report`, `followup`) |
  300. | `flybook.py` | turns a `flytalk.py` run into the Flybook feed (`docs/assets/flybook.json`) |
  301. | `talk/`, `talk-fix/`, `talk-2ms/` | results of the three talking-flies runs (`results.json`; the raw `.npz` recordings are not committed) |
  302. | `mine/` | fly.ai compute: integer brain (CPU and WebGPU), checking server on fly.io, paid orders and buyers' programs (WASM, WGSL), house orders, website pages, Chrome extension, staking and monthly-claims contracts, example programs ([README](mine/README.md)) |
  303. | `sshfighter/` | the SSH Fighter bot, dashboard and trained readout ([README](sshfighter/README.md)), built on `flybrain/reservoir.py` |
  304. | `drone/` | the connectome flying a simulated quadcopter: following by camera, learning who to follow, hand gestures ([README](drone/README.md)) |
  305. ## What's next
  306. * ~~A generic readout interface~~ done: `flybrain/reservoir.py`. Encoders (mapping images, sound,
  307. odour-like patterns, sensor readings onto neuron groups) are still written per task -- see
  308. ROADMAP.md for candidate tasks to try it on next.
  309. * A benchmark: does the real wiring beat randomly rewired copies of itself on the same tasks?
  310. The talking-flies control is the first data point, and it points both ways: scrambled wiring
  311. carries nothing at 20 ms and as much as the real brain at 2 ms.
  312. * Learning inside the brain through the mushroom body's dopamine rule, the way real flies learn. First working use:
  313. [`drone/`](drone/README.md) learns who to follow by colour, with the learned weights kept outside the connectome's own.
  314. * ~~A 3-D world~~ built as a prototype in [`world/`](world/)
  315. ([flyaiworld.com/simulation](https://flyaiworld.com/simulation/)). It runs a separate,
  316. 748-neuron model per fly, not the connectome, with a mushroom body that learns which smells to avoid.
  317. It also runs around the clock on a server (`world/server/`) that records the population to the database. **Wiz**, a giant wizard in that world, runs the full
  318. connectome in the browser: his senses feed it, and its descending neurons pull his puppet strings.
  319. Descending commands don't reach this model's motor neurons (three calibration attempts, all failed
  320. their pre-set criteria), so his wish to wander is coded; see [world/README.md](world/README.md).
  321. * ~~**Flybook**~~ live at [flyaiworld.com/flybook](https://flyaiworld.com/flybook/): people create and breed their own
  322. flies, and the flies post, react, set off chains of reactions, duel and trade in a simulated market from their real signals.
  323. * The same brain in a different body: driving a [Smol](https://opensea.io/collection/smols-752105135)
  324. inside that world. The connectome stays frozen; only the encoder and the readout change.
  325. ## Credits
  326. * **Connectome:** MaleCNS v1.0 by FlyEM (HHMI Janelia), the University of Cambridge, the MRC
  327. Laboratory of Molecular Biology and Google Research. Data used under
  328. [CC BY 4.0](https://male-cns.janelia.org/download/).
  329. * **[Fly64](https://github.com/ornata/fly)** by Jessica Paquette, who got the MaleCNS brain
  330. to play Super Mario 64. The neuron model, weight normalization and optic-column handling here
  331. are adapted from it.
  332. * **[Eon Systems](https://eon.systems/updates/embodied-brain-emulation)**, for the idea of
  333. feeding a visual front end into an embodied connectome.
  334. * Written with [Claude Code](https://claude.com/claude-code).
  335. ## References
  336. 1. Berg, S. et al. (2026). Sexual dimorphism in the complete connectome of the *Drosophila* male central nervous system. *Cell*. Data: [male-cns.janelia.org](https://male-cns.janelia.org)
  337. 2. Google Research (2026). [A connectomics milestone: mapping the complete male fruit fly brain](https://research.google/blog/a-connectomics-milestone-mapping-the-complete-male-fruit-fly-brain/)
  338. 3. flyconnectome/2025malecns: [optic column type assignments v1.0](https://github.com/flyconnectome/2025malecns)
  339. 4. Plaza, S. M. et al. (2022). neuPrint: an open access tool for EM connectomics. *Frontiers in Neuroinformatics* 16.
  340. 5. Dorkenwald, S. et al. (2024). Neuronal wiring diagram of an adult brain. *Nature* 634.
  341. 6. Shiu, P. K. et al. (2024). A *Drosophila* computational brain model reveals sensorimotor processing. *Nature* 634.
  342. 7. Wang-Chen, S. et al. (2024). NeuroMechFly v2: simulating embodied sensorimotor control in adult *Drosophila*. *Nature Methods* 21, 2353–2362.
  343. 8. von Reyn, C. R. et al. (2014). A spike-timing mechanism for action selection. *Nature Neuroscience* 17, 962–970.
  344. 9. Ache, J. M. et al. (2019). Neural basis for looming size and velocity encoding in the *Drosophila* giant fiber escape pathway. *Current Biology* 29, 1073–1081.
  345. 10. Ribeiro, I. M. A. et al. (2018). Visual projection neurons mediating directed courtship in *Drosophila*. *Cell* 174, 607–621.
  346. 11. Rayshubskiy, A. et al. (2020). Neural control of steering in walking *Drosophila*. *bioRxiv*.
  347. 12. Bidaye, S. S. et al. (2014). Neuronal control of *Drosophila* walking direction. *Science* 344, 97–101.
  348. 13. von Philipsborn, A. C. et al. (2011). Neuronal control of *Drosophila* courtship song. *Neuron* 69, 509–522.
  349. 14. Paquette, J. (2026). [Fly64: a fly brain model plays Super Mario 64](https://github.com/ornata/fly).
  350. 15. Eon Systems (2026). [How the Eon team produced a virtual embodied fly](https://eon.systems/updates/embodied-brain-emulation).
  351. If you use the connectome data, cite reference 1 and follow the
  352. [MaleCNS attribution terms](https://male-cns.janelia.org/download/).
  353. ## License
  354. The code in this repository is released under the [MIT License](LICENSE).
  355. The MaleCNS connectome data is **not** in the repository or the pip package. `flybrain build`
  356. downloads it from its source; `flybrain download` fetches files derived from it (the normalized
  357. weight matrix and neuron annotations). Both stay under the data's own [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) license from
  358. FlyEM (HHMI Janelia) and collaborators.

Ratings and comments

Sign in to rate this skill.

Sign in

Free to use. If it’s helped, pass it on.