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,127 @@
1
+ # The optimization PR
2
+
3
+ One PR on the original's branch, with one commit per kept change, read by
4
+ reviewers who never saw the search. Its folder is
5
+ `D=$WORK/ship/pr-optimization`. `references/documents.md` has what every
6
+ document holds and what none may say; posting is `ship.py post`
7
+ (`references/step5-ship.md`).
8
+
9
+ ## The tables
10
+
11
+ ```bash
12
+ python3 $AO/opt_pr_tables.py $WORK # --id A7 for another iteration than the winner
13
+ ```
14
+
15
+ It writes, from the search's records only:
16
+
17
+ | File | Holds |
18
+ |---|---|
19
+ | `branch.json` | the target branch, the commit the PR builds on, the kept changes in order, whether a unit-test suite sits under the search, the documents chosen at step 5 |
20
+ | `changes.tsv` | one row per kept change: id, title, files, +, - |
21
+ | `files.tsv` | one row per file the PR changes, the suite's files left out |
22
+ | `performance.tsv` | the objective and each observer: median, min, max and runs of the first measurement (the target branch) and of the kept code |
23
+ | `gates.tsv` | each output check: name, op, threshold, worst value, runs |
24
+ | `checks.json` | the separate output comparison's summary, and the first call's time on both |
25
+ | `paired.json`, `machine.json` | the paired timing `end` made, and the machine it ran on; null when the search has none |
26
+ | `tests.json` | the unit tests' result on the kept code, with the counts read from their log |
27
+ | `fragments.json` | what each kept change's notes say about it (`## Change`), for the template |
28
+ | `messages/<id>.txt` | each kept change's commit message, from its `## Commit message` with `after.commit_trailer`; a missing one is a skeleton to write |
29
+
30
+ The counts come from a pytest, testthat or "N passed" summary in the log.
31
+ Another runner's summary needs `--tests-format KEY=REGEX` per count (KEY one
32
+ of `passed`, `failed`, `skipped`, `errors` or `total`; one group, the
33
+ count). Without one the PR says the tests passed and gives no counts; never
34
+ type them.
35
+
36
+ ## The prose
37
+
38
+ ```bash
39
+ python3 $AO/opt_pr_body.py $D --template > $D/prose.md # once
40
+ python3 $AO/opt_pr_body.py $D --title '<imperative>' --out $D/body.md
41
+ ```
42
+
43
+ `--template` explains each field it lists:
44
+
45
+ | Field | Holds |
46
+ |---|---|
47
+ | `summary` | one or two sentences: what the PR changes in the code |
48
+ | `input` | the main input, as it follows "On" |
49
+ | `row <measure>` | the Measure cell of each row of the Performance table |
50
+ | `timed` | what one run measures |
51
+ | `machine` | only when the search recorded none |
52
+ | `outliers` | each row made worse beyond the run-to-run spread, and why; required then |
53
+ | `cold` | why the first call takes longer; required when it takes more than twice as long |
54
+ | `portability` | the OS-specific calls and the constants fitted to one machine, or that there are none |
55
+ | `vendored` | code from another project, or `none` |
56
+ | `change <name>` | one entry per change: a first line `iterations: A4, A11` (never printed), then what it does |
57
+ | `behaviour` | every difference a user can see, or that there is none |
58
+ | `tests` | the test suite and how it was run, as the subject of "passed on this branch" |
59
+ | `gate <name>` | what each output check compares |
60
+ | `compare` | the inputs of the separate output comparison |
61
+
62
+ **What the reader sees.** The opening paragraph is the summary, then the
63
+ measured change on the main input (and the paired timing, when made), then
64
+ a link to *How the output was checked*. Then portability, what the PR
65
+ targets and holds, *Performance* (the table, the first call, and a collapsed
66
+ *How it was measured* with the machine, the ranges and the paired runs),
67
+ *Changes* (each change's name and commits; its files and description
68
+ collapsed), *Behaviour changes*, *Tests*, and *How the output was checked*:
69
+ each output check with its worst value, the separate comparison, the unit
70
+ tests, and the bug report when it is chosen.
71
+
72
+ **Each `change` entry is one change as it stands in this branch.** Read the
73
+ diff of every kept change it covers (`git -C $WORK/autooptimize/repo.git
74
+ diff autoopt/<parent>..autoopt/<id>`) and the net diff of its files.
75
+ Changes that refine one idea share an entry; one later undone is described
76
+ where it ended up. Every kept change is in exactly one entry and every file
77
+ the PR changes is named by one. Where a README claims something no diff
78
+ shows, write what the diff shows and tell the user.
79
+
80
+ **Prose types no number a table gives.** Write `{{first}}`, `{{kept}}`
81
+ (the objective's median on the target and on this branch), `{{speedup}}`,
82
+ `{{runs}}`, `{{commits}}`, `{{files}}` or `{{target}}` instead; the renderer
83
+ refuses a number of three or more digits it computed.
84
+
85
+ ## The commit messages
86
+
87
+ One file per kept change, `messages/<id>.txt`, in the repository's own style
88
+ (`git -C $WORK/autooptimize/repo.git log --oneline -20`): an imperative
89
+ subject of at most 72 characters with no closing period, a blank line, then
90
+ what the change does and what stays the same, wrapped at 72 columns, ending
91
+ with `after.commit_trailer` when one is set. `autoopt.py pr` refuses a
92
+ message that breaks this or names an iteration label.
93
+
94
+ ## The preview
95
+
96
+ ```bash
97
+ python3 $AO/autoopt.py pr $WORK # what `ship.py rehearse` runs
98
+ ```
99
+
100
+ It checks that the winner passed every check, that its branch is the commit
101
+ the runner measured, that `body.md` is what the tables and prose render to,
102
+ and the commit messages; makes the commits in the search's `repo.git` (left
103
+ at `refs/pr/<id>`); and prints the commits, the diffstat, the push target,
104
+ the title, every message and the body. The branch it pushes is named from the
105
+ title, after `auto-optimize/` when the user chose that prefix
106
+ (`after.branch_prefix`; `ship.py rehearse` and `post` with `--branch optimization=NAME` for another name). Read the diffstat: a file no change should
107
+ have touched means scratch work was committed; stop and tell the user. With a
108
+ unit-test suite the commits sit on the original's commit
109
+ (`references/step5-ship.md`, *Separate from the unit tests*).
110
+
111
+ `--post` (run by `ship.py post`) pushes the branch, opens the PR with `gh`,
112
+ and records it in `$D/pr.json`; a second post opens nothing. Once the PR
113
+ is open, the plain preview prints the title and body that `--edit` would put
114
+ on it when they changed; show the user, and on their yes `--edit` replaces
115
+ them and pushes nothing. `--edit` refuses when the winner changed after the
116
+ PR was opened, since the PR would describe commits it does not carry.
117
+
118
+ ## When it refuses
119
+
120
+ | Refusal | Do |
121
+ |---|---|
122
+ | `body.md is not what the tables and prose render to` | render it again; never edit `body.md` |
123
+ | `no "=== change" field covers A4`, `no change entry names <file>` | add the change to an entry |
124
+ | `types 1.51, which the tables give` | the token, or leave the number to the table |
125
+ | `the commit messages are refused` | fix each file it names |
126
+ | `the commits … are not the measured change outside the unit-test suite's files`, `changes …, which the unit-test suite adds` | the optimization cannot be separated from the suite: tell the user, and offer the unit-test PR alone, or a local branch (`ship.py branch`, which has the same rule) built by hand from the search's `autoopt/<id>` |
127
+ | `is not a GitHub URL` | the original is not on GitHub: `ship.py branch` |
@@ -0,0 +1,254 @@
1
+ # The unit-test PR
2
+
3
+ One of the documents step 5 can post, when step 1 wrote a suite and the
4
+ user chose this PR (`after.ship_documents` holds `tests`). It is opened from
5
+ step 1's branch, its commits as they are, and holds only test files: at most one dependency
6
+ manifest that declares a test dependency, the repository's test driver when
7
+ the user allowed it, and files the user approved by name may join them. It
8
+ changes no source, build or workflow file, so it can be merged whether or not
9
+ the optimization is.
10
+
11
+ | | |
12
+ |---|---|
13
+ | Branch | step 1's `auto-optimize/<YYYY-MM-DD>-unit-tests` in `$WORK/tests/suite`, one commit above the original's, pushed under that name, or as `unit-tests-<YYYY-MM-DD>` when the user said branch names do not start with `auto-optimize/` (`after.branch_prefix=no`) |
14
+ | Targets | the original's branch: `branch` in `$WORK/tests/branch.json` |
15
+ | Title | "Add unit tests for `<scope>`", passed to `tests_pr_body.py --title`, which refuses a title that does not start with a capital letter, ends with a period or is longer than 72 characters, and writes it to `$WORK/ship/pr-tests/body.title` |
16
+ | Body | `$WORK/ship/pr-tests/body.md`, rendered by `tests_pr_body.py` from the tables in `$WORK/ship/pr-tests/` and the prose in `$WORK/ship/pr-tests/prose.md` |
17
+
18
+ `tests_pr_tables.py` writes the tables from the files step 1 left in
19
+ `$WORK/tests/work/` and from the clone, the document writer writes only what no table
20
+ can say, and `tests_pr_body.py` renders the two: every count, total,
21
+ percentage and ranking is computed from the tables. The body says what the
22
+ suite is and what it checks. It does not name the tool that wrote it, and it
23
+ does not describe any check other than the ones step 1 ran.
24
+
25
+ ## Its shape
26
+
27
+ Every unit-test PR has the layout and the thoroughness of
28
+ [BenLangmead/bowtie2#535](https://github.com/BenLangmead/bowtie2/pull/535),
29
+ which added a pytest suite for a C++ repository's three command-line
30
+ programs: a summary paragraph, coverage by part, how to run the suite and
31
+ where it passed, how its expected values were derived, a table of its
32
+ modules, line coverage before and after, and an account of what it leaves
33
+ out. Its numbers describe that repository and nothing else. The sections, in
34
+ order; `tests_pr_body.py --template` prints each prose field with what it
35
+ holds:
36
+
37
+ | Section | Computed from | Prose fields |
38
+ |---|---|---|
39
+ | (opening paragraph) | `collection.tsv`; `files.tsv` checks "It changes no source, build or workflow file." (below) | `opening`, `support`, `declares`, `driver <path>` |
40
+ | *Tests and line coverage by part* | `coverage.tsv`, `parts.tsv` | `parts.tests` (only when tests per part were not counted) |
41
+ | *Running it* | nothing | `running.commands`, `running.notes`, `running.ci`, `checked` (its last paragraph) |
42
+ | *How expected values are derived* | the `pinned` column of `collection.tsv` | `docs`, `derivation` |
43
+ | *What it covers* | `collection.tsv` | `module <path>`, one per module |
44
+ | *Line coverage* | `coverage.tsv` | `coverage.method` |
45
+ | *What the suite does not cover* | `names.tsv`, `coverage.tsv` | `contradictions`, `contradictions.marked`, `platforms` |
46
+
47
+ The opening paragraph starts with the `opening` field, such as "This PR adds
48
+ a pytest suite for `pkg` and its command-line programs.", and the renderer
49
+ adds the number of tests and modules and the sentence about changed files.
50
+ A file outside the suite's directory is refused, with three exceptions:
51
+
52
+ - A dependency manifest (`DESCRIPTION`, `requirements-dev.txt`,
53
+ `requirements-test.txt`, `test-requirements.txt`, `dev-requirements.txt`)
54
+ with the `declares` field: the sentence becomes "It changes no source or
55
+ workflow file. Its one change outside the tests is <declares>."
56
+ - The repository's own test driver, with `=== driver <path>` (a clause after
57
+ "which"), once `after.tests_driver_edit` is `yes` in
58
+ `$WORK/autooptimize/config.json`. `ask`, `no` or no value refuses it.
59
+ `--config` names another config.json.
60
+ - A file the user approved by name, with `--allow-source` (below).
61
+
62
+ **A section is left out only when it does not apply to the repository**: a
63
+ package with no public Python names has no names line. The renderer drops a
64
+ section whose tables are absent and names each one on stderr. A table that
65
+ applies but was not made is not a reason to drop its section: make it, or
66
+ tell the user which section is missing and why before the PR is posted.
67
+
68
+ ## Making the tables
69
+
70
+ All of them go into one folder, `T=$WORK/ship/pr-tests`, which also holds the
71
+ prose, the body and, once posted, `pr.json`. What is specific to the
72
+ repository (how it was built with coverage, which tests are its own) comes
73
+ from step 1's record in `$WORK/tests/work/`; the generators do the counting.
74
+
75
+ 1. **The collection and the changed files**, against the original's commit,
76
+ which `$WORK/tests/branch.json` records:
77
+
78
+ ```bash
79
+ T=$WORK/ship/pr-tests; mkdir -p $T
80
+ BASE=$(python3 -c 'import json, sys; print(json.load(open(sys.argv[1]))["commit"])' $WORK/tests/branch.json)
81
+ BRANCH=$(python3 -c 'import json, sys; print(json.load(open(sys.argv[1]))["tests_branch"])' $WORK/tests/branch.json)
82
+ (cd $WORK/tests/suite && python3 -m pytest --collect-only -q <the suite's directory>) > $T/collect.txt
83
+ python3 $AO/tests_pr_tables.py collection --collect-output $T/collect.txt --root $WORK/tests/suite --out $T
84
+ python3 $AO/tests_pr_tables.py files --repo $WORK/tests/suite --base $BASE --head $BRANCH --out $T
85
+ ```
86
+
87
+ `files` also writes `$T/branch.json` (the clone, the branch and `$BASE`),
88
+ which the push reads. A test counts as pinning the current output when its
89
+ docstring or a comment says so in step 1's words, "pins the current
90
+ output".
91
+ 2. **Line coverage**, from the JSON step 1 left in `$WORK/tests/work/`
92
+ (`references/step1-unit-tests.md`, *Report its coverage*): one file for
93
+ the existing tests on the original's commit (or one per CI step, each
94
+ with its own label) and one for the new test files alone on the branch.
95
+ When step 1 kept no JSON, or kept it without per-test data, measure it
96
+ again the same way:
97
+ - Python: `pytest --cov=<package> --cov-context=test`, then `coverage json
98
+ --show-contexts -o <file>`. `--cov=<package>` lists the files no test
99
+ imports, which would otherwise be missing. Tests that run the program
100
+ as a subprocess need `parallel = true` and `patch = subprocess` in the
101
+ coverage config and a `coverage combine` before the JSON; their lines
102
+ carry no per-test context, so give `coverage` a `--part-tests` file.
103
+ - Compiled code: a build with `--coverage -O0` (and
104
+ `-fprofile-update=atomic` for a threaded program, whose counters
105
+ otherwise race), one build or one counter reset per suite, then `gcovr
106
+ -r <source> --json <file>`.
107
+ - Numba code: coverage.py cannot trace compiled functions. Run both
108
+ coverage runs with `NUMBA_DISABLE_JIT=1`, which runs them as Python, and
109
+ say in `coverage.method` that the figures are lower bounds when a test
110
+ had to be dropped from them because it fails only without the compiler.
111
+
112
+ ```bash
113
+ python3 $AO/tests_pr_tables.py coverage --existing '`make test`=base.json' --suite suite.json \
114
+ --strip <build prefix> --drop 'tests/*' --exclude 'third_party/*' --out $T
115
+ ```
116
+
117
+ The existing tests' columns and the suite's are combined; a test run in
118
+ both is counted once and `coverage` warns, but the "this suite alone" row
119
+ then includes the existing tests. A repository whose sources sit in one
120
+ flat directory needs `--part-map`, a table of globs and the part each
121
+ names.
122
+ 3. **Public names**, for a Python package: `python3 $AO/tests_pr_tables.py
123
+ names --source <package> --tests <the suite's directory> --out $T`.
124
+
125
+ ## The prose, and rendering
126
+
127
+ ```bash
128
+ python3 $AO/tests_pr_body.py $T --template > $T/prose.md # once: one <<FILL per field the tables call for
129
+ python3 $AO/tests_pr_body.py $T --title 'Add unit tests for <scope>' --out $T/body.md
130
+ ```
131
+
132
+ Each field starts with a line `=== <field>`, and `module` and `driver` name
133
+ what they describe after it (`=== module tests/test_io.py`). Fields hold
134
+ plain, complete sentences and no headings. **Prose MUST NOT type a number a
135
+ table computes**: it writes a token instead, which the renderer fills.
136
+
137
+ | Token | Value |
138
+ |---|---|
139
+ | `{{tests}}`, `{{modules}}`, `{{functions}}`, `{{pinned}}` | from `collection.tsv` |
140
+
141
+ **Where the suite was run** is the `checked` field: one paragraph, the last
142
+ of *Running it*, naming the CI configurations step 1 ran the suite in (each
143
+ workflow job's install and test commands, in each Python or compiler
144
+ version it could provide) and saying that the suite passed in each. Take it
145
+ from step 1's record of those runs in `$WORK/tests/work/`, and name only the
146
+ configurations that record shows; a configuration step 1 did not run is not
147
+ named, and one CI runs that step 1 could not is said under `platforms`.
148
+
149
+ **Where the untested cases are listed** is the `contradictions` field, one
150
+ paragraph or the single word `none`. When the bug report is among the
151
+ documents chosen at step 5, it names the report as `#<bug issue>`, which is
152
+ replaced by the report's number once the report is filed. When the bug
153
+ report is not chosen, that issue will never exist: `#<bug issue>` anywhere in
154
+ the prose is refused, and `contradictions` names an issue number, a URL, or a
155
+ file in the repository in backticks (`tests/KNOWN.md`), which must be in
156
+ `files.tsv` or on the tests branch.
157
+
158
+ **Where the suite records each case it leaves untested** is prose, in
159
+ `contradictions.marked`, because suites differ, and it MUST be true of this
160
+ suite. When every affected test says so itself, the field is "Each affected
161
+ test says so in a docstring or comment." When the cases are named in a
162
+ document instead (a `TARGETS.md` with a row per function or option, say), the
163
+ field names the document and says how many of the cases it and the tests
164
+ name; count them before writing the number, since no table holds it. The
165
+ renderer puts the field, one paragraph, between "… is left untested, so that
166
+ fixing it will not break the suite." and the `contradictions` paragraph. It
167
+ is required whenever `contradictions` is not `none`.
168
+
169
+ **Source files the user chose to ship in this PR.** A file that is neither a
170
+ test file, a dependency manifest nor the test driver (a one-line source fix,
171
+ the build file that registers a new test target) is refused by default. When
172
+ the user chose to ship it here, write their words in `spec.md` first, then
173
+ name each file with `--allow-source PATH` (repeatable) on `tests_pr_body.py`
174
+ and give `tests_pr_push.py` the same flags. Also list each path, one per
175
+ line, in `$T/allow-source.txt`: `ship.py` renders and pushes with the flags
176
+ that file gives. The `declares` field MUST also
177
+ name every such file, in backticks, and say what changed; a file named by the
178
+ flag but not by `declares`, or by the flag but not changed, is refused. The
179
+ opening then says "It changes no workflow file. It changes `a` and `b`
180
+ outside the tests: <declares>." in place of the claim about source files.
181
+
182
+ `tests_pr_body.py` exits 1, writes nothing and lists every problem on stderr:
183
+ a prose problem (a placeholder, an unknown field or token, a missing field,
184
+ an `opening` that does not start with a capital letter, a `checked` or
185
+ `contradictions` that is a list, a `contradictions` that says nowhere the
186
+ cases are listed, a module cell over 25 words), tables that disagree with
187
+ each other (coverage that does not add up, a changed file outside the suite's
188
+ directory), a title that breaks the rule above, or a word of the search's own
189
+ vocabulary or a local path in the body or title (`lint_text.py`). A prose
190
+ field no section uses is named on stderr.
191
+
192
+ ## The hand-written inputs
193
+
194
+ Every other table is written by a generator and read by the renderer; none is
195
+ edited by hand.
196
+
197
+ | File | What it holds |
198
+ |---|---|
199
+ | `prose.md` | the prose fields, from `--template` |
200
+ | a part map, a `--part-tests` file | `tests_pr_tables.py coverage --help` |
201
+
202
+ ## Pushing it
203
+
204
+ ```bash
205
+ python3 $AO/tests_pr_push.py $T --repo <owner/repo> # preview: pushes and opens nothing
206
+ ```
207
+
208
+ The preview refuses, listing every problem, when the title or body breaks a
209
+ rule, the body is not what the tables and prose render to now, `files.tsv` is
210
+ not the branch's files, the clone has uncommitted changes, a commit lacks
211
+ `after.commit_trailer`, or `pr.json` names another repository. Otherwise it
212
+ prints the repository, the target branch, the remote and the head, the
213
+ title, the sections, the commit's files and what the post needs.
214
+
215
+ Posting is done for every chosen document together, after the user has
216
+ reviewed them all: `python3 $AO/ship.py rehearse $WORK`,
217
+ then `python3 $AO/ship.py post $WORK all --approved --digest D`
218
+ (`references/step5-ship.md`). No document is posted on its own. The post
219
+ pushes step 1's branch, under the name the user's answer about branch
220
+ names gives (`references/step5-ship.md`; `ship.py rehearse` and `post` with
221
+ `--branch tests=NAME` for another, which reaches this script as `--remote-branch`),
222
+ opens the PR with `gh pr create`, and
223
+ records it in `$T/pr.json` (repository, URL, number, branch, title, a digest
224
+ of title and body, and the time); `ship.py post` then renders the other
225
+ documents again so that they hold its number. A second `--post` is refused.
226
+
227
+ Each default gives way to its flag:
228
+
229
+ | | Default | Flag |
230
+ |---|---|---|
231
+ | clone, branch, base commit | `$T/branch.json` | `--suite`, `--branch`, `--base` |
232
+ | target branch | `branch` in `$WORK/tests/branch.json`; for a search made before that file existed, the original's branch as the search's config.json records it | `--target-branch` |
233
+ | remote | `after.pr_remote`, else `origin` | `--remote` |
234
+ | head | `after.pr_head_owner:<branch>` when the remote is `after.pr_remote`, else the branch | `--head OWNER:BRANCH` |
235
+
236
+ **When the original belongs to another account** (an open-source upstream),
237
+ the PR comes from the user's fork, and `tests-branch` leaves the clone's
238
+ `origin` pointing at the upstream. Step 5 records the fork as
239
+ `after.pr_remote` and `after.pr_head_owner` (`references/step5-ship.md`,
240
+ *From a fork*), and `ship.py post` uses it. A post refused for another
241
+ account's repository prints `refused, nothing done` **below** the preview
242
+ and exits 1: read the exit code, not only the first lines.
243
+
244
+ **A change to the tests branch after the search** (a test removed because
245
+ CI fails it, say) is committed on the branch, which may hold any number of
246
+ commits over its base, and pushed with `git push --force-with-lease` if it
247
+ rewrites history, once the user agrees: a force push rewrites a branch the
248
+ PR already shows. It is not in the measured optimization branch. Say so in
249
+ the optimization PR, and run the optimized code's tests against the updated
250
+ branch before the user merges either. Run `tests_pr_tables.py collection`
251
+ and `files` again, and `coverage` when the change could move it, render the
252
+ body again, run `tests_pr_push.py $T --repo <owner/repo>` with no flag to
253
+ preview the new title and body, show the user, and on their yes replace
254
+ them with `--edit`, which pushes nothing.
@@ -0,0 +1,133 @@
1
+ # Promoting, and predicting what a change is worth
2
+
3
+ ## Promotion follows the keep rule
4
+
5
+ With `promote: auto`, `init`'s default, each iteration's runner
6
+ applies the default keep rule against the iteration's parent: a median that
7
+ beats the parent's by more than the noise band. It records the verdict as `keep` in `result.json` and prints a `keep:`
8
+ line. When the verdict passes and the parent is still the
9
+ root, the runner promotes the iteration, the round closes, and the runner runs
10
+ that round's external validation if the user approved one. The orchestrator
11
+ does nothing.
12
+
13
+ | `keep:` line | Means |
14
+ |---|---|
15
+ | `promoted to the root (…); round N closed` | it is the root; every iteration briefed after it forks from it |
16
+ | `no, its median is within the noise band …` | kept out, for the reason given |
17
+ | `passes (…); promotion is the orchestrator's (config "promote")` | `promote: orchestrator` |
18
+ | `passes; already on the root's path` | it is the root or one of its ancestors already, as on a re-run of a promoted iteration |
19
+ | `` passes (…); not promoted: an iteration made after the end becomes the winner only by `promote --id` `` | made with `--after-end`: its runner never promotes it (`references/step4-final.md`, *An iteration made after the end*) |
20
+ | `passes (…); not promoted: <reason>` | `promote` refused it (*The preflight*, the toolchain scan, a root that moved): the subagent fixes what the reason names and runs `finish`; the orchestrator then runs `promote --id <it>` |
21
+ | `passes (…); not promoted (--no-promote)` | the runner was told not to: a re-measurement |
22
+
23
+ **A wider margin or a minimum gain stays with the runner.** "Keep only a
24
+ change worth 2%" or "twice the noise band" is a setting, and `promote: auto`
25
+ keeps working:
26
+
27
+ ```bash
28
+ python3 $AO/autoopt.py config $WORK --set keep.min_gain_pct=2 --reason "<their words>" # at least 2% of the parent's median
29
+ python3 $AO/autoopt.py config $WORK --set keep.band_k=2 --reason "<their words>" # beat the parent by twice the noise band
30
+ ```
31
+
32
+ Both must hold; the defaults (`band_k` 1, `min_gain_pct` 0) are the default
33
+ rule, and the `keep:` line names a setting only when it is not the default.
34
+ Set them before the first iteration and record them in `spec.md`'s keep rule:
35
+ a change mid-search judges later iterations by a rule earlier ones were not.
36
+
37
+ **A keep rule in the user's own words**, such as a tie rule or a second
38
+ measure that must not regress, is beyond the runner. Set it at step 0 with
39
+ `init --promote orchestrator` (later, `config --set promote=orchestrator`),
40
+ and promote by hand on that rule
41
+ (`references/step3-rounds.md`, *The loop*):
42
+
43
+ ```bash
44
+ python3 $AO/autoopt.py promote $WORK --id A7
45
+ ```
46
+
47
+ - `promote` refuses anything not `ok`; a same-code control; with a `{selected}` test command, one whose last test
48
+ pass was a subset (it prints the `run_iteration.py <dir> --full-tests`
49
+ command that fixes it); an iteration that does not descend from the current
50
+ root, whose promotion would drop the root's change; and, when the search has
51
+ checks, one with no passing compare, such as an iteration measured before
52
+ the checks existed (`autoopt.py check $WORK --id A7` runs it by hand).
53
+ Promoting the current root again changes nothing.
54
+ - **The keep rule compares an iteration with the root it forked from**, its
55
+ parent. A `NEW FRONTIER` inside the noise band is not a promotion.
56
+ - **A root that nothing beats may be a lucky median.** If a whole round
57
+ produces nothing above it, brief a same-code control of the root before
58
+ blaming the ideas (`references/step3-rounds.md`, *The machine during the
59
+ search*). Never `--rerun` the root itself.
60
+
61
+ ## The preflight
62
+
63
+ In repository mode `promote` also runs `python3 $AO/preflight.py $WORK --id
64
+ <id>` on the iteration's own change and refuses with every problem listed.
65
+ Fix each in the iteration's worktree and run `run_iteration.py` again (it
66
+ commits the edit and measures every seed afresh; the new median decides the
67
+ keep rule again), then `finish` and promote. This is for an iteration being
68
+ promoted; a problem found in the winner after `end` is fixed by a new
69
+ `--after-end` iteration (`references/step4-final.md`, *An iteration made after
70
+ the end*). The repository's CI is not part of it. `--id best --path` checks
71
+ the whole path from the commit the search copied and writes
72
+ `$WORK/autooptimize/preflight.json` (`{winner, problems}`).
73
+
74
+ | Check | A problem is |
75
+ |---|---|
76
+ | `text` | an added comment that names the search (`lint_text.py`: winner, baseline, a label such as A12, a path on this machine); the same in the iteration's `notes.md` `## Change`; a `## Commit message` that breaks the message rules; for an iteration made with `--after-end`, either section missing (an ordinary iteration writes them once its `keep:` line reads `promoted` or `passes`, and `finish` refuses its README without them) |
77
+ | `indent` | an added line indented with tabs in a file indented with spaces, or the reverse. A new file is compared with the repository's files of the same extension. Four fifths of the indented lines decide a file's style; a file with fewer than five decides nothing |
78
+ | `license` | an added line with a marker of a license a permissive repository cannot take: GPL, LGPL, AGPL, MPL, non-commercial, share-alike (*Code from another project*, below). Code copied without any marker is not found: say what you copied in `notes.md` |
79
+ | `toolchain` | `after.oldest_toolchain_command` (`{src}` is an export of the tree) exits non-zero. Skipped while the key is unset |
80
+
81
+ Exit 0 no problem, 1 a problem (`check: path:line: text`), 2 refused.
82
+
83
+ ### Code from another project
84
+
85
+ Code copied or translated from another project (numpy, scipy, a C library)
86
+ keeps that project's license notice above it. A line-by-line translation is a
87
+ derivative and carries the source's license; calls into a public API, and an
88
+ implementation written from a paper or a documented interface, need no
89
+ notice. For a repository under a permissive license (MIT, BSD, Apache-2.0):
90
+
91
+ | Source license | Copy it in? |
92
+ |---|---|
93
+ | MIT, BSD-2-Clause, BSD-3-Clause, ISC, zlib, Unlicense, CC0 | yes, with its copyright notice, conditions and disclaimer above the code, verbatim from its license file |
94
+ | Apache-2.0 | yes, keeping its license text and any `NOTICE` file, and marking what changed |
95
+ | MPL-2.0 | only as separate files that stay MPL-2.0 |
96
+ | LGPL, GPL, AGPL; non-commercial or academic-only; no license at all; CC-BY-SA or CC-BY-NC on code | no |
97
+
98
+ A file's own header governs it. Anything else, or a destination under another
99
+ license, goes to the user.
100
+
101
+ ## Predicting what a change is worth
102
+
103
+ **Changes in different kernels add in the objective's units, and only when
104
+ independent.** An edit carries about the same absolute gain from one root to
105
+ the next; its percentage grows as the root shrinks, so the same edit on a
106
+ faster root looks bigger while contributing the same amount.
107
+
108
+ **Predict in the objective's units and record it**:
109
+ `brief … --predict -0.03 --predict-basis "A88 measured -0.026 on A86"`,
110
+ against the parent's median. It lands in `meta.json`, `result.json` and the
111
+ README, and the round summary prints it beside the measured change. A
112
+ prediction that lands inside the noise band is evidence the changes are
113
+ independent; a miss is a finding.
114
+
115
+ **Quote the increment over the actual parent, not a variant's headline.** If
116
+ the root already holds part of the change, the headline overstates it and the
117
+ subagent reports a shortfall that was never real.
118
+
119
+ **An idea's value belongs to the pair of change and root.** The same edit can
120
+ be worth several times more on a later root, once an earlier change removes
121
+ the bottleneck that hid it. Name known dependencies in the brief and sequence
122
+ them; when an idea fails, ask whether it was merely early.
123
+
124
+ **A shortfall larger than the noise band has a mechanism; find it.** One
125
+ inside the band is the prediction holding.
126
+
127
+ | Mechanism | Example |
128
+ |---|---|
129
+ | the root already removed much of the work this edit accelerates | another edit deleted most of the loop this one sped up |
130
+ | the compiler already did part of the edit | under `fastmath` the compiler already turns a divide by a loop-invariant value into a multiply by its reciprocal, so hoisting the divide by hand gains little |
131
+ | two edits compete for the same hardware | both land in one kernel and contend for front-end and store-forwarding capacity |
132
+
133
+ Record the prediction regardless.
@@ -0,0 +1,65 @@
1
+ # Reading a search without changing it
2
+
3
+ For a question about a search: one this session runs, one another session
4
+ started, or one that ended. Every command here only reads, and none starts a
5
+ process that outlives it. To continue a search instead, follow
6
+ `references/resume.md`, which starts the dashboard publisher and acts on what
7
+ it finds; answering a question needs neither.
8
+
9
+ ## Find it
10
+
11
+ `$WORK` is the folder that holds `autooptimize/`. Searches go in
12
+ `~/auto-optimize/<YYYY-MM-DD>-<name>/` unless the user chose another place at
13
+ step 0; `ls ~/auto-optimize/` lists them.
14
+
15
+ `$WORK/autooptimize/config.json`'s `skill.name` says which skill made the
16
+ search. These scripts read a search made by `auto-optimize-code` or by an
17
+ earlier version with no name; for any other name they refuse with `this search
18
+ was made by the … skill`, and the search is read with that skill's scripts.
19
+
20
+ ## Two calls first
21
+
22
+ ```bash
23
+ python3 $AO/stages.py status $WORK # the six stages and the next move
24
+ python3 $AO/autoopt.py status $WORK --brief # round, root, counts, what is in flight, the last six settled
25
+ ```
26
+
27
+ ## Question to command
28
+
29
+ | Question | Command or file |
30
+ |---|---|
31
+ | Has it ended, and what won? | `$WORK/autooptimize/ended.md`, present only after `end`; the paired timing of the winner against A0 is `final.json` beside it |
32
+ | What is the best so far, and by how much over A0? | `autoopt.py table $WORK --status ok --sort best --limit 5 --fields id,title,median,vs_base,vs_base_pct` |
33
+ | Which iterations improved on everything before them? | `autoopt.py table $WORK --frontier` |
34
+ | Every iteration, or one slice | `autoopt.py table $WORK` with `--status`, `--category`, `--round`, `--parent A5`, `--promoted`, `--sort`, `--limit`, `--fields` (`references/cli.md`) |
35
+ | What did A7 try, and how did it do? | `autoopt.py show $WORK A7`: numbers, both differences, the keep verdict, gates, observers, the code change, the notes, and the paths to read further |
36
+ | Why did A12 fail? | `autoopt.py show $WORK A12` prints the status, the gate that broke, the failed check or each failed seed's error; then its `README.md`; a run's `runs/seed-<n>/log.txt` only for the full error |
37
+ | What changed in the code? | `show` prints the change's size and the command for the whole diff: `git -C $WORK/autooptimize/repo.git diff autoopt/<parent>...autoopt/<id>` |
38
+ | The path from A0 to the winner | `autoopt.py path $WORK --markdown` |
39
+ | What happened in round N | `$WORK/autooptimize/rounds/round-<N>.md` |
40
+ | What the search has learned | `$WORK/autooptimize/knowledge.md` |
41
+ | Which ideas are left, and which were tried | `$WORK/autooptimize/ideas.md` |
42
+ | The objective, the gates, the keep rule, what is off limits | `$WORK/autooptimize/spec.md`; the numbers in `config.json` |
43
+ | What a subagent was told | `$WORK/autooptimize/briefs/<id>.md` (bare number: `briefs/7.md`) |
44
+ | Was it shipped, and where? | `python3 $AO/ship.py status $WORK`; the records are `$WORK/ship/applied.json` (files written), `ship/branch.json` (a local branch) and, once posted, `ship/issue-bugs/filed.json`, `ship/pr-tests/pr.json` and `ship/pr-optimization/pr.json` (each URL) |
45
+ | The report to the user | `$WORK/finish/final-report.md`, written at step 6 |
46
+ | What it cost in tokens | `autoopt.py tokens $WORK`, from Claude Code's transcripts |
47
+
48
+ ## For a program
49
+
50
+ `table --json`, `show --json` and `path --json` print raw values, and
51
+ `table --tsv` a header and tab-separated rows. The record files and their
52
+ fields are in `references/layout.md`; each carries `schema_version`
53
+ (*Version fields*). Read `result.json` and `meta.json` rather than recomputing
54
+ anything from `runs/`.
55
+
56
+ ## What not to open
57
+
58
+ - `status --json` prints every `result.json` whole, every seed included, and
59
+ grows with the search. `table --json --fields …` gives the same rows in the
60
+ columns asked for.
61
+ - `runs/*/log.txt`, unless a run's error is the question.
62
+ - `repo.git/`, `reference/` and `cache/`: git objects, cached outputs and
63
+ compiler caches, none of it prose.
64
+ - An iteration's code, unless the question is about the code: `show` and the
65
+ diff say what changed.