auto-optimize 1.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. auto_optimize/__init__.py +3 -0
  2. auto_optimize/__main__.py +5 -0
  3. auto_optimize/cli.py +651 -0
  4. auto_optimize/skills/auto-optimize-code/LICENSE +21 -0
  5. auto_optimize/skills/auto-optimize-code/SKILL.md +251 -0
  6. auto_optimize/skills/auto-optimize-code/VERSION +1 -0
  7. auto_optimize/skills/auto-optimize-code/references/algorithm.md +182 -0
  8. auto_optimize/skills/auto-optimize-code/references/changes.md +146 -0
  9. auto_optimize/skills/auto-optimize-code/references/cli.md +206 -0
  10. auto_optimize/skills/auto-optimize-code/references/dashboard.md +203 -0
  11. auto_optimize/skills/auto-optimize-code/references/documents.md +55 -0
  12. auto_optimize/skills/auto-optimize-code/references/extending.md +87 -0
  13. auto_optimize/skills/auto-optimize-code/references/external-validation.md +98 -0
  14. auto_optimize/skills/auto-optimize-code/references/glossary.md +134 -0
  15. auto_optimize/skills/auto-optimize-code/references/idea-miner.md +108 -0
  16. auto_optimize/skills/auto-optimize-code/references/issue-bugs.md +182 -0
  17. auto_optimize/skills/auto-optimize-code/references/layout.md +300 -0
  18. auto_optimize/skills/auto-optimize-code/references/main-session.md +45 -0
  19. auto_optimize/skills/auto-optimize-code/references/measuring.md +208 -0
  20. auto_optimize/skills/auto-optimize-code/references/pr-optimization.md +127 -0
  21. auto_optimize/skills/auto-optimize-code/references/pr-tests.md +254 -0
  22. auto_optimize/skills/auto-optimize-code/references/promotion.md +133 -0
  23. auto_optimize/skills/auto-optimize-code/references/reading-a-search.md +65 -0
  24. auto_optimize/skills/auto-optimize-code/references/repo-mode.md +224 -0
  25. auto_optimize/skills/auto-optimize-code/references/resume.md +81 -0
  26. auto_optimize/skills/auto-optimize-code/references/shared-knowledge.md +114 -0
  27. auto_optimize/skills/auto-optimize-code/references/step0-interview.md +298 -0
  28. auto_optimize/skills/auto-optimize-code/references/step1-unit-tests.md +136 -0
  29. auto_optimize/skills/auto-optimize-code/references/step2-baseline.md +708 -0
  30. auto_optimize/skills/auto-optimize-code/references/step3-rounds.md +350 -0
  31. auto_optimize/skills/auto-optimize-code/references/step4-final.md +121 -0
  32. auto_optimize/skills/auto-optimize-code/references/step5-ship.md +220 -0
  33. auto_optimize/skills/auto-optimize-code/references/step6-finish.md +67 -0
  34. auto_optimize/skills/auto-optimize-code/references/subagent.md +467 -0
  35. auto_optimize/skills/auto-optimize-code/references/symptoms.md +67 -0
  36. auto_optimize/skills/auto-optimize-code/references/writing-briefs.md +117 -0
  37. auto_optimize/skills/auto-optimize-code/scripts/attribution.py +156 -0
  38. auto_optimize/skills/auto-optimize-code/scripts/autoopt.py +12863 -0
  39. auto_optimize/skills/auto-optimize-code/scripts/check_seeding.py +334 -0
  40. auto_optimize/skills/auto-optimize-code/scripts/cold.py +90 -0
  41. auto_optimize/skills/auto-optimize-code/scripts/dashboard/README.md +165 -0
  42. auto_optimize/skills/auto-optimize-code/scripts/dashboard/autoopt_monitor.py +850 -0
  43. auto_optimize/skills/auto-optimize-code/scripts/dashboard/gpu_scan.py +954 -0
  44. auto_optimize/skills/auto-optimize-code/scripts/dashboard/monitor_writer.py +684 -0
  45. auto_optimize/skills/auto-optimize-code/scripts/dashboard/scan.py +1030 -0
  46. auto_optimize/skills/auto-optimize-code/scripts/dashboard/static/dashboard.css +775 -0
  47. auto_optimize/skills/auto-optimize-code/scripts/dashboard/static/dashboard.js +3652 -0
  48. auto_optimize/skills/auto-optimize-code/scripts/dashboard/static/index.html +191 -0
  49. auto_optimize/skills/auto-optimize-code/scripts/issue_body.py +2118 -0
  50. auto_optimize/skills/auto-optimize-code/scripts/lint_text.py +448 -0
  51. auto_optimize/skills/auto-optimize-code/scripts/opt_pr_body.py +894 -0
  52. auto_optimize/skills/auto-optimize-code/scripts/opt_pr_tables.py +367 -0
  53. auto_optimize/skills/auto-optimize-code/scripts/paired.py +188 -0
  54. auto_optimize/skills/auto-optimize-code/scripts/preflight.py +280 -0
  55. auto_optimize/skills/auto-optimize-code/scripts/probe_run.py +72 -0
  56. auto_optimize/skills/auto-optimize-code/scripts/publish.py +385 -0
  57. auto_optimize/skills/auto-optimize-code/scripts/run_iteration.py +1382 -0
  58. auto_optimize/skills/auto-optimize-code/scripts/ship.py +1193 -0
  59. auto_optimize/skills/auto-optimize-code/scripts/stages.py +651 -0
  60. auto_optimize/skills/auto-optimize-code/scripts/tests_pr_body.py +1267 -0
  61. auto_optimize/skills/auto-optimize-code/scripts/tests_pr_push.py +426 -0
  62. auto_optimize/skills/auto-optimize-code/scripts/tests_pr_tables.py +779 -0
  63. auto_optimize-1.0.0.dist-info/METADATA +610 -0
  64. auto_optimize-1.0.0.dist-info/RECORD +67 -0
  65. auto_optimize-1.0.0.dist-info/WHEEL +4 -0
  66. auto_optimize-1.0.0.dist-info/entry_points.txt +2 -0
  67. auto_optimize-1.0.0.dist-info/licenses/LICENSE +21 -0
