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.
- auto_optimize/__init__.py +3 -0
- auto_optimize/__main__.py +5 -0
- auto_optimize/cli.py +651 -0
- auto_optimize/skills/auto-optimize-code/LICENSE +21 -0
- auto_optimize/skills/auto-optimize-code/SKILL.md +251 -0
- auto_optimize/skills/auto-optimize-code/VERSION +1 -0
- auto_optimize/skills/auto-optimize-code/references/algorithm.md +182 -0
- auto_optimize/skills/auto-optimize-code/references/changes.md +146 -0
- auto_optimize/skills/auto-optimize-code/references/cli.md +206 -0
- auto_optimize/skills/auto-optimize-code/references/dashboard.md +203 -0
- auto_optimize/skills/auto-optimize-code/references/documents.md +55 -0
- auto_optimize/skills/auto-optimize-code/references/extending.md +87 -0
- auto_optimize/skills/auto-optimize-code/references/external-validation.md +98 -0
- auto_optimize/skills/auto-optimize-code/references/glossary.md +134 -0
- auto_optimize/skills/auto-optimize-code/references/idea-miner.md +108 -0
- auto_optimize/skills/auto-optimize-code/references/issue-bugs.md +182 -0
- auto_optimize/skills/auto-optimize-code/references/layout.md +300 -0
- auto_optimize/skills/auto-optimize-code/references/main-session.md +45 -0
- auto_optimize/skills/auto-optimize-code/references/measuring.md +208 -0
- auto_optimize/skills/auto-optimize-code/references/pr-optimization.md +127 -0
- auto_optimize/skills/auto-optimize-code/references/pr-tests.md +254 -0
- auto_optimize/skills/auto-optimize-code/references/promotion.md +133 -0
- auto_optimize/skills/auto-optimize-code/references/reading-a-search.md +65 -0
- auto_optimize/skills/auto-optimize-code/references/repo-mode.md +224 -0
- auto_optimize/skills/auto-optimize-code/references/resume.md +81 -0
- auto_optimize/skills/auto-optimize-code/references/shared-knowledge.md +114 -0
- auto_optimize/skills/auto-optimize-code/references/step0-interview.md +298 -0
- auto_optimize/skills/auto-optimize-code/references/step1-unit-tests.md +136 -0
- auto_optimize/skills/auto-optimize-code/references/step2-baseline.md +708 -0
- auto_optimize/skills/auto-optimize-code/references/step3-rounds.md +350 -0
- auto_optimize/skills/auto-optimize-code/references/step4-final.md +121 -0
- auto_optimize/skills/auto-optimize-code/references/step5-ship.md +220 -0
- auto_optimize/skills/auto-optimize-code/references/step6-finish.md +67 -0
- auto_optimize/skills/auto-optimize-code/references/subagent.md +467 -0
- auto_optimize/skills/auto-optimize-code/references/symptoms.md +67 -0
- auto_optimize/skills/auto-optimize-code/references/writing-briefs.md +117 -0
- auto_optimize/skills/auto-optimize-code/scripts/attribution.py +156 -0
- auto_optimize/skills/auto-optimize-code/scripts/autoopt.py +12863 -0
- auto_optimize/skills/auto-optimize-code/scripts/check_seeding.py +334 -0
- auto_optimize/skills/auto-optimize-code/scripts/cold.py +90 -0
- auto_optimize/skills/auto-optimize-code/scripts/dashboard/README.md +165 -0
- auto_optimize/skills/auto-optimize-code/scripts/dashboard/autoopt_monitor.py +850 -0
- auto_optimize/skills/auto-optimize-code/scripts/dashboard/gpu_scan.py +954 -0
- auto_optimize/skills/auto-optimize-code/scripts/dashboard/monitor_writer.py +684 -0
- auto_optimize/skills/auto-optimize-code/scripts/dashboard/scan.py +1030 -0
- auto_optimize/skills/auto-optimize-code/scripts/dashboard/static/dashboard.css +775 -0
- auto_optimize/skills/auto-optimize-code/scripts/dashboard/static/dashboard.js +3652 -0
- auto_optimize/skills/auto-optimize-code/scripts/dashboard/static/index.html +191 -0
- auto_optimize/skills/auto-optimize-code/scripts/issue_body.py +2118 -0
- auto_optimize/skills/auto-optimize-code/scripts/lint_text.py +448 -0
- auto_optimize/skills/auto-optimize-code/scripts/opt_pr_body.py +894 -0
- auto_optimize/skills/auto-optimize-code/scripts/opt_pr_tables.py +367 -0
- auto_optimize/skills/auto-optimize-code/scripts/paired.py +188 -0
- auto_optimize/skills/auto-optimize-code/scripts/preflight.py +280 -0
- auto_optimize/skills/auto-optimize-code/scripts/probe_run.py +72 -0
- auto_optimize/skills/auto-optimize-code/scripts/publish.py +385 -0
- auto_optimize/skills/auto-optimize-code/scripts/run_iteration.py +1382 -0
- auto_optimize/skills/auto-optimize-code/scripts/ship.py +1193 -0
- auto_optimize/skills/auto-optimize-code/scripts/stages.py +651 -0
- auto_optimize/skills/auto-optimize-code/scripts/tests_pr_body.py +1267 -0
- auto_optimize/skills/auto-optimize-code/scripts/tests_pr_push.py +426 -0
- auto_optimize/skills/auto-optimize-code/scripts/tests_pr_tables.py +779 -0
- auto_optimize-1.0.0.dist-info/METADATA +610 -0
- auto_optimize-1.0.0.dist-info/RECORD +67 -0
- auto_optimize-1.0.0.dist-info/WHEEL +4 -0
- auto_optimize-1.0.0.dist-info/entry_points.txt +2 -0
- auto_optimize-1.0.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,610 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: auto-optimize
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Claude Code skills that search for faster, leaner or smaller code by running many small measured experiments.
|
|
5
|
+
Project-URL: Homepage, https://github.com/jmschrei/auto-optimize
|
|
6
|
+
Project-URL: Issues, https://github.com/jmschrei/auto-optimize/issues
|
|
7
|
+
Project-URL: Changelog, https://github.com/jmschrei/auto-optimize/blob/main/CHANGELOG.md
|
|
8
|
+
Author: Jacob Schreiber
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: agent-skills,benchmarking,claude-code,optimization,performance
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Environment :: Console
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Intended Audience :: Science/Research
|
|
16
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Topic :: Software Development :: Testing
|
|
19
|
+
Requires-Python: >=3.9
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
|
|
22
|
+
<h1 align="center"><img src="docs/banner/banner.png" alt="auto-optimize" width="880"></h1>
|
|
23
|
+
|
|
24
|
+
[](https://github.com/jmschrei/auto-optimize/actions/workflows/ci.yml)
|
|
25
|
+
[](LICENSE)
|
|
26
|
+
|
|
27
|
+
Historically, the task of improving software has been performed by humans who knew
|
|
28
|
+
too much about how computers worked. As punishment for learning too much about how
|
|
29
|
+
computers worked, the computers punished us by becoming better than us at this task.
|
|
30
|
+
|
|
31
|
+
Auto-optimization is the process by which agents iteratively find improvements
|
|
32
|
+
to a codebase which optimize a given performance measure (or set of such measures).
|
|
33
|
+
This repository is a Claude Code skill that implements auto-optimization with all
|
|
34
|
+
the quality-of-life features I always wished I had in the past, including:
|
|
35
|
+
|
|
36
|
+
- an interview at the beginning: the number to improve, what must not change and how strictly (bitwise, a tolerance, a correlation), and a budget in iterations, batches of ideas or hours
|
|
37
|
+
- separation of "runs" from "iterations", where each "iteration" is an idea and multiple "runs" can be done to establish performance distributions; a change is kept only when its median beats its parent's by more than the noise band
|
|
38
|
+
- a setup subagent that writes the benchmark and proves that each gate catches a planted fault before the baseline is measured
|
|
39
|
+
- a unit-test gate run on every iteration, and an optional external validation, once a round, on inputs the search never measures, such as a complete processing step, to ensure no drift
|
|
40
|
+
- observational measures that are also recorded each iteration but not used to decide (e.g., memory usage, first run compile time, timings on tiny or very large inputs)
|
|
41
|
+
- an idea miner that reads the profile and writes ideas by category, one subagent per idea in its own git worktree, and each kept change becoming the root the next ideas build on
|
|
42
|
+
- the winner timed against the baseline in alternating, separate processes at the end
|
|
43
|
+
- a pretty interactive dashboard to monitor progress
|
|
44
|
+
- repository mode: a copy of a git repository is searched, optionally after a new unit-test suite is written for it, and the original is never touched
|
|
45
|
+
- shipping the winner into your files, as a branch, or as GitHub pull requests and a bug report that you review before anything is posted
|
|
46
|
+
- clean logging, formatting, usage of git worktrees, and documentation at each step, with instructions for future agents to build on top of what I have built here
|
|
47
|
+
- clean division of work done by subagents and work done by deterministic scripts, to give consistent and robust results
|
|
48
|
+
|
|
49
|
+
**See a finished search before you install anything.** Two pages show the
|
|
50
|
+
dashboard of the search in the walkthrough below, which made a one-hot
|
|
51
|
+
encoder 1,070 times faster:
|
|
52
|
+
|
|
53
|
+
- [**The search's dashboard**](https://claude.ai/artifact/724GcNKDAktnrgNkGxwh2f):
|
|
54
|
+
the objective by iteration, the frontier, the search tree, every run, and
|
|
55
|
+
each iteration's code change and README, as the skill leaves them when a
|
|
56
|
+
search ends.
|
|
57
|
+
- [**The same dashboard with its terms labeled**](https://claude.ai/artifact/S1nrSF1CSE3KLpZBEDxomB):
|
|
58
|
+
hover any part to see which term it shows (run, iteration, round, root,
|
|
59
|
+
frontier, noise band, …) and where else that term appears.
|
|
60
|
+
|
|
61
|
+
Conceptually, there are many things that one may wish to auto-optimize. Each thing
|
|
62
|
+
is shaped slightly differently, and so our approach will be to release skills for
|
|
63
|
+
each kind of thing one can auto-optimize that perfectly fits that setting.
|
|
64
|
+
|
|
65
|
+
(1) auto-optimize-code: the focus of this skill is optimizing the runtime and memory
|
|
66
|
+
usage of code while keeping its outputs identical, or within a tolerance you set. Hence, things like unit tests, running
|
|
67
|
+
small real examples at each iteration, and comparison of outputs at the byte-level
|
|
68
|
+
are relevant. This can be run on functions in a code-base, command-line tools, or
|
|
69
|
+
entire end-to-end algorithms or multi-step procedures.
|
|
70
|
+
|
|
71
|
+
(More to come.)
|
|
72
|
+
|
|
73
|
+
Developed at the [Programmable Genomics Laboratory](https://programmable-genomics.github.io) @ UMass Chan Medical School.
|
|
74
|
+
|
|
75
|
+
## Requirements
|
|
76
|
+
|
|
77
|
+
- Claude Code. The skill spawns subagents and asks you questions, so it needs
|
|
78
|
+
Claude Code's Agent and AskUserQuestion tools; the orchestrator, itself a
|
|
79
|
+
subagent, spawns the iteration subagents.
|
|
80
|
+
- Linux, Python 3.9 or later as `python3`, git and tar. The skill's scripts use
|
|
81
|
+
only the standard library.
|
|
82
|
+
- For the dashboard in a notebook: JupyterLab, IPython and plotly; psutil for
|
|
83
|
+
the host and process panels.
|
|
84
|
+
- For a benchmark that uses GPUs: `CUDA_VISIBLE_DEVICES` set by the machine's
|
|
85
|
+
GPU allocator, which the interview asks about.
|
|
86
|
+
|
|
87
|
+
`auto-optimize doctor` checks these once the installer is available (below).
|
|
88
|
+
|
|
89
|
+
## Install
|
|
90
|
+
|
|
91
|
+
The skill is one folder, `skills/auto-optimize-code/`. Each method below puts
|
|
92
|
+
that folder where Claude Code looks for skills; use one of them.
|
|
93
|
+
|
|
94
|
+
**As a Claude Code plugin.** In Claude Code:
|
|
95
|
+
|
|
96
|
+
```
|
|
97
|
+
/plugin install auto-optimize --marketplace jmschrei/auto-optimize
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
or, in two steps, `/plugin marketplace add jmschrei/auto-optimize` and then
|
|
101
|
+
`/plugin install auto-optimize@auto-optimize`. From a shell, `claude plugin
|
|
102
|
+
marketplace add jmschrei/auto-optimize` and then `claude plugin install
|
|
103
|
+
auto-optimize@auto-optimize`. The skill shows as
|
|
104
|
+
`auto-optimize:auto-optimize-code`. Update it with `claude plugin update
|
|
105
|
+
auto-optimize@auto-optimize`.
|
|
106
|
+
|
|
107
|
+
**With the installer, no clone.** With [uv](https://docs.astral.sh/uv/):
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
uvx auto-optimize install # into ~/.claude/skills/, for every project
|
|
111
|
+
uvx auto-optimize install --project # into ./.claude/skills/, for this project only
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
or `pipx run auto-optimize install`, or `pip install auto-optimize` and then
|
|
115
|
+
`auto-optimize install`. Run `install` again with a newer version to update.
|
|
116
|
+
The installer writes nothing until you run `install`, and replaces only a
|
|
117
|
+
copy it made itself; `--force` replaces anything else at that path.
|
|
118
|
+
|
|
119
|
+
| Command | Does |
|
|
120
|
+
|---|---|
|
|
121
|
+
| `auto-optimize install [--project [DIR] \| -d DIR] [--symlink] [-f]` | copy (or link) the skill into a skills folder |
|
|
122
|
+
| `auto-optimize uninstall [--project [DIR] \| -d DIR] [-f]` | remove a copy the installer made |
|
|
123
|
+
| `auto-optimize list` | every copy Claude Code would load from here: user, project and plugin, and a clone of this repository from before 1.0.0, which competes with the skill |
|
|
124
|
+
| `auto-optimize path` | the installed skill's folder |
|
|
125
|
+
| `auto-optimize doctor` | check Linux, `python3`, git, tar, the dashboard's modules and the installed copies |
|
|
126
|
+
|
|
127
|
+
When `CLAUDE_CONFIG_DIR` is set, the installer uses its `skills/` folder in
|
|
128
|
+
place of `~/.claude/skills/`.
|
|
129
|
+
|
|
130
|
+
**From a clone, linked.** Edits in the clone and `git pull` reach Claude Code
|
|
131
|
+
at once:
|
|
132
|
+
|
|
133
|
+
```bash
|
|
134
|
+
git clone https://github.com/jmschrei/auto-optimize
|
|
135
|
+
cd auto-optimize
|
|
136
|
+
uv run auto-optimize install --symlink # or: ln -s "$PWD/skills/auto-optimize-code" ~/.claude/skills/
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
**By hand.** Copy `skills/auto-optimize-code/` into any skills folder. It is
|
|
140
|
+
self-contained and carries its own `LICENSE`.
|
|
141
|
+
|
|
142
|
+
Install it one way only: Claude Code loads every copy it finds, and two copies
|
|
143
|
+
of one skill compete for the same requests. `auto-optimize list` shows them.
|
|
144
|
+
|
|
145
|
+
## A first search
|
|
146
|
+
|
|
147
|
+
The quickest test is the example in this repository, a correct and slow
|
|
148
|
+
one-hot encoder:
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
git clone https://github.com/jmschrei/auto-optimize
|
|
152
|
+
cd auto-optimize/examples/one-hot
|
|
153
|
+
python3 -m pip install numpy # the example's dependency; add numba if the search may use it
|
|
154
|
+
python3 onehot.py # prints a small encoding: the code runs
|
|
155
|
+
claude
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
Then ask:
|
|
159
|
+
|
|
160
|
+
> Use auto-optimize-code to make one_hot_encode in onehot.py faster on a 10
|
|
161
|
+
> Mbp DNA sequence. Its output must stay bitwise identical.
|
|
162
|
+
|
|
163
|
+
On your own code, ask in plain words: "Optimize `count_kmers` in `kmers.py`
|
|
164
|
+
for speed. The output must stay identical."
|
|
165
|
+
|
|
166
|
+
The skill starts with an interview: what number to improve and in which
|
|
167
|
+
direction, what must not change and how strictly (bitwise, a tolerance, a
|
|
168
|
+
correlation), what to record without optimizing, how many runs per
|
|
169
|
+
iteration, the GPUs, which model runs the iteration subagents, the budget,
|
|
170
|
+
and where the search lives. The default is
|
|
171
|
+
`~/auto-optimize/<YYYY-MM-DD>-<name>/`, which needs room for a copy of the
|
|
172
|
+
code per iteration. Then, without you:
|
|
173
|
+
|
|
174
|
+
1. a setup subagent writes the benchmark, checks that its seed controls what
|
|
175
|
+
it should, proves that each gate catches a planted fault, measures the
|
|
176
|
+
noise and runs the baseline, A0;
|
|
177
|
+
2. an idea miner reads A0's profile and lists ideas by category;
|
|
178
|
+
3. iteration subagents each take one idea, implement it in a fresh worktree
|
|
179
|
+
forked from the root (the last change kept), measure it and write a
|
|
180
|
+
README; a change that passes the keep rule becomes the next root;
|
|
181
|
+
4. the search ends on your word or at the budget you set: the winner is timed
|
|
182
|
+
against A0 in paired runs and summarized in `ended.md`, and the search is
|
|
183
|
+
over;
|
|
184
|
+
5. the skill asks how you want to ship the winner: written into your original
|
|
185
|
+
files, as a branch in your repository, or as GitHub pull requests and a
|
|
186
|
+
bug report that you review before anything is posted (*Getting the
|
|
187
|
+
result back*, below);
|
|
188
|
+
6. the winner is copied out with a final report, and the disk is reclaimed
|
|
189
|
+
once you agree.
|
|
190
|
+
|
|
191
|
+
The walkthrough below is a search on `examples/one-hot/`.
|
|
192
|
+
|
|
193
|
+
**What it costs.** Every iteration is a subagent session, and so are the
|
|
194
|
+
setup subagent, each idea-miner stage and each orchestrator phase, so a
|
|
195
|
+
search of a few dozen iterations
|
|
196
|
+
runs that many agent sessions. `autoopt.py tokens <work>` adds up what a
|
|
197
|
+
search's agents spent, from Claude Code's transcripts; the walkthrough's
|
|
198
|
+
numbers are at its end. Its 15 iterations took about two hours, so for a
|
|
199
|
+
first try give the interview a smaller budget, such as 4 or 5 iterations, and
|
|
200
|
+
a smaller model for the iteration subagents, as the [shorter
|
|
201
|
+
examples](#more-examples) do.
|
|
202
|
+
|
|
203
|
+
### Before you leave it running
|
|
204
|
+
|
|
205
|
+
A search is meant to go on without you once the interview is over. Three
|
|
206
|
+
things decide whether it can:
|
|
207
|
+
|
|
208
|
+
- **Tool permissions.** The subagents run `python3` and `git` commands and
|
|
209
|
+
write files in the search directory, which sits outside your project. Each
|
|
210
|
+
call your permission settings do not allow waits for your approval, and the
|
|
211
|
+
search waits with it. Approve them for the session as they come up, or allow
|
|
212
|
+
them ahead of time with `/permissions`, and add the search directory with
|
|
213
|
+
`/add-dir`.
|
|
214
|
+
- **Unanswered questions.** The skill asks questions during setup and when a
|
|
215
|
+
result looks wrong. Claude Code's `askUserQuestionTimeout` setting
|
|
216
|
+
(`/config`, or `settings.json`: `60s`, `5m`, `10m` or `never`) lets an
|
|
217
|
+
unanswered question continue; the skill then takes the answer that does the
|
|
218
|
+
least damage if it is wrong and records it in `ideas.md`. The skill offers
|
|
219
|
+
this before a long search and does not change your settings itself.
|
|
220
|
+
- **What runs on your machine.** The subagents write code and run it, and the
|
|
221
|
+
benchmark, as your user. The search never writes to your code (a
|
|
222
|
+
repository is copied first); only step 5 does, after you choose how and
|
|
223
|
+
approve a preview. Run a search only on code and inputs you trust, on a
|
|
224
|
+
machine where long CPU or GPU jobs are acceptable.
|
|
225
|
+
|
|
226
|
+
## Walkthrough: a one-hot encoder, 1,070 times faster
|
|
227
|
+
|
|
228
|
+
A real search with this skill on a shared 256-core Linux server. The numbers,
|
|
229
|
+
the dashboard and the code below come from that run; the home directory is
|
|
230
|
+
written as `~`, and the dashboard's host and GPU strip is left out of the
|
|
231
|
+
pictures.
|
|
232
|
+
|
|
233
|
+
**The code.** `examples/one-hot/onehot.py` is correct and slow: two nested
|
|
234
|
+
loops test each position against each letter.
|
|
235
|
+
|
|
236
|
+
```python
|
|
237
|
+
def one_hot_encode(sequence, alphabet='ACGT', dtype=numpy.int8):
|
|
238
|
+
ohe = numpy.zeros((len(alphabet), len(sequence)), dtype=dtype)
|
|
239
|
+
|
|
240
|
+
for i, character in enumerate(sequence):
|
|
241
|
+
for j, letter in enumerate(alphabet):
|
|
242
|
+
if character == letter:
|
|
243
|
+
ohe[j, i] = 1
|
|
244
|
+
|
|
245
|
+
return ohe
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
**The prompt**, in Claude Code, from that folder:
|
|
249
|
+
|
|
250
|
+

|
|
251
|
+
|
|
252
|
+
**The interview.** Three sets of questions pinned the search down. Every
|
|
253
|
+
answer, and each default taken without asking, went into the search's
|
|
254
|
+
`spec.md`, which every subagent reads.
|
|
255
|
+
|
|
256
|
+
| Question | Answer |
|
|
257
|
+
|---|---|
|
|
258
|
+
| Where the search lives | `~/auto-optimization/2026-11-21-one-hot/` |
|
|
259
|
+
| Objective | seconds per call, lower is better |
|
|
260
|
+
| Benchmark input | one 10 Mbp sequence, about 1% N and 1% lowercase bases |
|
|
261
|
+
| What must not change | the output, bitwise: values, dtype and shape |
|
|
262
|
+
| Runs per iteration | 5 |
|
|
263
|
+
| Dependencies | numba may be added; the signature and behavior stay |
|
|
264
|
+
| Tracked, not gated | 1 bp, 50 Mbp, all lowercase, all N and one repeated base |
|
|
265
|
+
| Threads in the timed call | up to 4 |
|
|
266
|
+
| Iteration subagents | sonnet |
|
|
267
|
+
| Budget | 15 iterations |
|
|
268
|
+
|
|
269
|
+
**Setup.** A setup subagent wrote the benchmark and proved the gate before
|
|
270
|
+
measuring anything: unchanged code and a loop-order swap gave 0 mismatches,
|
|
271
|
+
and a case-insensitive version gave 100,300 and failed. It checked that the
|
|
272
|
+
seed changes the input but not the timing, and that two runs at once do not
|
|
273
|
+
disturb each other. It stopped once to ask whether to run beside another job
|
|
274
|
+
on the machine (the answer was yes). The baseline, A0: a median of 1.507 s
|
|
275
|
+
over 5 runs.
|
|
276
|
+
|
|
277
|
+
**The search.** An idea miner read A0's profile, which put the whole call in
|
|
278
|
+
`one_hot_encode`, and wrote seven ideas. An orchestrator subagent handed them
|
|
279
|
+
to iteration subagents one at a time. The first, A1, replaced the loops with
|
|
280
|
+
a numba kernel and took the call from 1.507 s to 3.5 ms. A change of more
|
|
281
|
+
than tenfold stops the orchestrator: one 3.5 ms call is noisy (A1's runs
|
|
282
|
+
spanned 3.1 to 4.5 ms), so it asked whether to go on, start a new search
|
|
283
|
+
whose benchmark repeats the call, or stop. Nobody answered within ten
|
|
284
|
+
minutes, so the main session took the answer that does the least damage if
|
|
285
|
+
wrong, going on, and wrote it down in `ideas.md`. Four more idea-miner
|
|
286
|
+
stages refilled the ideas as they ran out.
|
|
287
|
+
|
|
288
|
+
The dashboard in JupyterLab, after the search ended (the same dashboard is
|
|
289
|
+
[online](https://claude.ai/artifact/724GcNKDAktnrgNkGxwh2f), to click
|
|
290
|
+
through):
|
|
291
|
+
|
|
292
|
+

|
|
293
|
+
|
|
294
|
+
The objective by iteration, on a log axis. Each point is one iteration's
|
|
295
|
+
median over its 5 runs, colored by the kind of idea; the dotted pink
|
|
296
|
+
staircase is the best so far, and the dashed purple lines mark each new batch
|
|
297
|
+
of ideas:
|
|
298
|
+
|
|
299
|
+

|
|
300
|
+
|
|
301
|
+
Three changes were kept, each the root of the next round: A1, the numba
|
|
302
|
+
kernel; A3, which reads an ASCII string's own buffer in place of an `encode`
|
|
303
|
+
copy (2.74 ms, and 9.5 MB less peak memory); and A7, which runs the kernel on
|
|
304
|
+
4 threads over contiguous chunks above 2^20 positions (1.405 ms). The
|
|
305
|
+
dashboard's frontier names A11 (1.343 ms), the best median measured: its gain
|
|
306
|
+
over A7 was inside the noise band, so the keep rule did not take it, and A7
|
|
307
|
+
is the winner.
|
|
308
|
+
|
|
309
|
+
**Clicking an iteration.** A click on A1's point on the chart opens its code
|
|
310
|
+
change against its parent: the loops became a kernel over the sequence's
|
|
311
|
+
bytes, with the original loop kept for the inputs the kernel does not handle.
|
|
312
|
+
|
|
313
|
+

|
|
314
|
+
|
|
315
|
+
A click on A7 in the search tree opens its README: the idea, what happened,
|
|
316
|
+
every run, and its notes, which say that the one-thread time rose by 0.5 ms
|
|
317
|
+
and that the cause was not found.
|
|
318
|
+
|
|
319
|
+

|
|
320
|
+
|
|
321
|
+
**The end.** At the 15-iteration budget, `end` timed A7 against A0 in
|
|
322
|
+
alternating separate processes and wrote `ended.md`:
|
|
323
|
+
|
|
324
|
+
```
|
|
325
|
+
- Objective `seconds` (min): the median goes from 1.507 in A0 to 0.001405 in A7: 1.507 -> 0.001405 s (-1.505, -99.9%).
|
|
326
|
+
- Gates, worst run of A7: `n_mismatch_vs_base == 0`: pass (0).
|
|
327
|
+
- Paired, on the search's own input: A7 vs A0, B better, -1.5, 9/9, p = 0.0039; at 4 threads, B better, -1.5, 9/9, p = 0.0039.
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
The read-only commands answer questions about it afterwards:
|
|
331
|
+
|
|
332
|
+
```
|
|
333
|
+
$ python3 $AO/autoopt.py table ~/auto-optimization/2026-11-21-one-hot --status ok --sort best --limit 5 \
|
|
334
|
+
--fields id,category,title,median,vs_base_pct,keep
|
|
335
|
+
id category title median vs_base_pct keep
|
|
336
|
+
--- ------------ ---------------------------------------- -------- ----------- ----
|
|
337
|
+
A11 PARALLEL _encode4_threaded: replace the ThreadPoo 0.001343 -99.91 fail
|
|
338
|
+
A7 PARALLEL _one_hot_fast: above one fixed size cuto 0.001405 -99.91 pass
|
|
339
|
+
A9 CACHE_MISS _encode4: change the loop order from one 0.001406 -99.91 fail
|
|
340
|
+
A15 OPTIMIZATION _one_hot_fast: on Linux only 0.001455 -99.9 fail
|
|
341
|
+
A14 PARALLEL _encode4_threaded: when the output dtype 0.001468 -99.9 fail
|
|
342
|
+
|
|
343
|
+
$ python3 $AO/autoopt.py show ~/auto-optimization/2026-11-21-one-hot A7 # an excerpt
|
|
344
|
+
A7 _one_hot_fast: above one fixed size cutoff
|
|
345
|
+
category PARALLEL, round 3, parent A3, branch autoopt/7, commit 89b13cd92e90
|
|
346
|
+
status ok at 5 runs
|
|
347
|
+
median 0.0014054 s (std 0.00021, range 0.00128587 to 0.0018017, 5 runs)
|
|
348
|
+
vs parent -0.001337 (-48.8%) against A3's 0.00274276
|
|
349
|
+
vs A0 -1.505 (-99.9%) against A0's 1.50683
|
|
350
|
+
keep pass: its median beats its parent's by 0.001337 > the noise band 0.000576
|
|
351
|
+
gate n_mismatch_vs_base == 0: pass (worst 0)
|
|
352
|
+
check cold first call 0.2417 s (parent 0.2416 s); compare pass (57 inputs identical)
|
|
353
|
+
change 1 file changed, 51 insertions(+), 1 deletion(-); git -C … diff autoopt/3...autoopt/7
|
|
354
|
+
…
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
The 12 iterations that were not kept all passed the gate; they were slower
|
|
358
|
+
or inside the noise band. Among them: numba's `prange` over the kernel's
|
|
359
|
+
loop (A2, slower than the serial kernel), two numpy-only versions (3.6 and
|
|
360
|
+
2.1 times slower than the kernel they were measured against), and a
|
|
361
|
+
huge-page-aligned output. The observers recorded what the
|
|
362
|
+
winner costs elsewhere: a cold first call of 0.24 s for numba's compile
|
|
363
|
+
(once per machine, since the kernels are cached), and a 1 bp input at
|
|
364
|
+
3.1 µs where the loop took 0.43 µs.
|
|
365
|
+
|
|
366
|
+
**What it took.** 15 iterations and the baseline, 80 runs and 217 s of
|
|
367
|
+
benchmark time. The wall clock was 2 h 9 min, about 30 minutes of it
|
|
368
|
+
waiting on questions nobody was there to answer. When the search ended,
|
|
369
|
+
`autoopt.py tokens` counted 9.5 million weighted tokens over 25 agent
|
|
370
|
+
sessions (cache reads weigh 0.05, output 5): 6.8 million in the 24
|
|
371
|
+
subagents, where each iteration subagent averaged 131 thousand, and the rest
|
|
372
|
+
in the main session. The main session's count goes on growing with whatever
|
|
373
|
+
else that session is used for, so a later `tokens` reports more.
|
|
374
|
+
|
|
375
|
+
## More examples
|
|
376
|
+
|
|
377
|
+
Three shorter searches, each with a budget of 4 iterations and sonnet
|
|
378
|
+
subagents, show other parts of the skill. Each folder holds the slow code,
|
|
379
|
+
the prompt, the dashboard when the search ended, and what it found.
|
|
380
|
+
|
|
381
|
+
| Example | What it shows | Result | Time |
|
|
382
|
+
|---|---|---|---|
|
|
383
|
+
| [`examples/fasta-stats/`](examples/fasta-stats/) | a whole command timed, its output file gated byte for byte | 1.271 s to 0.2048 s, three changes kept | 20 min |
|
|
384
|
+
| [`examples/kmer-memory/`](examples/kmer-memory/) | peak memory as the objective, the time per call recorded beside it | 332.9 MB to 5.136 MB in one change, the size of the returned dict | 18 min |
|
|
385
|
+
| [`examples/smooth-coverage/`](examples/smooth-coverage/) | a tolerance of 1e-9 as the gate, which a prefix-sum rewrite passes and a bitwise gate would refuse | 1.671 s to 0.002741 s, and the costs the observers caught | 24 min |
|
|
386
|
+
|
|
387
|
+
The time runs from the start of setup to the end of the search, and does not
|
|
388
|
+
include the interview or the minutes the main session waits on you. By
|
|
389
|
+
`autoopt.py tokens` when it ended, each search had spent about 4 million
|
|
390
|
+
weighted tokens.
|
|
391
|
+
|
|
392
|
+
## Watching it
|
|
393
|
+
|
|
394
|
+
The skill starts the dashboard with the first iteration and tells you where
|
|
395
|
+
it is: `<work>/dashboard.ipynb`, a live page in JupyterLab with the objective
|
|
396
|
+
by iteration, the frontier, the search tree, every run, the GPUs, the running
|
|
397
|
+
processes, and each iteration's code change against its parent. At the end it
|
|
398
|
+
writes a self-contained snapshot, `<work>/autooptimize/final/dashboard.html`,
|
|
399
|
+
which opens in any browser. The snapshot leaves out the hostname, GPU serial
|
|
400
|
+
numbers and GPU lease holders, and writes your home directory as `~`, so it
|
|
401
|
+
can be shared.
|
|
402
|
+
|
|
403
|
+
## Where things are
|
|
404
|
+
|
|
405
|
+
Everything a search makes lives in the search directory you choose at the
|
|
406
|
+
interview, `<work>` below (`~/auto-optimize/<YYYY-MM-DD>-<name>/` by
|
|
407
|
+
default). Your own code is only read; step 5 writes to it only after you
|
|
408
|
+
choose how and approve a preview. One folder per step, plain names:
|
|
409
|
+
|
|
410
|
+
```
|
|
411
|
+
<work>/
|
|
412
|
+
NOTES.md where the search stands: the six stages and the next command
|
|
413
|
+
dashboard.ipynb the live dashboard; open it in JupyterLab
|
|
414
|
+
interview/ step 0: the interview, license terms on the inputs, bugs you already knew of
|
|
415
|
+
inputs/ the data the benchmark reads
|
|
416
|
+
tests/ step 1, repository mode: the new unit tests and the bugs they found
|
|
417
|
+
setup/ step 2's scratch: the gate proofs and the concurrency measurement
|
|
418
|
+
autooptimize/ the search's own record
|
|
419
|
+
spec.md the rules the search runs by, in your words
|
|
420
|
+
config.json the objective, the gates, the observers and every setting
|
|
421
|
+
ideas.md every idea, the tried ones struck through, and decisions taken while you were away
|
|
422
|
+
knowledge.md what the subagents established, for the ones after them
|
|
423
|
+
iterations/<id>/ one per iteration: its code, notes.md, README.md, result.json and runs/
|
|
424
|
+
rounds/round-<N>.md one summary per round
|
|
425
|
+
repo.git/ every iteration's code, one branch each (autoopt/<id>)
|
|
426
|
+
ended.md, ended.json the result, once the search has ended
|
|
427
|
+
final/dashboard.html the dashboard as a single file, written when the search ends
|
|
428
|
+
ship/ step 5: the files applied, the branch made, or each GitHub document and its preview
|
|
429
|
+
finish/ step 6: final-report.md, and archive/ with the winner's code and patch
|
|
430
|
+
scratch/ anything disposable
|
|
431
|
+
```
|
|
432
|
+
|
|
433
|
+
An iteration's `README.md` says what it tried, what happened and every run;
|
|
434
|
+
its `result.json` holds the numbers every table, chart and document reads.
|
|
435
|
+
`skills/auto-optimize-code/references/layout.md` describes every file and
|
|
436
|
+
field.
|
|
437
|
+
|
|
438
|
+
## Reading the results
|
|
439
|
+
|
|
440
|
+
Ask Claude ("what did the search find?", "what did A7 try?"); the skill
|
|
441
|
+
answers from read-only commands. Or run them yourself:
|
|
442
|
+
|
|
443
|
+
```bash
|
|
444
|
+
AO="$(auto-optimize path)/scripts" # or the skills folder you installed into
|
|
445
|
+
python3 $AO/autoopt.py status <work> --brief # where it stands
|
|
446
|
+
python3 $AO/autoopt.py table <work> --status ok --sort best # every passing iteration, best first
|
|
447
|
+
python3 $AO/autoopt.py show <work> A7 # one iteration: numbers, verdict, change, notes
|
|
448
|
+
python3 $AO/autoopt.py path <work> --markdown # the kept changes from A0 to the winner
|
|
449
|
+
```
|
|
450
|
+
|
|
451
|
+
`<work>/autooptimize/ended.md` summarizes an ended search, and
|
|
452
|
+
`<work>/finish/final-report.md` is the final report. `table --json` and
|
|
453
|
+
`show --json` print raw values for a program; the record files are described
|
|
454
|
+
in `skills/auto-optimize-code/references/layout.md`.
|
|
455
|
+
|
|
456
|
+
## Getting the result back
|
|
457
|
+
|
|
458
|
+
The search never writes to your code. Once it has ended, step 5 asks you how
|
|
459
|
+
to ship the winner, and nothing leaves the search before you answer. Each
|
|
460
|
+
route shows you a preview first and writes nothing until you agree.
|
|
461
|
+
|
|
462
|
+
**A function or a script** (a search made from copied files). The skill
|
|
463
|
+
writes the winner's version of each file back where it was copied from, and
|
|
464
|
+
adds any file the change created beside it. A file you edited since the copy
|
|
465
|
+
is refused, so your edit is never overwritten (once you merge the change into
|
|
466
|
+
it by hand, `apply --by-hand` records it); the benchmark the search wrote for
|
|
467
|
+
itself is left out.
|
|
468
|
+
|
|
469
|
+
```bash
|
|
470
|
+
python3 $AO/ship.py apply <work> # preview
|
|
471
|
+
python3 $AO/ship.py apply <work> --yes # write the files
|
|
472
|
+
```
|
|
473
|
+
|
|
474
|
+
**A git repository, as a branch.** One commit per kept change, each with the
|
|
475
|
+
commit message the change's subagent wrote, made as a new branch in your
|
|
476
|
+
repository. It is not checked out, and nothing is pushed.
|
|
477
|
+
|
|
478
|
+
```bash
|
|
479
|
+
python3 $AO/ship.py branch <work> --name faster # preview
|
|
480
|
+
python3 $AO/ship.py branch <work> --name faster --yes # make the branch
|
|
481
|
+
```
|
|
482
|
+
|
|
483
|
+
These two are the commands the skill runs at step 5, once it has recorded
|
|
484
|
+
your choice (`after.ship`); each `--yes` refuses until then.
|
|
485
|
+
|
|
486
|
+
**A repository on GitHub, as pull requests.** You check which documents to
|
|
487
|
+
open:
|
|
488
|
+
|
|
489
|
+
| Document | Holds |
|
|
490
|
+
|---|---|
|
|
491
|
+
| the optimization PR | one commit per kept change on your branch, with the measured change on the main input, a table of every measure the search tracked, what each change does, and how the output was checked |
|
|
492
|
+
| the unit-test PR | the suite written before the search, when you asked for one, with its coverage before and after; separate from the optimization PR, so the two merge in either order |
|
|
493
|
+
| the bug report | one issue for the bugs that suite found, each with a reproduction the skill reran on your code |
|
|
494
|
+
|
|
495
|
+
A document-writer subagent drafts the chosen documents from what the search recorded:
|
|
496
|
+
every number in them comes from the search's own measurements. They name no
|
|
497
|
+
tool, and say nothing about checks the search did not run. You review all of
|
|
498
|
+
them together (`ship.py rehearse` renders them and previews every push), and
|
|
499
|
+
`ship.py post` posts them only after you approve that exact batch: the bug
|
|
500
|
+
report first, then the unit-test PR, then the optimization PR, each holding
|
|
501
|
+
the numbers of the ones before it. A repository you cannot push to is reached
|
|
502
|
+
from your fork. With the same questions you choose whether the branches it
|
|
503
|
+
pushes start with `auto-optimize/`; the documents themselves name no tool.
|
|
504
|
+
|
|
505
|
+
**Or not now.** The change stays in the search; ask later, or take it by hand
|
|
506
|
+
from `<work>/finish/archive/` (`idea.patch` and the winner's files) after
|
|
507
|
+
step 6.
|
|
508
|
+
|
|
509
|
+
**Before you merge**, read the final report and the winning iterations'
|
|
510
|
+
READMEs (`autoopt.py show <work> A7`). Their notes say what a change costs
|
|
511
|
+
outside the benchmark: in the walkthrough, numba's compile on the first call
|
|
512
|
+
and a slower 1 bp input. A change that adds a dependency, such as numba there,
|
|
513
|
+
needs it added to your project's requirements. Run your own tests and CI on
|
|
514
|
+
the result as well: the gates covered the inputs and the machine the search
|
|
515
|
+
measured on.
|
|
516
|
+
|
|
517
|
+
**Then the disk.** Step 6 reports what `prune` would delete and deletes it
|
|
518
|
+
only on your yes. Keep the search directory while you may still reopen the
|
|
519
|
+
search or check out an iteration again (`autoopt.py restore <work> --id
|
|
520
|
+
A7`). When you are done with it, stop its dashboard publisher
|
|
521
|
+
(`python3 $AO/dashboard/autoopt_monitor.py <work>/autooptimize --stop`) and
|
|
522
|
+
remove `<work>`.
|
|
523
|
+
|
|
524
|
+
## Resuming, stopping and common problems
|
|
525
|
+
|
|
526
|
+
| Situation | Do |
|
|
527
|
+
|---|---|
|
|
528
|
+
| Claude Code closed during a search | open it again and ask it to resume the search in `<work>`; everything the next session needs is on disk |
|
|
529
|
+
| You want the search to stop | say so; it lets the iteration in flight settle, then ends the search and times the winner against A0 |
|
|
530
|
+
| You want an ended search to go on | ask to reopen it (`autoopt.py end <work> --reopen`) |
|
|
531
|
+
| No JupyterLab | `python3 $AO/autoopt.py status <work>` in a terminal, or `python3 $AO/dashboard/autoopt_monitor.py <work>/autooptimize --export dashboard.html` for a static page |
|
|
532
|
+
| macOS or Windows | not supported: the scripts use Linux's `flock`, `/proc` and `/sys` |
|
|
533
|
+
| An error or a refusal | ask Claude: `references/symptoms.md` maps the skill's messages to their fixes |
|
|
534
|
+
| A bug | open an issue with the output of `auto-optimize doctor` and `autoopt.py status <work> --brief`, and the message |
|
|
535
|
+
|
|
536
|
+
## How it works
|
|
537
|
+
|
|
538
|
+
`skills/auto-optimize-code/SKILL.md` is what Claude reads. It defines the
|
|
539
|
+
words (a **run** is one seed, an **iteration** one idea measured over several
|
|
540
|
+
runs, a **round** the iterations forked from one root), the rules that hold
|
|
541
|
+
throughout, and routes each step to a file in `references/`. The scripts in
|
|
542
|
+
`scripts/` keep every number: `run_iteration.py` measures an iteration and
|
|
543
|
+
judges it against its gates and the noise band, and `autoopt.py` keeps the
|
|
544
|
+
search tree, the briefs, the promotions and the records. Only a median the
|
|
545
|
+
runner computed counts as a result; no agent types a number in.
|
|
546
|
+
|
|
547
|
+
## Changing what it does
|
|
548
|
+
|
|
549
|
+
Most changes are settings a search already reads, set in the interview or
|
|
550
|
+
later with `autoopt.py config <work> --set KEY=VALUE --reason "…"`:
|
|
551
|
+
|
|
552
|
+
| To change | Setting |
|
|
553
|
+
|---|---|
|
|
554
|
+
| how outputs are compared, timed and profiled | `checks.compare`, `checks.time`, `checks.first_call`, `checks.profile` |
|
|
555
|
+
| your package's tests as a gate on every iteration | `tests.command` |
|
|
556
|
+
| keep only changes worth at least 2%, or twice the noise | `keep.min_gain_pct=2`, `keep.band_k=2` |
|
|
557
|
+
| how many iterations, batches of ideas or hours the search may spend | `after.budget_iterations`, `after.budget_stages`, `after.budget_hours` |
|
|
558
|
+
| a keep rule in your own words | `promote=orchestrator`, and the rule in `spec.md` |
|
|
559
|
+
| your cluster's GPU allocator | `gpu_command` (`srun --gres=gpu:1`) |
|
|
560
|
+
| when another job counts as busy | `busy_percent` |
|
|
561
|
+
| the model the iteration subagents use | `subagent_model` |
|
|
562
|
+
| when to stop, how the winner ships, the disk | `after.*` |
|
|
563
|
+
|
|
564
|
+
`skills/auto-optimize-code/references/extending.md` lists every setting,
|
|
565
|
+
environment variable and code hook, and where to edit the code when no
|
|
566
|
+
setting fits: the idea categories, the words a pull request may not use, the
|
|
567
|
+
dashboard's colors.
|
|
568
|
+
|
|
569
|
+
## When it is the wrong tool
|
|
570
|
+
|
|
571
|
+
- One measurement, not a search: timing a function once needs a benchmark
|
|
572
|
+
alone.
|
|
573
|
+
- No measurable objective: if no script can emit it as a number, that comes
|
|
574
|
+
first.
|
|
575
|
+
- Improving a model's accuracy or training recipe: this skill optimizes code,
|
|
576
|
+
with its outputs gated.
|
|
577
|
+
|
|
578
|
+
## Repository layout
|
|
579
|
+
|
|
580
|
+
```
|
|
581
|
+
.claude-plugin/ the plugin manifest and its one-plugin marketplace
|
|
582
|
+
skills/
|
|
583
|
+
auto-optimize-code/ the skill: SKILL.md, references/, scripts/, LICENSE, VERSION
|
|
584
|
+
src/auto_optimize/ the installer (standard library only)
|
|
585
|
+
tests/
|
|
586
|
+
code/ the skill's script suites; dashboard/ holds the browser tests
|
|
587
|
+
package/ the installer and the shipped files (pytest)
|
|
588
|
+
examples/ one-hot/, the walkthrough's slow function, and three shorter examples
|
|
589
|
+
docs/walkthrough/ the walkthrough's screenshots, and the scripts that captured them
|
|
590
|
+
docs/banner/ the banner above, and make_banner.py, which draws it
|
|
591
|
+
```
|
|
592
|
+
|
|
593
|
+
## Development
|
|
594
|
+
|
|
595
|
+
```bash
|
|
596
|
+
python3 tests/code/run_tests.py # every script suite, one line each (a few minutes)
|
|
597
|
+
python3 tests/code/run_tests.py test_reading # one suite
|
|
598
|
+
uv run pytest # the installer and the shipped files
|
|
599
|
+
python3 tests/code/dashboard/test_frontend.py # the dashboard in headless Chromium (needs playwright)
|
|
600
|
+
python3 tests/code/dashboard/test_notebook.py # the dashboard mounted in JupyterLab
|
|
601
|
+
```
|
|
602
|
+
|
|
603
|
+
`tests/code/dashboard/README.md` describes the dashboard's suites. The
|
|
604
|
+
version is `__version__` in `src/auto_optimize/__init__.py`; the skill's
|
|
605
|
+
`VERSION` file and both plugin manifests carry the same number, which
|
|
606
|
+
`tests/package/test_skill_files.py` checks.
|
|
607
|
+
|
|
608
|
+
## License
|
|
609
|
+
|
|
610
|
+
MIT (`LICENSE`).
|