{"id":51450890,"url":"https://github.com/migkapa/flyputer","last_synced_at":"2026-07-05T20:30:39.649Z","repository":{"id":365808304,"uuid":"1273867317","full_name":"migkapa/flyputer","owner":"migkapa","description":null,"archived":false,"fork":false,"pushed_at":"2026-06-19T00:48:26.000Z","size":40,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-06-19T02:21:16.293Z","etag":null,"topics":["brain-simulation","connectome","drosophila","energy-efficiency","flywire","llm-agent","logic-gates","neuromorphic-computing","neuroscience","threejs"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/migkapa.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":"CITATION.md","codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-06-19T00:31:08.000Z","updated_at":"2026-06-19T00:48:29.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/migkapa/flyputer","commit_stats":null,"previous_names":["migkapa/flyputer"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/migkapa/flyputer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/migkapa%2Fflyputer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/migkapa%2Fflyputer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/migkapa%2Fflyputer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/migkapa%2Fflyputer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/migkapa","download_url":"https://codeload.github.com/migkapa/flyputer/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/migkapa%2Fflyputer/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35168795,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-05T02:00:06.290Z","response_time":100,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["brain-simulation","connectome","drosophila","energy-efficiency","flywire","llm-agent","logic-gates","neuromorphic-computing","neuroscience","threejs"],"created_at":"2026-07-05T20:30:38.993Z","updated_at":"2026-07-05T20:30:39.643Z","avatar_url":"https://github.com/migkapa.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Ask the Fly Brain 🪰🧠\n\nLet a local **Gemma** model drive a simulation of the **FlyWire** fruit-fly brain\nconnectome. You ask a question in plain English; Gemma calls tools that pull the *real*\nconnectome (the ~140k-neuron wiring diagram of an adult *Drosophila*) and run a small\nspiking simulation, then explains what lit up — gates, arithmetic, a heading memory, a\nmoving fly, shortest paths, even a game you play against the fly's real escape reflex.\n\n```\nyou (English) ─▶ Gemma (local, via Ollama) ─▶ {\"tool\": ...}\n                                                  │\n        find_neurons ─ stimulate ─ show_logic_gate ─ do_math ─ show_compass\n        ─ move_fly ─ navigate_fly ─ show_path ─ dodge_swatter ─ neuroglancer\n                                                  │\n                          real FlyWire data + a tiny LIF sim\n                                                  │\n                                results ─▶ Gemma ─▶ plain-English answer\n```\n\n## Setup\n\n1. **Ollama + a Gemma model.** Defaults to `gemma4:latest`. Check what you have:\n   ```bash\n   ollama list\n   # don't have it? `ollama pull gemma3:4b` and set MODEL in agent.py\n   ```\n2. **Python deps** (uses a local venv with system site-packages):\n   ```bash\n   python3 -m venv .venv --system-site-packages\n   .venv/bin/pip install -r requirements.txt\n   ```\n3. **Connectome data** (one-time, ~852 MB, no login):\n   ```bash\n   bash get_data.sh\n   ```\n   The neuron annotation file (~32 MB) auto-downloads on first run.\n\n## Run — live chat + 3D (start here)\n\n```bash\n.venv/bin/python server.py        # then open http://localhost:8000\n```\nChat on the right, a live 3D fly brain on the left. (First start loads the connectome, ~5s,\nthen warms the gates / routing graph / escape circuit in the background.)\n\nThings to ask — each lights up the real connectome and comes back with an energy ledger:\n\n- **\"What happens when the fly smells something?\"** — stimulates olfactory neurons and you\n  watch the signal cascade through the brain.\n- **\"Show me the fly brain computing an AND gate\"** — three real neurons cycle through every\n  input combination with a live truth table, a robustness chip, and an energy cost. The\n  same convergent motif computes **AND or OR** depending on excitability; gates that work:\n  AND, OR, AND-NOT. (`logic.py` finds the motifs; `energy.py` does the accounting.)\n- **\"Add 2 + 3 with the fly brain\"** — composes those real gates into a half/full adder and\n  ripple-carries across bits: `2 + 3 = 5` (`010 + 011 = 101`). It also **multiplies**\n  (\"multiply 6 × 7\" → 42). `flymath.py` is the adder/multiplier.\n- **\"Show me the fly's compass\"** — the central-complex ring of EPG/PEN/PEG/Δ7 neurons forms\n  a **heading bump** that holds like a memory and **steers to track a turn**, with a live\n  heading dial. First *stateful* computation in the project. (`compass.py`)\n- **\"Walk the fly forward, turn left, then make it escape\"** — drives the real **descending\n  command neurons** (DNp09 forward, MDN backward, DNa02 steering, DNp01 Giant Fiber escape)\n  and a virtual fly body moves in a top-down arena. (`fly.py`)\n- **\"Release the fly at heading 120 and let it navigate\"** — closed loop: the real\n  **compass → PFL3 → DNa02** steering pathway homes the fly onto a stable heading. (`fly.py`)\n- **\"Trace the path from sugar to motor\"** — \"six degrees of the fly brain\": one shortest\n  *wiring* path lights up hop-by-hop. The graph recovers textbook circuits on its own\n  (EPG→PFL3→DNa02 steering, olfactory ORN→PN→Kenyon). Pure topology, zero firing claims.\n- **\"Let me try to swat the fly\"** — a **playable game**: a looming swatter drives the real\n  LPLC2+LC4 detectors converging onto the Giant Fiber; swing faster than the circuit's\n  reaction limit to land it, slower and the real escape reflex jumps first. (`swatter.py`)\n- **\"How does the fly remember two smells without forgetting?\"** — two odors light up two\n  near-disjoint sparse sets of Kenyon cells (~0.6% each, ~2% overlap), so a new memory barely\n  touches an old one — the architecture behind not suffering catastrophic forgetting. (`sniff.py`)\n- **\"Show a heart on the fly's eye\"** — paint a picture onto the ~789 L1 lamina columns and\n  it travels along ~66k real L1→Mi1 synapses into the medulla: a recognizable image glowing\n  on the real optic lobe (a ~750-column brain's-eye view, not a camera). (`optic.py`)\n\n## Or use the pieces directly\n\n```bash\n.venv/bin/python agent.py                      # default: find sugar neurons → stimulate → explain\n.venv/bin/python agent.py \"Stimulate visual projection neurons and tell me what responds\"\n.venv/bin/python agent.py -i                   # interactive chat\n.venv/bin/python visualize.py                  # plot the response → fly_response.png\n.venv/bin/python visualize.py \"mushroom body\" 30 300   # any term, #seeds, duration(ms)\n.venv/bin/python export3d.py olfactory 40 200          # 3D web view: opens fly3d.html\n\n.venv/bin/python logic.py        # find AND / OR / AND-NOT gate motifs, with robustness\n.venv/bin/python flymath.py      # add \u0026 multiply through real composed gates (demo set)\n.venv/bin/python compass.py      # CUE → HOLD → TURN: heading-memory regime comparison\n.venv/bin/python fly.py forward left forward escape   # ASCII trajectory from real DNs\n.venv/bin/python swatter.py      # sweep swing speeds: who wins vs the escape circuit, and why\n.venv/bin/python sniff.py        # two odors -\u003e near-disjoint sparse Kenyon-cell codes\n.venv/bin/python optic.py heart  # relay an image through the real optic lobe (ASCII in/out)\n\n# find_neurons understands region names: sugar, gustatory, \"mushroom body\",\n# \"central complex\", clock, olfactory, descending, motor, Kenyon, MBON.\n```\n\nSmoke-test the backend alone (no LLM needed):\n```bash\n.venv/bin/python flysim.py\n```\n\nValidate the claims (precision, control circuits, gate robustness, arithmetic):\n```bash\n.venv/bin/python eval.py         # neurons | controls | gates  to run one layer\n```\n\n## How it works\n\n- **`flysim.py`** loads the connectome edge list + neuron annotations and exposes the core\n  tools: `find_neurons` (search by cell type / class / region), `stimulate` (inject current,\n  run a tiny leaky-integrate-and-fire sim over the 2-hop downstream subcircuit),\n  `shortest_path` (BFS routing for \"six degrees\"), and `neuroglancer` (a 3D viewer URL).\n- **`logic.py` / `flymath.py`** — real gate motifs and arithmetic composed from them.\n- **`compass.py`** — the central-complex ring attractor (heading memory + steering).\n- **`fly.py`** — descending-neuron → behavior mapping, body kinematics, and the closed-loop\n  compass→DNa02 steering controller.\n- **`swatter.py`** — the looming-escape circuit (LPLC2/LC4 → Giant Fiber) and the swat game.\n- **`sniff.py`** — the mushroom-body olfactory-learning slice and sparse-coding analysis.\n- **`optic.py`** — the retinotopic lamina→medulla (L1→Mi1) image relay.\n- **`energy.py`** — the energy ledger (see below). **`export3d.py`** builds the 3D scenes;\n  **`server.py`** is the web app; **`agent.py`** is the version-agnostic JSON tool-calling\n  loop around Gemma. **`eval.py`** is the validation harness.\n\nNo CAVE token, no `fafbseg`, no GPU — just the Zenodo file + the GitHub annotation TSV.\n\n### The energy ledger\n\nThe brain is **event-driven**: a synapse only costs energy when its neuron fires. A\nconventional chip simulating the same circuit is **clocked** — it re-evaluates every synapse\nevery tick whether it fired or not. So the fly-vs-chip ratio isn't a fixed number; it tracks\n**activity sparsity**, a real measured quantity. Sparse computations (a logic gate, ~3% of\nsynapses active) show the brain ~thousands of times cheaper; dense ones (a big olfactory\ncascade, ~44% active) much less. Per-synapse cost ≈ 10 fJ (Attwell \u0026 Laughlin) vs ≈ 1 pJ per\nclocked MAC (Horowitz); the chip clock is priced at a physical 1 kHz, not the sim's `dt`.\n\n## Honest caveats\n\n- The simulation is a **toy**: Shiu-style sign convention (ACh = excitatory, GABA/Glu =\n  inhibitory, neuromodulators ≈ 0), ~13% neurotransmitter-prediction error, and absolute\n  firing rates are **not** meaningful. It's for *qualitative* \"what's downstream of what\"\n  exploration and motif-level computation, not biophysics.\n- It runs a bounded **2-hop subcircuit**, not the whole brain at biophysical fidelity.\n- **The VNC + muscles are not in this dataset (brain only).** The moving fly and the swatter\n  game read the brain's *real* motor commands (descending neurons), but the body itself is a\n  labelled stand-in for the missing ventral nerve cord.\n- **\"Six degrees\" is topology, not timing** — it returns *a* shortest wiring path (one of\n  possibly many, at ≥5 synapses/edge), not a causal/temporal signal path.\n- **Dodge the swatter** reports the *order* of events (detectors charge → Giant Fiber spike →\n  lunge) and which swing speeds escape — **not** calibrated millisecond latencies.\n- The compass forms and steers a sharp bump faithfully; a *self-sustained* held heading needs\n  finer excitation/inhibition tuning than this toy provides.\n- **Two smells** demonstrates the *mechanism* (sparse, near-disjoint Kenyon-cell codes), not a\n  rigged benchmark — a dense net on random odors can separate them too; the point is *how* the\n  fly does it. The Kenyon code is a tuned coincidence threshold, not a calibrated firing rate.\n- **The fly's eye** is a ~750-column retinotopic sensor / brain's-eye view, **not** a camera:\n  no ommatidial optics, no T4/T5 motion detection, uncalibrated rates. The medulla is read out\n  at each cell's lamina column (a full undistorted 2D reconstruction needs de-warping the\n  curved hex lattice, which a plain PCA flatten can't do — verified retinotopic only in 1D).\n- Root IDs are pinned to FlyWire materialization **v783** (the Oct 2024 *Nature* release).\n\n## License / attribution\n\n- **Code:** MIT — see [`LICENSE`](LICENSE).\n- **Data:** the FlyWire connectome is **CC BY-NC 4.0 (non-commercial)**. See\n  [`CITATION.md`](CITATION.md) for the papers to cite and the non-commercial terms.\n- Independent hobby project — **not affiliated with the FlyWire consortium.**\n\n## What's next\n\nA sibling project turns the ~88-neuron central-complex \"compass\" circuit into an actual\n**chip blueprint** (connectome → Verilog → GDSII layout, free on a laptop). The compass and\nclosed-loop steering demos here are the on-ramp to it.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmigkapa%2Fflyputer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmigkapa%2Fflyputer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmigkapa%2Fflyputer/lists"}