No description
  • Pascal 99.7%
  • Batchfile 0.3%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-09-18 17:35:53 +02:00
.pi/tasks phase 1 2026-09-18 17:35:53 +02:00
bin phase 1 2026-09-18 17:35:53 +02:00
build.cmd pahase 0 2026-09-18 15:51:51 +02:00
Connectome.pas phase 1 2026-09-18 17:35:53 +02:00
FlyConnectome.dpr phase 1 2026-09-18 17:35:53 +02:00
FlyConnectome.dproj full barin 2026-09-18 16:48:28 +02:00
FlyConnectome.dproj.local full barin 2026-09-18 16:48:28 +02:00
FlyConnectome.res full barin 2026-09-18 16:48:28 +02:00
FlyExperiment.dpr pahase 0 2026-09-18 15:51:51 +02:00
FlyExperiment.dproj pahase 0 2026-09-18 15:51:51 +02:00
FlyExperiment.dproj.local pahase 0 2026-09-18 15:51:51 +02:00
FlyExperiment.res pahase 0 2026-09-18 15:51:51 +02:00
FlySim.Engine.pas full barin 2026-09-18 16:48:28 +02:00
FlySim.Main.pas full barin 2026-09-18 16:48:28 +02:00
Ocl.pas full barin 2026-09-18 16:48:28 +02:00
README.md phase 1 2026-09-18 17:35:53 +02:00

The Fly Experiment

A desktop spiking-simulation of a fly brain (Delphi 13, VCL, Win32). 451 LIF neurons / ~2.4k synapses built from identified Drosophila circuit motifs (FlyWire adult brain connectome + Janelia MaleCNS nerve cord), a modeled 2D room with odors, heat, sugar and light, a 6-leg tripod-gait body, and dopamine-gated learning so you can actually train the fly.

Run

bin\FlyExperiment.exe

(or open FlyExperiment.dproj in RAD Studio and press F9). Headless self-test: bin\FlyExperiment.exe --selftest (writes selftest.log, exit code 0 = all 5 checks passed).

How to play

  • Room (left): pick a stimulus type on the right panel, then click the room to place it.
    • Odor A / B – smellable plumes (~160 px reach), trainable
    • Sugar drop – reward: walking over it triggers PAM-like DA (+1) pulses
    • Heat lamp – punishment: hot antennae → escape; body > 39 °C → shock DA (−1)
    • Light spot – drives retina → T4/T5 motion detectors
    • Erase – click near a stimulus to remove it
  • Training recipes
    1. Appetitive: drop Odor A + a sugar drop on the same spot (repeat a few times).
    2. Aversive: drop Odor B + a heat lamp together (the fly will get shocked).
    3. Or just tick Auto-train — it alternates A+sugar (CS+) and B+heat (CS−) in 40 s cycles.
    4. Press Preference test: odors A and B are placed left/right with no rewards. A trained fly crowds the A side. Watch the KC→MBON weight bars and occupancy.
  • Speed slider: 1× (real time) to 60×. Charts show population firing rates, the EB ring-attractor heading estimate, KC→MBON weights, membrane voltage of the selected population, and the dopamine reward signal.

What's inside (circuit provenance)

Module Motif Source
Antennal lobe → MB ORN→PN convergence, sparse Kenyon cells with APL feedback inhibition, KC→MBON APP/AV synapses FlyWire (codex.flywire.ai); MB learning circuit per Aso et al. 2014
Mushroom-body learning dopamine three-factor rule: reward potentiates active odor→APP, depresses →AV; punishment the reverse (PAM/PPL1) Aso 2014, FlyWire MBON/DAN connectivity
Optic lobe retina → T4/T5 elementary motion detectors (HRC correlator, 4 directions) → lobula plate FlyWire optic lobe; Barlow-Levick HRC model
Central complex ellipsoid-body 8-wedge ring attractor + PB global inhibition = heading estimate Kakaria & de Bivort 2017 (wiring slaved to true heading: no haltere/path-integration model)
Innate odor steering lateral horn ipsilateral turn; MBON-APP/AV gate LHN gain FlyWire LH antennal-lobe circuits
Brain→leg DN_L/DN_R/DN_F descending neurons → VNC flexor/extensor interneurons → leg motor-neuron pools with antagonistic inhibition MaleCNS (male-cns.janelia.org, neuprint male-cns)
Gait tripod CPG (L1,R2,L3 / R1,L2,R3 anti-phase) driving joint-kinematic legs classic cockroach/fly tripod literature