@@ -0,0 +1,300 @@
1
+ # What is on disk, and what the record files hold
2
+
3
+ Every script flag is in `references/cli.md`; how to read a search without
4
+ changing it, in `references/reading-a-search.md`.
5
+
6
+ ## The search directory
7
+
8
+ `$WORK` is the directory `init` was given; `autooptimize/` is one folder of it.
9
+ Everything else sits in one folder for the step that writes it, named for what
10
+ it holds and carrying no number.
11
+ The layout is defined once, in `autoopt.PATHS` (a path helper:
12
+ `work_path(work, key, *more)`); no other script spells these folders.
13
+
14
+ ```
15
+ $WORK/
16
+ autooptimize/ steps 2-5: the search's own record, below
17
+ NOTES.md generated by `stages.py`: the six stages and the next command (never edited)
18
+ interview/ step 0: interview.md, TERMS.md, terms_raw/, known-bugs/
19
+ inputs/ what the benchmark reads: data/, env/, toolchains/
20
+ tests/ step 1, new unit tests: suite/ (the clone the tests branch is made in), analysis/ (the reading of the existing tests), work/ (scripts, coverage inputs and outputs, bugs/)
21
+ setup/ step 2 scratch, at fixed names: gateproof/ (copies of A0 for planted faults), width/ (the concurrent-run measurement, emptied each time)
22
+ ship/ step 5: applied.json and applied.patch (apply), branch.json (a local branch), or, on GitHub, one folder per document (pr-optimization/, pr-tests/, issue-bugs/: its tables, prose.md, body.md and body.title, then pr.json or filed.json once posted) beside rehearsal.json and rehearsal/, the last review's digest and previews
23
+ finish/ step 6: final-report.md, archive/ (the copied winner: idea.patch, code/, README.md, result.json), speedup-breakdown/
24
+ scratch/ anything disposable; step 6 may delete it
25
+ dashboard.ipynb stays at the top
26
+ ```
27
+
28
+ Rules:
29
+
30
+ - **One folder per step, plain names.** A new file goes in the folder of the
31
+ step that writes it. A folder is never named with a random suffix (`mkdtemp`
32
+ names do not appear in `$WORK`).
33
+ - **`autooptimize/` is the search's own record** and is not reorganized: it
34
+ holds the git worktrees.
35
+ - **A folder no step lists is left alone.** No search command reads, moves
36
+ or prunes a folder under `$WORK` that is not in the tree above.
37
+ - **Disposable means `scratch/`.** `prune` touches only `autooptimize/`;
38
+ `scratch/` is what step 6 removes with the user's yes, and nothing there is
39
+ referenced by a record.
40
+
41
+ ## The `autooptimize/` tree
42
+
43
+ Paths in this section are relative to `$WORK/autooptimize/`.
44
+
45
+ ```
46
+ autooptimize/
47
+ config.json the objective, the gates, the observers, the plan
48
+ spec.md step 0's record and the rules the search runs by
49
+ ideas.md one line per idea, filled by the idea miner, tried ones struck through; decisions taken while the user was away
50
+ setup/ step 2's notes.md (the setup subagent's notes: each item done, each proof's numbers), ledger.txt and logs (seeding, prove-gates, prove-compare, width), each log ending `exit <code>`
51
+ mining/stage-<n>.md each idea miner stage's ideas and notes (references/idea-miner.md)
52
+ mining/ledger-S<n>.txt the stage's ledger entries, appended by `mine --done`
53
+ knowledge.md what subagents established, one tagged entry each (references/shared-knowledge.md)
54
+ test-artifacts.txt files the unit-test runs created in a worktree, one per line: removed after each run, never committed or promoted (references/repo-mode.md, *The unit-test gate*)
55
+ tools/ helpers and checkers later iterations reuse, each listed in its README.md; not the harness
56
+ briefs/<id>.md the prompt each subagent was given (autoopt.py brief), with <id>.json, what `new --brief` reads; miner-<n>.md, each miner's (autoopt.py mine); setup.md, the setup subagent's (autoopt.py setup); loop-<n>.md, each orchestrator subagent phase's (autoopt.py loop)
57
+ state.json the root, the round and its history, the noise band's reference, the loop's, the miner's and setup's state
58
+ watch.json the running watch's pid (autoopt.py watch)
59
+ reference/ the baseline's outputs the gates compare against; inputs parsed once
60
+ checks/outputs/ A0's outputs on compare.py's inputs, which every compare reads; manifest.json says what they were cached from
61
+ repo.git/ bare repo; every iteration is a worktree of it
62
+ harness/ repository mode only: the benchmark, outside every worktree; `harness.json` (written by `setup --done`) hashes it, and a run refuses once it differs
63
+ checks/ the task's checks, written at step 2: compare.py, time_one.py, first_call.py
64
+ final.json, final/ the winner against A0 by paired timing (`autoopt.py final`, run by `end`; `final.log` from `final --background`); final/dashboard.html, the static snapshot `end` writes
65
+ ended.json, ended.md the search ended on the record (`autoopt.py end`, `references/step4-final.md`); ended-<n>.json after a reopen; end.log from `end --background`
66
+ reopen-lock.json `{"holds": [{"by", "reason", "at"}]}`: what shipped the winner, one hold each; `end --reopen` refuses while it holds one
67
+ preflight.json `{winner, problems}`, written by `preflight.py --path`
68
+ touched.json the files each iteration's change touched, keyed `<parent commit>..<commit>`: a cache `brief` fills, regenerable
69
+ tmp/ scratch of a script that needs it beside the search; emptied by that script
70
+ background.jsonl the main session's background commands (`autoopt.py bg`, `end`, `final`)
71
+ skill-seen.json the skill commit this search began on and the one last reported (`NOTICE`)
72
+ rounds/round-<N>.md one summary per round
73
+ validations/ external validation, one record per round; validate.log from `validate --background`
74
+ round-<N>.json what it measured, and against which iteration
75
+ round-<N>/ whatever the validation script wrote
76
+ iterations/
77
+ 0/ worktree on branch autoopt/0: the baseline
78
+ bench.py … the benchmark, whatever it is made of
79
+ meta.json what this iteration is trying <- autoopt.py new
80
+ result.json what it measured <- run_iteration.py
81
+ report.txt the block the subagent reports <- run_iteration.py
82
+ profile.txt where a root's call spends its time <- autoopt.py promote, profile
83
+ notes.md the subagent's prose <- the subagent
84
+ README.md notes.md plus the numbers <- autoopt.py finish
85
+ runs/seed-0/ metrics.json, log.txt, whatever the run saved
86
+ runs/seed-1/ …
87
+ unit-tests/ log.txt and result.json, when "tests" is configured
88
+ check/, check.json the exported trees and logs of the task's checks, and the compare's verdict
89
+ cold.json the cold first call, for the commit it timed
90
+ 1/ worktree on branch autoopt/1, forked from autoopt/0
91
+ 2/ …
92
+ ```
93
+
94
+ `init` creates `config.json`, `spec.md`, `state.json`, `ideas.md`,
95
+ `knowledge.md`, `tools/README.md`, `tools/checkers/README.md`, `reference/`,
96
+ `rounds/`, `repo.git/` and the baseline. In **repository mode** (`init
97
+ --repo`) each iteration's worktree is `iterations/<id>/src/`, with the records
98
+ above beside it (`references/repo-mode.md`, *Layout*).
99
+
100
+ A corrupt `config.json`, `state.json` or validation record stops
101
+ every script with `<file> is not valid JSON (…)`. Nothing is reset; fix or
102
+ restore the file.
103
+
104
+ `autooptimize/` holds a repository of its own and every run's outputs: add it
105
+ to the surrounding project's ignore list, if it has one.
106
+
107
+ ## The git model
108
+
109
+ The repo is **bare**, so the baseline is a worktree like every other
110
+ iteration. `autoopt.py new --new-id A3 --parent A0` runs `git worktree add -b
111
+ autoopt/3 iterations/3 autoopt/0`, so A3 starts from exactly the code A0 ran.
112
+
113
+ `run_iteration.py` commits whatever is uncommitted in the worktree before the
114
+ first run, so `git -C iterations/3 diff autoopt/0..autoopt/3` is exactly the
115
+ idea A3 tried.
116
+
117
+ Artifacts stay out of that diff through `repo.git/info/exclude`, which every
118
+ worktree shares: `runs/`, `unit-tests/`, `cache/`, `probe/`, `__pycache__/`,
119
+ `result.json`, `report.txt`, `meta.json`, `README.md`, `notes.md`,
120
+ `check/`, `check.json`, `cold.json` and `*.npz`. `init` refuses a
121
+ `--copy` file that matches the list (`copied file(s) match the plain-mode
122
+ exclude list`), since no iteration would have it; put such inputs in
123
+ `reference/`. When a benchmark writes another large file into its own
124
+ directory, add it to that file, not to a committed `.gitignore`.
125
+
126
+ **Never delete `iterations/0`**: the baseline is the commit every other
127
+ iteration descends from. To drop an iteration, `git -C repo.git worktree
128
+ remove iterations/<id>` rather than `rm -rf`, or git keeps a stale
129
+ registration and refuses the next `new`.
130
+
131
+ ## Version fields
132
+
133
+ `config.json`, `state.json`, every `result.json` and `ended.json` carry
134
+ `schema_version`, the version of their layout (1). It rises when a field
135
+ changes meaning or is removed, not when one is added. A file without it was
136
+ written before the field existed and reads as version 1. A tool outside the
137
+ skill that reads these files checks it.
138
+
139
+ `config.json`'s `skill.name` is the skill that made the search. Another skill
140
+ that writes the same layout (`auto-optimize-ml`) runs by other rules, so every
141
+ script refuses a search whose `name` is not `auto-optimize-code` with `this
142
+ search was made by the … skill`, and the search is read with that skill's
143
+ scripts. A search with no `name` was made before the field existed and is
144
+ accepted.
145
+
146
+ ## state.json
147
+
148
+ ```json
149
+ {
150
+ "root": 43, "round": 17, "roots": [{"round": 1, "id": 0}],
151
+ "loop": {"phase": 4, "open": false, "started": "2026-10-14…"},
152
+ "band": {"id": 43, "spread": 0.0021, "measured": "2026-10-14…",
153
+ "phase": 4},
154
+ "mining": {"stage": 3, "done": 2, "started": "2026-10-14…",
155
+ "finished": "2026-10-14…", "seen": [0, 1, 2]},
156
+ "setup": {"status": "done", "started": "2026-10-14…",
157
+ "finished": "2026-10-14…", "answers": [{"question": "…",
158
+ "answer": "…", "on": "2026-10-14…"}]}
159
+ }
160
+ ```
161
+
162
+ `setup` is step 2's: `status` is `open` while the setup subagent works,
163
+ `waiting` (with its `question`) while a question waits for the user, and
164
+ `done` once `setup --done` passed; `answers` keeps each question with the
165
+ user's answer.
166
+
167
+ `mining` is the idea miner's: the last stage opened and the last closed (one
168
+ is open while they differ), and the ids settled when the open stage started,
169
+ so the next stage lists only the READMEs written since. `new` copies `done`
170
+ into each `meta.json` as `mining_stage`.
171
+
172
+ `root` is the iteration new ones fork from, `round` the current round, and
173
+ `roots` each promotion in order. `band` is the noise band's reference: the
174
+ sample standard deviation of the runs of the root as it stood when the last
175
+ phase opened (`loop`); before the first phase the baseline's spread is used.
176
+
177
+ ## config.json
178
+
179
+ Written by `autoopt.py init`, changed mid-search by `autoopt.py config`.
180
+
181
+ ```json
182
+ {
183
+ "task": "Make the word counter faster without changing its counts.",
184
+ "command": "python3 bench.py --seed {seed} --out {out}",
185
+ "objective": {"name": "seconds", "direction": "min", "unit": "s"},
186
+ "gates": [{"name": "n_mismatch_vs_base", "op": "==", "threshold": 0}],
187
+ "observers": [{"name": "peak_rss_mb"}, {"name": "compile_seconds"}],
188
+ "runs_per_iteration": 5,
189
+ "confirm_runs": 5,
190
+ "staged": false,
191
+ "gpus_per_agent": 1,
192
+ "seed_base": 0,
193
+ "build_env": {"CC": "gcc"},
194
+ "timeout_seconds": 0,
195
+ "gpu": true
196
+ }
197
+ ```
198
+
199
+ | Field | Meaning |
200
+ |---|---|
201
+ | `command` | how one run is launched, from inside the iteration directory. **Must** contain `{seed}` and `{out}`; omitting either fails at `init` with `config.json "command" must contain both {seed} and {out}`. `{out_abs}`, `{iteration}`, `{src}` (the worktree: `iterations/<id>/src` in repository mode, the iteration directory otherwise) and `{cache}` (`iterations/<id>/cache/<first 12 characters of the commit>`, one compiler cache per commit: `references/measuring.md`, *A cached compile can outlive the edit*) are also substituted, shell-quoted, so never put a placeholder in quotes (`'{out}'`): `init` does not catch it, and the run splits the argument once a path holds a space. Write a shell variable as `$VAR`, not `${VAR}`, and double a literal brace; `init` refuses any other brace |
202
+ | `objective.direction` | `max` or `min` |
203
+ | `gates[].op` | `<=`, `<`, `>=`, `>` or `==`. With `tol`, `==` becomes \|value − threshold\| ≤ tol, which is how "the outputs must not move" is spelled; on the other four, `tol` loosens the threshold by that much |
204
+ | `observers` | recorded, never optimized, never gated; one dashboard chart each |
205
+ | `runs_per_iteration` | runs per iteration, one seed each, A0 included (`init --runs`, default 5) |
206
+ | `staged`, `confirm_runs` | off unless `init --staged`: screen at `runs_per_iteration`, then confirm to `confirm_runs` when the median nears the frontier. Otherwise `init` sets `confirm_runs` equal to `runs_per_iteration` |
207
+ | `gpus_per_agent` | GPUs one iteration holds, and so how many of its runs go at once. The runner pins each run to one of them through `CUDA_VISIBLE_DEVICES`. With `--no-gpu`, only how many runs an iteration starts at once |
208
+ | `seed_base` | the first seed. Run *i* uses `seed_base + i`, so every iteration runs the same seeds, 0–4 at the default count. Change it only to start a whole search on fresh draws |
209
+ | `timeout_seconds` | a run killed after this many seconds counts as failed; 0 disables |
210
+ | `gpu` | false when the benchmark needs no GPU, which also lifts the lease check |
211
+ | `skill` | `name` (`auto-optimize-code`), `version` (the skill's `VERSION` file) and `commit` (the skill's last commit, or null outside a git checkout) when `init` ran. `stages.py next` and `stages.py status` print one `NOTICE` line for each later commit (`autooptimize/skill-seen.json` holds the one last reported); nothing stops |
212
+ | `schema_version` | the layout version of the record files (*Version fields*) |
213
+ | `floor` | a minimized objective's smallest value worth measuring, or null. At or under it the search stops with the reason `floor`; the price table marks an A0 under 20 times it (`references/step2-baseline.md`, *The price of the base*) |
214
+ | `workers` | the worker, rank or thread count the task names, or null. Each run's process tree is sampled every 0.1 s for threads the kernel shows running; `result.json` `workers` holds the most seen at once, and `setup --done` refuses while A0's is lower |
215
+ | `gpu_command` | the machine's GPU allocator as the words before a command, which it runs with `CUDA_VISIBLE_DEVICES` set and releases at exit (`srun --gres=gpu:1`). `run_iteration.py`, `check_seeding.py`, `prove`, `end` and `final` start under it when they hold no lease (`references/step2-baseline.md`, *GPU leases*) |
216
+ | `promote` | `auto` (`init`'s default) or `orchestrator`: with `auto` each iteration's runner promotes it when it passes the default keep rule while its parent is still the root, then runs the closed round's approved validation; `orchestrator` for a keep rule in the user's words (`init --promote`, `config --set`). |
217
+ | `subagent_model` | `opus` (default), `sonnet`, `haiku` or `fable`: the model every iteration subagent and the setup subagent are spawned with (`init --subagent-model`, `config --set`); `brief` and `setup` name it on stderr. The idea miner and the orchestrator run on the session's model |
218
+ | `checks` | optional. `compare` (a command with `{src}` and `{reference}`), `time`, `first_call`, `build`, `profile` (each with `{src}`; `profile` also `{out}`), `threads` (an int), set by `config --set checks.<key>=…` (`references/step2-baseline.md`, *Write the checks*). With `compare` set, the runner checks every iteration whose runs pass their gates, and `promote` needs a pass |
219
+ | `loop_handback` | settled iterations one orchestrator phase sees before it hands back (default 16; `config --set`) |
220
+ | `allow_build_changes` | `yes` lets an iteration change build files, a binary or library, a vendored tree or an assembly file (`references/subagent.md`, *Portability*); set by `config --set` |
221
+ | `tests` | optional. `{"command", "timeout_seconds", "path"}`, set by `init --tests` and `--tests-path` (default `tests`). `{src}`, `{iteration}`, `{out}`, `{cache}`, `{selected}` substituted (`references/repo-mode.md`, *The unit-test gate*) |
222
+ | `repo` | repository mode only, written by `init --repo`: `path`, `branch` and `commit` of the original at the copy, `remote` and `remote_url` (as configured, before any `insteadOf` rewrite), `dirty_at_copy`. With a step-1 suite these describe the suite's clone; `tests/branch.json` (written by `tests-branch`) holds the original's `path`, `branch`, `commit` and `remote_url` |
223
+ | `copied` | plain mode only, written by `init --copy`: `[{"source", "as"}]`, each copied file or folder's absolute path and its name in the baseline. `ship.py apply` writes the change back there |
224
+ | `after` | the answers about everything after the search (`init --after JSON`, `config --set after.X=V`; `null` unsets a text or number). This skill's sixteen keys: `stop` (`ask`, `auto`), `budget_hours`, `budget_iterations` (a whole number of iterations, A0 and same-code controls not counted, or null), `budget_stages` (a whole number of idea-miner stages, or null), `disk` (`ask`, `keep`, `prune`), `pair_cap_hours` (4), `setup_questions` (`ask`, `recommended`), `oldest_toolchain_command`, `commit_trailer`, `tests_driver_edit` (`ask`, `yes`, `no`), `build_outputs` (`[]`), defined in `references/step0-interview.md`, *The questions*; and step 5's five, defined in `references/step5-ship.md`: `ship` (`ask`, `apply`, `branch`, `github`, `none`), `ship_documents` (a list of `optimization`, `tests`, `bugs`), `branch_prefix` (`ask`, `yes`, `no`: whether branch names start with `auto-optimize/`), `pr_remote` and `pr_head_owner` (a fork's remote and account). `config --set after.X=V` creates the block when a config has none (`init --force` would drop the rest of the config); `autoopt.py config` prints it. A choice outside a key's is refused. Any other key is kept as it is, and `config --set` on it is refused |
225
+ | `keep` | optional. `{"band_k": 1, "min_gain_pct": 0}`: the default keep rule's margin, in noise bands, and the least gain, in percent of the parent's median; `config --set keep.band_k=2` (`references/promotion.md`) |
226
+ | `busy_percent` | optional, default 110: the percent of one core above which `busy` and the runner name a process outside the search; `AUTOOPT_BUSY_PERCENT` overrides it |
227
+ | `origin` | written by `init`: `{cwd, session}`, the directory and Claude Code session the search was started from, which `tokens` reads to find its transcripts. Never shipped or shown on the dashboard |
228
+ | `external_validation` | optional. `{"command", "measures", "note", "approved"}`, and `"units"` added by hand. `approved` starts false and only `validate --approve` sets it, recording the time in `approved_on` (`references/external-validation.md`) |
229
+
230
+ ## metrics.json — the contract every benchmark meets
231
+
232
+ One per run, written by the benchmark into `{out}`: the only interface
233
+ between the benchmark and the scripts.
234
+
235
+ ```json
236
+ {
237
+ "objective": 4.812,
238
+ "gates": {"n_mismatch_vs_base": 0},
239
+ "observers": {"peak_rss_mb": 1840, "compile_seconds": 2.3},
240
+ "note": "the first call compiles; the timed call is the second"
241
+ }
242
+ ```
243
+
244
+ - `objective` is required and must be a finite number.
245
+ - **Every configured gate must appear.** A run that does not measure a gate
246
+ fails: `metrics.json has no numeric value for the gate "n_mismatch_vs_base"`. Fix
247
+ the benchmark, then `--rerun`.
248
+ - A missing observer is recorded as null and does not fail the run.
249
+ - A flat key (`{"n_mismatch_vs_base": 0}` at the top level) is accepted as a
250
+ fallback; nest under `gates` and `observers`.
251
+
252
+ ## result.json — what the runner writes
253
+
254
+ One per iteration, and the source of truth for every table, summary, README
255
+ and chart. Read it rather than recomputing anything from `runs/`.
256
+
257
+ | Key | Meaning |
258
+ |---|---|
259
+ | `status` | `ok`, `gate-failed` (a gate broke on at least one run, or the unit tests failed), `error` (a run crashed, timed out, or emitted nothing usable), or `partial` (fewer runs than `runs_per_iteration`) |
260
+ | `stage` | `confirmed` when the iteration has its full count of runs, `screen` when it has fewer (`--runs` below the count, or an iteration a failure stopped). The keep rule and `setup --done` need `confirmed` |
261
+ | `objective` | `name`, `direction` and `unit` from `config.json`; `median`, `mean`, `std`, `min`, `max`, and every run's `values` |
262
+ | `gates[name]` | `op`, `threshold`, `tol`, `values`, `median`, `worst`, `pass`, `n_violations` |
263
+ | `observers[name]` | `values`, `median`, `std` |
264
+ | `frontier_at_start`, `noise_band` | the frontier when the iteration started, and the noise band its keep verdict used |
265
+ | `frontier_holder`, `frontier_on_path` | the iteration that held that frontier, and whether it is this iteration's ancestor (true when there was none) |
266
+ | `runs[]` | per seed: `seed`, `dir`, `objective`, `seconds`, `gates`, `observers`, `note`, `idle` (percent of the CPUs idle just before the run) and `load` (the one-minute load average, recorded by runs older than `idle`) |
267
+ | `failures[]` | per failed seed: `seed`, `error`, `dir`, `seconds` |
268
+ | `tests` | the unit-test verdict: `command`, `exit_code`, `pass`, `scope` (`subset` or `full`), `selected` (the test files, or null for the full suite), `reason`, `seconds` (this pass), `seconds_total` (every pass on this commit), `commit`, `log`, `removed` (the files the run created in the worktree). `null` when not configured, or when a crash or broken gate settled the iteration first |
269
+ | `keep` | the default keep rule against the parent, on every `ok` iteration with a parent that is not a control: `verdict` (`pass` or `fail`) and `why`; after the runner's promotion attempt, `promoted`, and `round_closed` and `validation` |
270
+ | `check`, `failed_check` | with the task's checks: `compare` (`verdict` `pass`, `differ` or `error`, `exit`, `summary`, `log`) and `cold` (`verdict`, `seconds`, `runs`, `parent_seconds`). A compare that did not pass (`differ` or `error`) makes the status `gate-failed` with `failed_check: compare`; a cold first call that crashes makes it `error` before any run, with `failed_check: cold`. `check.json` beside it keeps the record for the commit and the cached outputs it was judged against |
271
+ | `id`, `n_runs`, `n_failed`, `seconds`, `gpu`, `finished` | the iteration's id; the runs that produced metrics and those that failed; the runs' seconds summed; the `CUDA_VISIBLE_DEVICES` the runner held; when it finished |
272
+ | `workers`, `busy_at_start`, `profile_seconds` | with `config.json` `workers`: `{expected, busy_peak, procs_peak, samples}`, the most threads seen running at once; on A0 of a CPU benchmark, the processes outside the search above `busy_percent` before its runs; the seconds `checks.profile` took when `promote` profiled this iteration as the new root |
273
+ | `best_run` | the run directory of the best single run: its outputs are one sample, so compare nothing to it |
274
+ | `commit`, `branch`, `parent`, `prediction`, `round`, `category`, `title`, `topic`, `control` | the record of what this was; `prediction` is `{"delta", "basis"}` or null; `control` is true for a same-code control, which is never on the frontier |
275
+ | `split` | true when an extension set `meta.split`: an iteration built from others' code, run once for the gates and tests, never on the frontier or kept, and never written up |
276
+
277
+ Only `status == "ok"` is eligible for the frontier. A `partial` iteration
278
+ (`--runs` below the count) stays out of the frontier, `promote` and the pass
279
+ rate until a run at the full count overwrites it. The frontier, the frontier path, the winner and
280
+ `best_run` are four different things (`references/glossary.md`, *The tree* and *After the search*).
281
+
282
+ ## The verdict, exactly
283
+
284
+ Every stage the runner runs, in order: `references/subagent.md`, *Checks
285
+ beyond the runner*. The status, from the first rule that applies:
286
+
287
+ 1. A cold first call that crashed: no runs at all, `error`.
288
+ 2. Any failed run: `error`.
289
+ 3. Any gate broken on any run: `gate-failed`.
290
+ 4. The unit tests, then the compare, when configured: a failure is
291
+ `gate-failed`.
292
+ 5. Fewer runs than `runs_per_iteration`: `partial`.
293
+ 6. Otherwise `ok`.
294
+
295
+ On an `ok` iteration with a parent, not a control, the default keep rule
296
+ passes when the median beats the parent's by more than the noise band:
297
+ `parent − median > band` when minimizing, `median − parent > band` when
298
+ maximizing. The band is the wider of the reference spread (the standard
299
+ deviation across the root's runs, re-measured when each phase opens; A0's
300
+ before the first) and this iteration's.
@@ -0,0 +1,45 @@
1
+ # The main session, from step 2 to the end
2
+
3
+ The main session talks to the user, and agents do the rest:
4
+ - the setup subagent does step 2;
5
+ - the idea miner writes the ideas;
6
+ - an orchestrator subagent runs step 3 in phases and spawns the
7
+ iterations, one at a time.
8
+
9
+ Every wake-up after a quiet spell rewrites the main session's whole context,
10
+ so it reads `status --brief` and the agents' reports, and nothing else: no
11
+ code, logs, READMEs or iteration files. Its commands are below; `$AO` and
12
+ `$WORK` are as in step 0.
13
+
14
+ **At every wake-up and after every report, run `python3 $AO/stages.py next $WORK`.** It prints the next move
15
+ and its kind: `agent` (do it; the table below says how), `run` (add `--run`: the script starts it, then run `next` again, until the kind is not `run`), `wait`
16
+ (`end` is finishing), or `stop` (the user answers); once every stage is complete it prints `every stage is complete` and nothing else. It ends the search under `after.stop=auto`.
17
+
18
+ | When | Do |
19
+ |---|---|
20
+ | step 0 is written down | `autoopt.py setup $WORK`, then spawn its prompt, unedited, with the description and model its stderr line names: the setup subagent runs on `subagent_model` (`references/step0-interview.md`, *Handing off step 2*). End the turn: the report wakes you, a setup question included, so start no timer, watch or polling loop |
21
+ | the idea miner's report carries idea lines because its file write was refused | write them to the stage's file (`mining/stage-<n>.md`) and `autoopt.py mine $WORK --done` |
22
+ | the setup subagent reports done | tell the user the `answers taken without asking` that `setup --done` listed, if any. `autoopt.py mine $WORK`, then spawn the idea miner from its prompt. It starts here, not with setup, because it prices ideas against A0's profile, which setup writes after the baseline. End the turn; its report wakes you |
23
+ | the setup subagent asks (its report, or `status`'s `setup (step 2): waiting for the user:`) | ask the user. An answer that changes a setting: `config --set … --reason "<their words>"`. Then `setup $WORK --answer "<their words>"`, which writes the dated line in `spec.md`, and send the message it prints to that subagent (SendMessage), or spawn the prompt it prints after the message if the subagent is gone |
24
+ | `status` stops printing `first iteration: waiting for …` | `autoopt.py busy $WORK`: when it exits 1, apply the answer setup recorded in `spec.md` for a busy machine, and ask the user only when setup recorded none (`references/step3-rounds.md`, *The machine during the search*). Then `autoopt.py loop $WORK`, spawn its prompt in the background with the description and model its stderr line names, and end the turn. Start no watch: the phase's report wakes you |
25
+ | a phase reports | show the user its round tables and decisions, and ask its questions. Then, by why it stopped. After `loop_handback` settled iterations, follow `stages.py next`: after a phase that promoted, it prints `loop $WORK`; after one that promoted nothing, the search has reached `stalled`, which it ends under `after.stop=auto` and asks about under `ask`. At another *When to stop* criterion the report names (the report's reason outranks `stages.py next`), the row below at once under `after.stop=auto`, and under `ask` only when the user does not go on |
26
+ | an iteration's report reaches you, or a phase ends without its report | the phase died: `loop $WORK --force`, and spawn what it prints. The new phase resumes from the records (`status --resume`) |
27
+ | the user writes | answer from `status --brief`. A rule or a setting they give: record it (`SKILL.md`, *Rules that hold everywhere*), then tell the orchestrator subagent in one line (SendMessage) |
28
+ | the user is away and a question waits | take the least-damage answer (`references/step3-rounds.md`, *Questions while the search runs*), record it under *Decisions taken while the user was away* in `ideas.md`, and say so in your next message |
29
+ | the user ends the search, or a phase reached *When to stop* and the search is not to go on | with a phase open, tell the orchestrator subagent to stop (SendMessage), or, without SendMessage, `autoopt.py loop $WORK --stop`, after which its next `brief --next` briefs nothing and tells it to hand back. Either way it lets the iteration in flight settle, closes the phase and reports. Then `autoopt.py end $WORK --reason <word or the user's words> --background`, then `autoopt.py wait $WORK/autooptimize/end.log`, again until it prints `wait: finished`. Show the user `ended.md`, with the paired verdict beside the medians, labeled "paired" (`references/step4-final.md`). The search is over: go to step 5, which asks the user how to ship (`references/step5-ship.md`), then step 6 (`references/step6-finish.md`) |
30
+ | step 5 starts (the search has ended) | `ship.py plan $WORK`; ask its questions in one AskUserQuestion call and record each answer with `config --set after.… --reason "<their words>"` (`references/step5-ship.md`, *Ask how to ship*). Show every preview before its `--yes`. On the GitHub route, spawn the document writer from `ship.py brief $WORK` and end the turn; its report wakes you |
31
+ | the document writer reports | show the user every document and preview together (`references/step5-ship.md`, *Review, then post all*); a change they ask for goes back to the writer. Post only on their word, with the digest of the batch they saw |
32
+ | a post stops part way | fix what its last line names, then run the same `post` command: what was posted is skipped |
33
+ | a line starting `NOTICE the auto-optimize-code skill changed` (from `stages.py next` or `stages.py status`) | tell the user in one line, with the commits the line's `git log` lists; do not stop or redo anything for it |
34
+ | the user asks what the search cost | `autoopt.py tokens $WORK`: each agent's and each role's weighted tokens, from the transcripts |
35
+
36
+ ## No timed updates
37
+
38
+ Nothing wakes the main session on a timer: an agent's report does, or the
39
+ `autoopt.py wait` it ends a turn on.
40
+
41
+ A claim in a brief (a count, a cause, a result) must come from a log the main session has read, not from memory of an
42
+ earlier turn or another agent's summary; when it has not read the log, it reads it first or leaves the claim out.
43
+
44
+ A resumed session starts with `references/resume.md`. `status` names a phase
45
+ still open from the old session, and `loop $WORK --force` replaces it.
@@ -0,0 +1,208 @@
1
+ # Telling whether a change actually helped
2
+
3
+ ## The runner's median is the number
4
+
5
+ `run_iteration.py`'s median, over separate processes, is the result.
6
+ Anything measured inside one process is for **ranking variants**
7
+ (`references/subagent.md`, *Timing variants*), never for claiming a gain.
8
+
9
+ Say which produced each figure. A sweep's delta can be several times the
10
+ runner's, and only the runner's number is in `result.json`: quoting the two
11
+ as one measurement leaves a frontier nobody can reproduce.
12
+
13
+ ## Paired separate processes: `paired.py`
14
+
15
+ A search pairs once, at the end: `autoopt.py final` times the winner
16
+ against A0 on the task's timing probe, `checks.time`
17
+ (`references/step4-final.md`). No iteration is paired with its parent. Late
18
+ in a search a gain is smaller than the runner's noise band, and in-process
19
+ sweeps can split two identical copies; pairs of separate processes resolve
20
+ it.
21
+
22
+ | It does | Why |
23
+ |---|---|
24
+ | a fresh process per timing, alternating which side runs first | the side run first in a pair is slower, so a fixed order hands the second a win |
25
+ | a compiler cache per side, warmed before the first pair | no pair times a compile, and neither side loads the other's code |
26
+ | stops on an exact sign test, checked after every pair from `--min-pairs` | a unanimous result stops at 9 pairs and a close call runs to `--max-pairs`. Looking after every pair raises the false-positive rate above `--alpha`: 1.2% at the defaults, under no real difference (`paired.py --help` gives the simulation) |
27
+ | aborts on a non-zero exit | the probe exits non-zero when its output differs from the reference, so a wrong variant is never timed as a fast one |
28
+
29
+ The probe (`checks/time_one.py`) imports the package from `{src}`, asserts
30
+ the import path (`sys.modules['<pkg>.<module>'].__file__`), loads the cached
31
+ inputs (`references/step2-baseline.md`, *Parse the inputs once*), warms up
32
+ at full size, times one call, compares its output with the reference bytes,
33
+ and prints the seconds as the last number on its last line. `final` runs it
34
+ again at `checks.threads`, with every common thread-pool variable set to it.
35
+
36
+ Report the verdict, the median paired difference and the count, labeled
37
+ "paired", beside the runner's median, which stays the number in
38
+ `result.json`: "paired: B better, −0.037 s, 9/9, p = 0.0039".
39
+
40
+ A subagent choosing between two of its own variants can pair them the same
41
+ way, on two exported trees: `paired.py --a $DIR/probe/v1 --b $DIR/probe/v2
42
+ --cmd "python3 $DIR/probe/time_one.py --src {src}"` (exporting:
43
+ `references/subagent.md`, *Rules*).
44
+
45
+ ## Profile the root you are actually on
46
+
47
+ Shares move every time something lands: a profile from a few roots back can
48
+ name a kernel that no longer dominates, and every brief written from it aims
49
+ at the wrong place. With `checks.profile`, `promote` writes each new root's
50
+ `iterations/<id>/profile.txt`, and a brief quotes the lines naming its idea's
51
+ function: read that before profiling by hand.
52
+
53
+ Three traps, all silent:
54
+
55
+ - **A profiler written against the baseline segfaults on a later root.** If
56
+ it allocates scratch in the baseline's shapes and calls the kernels
57
+ directly, a root that changed a workspace shape makes it write out of
58
+ bounds, and numba does not bounds-check. Mark such a script
59
+ `BASELINE ONLY` and profile from inside the current root's own top-level
60
+ function instead.
61
+ - **Timing a loop nest's parts separately can cost more than the whole, and
62
+ the parts then sum to a lie.** Split into passes, the loops re-read scratch
63
+ from memory that the fused version keeps in cache, and a decomposition
64
+ validated on one root stops being valid when a layout changes under it.
65
+ Price one part by replacing a **single call** inside an otherwise
66
+ verbatim copy of the whole function, and re-validate the decomposition
67
+ against an unsplit control every time you reuse it.
68
+ - **Cumulative truncation can be invalid and silent.** Timing a prefix of a
69
+ kernel to attribute cost can give *every* prefix as slower than the whole
70
+ kernel while a verbatim copy compiled in the probe module times correctly:
71
+ the compile is faithful and the decomposition is not. Time the sub-kernel
72
+ directly.
73
+
74
+ ## Reading the generated code
75
+
76
+ Asm is evidence about what to try, never proof that a change worked: a change
77
+ with identical instruction counts can be a regression. For numba:
78
+
79
+ ```python
80
+ kernel(out, x) # compile for the real argument types first
81
+ asm = kernel.inspect_asm(kernel.signatures[0])
82
+ lines = asm.splitlines()
83
+ print(len(lines), 'lines', sum('%zmm' in l for l in lines), 'zmm',
84
+ sum('%ymm' in l for l in lines), 'ymm')
85
+ ```
86
+
87
+ - **Dump with a fresh `NUMBA_CACHE_DIR`.** A function loaded from the cache
88
+ returns a stub.
89
+ - **Arguments of the wrong dimensionality return a stub of about 45 lines
90
+ with every count at 0, on both versions, without raising.** Check the line
91
+ count before believing "0 before, 0 after".
92
+ - **A callee that is not inlined is compiled on its own**: dump the callee to
93
+ see the code that runs.
94
+ - **What to count:** lines with `%zmm` or `%ymm` show how much of the work
95
+ became wide; scalar `vmulsd` or `vaddsd` in a hot loop means it did not
96
+ vectorize; a vectorized float `max` or `min` shows as `vcmp*pd` with a
97
+ blend or masked move, not `vmaxpd`, because numba keeps NaN semantics.
98
+ - **A loop compiles to several bodies, each behind a minimum trip count**
99
+ (`cmpq $N` before it). Read each guard against the real trip counts: the
100
+ widest body can sit behind a guard the data never reaches.
101
+
102
+ ## A cached compile can outlive the edit
103
+
104
+ For numba's `cache=True`, Triton, and `torch.compile`/Inductor.
105
+
106
+ numba's `cache=True` writes a compiled library keyed on the **decorated
107
+ function's own source file**. A callee's code is linked into its caller's
108
+ library, so editing only a callee in another file leaves the key unchanged
109
+ and the stale library is served. Without `NUMBA_CACHE_DIR` the cache is
110
+ `__pycache__/` beside the source, inside the worktree, so it survives from a
111
+ run to the edit after it.
112
+
113
+ It bites hardest when every kernel under search is a callee of one
114
+ `@njit(parallel=True, cache=True)` driver and each iteration edits a callee
115
+ alone, and it can segfault. **The symptom is a variant that measures
116
+ exactly at its control**; `inspect_asm()` on a stale library shows the old
117
+ instructions.
118
+
119
+ Triton (`@triton.jit`, `@triton.autotune(cache_results=True)` or
120
+ `TRITON_CACHE_AUTOTUNING=1`) and Inductor key their caches on the kernel's
121
+ source and its dependencies, so an edit is not served stale. Their defaults,
122
+ `~/.triton/cache` and `/tmp/torchinductor_<user>`, are shared by every process
123
+ on the machine: an iteration can load a compile or an **autotuning choice**
124
+ another iteration or session timed under its own load.
125
+
126
+ **Point every compiler cache at `{cache}` in `command` and `--tests`:**
127
+
128
+ ```
129
+ NUMBA_CACHE_DIR={cache}/numba TRITON_CACHE_DIR={cache}/triton TORCHINDUCTOR_CACHE_DIR={cache}/inductor python3 bench.py ...
130
+ ```
131
+
132
+ `{cache}` is the absolute path `iterations/<id>/cache/<first 12 characters
133
+ of the commit>`, the same for the runs and the tests. The runner commits
134
+ before any run, so the runs of one commit share compiled kernels, and an
135
+ edit after a run gets a new commit and an empty cache. Only the first
136
+ run compiles and autotunes, so every seed uses that run's autotuning choice:
137
+ one sample, made in whatever state the machine was in. Inductor's
138
+ `max-autotune` choices are cached on disk by default; a plain
139
+ `@triton.autotune` without `cache_results` keeps its choice in memory, so
140
+ each run autotunes afresh in its own process. `prune` deletes `cache/`
141
+ outside its protected set, and it is never committed.
142
+
143
+ **A cache removes the compile that was warming the process.** A long numba
144
+ compile leaves the allocator's pages mapped and the clocks up, so a small
145
+ warmup suffices. Loaded from a cache, the same code's timed call can run
146
+ slower, enough to make an iteration read short of its prediction; a warmup
147
+ call at full size brings the gap inside the noise. **Warm up at full size**,
148
+ and never compare medians across a switch to or from a shared cache without
149
+ re-measuring the root. The repository's `tests/code/test_runner.py`,
150
+ *shared compiler cache*, reproduces the numba case, with a control showing
151
+ that a cache kept across the edit is stale.
152
+
153
+ For a hand-timed sweep or an asm dump, give each variant its own new
154
+ `NUMBA_CACHE_DIR` inside the iteration directory. Never delete a cache to
155
+ force a recompile; `references/subagent.md`, *Rules*.
156
+
157
+ A compiler cache is one case of a general rule: anything long-lived holds a
158
+ copy of your code and will serve the old one.
159
+
160
+ ## A suspiciously large speedup is usually dead code
161
+
162
+ An edit that loses its write-backs lets the compiler delete the loop being
163
+ timed: a variant reads much faster while millions of elements mismatch.
164
+ Check the gate before believing a number, and be most suspicious when the
165
+ number is best. Inverted, such a bogus speedup is a real ceiling for
166
+ *removing* the work entirely, which tells the next iteration what is
167
+ available.
168
+
169
+ ## A harness error is not a result
170
+
171
+ Before a mismatch, a failure or a slow run is attributed to the code, and
172
+ before any count is written into a summary or a report, scan every
173
+ stderr for errors the harness itself raised: a process that never started,
174
+ a timeout the runner imposed, a missing input, an illegal combination of
175
+ options. One unstarted run otherwise reads as an output
176
+ difference. Give those their own outcome category and re-run them once
177
+ fixed; never count them as `mismatch` or as the program's failure.
178
+
179
+ ## Properties no gate can see
180
+
181
+ A gate compares outputs, so a change that alters the output only on inputs
182
+ the benchmark does not use is invisible to it. The subagent checks it
183
+ directly:
184
+
185
+ | Invisible to the gate | How to check it |
186
+ |---|---|
187
+ | `int16` overflow, since integer reassociation is exact mod 2^16 | an instrumented build carrying an `int64` shadow over the full data; report the range every value stays in |
188
+ | whether a skipped region really is all zeros | replay the loop bounds over every distinct shape pair the data produces |
189
+ | whether `min`/`max` reassociation is bitwise free | scan every value for NaN, inf and `-0.0` |
190
+ | an entry point the compare does not call | compile-check it and run it separately (`references/subagent.md`, *Off-benchmark callers of the code you are changing*) |
191
+
192
+ Name the premise the change rests on, then measure it over the real data
193
+ rather than asserting it.
194
+
195
+ ## Break the check before believing it
196
+
197
+ **A shadow check that re-narrows before comparing cannot fail.** An `int64`
198
+ shadow carried alongside an `int16` accumulator and compared as
199
+ `numpy.int16(shadow[k]) != t_sums[k]` wraps the shadow back into the type
200
+ whose overflow it exists to detect, and reports 0 disagreements even for a
201
+ value forced past 32,767. Compare the wide value raw. The same holds for
202
+ anything that clamps, saturates or rounds on the way to the comparison: a
203
+ survival probability clamped by `b if b > 0 else 0.0` swallows NaN, so a NaN
204
+ count downstream of it cannot fail either.
205
+
206
+ Show every verification failing once: corrupt the checker's input on
207
+ purpose (a skip mask, say), or run an unrelated branch as a negative control
208
+ to prove a table of assembly-instruction counts can differ.