# The room's connectome coding experiment

This integrates the actual bundled male fly connectome from [blendi-remade/fly-brain-minecraft](https://github.com/blendi-remade/fly-brain-minecraft), pinned to commit `6cfa30175003ef25da68a237d5eda958f8047b82`. It replaces the room's initial six-unit handcrafted controller.

## What is real, and what is an interface

- **Data:** the upstream `malecns-v1.0.flyb.gz` file is included without modification: 176,422 neurons and 6,287,749 directed connections, carrying 90,296,905 synapses. Connections with fewer than five synapses and autapses were removed upstream. This is the reference's full thresholded nervous-system graph, not a small illustrative neural network.
- **Dynamics:** `brain-engine.mjs` adapts the upstream `Connectome.java`, `PopulationIndex.java`, and default exponential-synapse pathway of `LifNetwork.java` into JavaScript. Every neuron has a membrane, synaptic drive, refractory state, and delayed synaptic inputs; only the active set is integrated. Excitatory/inhibitory signs and synapse-count weights come from the actual dataset.
- **Inputs:** the buttons inject named sensory/visual population stimuli as Poisson spike generators. Sugar, sugar+JO-F, sugar+bitter, looming, touch/wind, and quiet are synthetic cues. This adapter does not implement the Minecraft retina, odor world, or ray-cast room vision. In particular, looming directly stimulates the LC4/LPLC2 feature channels, as the reference's diagnostic mode does.
- **Readouts:** MN9, DNa02 left/right, DNp09, MDN, DNp01, DNg02, DNp07/10, DNg62/DNge078, Kenyon cells, and leg-motor populations are resolved using the dataset annotations. The room uses a small normalized rate decoder, not the reference's complete motor state machine. Positive MN9 feeding output advances template characters; the giant-fibre escape signal inhibits this adapter. Finishing the source enables program execution.
- **Coding:** MN9 has no biological relationship to programming. Mapping feeding to typing, choosing the XOR/XNOR template, the seated animation and emotional analogies, and triggering execution after the final character are all explicit human-built scaffolding. The fly does not understand or invent source code. Without the required motor output, the adapter cannot type or execute.
- **Program:** the resulting 2–6–1 neural-network program actually runs gradient descent; its loss, predictions, weights and accuracy are computed. Its four-row truth table is also its training set.

## Parameters and reproducibility

`dt=0.5 ms`, membrane time constant `20 ms`, synaptic time constant `5 ms`, rest/reset `−52 mV`, threshold `−45 mV`, refractory `2.2 ms`, delay `1.8 ms`, synaptic weight `0.275 mV × count × sign × 0.65`. As upstream does, delay and refractory durations are rounded to integer integration steps: at this dt their effective durations are both 2 ms. Kenyon-cell input gain is 0.25. Adaptation, input normalization, and injected-current modes are not implemented; their upstream defaults are off. No topology is learned or retrained.

State uses Float32 arrays, with JavaScript double-precision intermediate arithmetic. Poisson stimulation uses seeded xorshift32 instead of Java's SplittableRandom. Reservoir sampling uses a separate generator so drawing telemetry cannot alter neural activity. Runs are therefore deterministic within this implementation but **not bit-for-bit replicas of the Java engine**. Both local live runs and scheduled builds use seed `20260903`; changing stimuli changes subsequent dynamics. Different seeds/precisions can yield different recurrent activity. The 0.65 gain can over-excite the network under some stimuli; firing rates are model outputs, not validated biological measurements. Bitter stimulation can leave persistent activity and MN9 suppression after switching back to sugar. Restarting live mode creates a fresh brain; the adapter never fabricates spikes to recover.

## Browser and cron

The default view replays a **recorded, actually computed** build trace from `../programs/brain-run.json`, visibly labelled as replay at 0.25× neural time. It does not silently download the 23 MB graph. “Run live brain” loads and verifies the graph, starts a Web Worker, and enables interactive stimuli. It may run slower than real time, and the neuroscope reports compute speed. Live jobs have a 20-second neural-time budget after the latest stimulus change; lack of sufficient output stops the job without executing code. Hidden tabs pause workers and replay. After the coding gate completes, the separate program worker trains the generated network while the brain continues accepting sensory cues until its 20-second neural-time budget. The live controls then disable until the next run.

The brain map is a dorsal projection of the 141,781 known soma positions, with brain/nerve-cord axes derived from regional centroids like upstream `BrainViewHud`. The map retains each neuron's dense index; unknown soma positions are not invented. Colours represent broad annotated regions. Up to 256 reservoir-sampled spikes per tick are highlighted and rastered; the spike counts and population rates use all spikes. `brain-map.bin` is a derived display artifact (4-byte neuron count, 2 × Float32 coordinates per neuron, one region byte per neuron).

The six-hour GitHub Actions cron runs `scripts/run-fly-lab.mjs`: verify the data, simulate quiet then sugar cues, pass actual MN9 output through the coding adapter, save/execute the exact completed module, validate its results, then publish the source, trace, map, and report with the static site. A failed motor gate or failed program aborts the build. These are latest-run artifacts, not an append-only history. Browser downloads do not write to GitHub Pages. The workflow must be deployed on the default branch before its cron is active.

## Attribution and verification

Code adapted from Blendi Remade / fal.ai, copyright 2026, [MIT license](LICENSE). The unchanged connectome and the map/trace derived from it are attributed to the FlyEM Project Team (HHMI Janelia Research Campus), the Drosophila Connectomics Group (University of Cambridge / MRC LMB), and Google Research, under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/). See [upstream provenance](UPSTREAM-PROVENANCE.md) for the exact queries, transforms, publications, and license details.

Compressed SHA-256: `e33df182bed7a6f3ea279daf4790a82b05706d3d41e819a6a80c0473e8c559f3`. Both runtime and build verify this before simulation.

Tests cover silent full-network behavior, sugar-driven MN9 activity, bitter suppression, looming-driven giant-fibre activity, inhibitory/excitatory delayed transmission, checksum failure, the coding gate, and real anatomy counts. The upstream Java headless engine was also compiled locally and run against the same file/parameters: sugar drove MN9 there too; its exact activity trajectory differed, consistent with the RNG/numerical differences above. This is qualitative integration validation, not scientific equivalence or a new biological validation.

## Room-event analogies

`fly-behavior.mjs` maps work calls to looming (LC4/LPLC2), undertrained results and long shifts to sugar+bitter populations, and confirmed music playback to sugar and JO-F antennal mechanosensory populations. Focused coding also uses sugar as the work cue. There is no claim that these populations encode frustration, enjoy IU, recognize music, or write code. The event policy selects the input; the actual LIF graph computes all spikes and motor readouts. The avatar maps MN9 to front-leg typing/music movement, DNp01 to startle, and measured MN9 suppression under bitter input to a slumped pose. Playback is never inferred from clicking a button. The shift clock is deliberately accelerated (15 visible working seconds per simulated hour) and independent of neural time. Raw sensory controls override the story mapping until another story event.
