Skip to content

Latest commit

 

History

History
166 lines (148 loc) · 11.5 KB

File metadata and controls

166 lines (148 loc) · 11.5 KB

Mycelia — an adaptive mycelial ecosystem on the GPU (master plan)

Chosen 2026-06-10. The flagship web-supremacy proof point, in its real form: not a slime-mold screensaver but a living fungal organism that visibly solves its environment — grows toward food, pulls resource home through reinforcing cords, prunes dead ends, clashes into spalted-wood zone lines, and (later) fruits and reseeds. Engine = adaptive transport (Tero et al., Science 2010, adaptive network design); body = foraging + zone lines; payoff = the fruiting life cycle.

Thesis (locked)

A living mycelial ecosystem — hyphal growth, resource transport, adaptive network optimization, competition, and reproduction — whose entire simulation is ordinary, unit-tested Rust, compiled to your GPU by rust-gpu and verifiable on the CPU.

The honest boundary-push: a coupled per-frame relaxation solver with adaptive feedback, in rust-gpu, is something no rust-gpu demo has shown — it proves the stack does serious scientific simulation, not toys. The "it optimizes the network" behavior is a citable result, not hand-waving.

The model (biology → simulation)

Fields (planar f32 buffers at sim resolution W×H)

  • nutrient — substrate food. Consumed by foraging; static patches (later: slow regrow).
  • biomass[c] per colony c — the permanent hyphal network. Doubles as conductivity: resource flows only where biomass exists. This is what glows.
  • resource[c] per colony — transportable sugars. The thing the solver moves.
  • flux[c] per colony — scratch: resource throughput per cell this frame (drives adaptation).
  • (T5+) barrier — zone lines. (T6+) moisture, fruiting markers.

Agents — hyphal tips (NOT a swarm; tens of thousands of tips)

Tip { x, y, heading, colony, alive }. Tips extend the network; the population grows by branching and shrinks by anastomosis/atrophy. v1: fixed-max array + alive flag + atomic spawn counter; upgrade to indirect-dispatch compaction only if needed.

The transport solver — THE HEART (Tero adaptive model, field form)

Per relaxation iteration, per colony (Jacobi):

  • conductivity between cell i and 4-neighbor j: k_ij = min(B[i], B[j]) (cords = sharp).
  • resource diffuses, weighted by conductivity: R'[i] = R[i] + α · Σ_j k_ij · (R[j] − R[i]), α small for stability (α · 4 · max_k < 1; clamp).
  • accumulate throughput: F[i] += Σ_j k_ij · |R[j] − R[i]|. Run K iterations/frame (K≈4–12) so resource propagates several cells.

Sources & sinks (set before/after the iterations):

  • foraging tip on nutrient: R[cell] += income, nutrient[cell] −= forage_rate (source).
  • growing tip: consumes R[cell] −= growth_cost (sink) — growth is resource-limited.

Adaptation (once/frame, after transport) — the feedback that makes it intelligent: B[i] += adapt_rate · F[i] − atrophy · B[i] (clamp ≥ 0). High-throughput routes thicken into cords; unused biomass atrophies and prunes. This is exactly the Tero rule and it is what makes the network find efficient supply routes.

Tip growth (chemotropic, resource-limited)

Each frame, per tip: sense nutrient gradient (3 sensors) → steer up-gradient; mild avoidance of dense own-biomass (no backtracking) and rival biomass (T5 zone lines). If R[cell] ≥ growth_cost: advance, deposit B[cell] += deposit, pay the cost; else stall. At a nutrient cell: forage (income + deplete). Branch stochastically when resource-rich. Anastomose (terminate, free slot) when entering established own-biomass → closed loops.

Per-frame pass order

  1. grow tips (sense/steer/extend/deposit/forage/branch/anastomose) → sets R sources/sinks
  2. transport ×K (relaxation + flux accumulation)
  3. adapt (biomass thicken/prune from flux)
  4. compete (zone lines) — T5
  5. fruit/sporulate — T6
  6. render (compose fields → bioluminescent color)

Verification strategy

  • Per-function CPU unit tests: growth step, conductivity, one transport iteration (mass-conserving up to source/sink), adaptation monotonicity.
  • The killer integration test (T3, CPU): adaptive shortest path. Seed biomass connecting a source and a sink by TWO routes (short + long). Run grow-free transport+adaptation N steps. Assert the short route's biomass ends thicker than the long route's — the network chooses the efficient path. This both validates the solver and demonstrates the science.
  • GPU-vs-CPUdelivered (bench/src/bin/myc_verify.rs): deterministic axis-aligned grow is bit-exact; the transport field is ε-comparable (max rel err ~1e-7, fma-only) for a fixed biomass+resource setup. Run: cargo run -p bench --bin myc_verify --release.
  • Headless browser: renders, field is alive, mouse-drop foraging visibly connects.