Honesty note: connectivity is a literature-parameterized skeleton of the identified circuits at ~450 cells, not the raw 139k-neuron FlyWire graph. Simulation of the full connectome is out of scope for a 1 ms desktop loop; the wiring, neuromodulation and learning rules follow the published circuit motifs. Real connectome exports can extend population wiring (below).

Connectome CSV import

ImportEdgesCSV (wired into the engine; format):

# pre_pop,post_pop,conn,weight[,delay_ms]
ORN_A_L,PN_A,4,6.0,2      # conn <= 1 = probability, > 1 = edges per postsyn cell

Population names must match the engine's (ORN_A_L, PN_A, KC, DN_F, ...). Export FlyWire edges via the codex.flywire.ai UI (CSV, no login) or caveclient/neuprint (flywire dataset; MaleCNS = male-cns on neuprint.janelia.org, free token), group by (pre,post) type, and map to these pool names. All research-brief claims here were model-knowledge only (the research agent had no web tools) — spot-check before scripting against APIs.

Full-scale connectome module (FlyConnectome)

bin\FlyConnectome.exe runs the real wiring graph at full scale (event-driven LIF over a CSR adjacency, 1 ms ticks):

FlyConnectome --info                       device report + usage
FlyConnectome --selftest                   propagation/determinism/GPU-fallback checks
FlyConnectome --bench [neurons] [outDeg]   synthetic graph benchmark (GPU if available)
FlyConnectome --run edges.csv 60 gpu       simulate an exported connectome for 60 s

Getting real data (the engine is size-agnostic; FlyWire adult brain is ~139k neurons / ~34M synapses, MaleCNS similar for the male CNS):

  • FlyWire: codex.flywire.ai → query → download CSV (browser, no login), or caveclient (free token via Google sign-in); group synapses by (pre, post) pair and export pre_root_id, post_root_id, syn_count.
  • MaleCNS: neuprint.janelia.org dataset male-cns, free token, fetch_simple_connections → same CSV shape.
  • These API pointers came from a research agent without live web access — spot-check against the sites before scripting.

GPU: the simulator uses OpenCL (integrate + scatter kernels) when the machine has a working ICD, and falls back to a CPU event-driven path otherwise — the engine, loader and both paths are identical in behavior. On this machine the installed OpenCL.dll crashed during probing, so runs use CPU mode; on a machine with healthy NVIDIA/AMD/Intel drivers the same --run ... gpu line engages the GPU automatically.

What it is not: cell-type-specific sense/motor mapping and calibrated synaptic weights are future work — today the module is a stimulation sandbox on the real graph (inject current into a neuron range, watch propagation).

Typed connectomes: senses + behavior (--experiment)

The full graph can now live in the room. Provide a node table alongside the edge list and typed neurons get coupled to modeled senses/joints:

FlyConnectome --experiment edges.csv types.csv 60

types.csv: root_id,type,side[,odor] e.g. 912345678,ORN,l,a

  • type prefixes recognized (case-insensitive): ORN/OLF, GRN/GUST, HOT/WARM, COLD, MN/MOTOR/LEG, DN, PN, KC, MBON, APL, DAN/PAM/PPL, LHN
  • side: l/left, r/right
  • odor (ORN only): a/b — which trained odor the receptor maps to (default A; without receptor-specific data this is a documented hack)

Coupling: odor/heat/sugar fields drive typed ORN/GRN/HOT neurons (same field model as the mini app); DN_F gets tonic descending drive; MN pools receive tripod-CPG patterned injection; pool firing rates move the fly body. Chemotaxis on a typed synthetic graph is asserted in --selftest (x 600 → 1079 toward the source, MN alternation visible). DA-gated learning on real connectome weights is future work (v1 coupling is fixed-weight).

Rebuilding

Command-line dcc32 is blocked by the Delphi Community Edition license, so:

  • IDE: open FlyExperiment.dproj, press F9, or
  • batch: bds.exe -ns -b FlyExperiment.dproj (RAD Studio 13 at C:\Program Files (x86)\Embarcadero\Studio\37.0). Output goes to bin\, errors to FlyExperiment.err when built headless.

Files: FlySim.Engine.pas (network, body, room, learning, self-test), FlySim.Main.pas (code-only VCL UI), FlyExperiment.dpr.