textopt 0.0.0
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.
- package/LICENSE +21 -0
- package/README.md +509 -0
- package/dist/bootstrap-search/index.cjs +308 -0
- package/dist/bootstrap-search/index.d.cts +162 -0
- package/dist/bootstrap-search/index.d.mts +162 -0
- package/dist/bootstrap-search/index.mjs +307 -0
- package/dist/cache-CuSo0NJ8.d.cts +24 -0
- package/dist/cache-CuSo0NJ8.d.mts +24 -0
- package/dist/concurrency-C-cFzWW2.cjs +44 -0
- package/dist/concurrency-D58PWeSk.mjs +39 -0
- package/dist/demos-B0pVQjYC.d.mts +88 -0
- package/dist/demos-B9BJiNKz.cjs +143 -0
- package/dist/demos-BTuzFNsp.d.cts +88 -0
- package/dist/demos-Degx6UmP.mjs +126 -0
- package/dist/evaluation-BV0nSZVx.mjs +521 -0
- package/dist/evaluation-OZOp6TB7.cjs +598 -0
- package/dist/file-cache.cjs +70 -0
- package/dist/file-cache.d.cts +21 -0
- package/dist/file-cache.d.mts +21 -0
- package/dist/file-cache.mjs +69 -0
- package/dist/gepa/index.cjs +1671 -0
- package/dist/gepa/index.d.cts +385 -0
- package/dist/gepa/index.d.mts +385 -0
- package/dist/gepa/index.mjs +1652 -0
- package/dist/index.cjs +266 -0
- package/dist/index.d.cts +221 -0
- package/dist/index.d.mts +221 -0
- package/dist/index.mjs +245 -0
- package/dist/math-COOofUyv.cjs +101 -0
- package/dist/math-DhrDmpFS.mjs +78 -0
- package/dist/mipro/index.cjs +739 -0
- package/dist/mipro/index.d.cts +372 -0
- package/dist/mipro/index.d.mts +372 -0
- package/dist/mipro/index.mjs +736 -0
- package/dist/opro/index.cjs +487 -0
- package/dist/opro/index.d.cts +230 -0
- package/dist/opro/index.d.mts +230 -0
- package/dist/opro/index.mjs +485 -0
- package/dist/optimizer-B7SpRwl7.d.cts +288 -0
- package/dist/optimizer-DqCoth_w.d.mts +288 -0
- package/dist/random-search/index.cjs +321 -0
- package/dist/random-search/index.d.cts +156 -0
- package/dist/random-search/index.d.mts +156 -0
- package/dist/random-search/index.mjs +319 -0
- package/dist/reflection-CQToe-5B.d.cts +283 -0
- package/dist/reflection-Cr_upzU0.d.mts +283 -0
- package/dist/reflection-DRfbk6hu.cjs +249 -0
- package/dist/reflection-mwMhrjs_.mjs +214 -0
- package/dist/rng-BR5MOedA.d.cts +22 -0
- package/dist/rng-BR5MOedA.d.mts +22 -0
- package/dist/rng-DbA_rPIo.cjs +67 -0
- package/dist/rng-Dtc5eZ_W.mjs +62 -0
- package/dist/sampling-CfHt7Gue.mjs +59 -0
- package/dist/sampling-DFo_7RNJ.d.mts +23 -0
- package/dist/sampling-Dars7ctR.cjs +64 -0
- package/dist/sampling-axOwfZf5.d.cts +23 -0
- package/dist/simba/index.cjs +709 -0
- package/dist/simba/index.d.cts +289 -0
- package/dist/simba/index.d.mts +289 -0
- package/dist/simba/index.mjs +700 -0
- package/dist/testing.cjs +155 -0
- package/dist/testing.d.cts +53 -0
- package/dist/testing.d.mts +53 -0
- package/dist/testing.mjs +148 -0
- package/dist/text--v4Ffbus.mjs +21 -0
- package/dist/text-CK_HB3su.cjs +26 -0
- package/dist/types-CWv4IQFF.d.cts +129 -0
- package/dist/types-CWv4IQFF.d.mts +129 -0
- package/package.json +135 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { appendFileSync, mkdirSync, readFileSync } from "node:fs";
|
|
2
|
+
import { dirname } from "node:path";
|
|
3
|
+
//#region src/file-cache.ts
|
|
4
|
+
/**
|
|
5
|
+
* An evaluation cache that outlives the process, as an append-only log.
|
|
6
|
+
*
|
|
7
|
+
* A long run against a real provider is measured in hours and dollars, and an
|
|
8
|
+
* in-memory cache throws all of it away when the run ends — a crashed run, a
|
|
9
|
+
* re-run with a changed budget, or a second experiment over the same
|
|
10
|
+
* validation set all pay for identical rollouts again.
|
|
11
|
+
*
|
|
12
|
+
* Append-only rather than rewritten: a score is never invalidated (the key
|
|
13
|
+
* names the candidate, the instance, and the environment), and a log survives
|
|
14
|
+
* a process killed mid-write, which a file rewritten in place does not.
|
|
15
|
+
*/
|
|
16
|
+
function createFileCache(args) {
|
|
17
|
+
const { path, maxEntries = 1e6 } = args;
|
|
18
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
19
|
+
const entries = readLog(path);
|
|
20
|
+
return {
|
|
21
|
+
get: (key) => entries.get(key),
|
|
22
|
+
set: (key, cached) => {
|
|
23
|
+
if (entries.size >= maxEntries && !entries.has(key)) {
|
|
24
|
+
const oldest = entries.keys().next();
|
|
25
|
+
if (!oldest.done) entries.delete(oldest.value);
|
|
26
|
+
}
|
|
27
|
+
entries.set(key, cached);
|
|
28
|
+
appendFileSync(path, `${JSON.stringify([key, cached])}\n`);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Later records win, so a re-measured instance replaces its earlier reading.
|
|
34
|
+
* A record that does not parse is dropped rather than fatal: the last line of
|
|
35
|
+
* a log whose process was killed mid-write is routinely half-written, and
|
|
36
|
+
* losing one cached score is not worth failing a run over.
|
|
37
|
+
*/
|
|
38
|
+
function readLog(path) {
|
|
39
|
+
const entries = /* @__PURE__ */ new Map();
|
|
40
|
+
let contents;
|
|
41
|
+
try {
|
|
42
|
+
contents = readFileSync(path, "utf8");
|
|
43
|
+
} catch {
|
|
44
|
+
return entries;
|
|
45
|
+
}
|
|
46
|
+
for (const line of contents.split("\n")) {
|
|
47
|
+
if (line.length === 0) continue;
|
|
48
|
+
const entry = parseEntry(line);
|
|
49
|
+
if (entry !== void 0) entries.set(entry[0], entry[1]);
|
|
50
|
+
}
|
|
51
|
+
return entries;
|
|
52
|
+
}
|
|
53
|
+
function parseEntry(line) {
|
|
54
|
+
let parsed;
|
|
55
|
+
try {
|
|
56
|
+
parsed = JSON.parse(line);
|
|
57
|
+
} catch {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
if (!Array.isArray(parsed) || parsed.length !== 2) return;
|
|
61
|
+
const [key, cached] = parsed;
|
|
62
|
+
if (typeof key !== "string" || !isCachedScore(cached)) return;
|
|
63
|
+
return [key, cached];
|
|
64
|
+
}
|
|
65
|
+
function isCachedScore(value) {
|
|
66
|
+
return typeof value === "object" && value !== null && typeof value.score === "number";
|
|
67
|
+
}
|
|
68
|
+
//#endregion
|
|
69
|
+
export { createFileCache };
|