Build phases

  • T1 — Organism foundation. shared/src/mycelium.rs: Tip (6×f32), single-colony chemotropic growth (Jones steer toward nutrient), permanent biomass deposit, foraging depletion, branching (deterministic, returns child via Step), anastomosis (fuse on thick biomass ahead), radial spore inoculation, tested shade() (foxfire glow). 6 CPU tests green. GPU entries mycelium_spawn/grow/render_cs compile to SPIR-V (Step struct lowers fine). Branch-append (atomic) deferred to T4 per note.
  • T2 — The transport solver. resource + flux fields; saturating biomass conductivity k = m/(m+k_half) (m = min(B_i,B_j)) that keeps the Jacobi relaxation stable (α ≤ ¼) and mass-conserving however thick cords grow; transport_at (per-cell, toroidal, returns new R + |throughput|). Growth is now resource-limited: tips forage nutrient→sugar at home, pay growth_cost to advance, and stall (hold position, keep foraging) when the network can't supply them. 6 new CPU tests — R conservation + maximum principle, flow-along-cord-not-through-gaps, frozen-without-biomass, flux-tracks-gradient, resource-gated growth, forage-funded growth — 12/12 green. mycelium_transport_cs + the updated mycelium_grow_cs compile to SPIR-V and transpile through naga to WGSL (web path verified, "double-check trap" cleared). 2026-06-10.
  • T3 — Adaptive feedback + the shortest-path proof. adapt_at — the Tero B += adapt_rate·F − atrophy·B rule; cords reinforce on throughput, unused hyphae prune. Shipped the two-route shortest-path integration test (the citable result): a fair race (equal seed) between a short route and a 2× detour, transport + adaptation only — the short route reinforces to 20.3, the long to 8.1 (long/short ≈ 0.40), a decisive, non-marginal win. Plus a control — two equal-length routes tie to spread = 0.0000 — proving the separation is length-driven, not a row-major iteration artifact (the rigor that caught the NVIDIA false-positive). Pinned S/T make parallel routes equilibrate independently by length, so the numbers cross-validate. Tuned α=0.2, K=8, adapt_rate=0.08, atrophy=0.03 on CPU. mycelium_adapt_cs compiles to SPIR-V + transpiles naga→WGSL. 15/15 mycelium tests green. 2026-06-10.
  • T4 — GPU + page. All five rust-gpu entries (scatter-spawn / grow / transport / adapt+feed / render) compile + transpile naga→WGSL; web/mycelium.html runs the full multi-pass pipeline (ping-pong resource, K=6 transport sub-dispatches, per-frame grow→transport→adapt→render→present, zero readback); bioluminescent render (foxfire cyan-green cord glow + resource shimmer on a near-black substrate); mouse drops a nutrient disk (folded into the adapt pass — a standalone single-&mut[f32] threads(8,8) entry is silently culled by this rust-gpu build, gotcha recorded); scattered inoculation seeds a living field. Reusable headless verifier web/headless.pyverified OK (304 frames, field alive, no error). GPU-vs-CPU determinism gate bench/src/bin/ myc_verify.rs (real rust-gpu SPIR-V via PASSTHROUGH vs the CPU reference) — GATE OK: transport max rel err 1.6e-7 (resource) / 5.3e-7 (flux); grow bit-exact (0.0 diff on tips + all three fields). 2026-06-10. (Cords-between-colonies look = T7 polish.)
  • [~] T5 — Competition & zone lines. KERNEL + PROOF DONE: two colonies encoded as the sign of biomass (+ = colony 0, − = colony 1) — a design that adds no new buffers and leaves single-colony behaviour byte-identical. conductivity is sign-gated (rival cells never exchange resource → colonies stay metabolically separate); grow_tip gains rival-biomass avoidance (steers on a combined nutrient−rival signal) and a clash → stop rule that leaves the spalted-wood zone line at the interface. 4 CPU tests incl. the zone-line proof — two colonies grow head-on, meet, and form a boundary neither crosses (no interleaving) — 20/20 mycelium tests green. 2026-06-10. PENDING (T5b/c): multi-colony scatter-spawn (assign colony per tip) + colony-hued render with dark zone lines + page wiring — do the shader rebuild + paramsBytes update (Params grew by rival_avoid/ clash_thresh) together so build.ps1 stays coherent.
  • T6 — Life cycle (the payoff). Fruiting detection (biomass+resource > threshold), primordium growth, spore emission (new tips at a dispersal radius) → generational turnover. Atomic spawn / indirect dispatch as needed.
  • T7 — Polish. Look tuning (Carter's eye is the gate), presets (forest floor / petri dish / log), performance (field res × K for 60 fps), HUD, capture, README with the honest thesis + hero capture. Headless ?auto beacons throughout.
  • T8 — [RED] Package + announce. Own-repo extraction + Pages; name decision (working "Mycelia"; Foxfire is a candidate if we lean into the bioluminescence). Any outward announce needs an Approvals line.

Risks & unknowns

  • Solver stability — relaxation diverges if α/K wrong; the CPU tests + clamps catch it. Budget T3 tuning time.
  • Performance — K transport iterations × W×H × C colonies per frame is the cost center. Lever: lower sim res than display res (render upscales), cap K, fewer colonies. Measure early.
  • GPU tip population — branching/death needs compaction or fixed-max+flags. Start fixed-max+alive; only build indirect-dispatch compaction if the cap bites.
  • Determinism for GPU-vs-CPU — keep growth deterministic from (tip-id, frame); transport is deterministic; verify on a single tip + a fixed field.
  • The look — bioluminescent cords on dark substrate; needs render tuning and his eye (T7).

Reuse / supersession

  • The multi-species-physarum prototype (shared/src/mycelia.rs, web/mycelia.html) was the plumbing rehearsal — it taught us the WebGPU multi-pass + present-blit + headless-shot loop, and shade()/the present pass carry over. It becomes a simpler sibling or is retired once the ecosystem engine lands; not the flagship.
  • Palettes/tonemap: gpu-shader-lib. Present-blit + ?auto screenshot harness: from mycelia.html.

Open decisions (defaults chosen; Carter can redirect)

  • 2D top-down field (3D is a separate, much larger project). Default: 2D.
  • Single colony through T4, multi-colony competition at T5. Default: single-first.
  • Lives in the rustgpu-bench workspace during the build; own repo at T8. Default: yes.
  • Name: working Mycelia; Foxfire if we center the glow. Decide at T8.