T-001: Sim core architecture and skeleton
Goal
Build the foundation every other sim ticket stands on: the data model, the step loop, determinism, checkpoints and speed measurement. You are deciding the architecture. Write it down so that six agents can then work on separate modules at the same time without colliding.
Scope
- World data model in
crates/sim: cells, bonds and organisms as flat arrays laid out for speed and for parallel updates. Stable ids. Cells and bonds are created and removed constantly mid-run, so that must be cheap and must not break references. Params: every tunable number in one serde struct, loadable from TOML and stored in checkpoints. Tuning agents will sweep these values, so each one gets a doc comment giving its meaning, unit and sensible range.- Step pipeline with named stages that later tickets fill in: fields, sensing, control, physics, interactions, metabolism, development, reproduction, bookkeeping. Fixed time step.
- Deterministic randomness. The same seed and params give the identical world on the same build, whatever the thread count.
- Parallelism. Native uses all cores.
wasm32-unknown-unknownruns on one thread. Both from the same code. - Spatial index for neighbour queries, as a shared service. Physics, senses and feeding will all need it.
- Checkpoints. Save and load a whole world to bytes: versioned header, compressed, same format on native and web.
- Just enough physics to prove the loop: position integration, distance bonds, world bounds. T-009 replaces it.
- Read-only view for the viewer: iterate cells (position, radius, colour, opacity, type, organism) and bonds without copying the world.
runner bench: worlds of 10k, 100k and 1M bonded, jiggling cells. Report steps per second on one thread and on all threads. Append results todocs/perf/LOG.md.docs/ARCHITECTURE.md: module map, data layout, step order, determinism rules, checkpoint versioning rules, and how to add a cell type, a field or a stage. State which module each of T-009 to T-019 owns.
Done when
- ☐ Tests pass: same result on 1 thread and on all threads, checkpoint round trip, and "run 200 steps" equals "run 100, save, load, run 100".
- ☐
cargo build -p sim --target wasm32-unknown-unknownsucceeds. - ☐ Benchmark numbers are in
docs/perf/LOG.md, with an honest statement of whether 100k cells runs faster than real time. - ☐
docs/ARCHITECTURE.mdexists and another agent could start T-009 from it alone.
Notes
- Cross-platform bit-for-bit determinism is not required (
docs/DESIGN.mdsection 12). - Prefer few dependencies in
sim. No Bevy. - Generation time is a design choice: say in the architecture doc what one step represents and how many steps you expect a lifetime to be.
Result
Branch t-001-sim-core. Everything in scope is delivered. The physics is a placeholder,
as the ticket asked.
Done when
- ☑ Tests pass.
cargo test -p sim -p runner: 59 tests. Same result on 1, 2, 3 and all threads with births, deaths, growth, bites, splits and memory repacks going on. Checkpoint round trip is exact. Run 200 equals run 100, save, load, run 100. - ☑
cargo build -p sim --target wasm32-unknown-unknownsucceeds, andcrates/sim/examples/wasm_probe.shshows a native checkpoint loading in WebAssembly under Node and the file WebAssembly saves loading natively. - ☑ Benchmark numbers are in
docs/perf/LOG.md. 100,000 cells runs at 82 steps/s on one thread and 441 on twelve, against 30 for real time. So yes, faster than real time today, but only the placeholder physics is running. The log says so plainly and gives the margin: about 15 times on all cores, 2.7 times on one thread. - ☑
docs/ARCHITECTURE.mdexists. Whether another agent can start T-009 from it alone is for the T-009 agent to say. The stage-writing patterns it teaches are compiled and run bycrates/sim/tests/patterns.rs.
Measured
| Cells | 1 thread | 4 threads | 12 threads |
|---|---|---|---|
| 10,000 | 798 steps/s | 1,887 | 2,214 |
| 100,000 | 82 steps/s | 250 | 441 |
| 1,000,000 | 8.6 steps/s | 30 | 60 |
Every row ended in the same world, bit for bit, as the one-thread row. WebAssembly on one thread: 706 steps/s at 10,000 cells. About 120 bytes per cell in memory, 61 in a checkpoint. A world of 1,000,000 cells saves in 66 ms and loads in 28 ms.
What fell short or is uncertain
- Scaling across cores is modest: 5.4 times on twelve threads at 100,000 cells. Not investigated.
- The benchmarks ran while other agents were compiling (load average about 10). The many-thread rows are good to about 20%.
- The real-time question is not settled until real physics and senses exist.
- Two thirds of a step is the per-cell neighbour query, which mostly finds the organism's own cells. An obvious improvement was left for T-009, which owns contacts.
- Changing a column group's version refuses old checkpoints outright. There is no hook to convert old column data yet.
Decisions made here
Recorded in docs/ARCHITECTURE.md section 14. The ones most likely to be questioned:
- One step is 1/30 s,
yis up, one unit is about one cell diameter. - A lifetime is planned at about 5,000 steps.
- Bonds never join two organisms, and an organism is limited to 65,535 cells.
- The world is a closed box. Wrapping the sides is left open.
- Thread count is not a parameter and is not saved.
fields::FieldsState::floor_heightandcurrentwere added as stubs so that T-009 and T-011 can work at the same time.