# GEN-CODE result, 8 September 2026 Work package GEN-CODE of the SGH programme (`operations/research/sgh-program-20260908/`). Everything below is engineering evidence: code, tests and job manifests. No image was generated (no GPU in this package), nothing here is clinically validated, and nothing here is "solved". Everything runs from the programme root. Nothing in `research/sgh-synthetic-histopathology/` was edited; the canonical generator, `sydney_qa.py`, `sydney_qa_v1.json` and `pixcell_stain_match.py` were copied into `code/` and only the copies were changed. Nothing was committed to git. ## 1. What was built | file | lines | what it is | |---|---:|---| | `code/pixcell_generate.py` | 667 | the canonical generator (438 lines, md5 `ab317dd1...`) plus three token sources | | `code/build_token_library.py` | 411 | composition-indexed UNI2-h token library from real donor fields (GPU) | | `code/token_stats.py` | 152 | per-category grand mean, k-means centroids and nearest-real-window (torch only) | | `code/test_generate_cpu.py` | 576 | 9 CPU tests, stub encoder + stub pipeline, no weights | | `code/make_jobs.py` | 428 | writes all 15 manifests + `jobs/README.md`, deterministically | | `code/resolve_jobs.py` | 103 | resolves `PASS1/` and drops jobs whose inputs are missing | | `code/split_manifests.py` | 171 | balanced N-slot partition that never splits a pass-1 -> pass-2 chain | | `code/worker.sh` | 197 | one GPU slot: cartoons, libraries, stats, manifests, evidence, self-stop | | `code/sydney_qa.py`, `code/sydney_qa_v1.json`, `code/pixcell_stain_match.py` | - | unmodified copies the above import | ## 2. Generator changes (`code/pixcell_generate.py`) Line numbers are in the new file. | lines | change | |---|---| | 11-38 | module docstring: the three new sources, their job fields and the precedence rule | | 328-332 | `TokenCache.library()` - one `TokenLibrary` per path per process, so 20 A2 jobs load `tokens.pt` once | | 335-379 | composition vector: `COMPOSITION_FIELDS`, the label-id groups, `STROMA_NUCLEUS_DENSITY_SCALE = 0.35`, `normalise_stroma_nucleus_density`, `label_composition`, `load_label_map` | | 382-426 | `TokenLibrary`: loads `index.json` (list, or dict with `entries`) + `tokens.pt`, validates `(N, 16, 1536)` and the entry count, indexes by category, `nearest()` by exact L2 | | 429-441 | `load_token_file`: accepts `(1, 16, 1536)` or `(16, 1536)`, rejects anything else and non-finite tokens | | 444-474 | `tokens_from_library`: per-window composition of the job's label map -> nearest library entry -> its grid; builds the per-window provenance list | | 477-508 | `tokens_from_blend`: weighted sum of per-window grids, `self` = the job's own `reference`, size and shape asserted | | 511-528 | `resolve_tokens`: the single precedence point, returns `(tokens, hashes, provenance)` | | 562 | `reconstruct` records `token_source: null` (a VAE round trip uses no conditioning) | | 564-567 | `run_job` calls `resolve_tokens` and merges the provenance into the record | The canonical variable `token_source` (a PIL image) was renamed `token_image` so the record key `token_source` (a string) is unambiguous; no behaviour changed. ### Job schema additions | field | experiment | meaning | |---|---|---| | `token_file: ` | A3 | one `(1,16,1536)` / `(16,1536)` grid used for every window | | `token_library: ` + `labels: