ppef 1.0.0 → 1.0.1
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/README.md +172 -0
- package/dist/__tests__/framework-pipeline.integration.test.d.ts +7 -0
- package/dist/__tests__/framework-pipeline.integration.test.d.ts.map +1 -0
- package/dist/__tests__/framework-pipeline.integration.test.js +413 -0
- package/dist/__tests__/framework-pipeline.integration.test.js.map +1 -0
- package/dist/__tests__/registry-executor.integration.test.d.ts +5 -0
- package/dist/__tests__/registry-executor.integration.test.d.ts.map +1 -0
- package/dist/__tests__/registry-executor.integration.test.js +349 -0
- package/dist/__tests__/registry-executor.integration.test.js.map +1 -0
- package/dist/__tests__/test-helpers.d.ts +94 -0
- package/dist/__tests__/test-helpers.d.ts.map +1 -0
- package/dist/__tests__/test-helpers.js +271 -0
- package/dist/__tests__/test-helpers.js.map +1 -0
- package/dist/aggregation/aggregators.d.ts +54 -0
- package/dist/aggregation/aggregators.d.ts.map +1 -0
- package/dist/aggregation/aggregators.js +228 -0
- package/dist/aggregation/aggregators.js.map +1 -0
- package/dist/aggregation/index.d.ts +8 -0
- package/dist/aggregation/index.d.ts.map +1 -0
- package/dist/aggregation/index.js +8 -0
- package/dist/aggregation/index.js.map +1 -0
- package/dist/aggregation/pipeline.d.ts +38 -0
- package/dist/aggregation/pipeline.d.ts.map +1 -0
- package/dist/aggregation/pipeline.js +198 -0
- package/dist/aggregation/pipeline.js.map +1 -0
- package/dist/claims/evaluator.d.ts +33 -0
- package/dist/claims/evaluator.d.ts.map +1 -0
- package/dist/claims/evaluator.js +174 -0
- package/dist/claims/evaluator.js.map +1 -0
- package/dist/claims/index.d.ts +7 -0
- package/dist/claims/index.d.ts.map +1 -0
- package/dist/claims/index.js +7 -0
- package/dist/claims/index.js.map +1 -0
- package/dist/collector/index.d.ts +8 -0
- package/dist/collector/index.d.ts.map +1 -0
- package/dist/collector/index.js +8 -0
- package/dist/collector/index.js.map +1 -0
- package/dist/collector/result-collector.d.ts +159 -0
- package/dist/collector/result-collector.d.ts.map +1 -0
- package/dist/collector/result-collector.js +213 -0
- package/dist/collector/result-collector.js.map +1 -0
- package/dist/collector/schema.d.ts +34 -0
- package/dist/collector/schema.d.ts.map +1 -0
- package/dist/collector/schema.js +145 -0
- package/dist/collector/schema.js.map +1 -0
- package/dist/executor/__tests__/checkpoint-hash-bug.diagnostic.test.d.ts +10 -0
- package/dist/executor/__tests__/checkpoint-hash-bug.diagnostic.test.d.ts.map +1 -0
- package/dist/executor/__tests__/checkpoint-hash-bug.diagnostic.test.js +122 -0
- package/dist/executor/__tests__/checkpoint-hash-bug.diagnostic.test.js.map +1 -0
- package/dist/executor/__tests__/checkpoint-manager.integration.test.d.ts +7 -0
- package/dist/executor/__tests__/checkpoint-manager.integration.test.d.ts.map +1 -0
- package/dist/executor/__tests__/checkpoint-manager.integration.test.js +330 -0
- package/dist/executor/__tests__/checkpoint-manager.integration.test.js.map +1 -0
- package/dist/executor/__tests__/checkpoint-manager.unit.test.d.ts +7 -0
- package/dist/executor/__tests__/checkpoint-manager.unit.test.d.ts.map +1 -0
- package/dist/executor/__tests__/checkpoint-manager.unit.test.js +449 -0
- package/dist/executor/__tests__/checkpoint-manager.unit.test.js.map +1 -0
- package/dist/executor/__tests__/checkpoint-merge-bug.diagnostic.test.d.ts +11 -0
- package/dist/executor/__tests__/checkpoint-merge-bug.diagnostic.test.d.ts.map +1 -0
- package/dist/executor/__tests__/checkpoint-merge-bug.diagnostic.test.js +224 -0
- package/dist/executor/__tests__/checkpoint-merge-bug.diagnostic.test.js.map +1 -0
- package/dist/executor/__tests__/checkpoint-merge-bug.unit.test.d.ts +8 -0
- package/dist/executor/__tests__/checkpoint-merge-bug.unit.test.d.ts.map +1 -0
- package/dist/executor/__tests__/checkpoint-merge-bug.unit.test.js +164 -0
- package/dist/executor/__tests__/checkpoint-merge-bug.unit.test.js.map +1 -0
- package/dist/executor/__tests__/checkpoint-storage.unit.test.d.ts +7 -0
- package/dist/executor/__tests__/checkpoint-storage.unit.test.d.ts.map +1 -0
- package/dist/executor/__tests__/checkpoint-storage.unit.test.js +386 -0
- package/dist/executor/__tests__/checkpoint-storage.unit.test.js.map +1 -0
- package/dist/executor/__tests__/executor.unit.test.d.ts +7 -0
- package/dist/executor/__tests__/executor.unit.test.d.ts.map +1 -0
- package/dist/executor/__tests__/executor.unit.test.js +134 -0
- package/dist/executor/__tests__/executor.unit.test.js.map +1 -0
- package/dist/executor/__tests__/parallel-checkpoint-merge.integration.test.d.ts +12 -0
- package/dist/executor/__tests__/parallel-checkpoint-merge.integration.test.d.ts.map +1 -0
- package/dist/executor/__tests__/parallel-checkpoint-merge.integration.test.js +196 -0
- package/dist/executor/__tests__/parallel-checkpoint-merge.integration.test.js.map +1 -0
- package/dist/executor/__tests__/parallel-executor.integration.test.d.ts +7 -0
- package/dist/executor/__tests__/parallel-executor.integration.test.d.ts.map +1 -0
- package/dist/executor/__tests__/parallel-executor.integration.test.js +249 -0
- package/dist/executor/__tests__/parallel-executor.integration.test.js.map +1 -0
- package/dist/executor/__tests__/parallel-executor.unit.test.d.ts +7 -0
- package/dist/executor/__tests__/parallel-executor.unit.test.d.ts.map +1 -0
- package/dist/executor/__tests__/parallel-executor.unit.test.js +203 -0
- package/dist/executor/__tests__/parallel-executor.unit.test.js.map +1 -0
- package/dist/executor/checkpoint-manager.d.ts +231 -0
- package/dist/executor/checkpoint-manager.d.ts.map +1 -0
- package/dist/executor/checkpoint-manager.js +395 -0
- package/dist/executor/checkpoint-manager.js.map +1 -0
- package/dist/executor/checkpoint-storage.d.ts +230 -0
- package/dist/executor/checkpoint-storage.d.ts.map +1 -0
- package/dist/executor/checkpoint-storage.js +370 -0
- package/dist/executor/checkpoint-storage.js.map +1 -0
- package/dist/executor/checkpoint-types.d.ts +48 -0
- package/dist/executor/checkpoint-types.d.ts.map +1 -0
- package/dist/executor/checkpoint-types.js +8 -0
- package/dist/executor/checkpoint-types.js.map +1 -0
- package/dist/executor/executor.d.ts +164 -0
- package/dist/executor/executor.d.ts.map +1 -0
- package/dist/executor/executor.js +408 -0
- package/dist/executor/executor.js.map +1 -0
- package/dist/executor/index.d.ts +11 -0
- package/dist/executor/index.d.ts.map +1 -0
- package/dist/executor/index.js +11 -0
- package/dist/executor/index.js.map +1 -0
- package/dist/executor/memory-monitor.d.ts +115 -0
- package/dist/executor/memory-monitor.d.ts.map +1 -0
- package/dist/executor/memory-monitor.js +168 -0
- package/dist/executor/memory-monitor.js.map +1 -0
- package/dist/executor/parallel-executor.d.ts +53 -0
- package/dist/executor/parallel-executor.d.ts.map +1 -0
- package/dist/executor/parallel-executor.js +194 -0
- package/dist/executor/parallel-executor.js.map +1 -0
- package/dist/executor/run-id.d.ts +71 -0
- package/dist/executor/run-id.d.ts.map +1 -0
- package/dist/executor/run-id.js +67 -0
- package/dist/executor/run-id.js.map +1 -0
- package/dist/executor/worker-entry.d.ts +8 -0
- package/dist/executor/worker-entry.d.ts.map +1 -0
- package/dist/executor/worker-entry.js +67 -0
- package/dist/executor/worker-entry.js.map +1 -0
- package/dist/index.cjs +11 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -0
- package/dist/registry/case-registry.d.ts +113 -0
- package/dist/registry/case-registry.d.ts.map +1 -0
- package/dist/registry/case-registry.js +160 -0
- package/dist/registry/case-registry.js.map +1 -0
- package/dist/registry/index.d.ts +8 -0
- package/dist/registry/index.d.ts.map +1 -0
- package/dist/registry/index.js +8 -0
- package/dist/registry/index.js.map +1 -0
- package/dist/registry/sut-registry.d.ts +96 -0
- package/dist/registry/sut-registry.d.ts.map +1 -0
- package/dist/registry/sut-registry.js +126 -0
- package/dist/registry/sut-registry.js.map +1 -0
- package/dist/renderers/index.d.ts +10 -0
- package/dist/renderers/index.d.ts.map +1 -0
- package/dist/renderers/index.js +9 -0
- package/dist/renderers/index.js.map +1 -0
- package/dist/renderers/latex-renderer.d.ts +84 -0
- package/dist/renderers/latex-renderer.d.ts.map +1 -0
- package/dist/renderers/latex-renderer.js +208 -0
- package/dist/renderers/latex-renderer.js.map +1 -0
- package/dist/renderers/types.d.ts +106 -0
- package/dist/renderers/types.d.ts.map +1 -0
- package/dist/renderers/types.js +23 -0
- package/dist/renderers/types.js.map +1 -0
- package/dist/robustness/analyzer.d.ts +61 -0
- package/dist/robustness/analyzer.d.ts.map +1 -0
- package/dist/robustness/analyzer.js +191 -0
- package/dist/robustness/analyzer.js.map +1 -0
- package/dist/robustness/index.d.ts +8 -0
- package/dist/robustness/index.d.ts.map +1 -0
- package/dist/robustness/index.js +8 -0
- package/dist/robustness/index.js.map +1 -0
- package/dist/robustness/perturbations.d.ts +46 -0
- package/dist/robustness/perturbations.d.ts.map +1 -0
- package/dist/robustness/perturbations.js +184 -0
- package/dist/robustness/perturbations.js.map +1 -0
- package/dist/statistical/index.d.ts +8 -0
- package/dist/statistical/index.d.ts.map +1 -0
- package/dist/statistical/index.js +8 -0
- package/dist/statistical/index.js.map +1 -0
- package/dist/statistical/mann-whitney-u.d.ts +62 -0
- package/dist/statistical/mann-whitney-u.d.ts.map +1 -0
- package/dist/statistical/mann-whitney-u.js +127 -0
- package/dist/statistical/mann-whitney-u.js.map +1 -0
- package/dist/types/aggregate.d.ts +124 -0
- package/dist/types/aggregate.d.ts.map +1 -0
- package/dist/types/aggregate.js +9 -0
- package/dist/types/aggregate.js.map +1 -0
- package/dist/types/case.d.ts +105 -0
- package/dist/types/case.d.ts.map +1 -0
- package/dist/types/case.js +10 -0
- package/dist/types/case.js.map +1 -0
- package/dist/types/claims.d.ts +122 -0
- package/dist/types/claims.d.ts.map +1 -0
- package/dist/types/claims.js +14 -0
- package/dist/types/claims.js.map +1 -0
- package/dist/types/index.d.ts +12 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +7 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/perturbation.d.ts +105 -0
- package/dist/types/perturbation.d.ts.map +1 -0
- package/dist/types/perturbation.js +9 -0
- package/dist/types/perturbation.js.map +1 -0
- package/dist/types/result.d.ts +150 -0
- package/dist/types/result.d.ts.map +1 -0
- package/dist/types/result.js +12 -0
- package/dist/types/result.js.map +1 -0
- package/dist/types/sut.d.ts +128 -0
- package/dist/types/sut.d.ts.map +1 -0
- package/dist/types/sut.js +12 -0
- package/dist/types/sut.js.map +1 -0
- package/package.json +283 -7
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checkpoint Storage Backends
|
|
3
|
+
*
|
|
4
|
+
* Pluggable storage for experiment checkpoints:
|
|
5
|
+
* - FileStorage: JSON files in local filesystem (fast, no git required)
|
|
6
|
+
* - GitStorage: Git notes attached to commits (version controlled, shareable)
|
|
7
|
+
*
|
|
8
|
+
* Dependency Injection:
|
|
9
|
+
* - FileSystem interface enables mocking for tests
|
|
10
|
+
* - Lock interface enables pluggable concurrency control
|
|
11
|
+
*
|
|
12
|
+
* Usage:
|
|
13
|
+
* ```typescript
|
|
14
|
+
* // File-based (default)
|
|
15
|
+
* const fileStorage = new FileStorage("results/execute/checkpoint.json");
|
|
16
|
+
*
|
|
17
|
+
* // Git-based (stores as git notes)
|
|
18
|
+
* const gitStorage = new GitStorage("results-execute");
|
|
19
|
+
*
|
|
20
|
+
* // With mock file system for testing
|
|
21
|
+
* const mockFs = new MockFileSystem();
|
|
22
|
+
* const fileStorage = new FileStorage("checkpoint.json", mockFs);
|
|
23
|
+
*
|
|
24
|
+
* // Auto-detect based on mode
|
|
25
|
+
* const storage = createCheckpointStorage("file", "results/execute/checkpoint.json");
|
|
26
|
+
* const storage = createCheckpointStorage("git", "results-execute");
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
import { execSync } from "node:child_process";
|
|
30
|
+
import { mkdir, readdir, readFile, unlink, writeFile } from "node:fs/promises";
|
|
31
|
+
import { dirname, resolve } from "node:path";
|
|
32
|
+
/**
|
|
33
|
+
* Production file system implementation using node:fs/promises.
|
|
34
|
+
*/
|
|
35
|
+
export class NodeFileSystem {
|
|
36
|
+
async readFile(path) {
|
|
37
|
+
return readFile(path, "utf-8");
|
|
38
|
+
}
|
|
39
|
+
async writeFile(path, content) {
|
|
40
|
+
await writeFile(path, content, "utf-8");
|
|
41
|
+
}
|
|
42
|
+
async mkdir(path, options) {
|
|
43
|
+
await mkdir(path, options);
|
|
44
|
+
}
|
|
45
|
+
async unlink(path) {
|
|
46
|
+
await unlink(path);
|
|
47
|
+
}
|
|
48
|
+
async access(path) {
|
|
49
|
+
const { constants } = await import("node:fs/promises");
|
|
50
|
+
const { access } = await import("node:fs/promises");
|
|
51
|
+
await access(path, constants.F_OK);
|
|
52
|
+
}
|
|
53
|
+
async readdir(path) {
|
|
54
|
+
return readdir(path);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* In-memory lock for single-process use.
|
|
59
|
+
* Provides queue-based locking for concurrent saves within a process.
|
|
60
|
+
*/
|
|
61
|
+
export class InMemoryLock {
|
|
62
|
+
locked = false;
|
|
63
|
+
queue = [];
|
|
64
|
+
async acquire() {
|
|
65
|
+
return new Promise((resolve) => {
|
|
66
|
+
if (this.locked) {
|
|
67
|
+
this.queue.push(resolve);
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
this.locked = true;
|
|
71
|
+
resolve();
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
release() {
|
|
76
|
+
const next = this.queue.shift();
|
|
77
|
+
if (next) {
|
|
78
|
+
next();
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
this.locked = false;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* File-based checkpoint storage.
|
|
87
|
+
* Stores checkpoints as JSON files in the local filesystem.
|
|
88
|
+
*
|
|
89
|
+
* Supports dependency injection of FileSystem for testing.
|
|
90
|
+
*/
|
|
91
|
+
export class FileStorage {
|
|
92
|
+
type = "file";
|
|
93
|
+
path;
|
|
94
|
+
fs;
|
|
95
|
+
constructor(path, fs) {
|
|
96
|
+
this.path = resolve(path);
|
|
97
|
+
this.fs = fs ?? new NodeFileSystem();
|
|
98
|
+
}
|
|
99
|
+
async load() {
|
|
100
|
+
try {
|
|
101
|
+
const content = await this.fs.readFile(this.path);
|
|
102
|
+
return JSON.parse(content);
|
|
103
|
+
}
|
|
104
|
+
catch {
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
async save(data) {
|
|
109
|
+
try {
|
|
110
|
+
await this.fs.mkdir(dirname(this.path), { recursive: true });
|
|
111
|
+
data.updatedAt = new Date().toISOString();
|
|
112
|
+
const content = JSON.stringify(data, null, 2);
|
|
113
|
+
await this.fs.writeFile(this.path, content);
|
|
114
|
+
}
|
|
115
|
+
catch (error) {
|
|
116
|
+
console.warn(`Failed to save checkpoint to ${this.path}: ${String(error)}`);
|
|
117
|
+
throw error;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
async delete() {
|
|
121
|
+
try {
|
|
122
|
+
await this.fs.unlink(this.path);
|
|
123
|
+
}
|
|
124
|
+
catch {
|
|
125
|
+
// Ignore if file doesn't exist
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
async exists() {
|
|
129
|
+
try {
|
|
130
|
+
const content = await this.fs.readFile(this.path);
|
|
131
|
+
const data = JSON.parse(content);
|
|
132
|
+
return data !== null && typeof data === "object";
|
|
133
|
+
}
|
|
134
|
+
catch {
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
getPath() {
|
|
139
|
+
return this.path;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Find all worker checkpoint shard files in a directory.
|
|
143
|
+
* Looks for files matching the pattern "checkpoint-worker-*.json".
|
|
144
|
+
*
|
|
145
|
+
* @param baseDir - Directory to search for shard files
|
|
146
|
+
* @param fs - FileSystem implementation (defaults to NodeFileSystem)
|
|
147
|
+
* @returns Sorted array of shard file paths
|
|
148
|
+
*/
|
|
149
|
+
static async findShards(baseDir, fs) {
|
|
150
|
+
const fileSystem = fs ?? new NodeFileSystem();
|
|
151
|
+
const shardFiles = [];
|
|
152
|
+
try {
|
|
153
|
+
const entries = await fileSystem.readdir(baseDir);
|
|
154
|
+
for (const entry of entries) {
|
|
155
|
+
if (entry.startsWith("checkpoint-worker-") && entry.endsWith(".json")) {
|
|
156
|
+
shardFiles.push(resolve(baseDir, entry));
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
catch {
|
|
161
|
+
// Directory doesn't exist or is not readable
|
|
162
|
+
return [];
|
|
163
|
+
}
|
|
164
|
+
// Sort by worker index (extract numeric part for proper ordering)
|
|
165
|
+
return shardFiles.sort((a, b) => {
|
|
166
|
+
const aMatch = /checkpoint-worker-(\d+)\.json/.exec(a);
|
|
167
|
+
const bMatch = /checkpoint-worker-(\d+)\.json/.exec(b);
|
|
168
|
+
const aIndex = aMatch ? Number.parseInt(aMatch[1], 10) : -1;
|
|
169
|
+
const bIndex = bMatch ? Number.parseInt(bMatch[1], 10) : -1;
|
|
170
|
+
return aIndex - bIndex;
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Generate a shard file path for a specific worker.
|
|
175
|
+
*
|
|
176
|
+
* @param baseDir - Base directory for checkpoints
|
|
177
|
+
* @param workerIndex - Worker index (0-based)
|
|
178
|
+
* @returns Path to the shard checkpoint file
|
|
179
|
+
*/
|
|
180
|
+
static shardPath(baseDir, workerIndex) {
|
|
181
|
+
return resolve(baseDir, `checkpoint-worker-${String(workerIndex).padStart(2, "0")}.json`);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Git-based checkpoint storage using git notes.
|
|
186
|
+
*
|
|
187
|
+
* Checkpoints are stored as git notes attached to the current HEAD.
|
|
188
|
+
* This provides:
|
|
189
|
+
* - Version control: Checkpoints tracked in git history
|
|
190
|
+
* - Shareability: Team members can access each other's checkpoints
|
|
191
|
+
* - Reproducibility: Linked to specific commits
|
|
192
|
+
* - Safety: No accidental deletion through git clean
|
|
193
|
+
*
|
|
194
|
+
* Each checkpoint is stored as a note with a unique ref based on the namespace.
|
|
195
|
+
*/
|
|
196
|
+
export class GitStorage {
|
|
197
|
+
type = "git";
|
|
198
|
+
namespace;
|
|
199
|
+
repoRoot;
|
|
200
|
+
constructor(namespace, repoRoot = process.cwd()) {
|
|
201
|
+
this.namespace = namespace;
|
|
202
|
+
this.repoRoot = repoRoot;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Get the full notes ref for this checkpoint.
|
|
206
|
+
*/
|
|
207
|
+
getNotesRef() {
|
|
208
|
+
return `refs/notes/checkpoints/${this.namespace}`;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Check if git is available and we're in a git repo.
|
|
212
|
+
*/
|
|
213
|
+
checkGitAvailable() {
|
|
214
|
+
try {
|
|
215
|
+
execSync("git rev-parse --git-dir", {
|
|
216
|
+
cwd: this.repoRoot,
|
|
217
|
+
stdio: "pipe",
|
|
218
|
+
});
|
|
219
|
+
return true;
|
|
220
|
+
}
|
|
221
|
+
catch {
|
|
222
|
+
return false;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
load() {
|
|
226
|
+
if (!this.checkGitAvailable()) {
|
|
227
|
+
console.warn("Git not available, falling back to null checkpoint");
|
|
228
|
+
return null;
|
|
229
|
+
}
|
|
230
|
+
try {
|
|
231
|
+
// Get the note content
|
|
232
|
+
const content = execSync(`git --work-tree="${this.repoRoot}" notes --ref=${this.getNotesRef()} show 2>/dev/null || echo ""`, { encoding: "utf-8", cwd: this.repoRoot });
|
|
233
|
+
if (!content.trim()) {
|
|
234
|
+
return null;
|
|
235
|
+
}
|
|
236
|
+
return JSON.parse(content);
|
|
237
|
+
}
|
|
238
|
+
catch {
|
|
239
|
+
return null;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
async save(data) {
|
|
243
|
+
if (!this.checkGitAvailable()) {
|
|
244
|
+
console.warn("Git not available, skipping checkpoint save");
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
try {
|
|
248
|
+
data.updatedAt = new Date().toISOString();
|
|
249
|
+
// Write to a temp file first
|
|
250
|
+
const temporaryPath = resolve(this.repoRoot, ".git", "checkpoint-tmp.json");
|
|
251
|
+
await writeFile(temporaryPath, JSON.stringify(data, null, 2), "utf-8");
|
|
252
|
+
// Add the note using the temp file
|
|
253
|
+
execSync(`git --work-tree="${this.repoRoot}" notes --ref=${this.getNotesRef()} add -F "${temporaryPath}"`, { stdio: "pipe", cwd: this.repoRoot });
|
|
254
|
+
// Clean up temp file
|
|
255
|
+
await unlink(temporaryPath).catch(() => undefined);
|
|
256
|
+
}
|
|
257
|
+
catch (error) {
|
|
258
|
+
console.warn(`Failed to save git checkpoint: ${String(error)}`);
|
|
259
|
+
throw error;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
delete() {
|
|
263
|
+
if (!this.checkGitAvailable()) {
|
|
264
|
+
return undefined;
|
|
265
|
+
}
|
|
266
|
+
try {
|
|
267
|
+
execSync(`git --work-tree="${this.repoRoot}" notes --ref=${this.getNotesRef()} remove`, {
|
|
268
|
+
stdio: "pipe",
|
|
269
|
+
cwd: this.repoRoot,
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
catch {
|
|
273
|
+
// Ignore if note doesn't exist
|
|
274
|
+
}
|
|
275
|
+
return undefined;
|
|
276
|
+
}
|
|
277
|
+
exists() {
|
|
278
|
+
const data = this.load();
|
|
279
|
+
return data !== null;
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* List all checkpoints for this namespace across git history.
|
|
283
|
+
* Returns a map of commit SHA to checkpoint metadata.
|
|
284
|
+
*/
|
|
285
|
+
listHistory() {
|
|
286
|
+
if (!this.checkGitAvailable()) {
|
|
287
|
+
return [];
|
|
288
|
+
}
|
|
289
|
+
try {
|
|
290
|
+
// Get all commits that have notes for this namespace
|
|
291
|
+
const output = execSync(`git --work-tree="${this.repoRoot}" notes --ref=${this.getNotesRef()} list`, { encoding: "utf-8", cwd: this.repoRoot });
|
|
292
|
+
const lines = output.trim().split("\n");
|
|
293
|
+
const results = [];
|
|
294
|
+
for (const line of lines) {
|
|
295
|
+
const [commitSha] = line.split(/\s+/);
|
|
296
|
+
try {
|
|
297
|
+
const content = execSync(`git --work-tree="${this.repoRoot}" notes --ref=${this.getNotesRef()} show ${commitSha}`, { encoding: "utf-8", cwd: this.repoRoot });
|
|
298
|
+
const checkpoint = JSON.parse(content);
|
|
299
|
+
results.push({ commit: commitSha, checkpoint });
|
|
300
|
+
}
|
|
301
|
+
catch {
|
|
302
|
+
// Skip invalid entries
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
return results;
|
|
306
|
+
}
|
|
307
|
+
catch {
|
|
308
|
+
return [];
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Restore checkpoint from a specific commit.
|
|
313
|
+
* @param commitSha
|
|
314
|
+
*/
|
|
315
|
+
restoreFromCommit(commitSha) {
|
|
316
|
+
if (!this.checkGitAvailable()) {
|
|
317
|
+
return null;
|
|
318
|
+
}
|
|
319
|
+
try {
|
|
320
|
+
const content = execSync(`git --work-tree="${this.repoRoot}" notes --ref=${this.getNotesRef()} show ${commitSha}`, { encoding: "utf-8", cwd: this.repoRoot });
|
|
321
|
+
return JSON.parse(content);
|
|
322
|
+
}
|
|
323
|
+
catch {
|
|
324
|
+
return null;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* Create a checkpoint storage instance based on mode.
|
|
330
|
+
* @param mode - Storage mode ("file", "git", or "auto")
|
|
331
|
+
* @param pathOrNamespace - File path or git namespace
|
|
332
|
+
* @param repoRoot - Git repository root (for git storage)
|
|
333
|
+
*/
|
|
334
|
+
export const createCheckpointStorage = (mode, pathOrNamespace, repoRoot) => {
|
|
335
|
+
const effectiveMode = mode === "auto" ? detectPreferredMode() : mode;
|
|
336
|
+
if (effectiveMode === "git") {
|
|
337
|
+
return new GitStorage(pathOrNamespace, repoRoot);
|
|
338
|
+
}
|
|
339
|
+
return new FileStorage(pathOrNamespace);
|
|
340
|
+
};
|
|
341
|
+
/**
|
|
342
|
+
* Detect preferred checkpoint mode based on environment.
|
|
343
|
+
* Returns "git" if in a git repo with commits, otherwise "file".
|
|
344
|
+
*/
|
|
345
|
+
const detectPreferredMode = () => {
|
|
346
|
+
try {
|
|
347
|
+
// Check if we're in a git repo with commits
|
|
348
|
+
execSync("git rev-parse --git-dir > /dev/null 2>&1", { stdio: "pipe" });
|
|
349
|
+
// Check if there are any commits
|
|
350
|
+
try {
|
|
351
|
+
execSync("git rev-parse HEAD > /dev/null 2>&1", { stdio: "pipe" });
|
|
352
|
+
return "git";
|
|
353
|
+
}
|
|
354
|
+
catch {
|
|
355
|
+
// Git repo but no commits yet
|
|
356
|
+
return "file";
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
catch {
|
|
360
|
+
// Not a git repo
|
|
361
|
+
return "file";
|
|
362
|
+
}
|
|
363
|
+
};
|
|
364
|
+
/**
|
|
365
|
+
* Get default checkpoint namespace for git storage.
|
|
366
|
+
* Based on results directory path.
|
|
367
|
+
* @param resultsDir
|
|
368
|
+
*/
|
|
369
|
+
export const getGitNamespace = (resultsDir) => resultsDir.replace(/[/\\]/g, "-").replace(/^\./, "").replace(/^\/+/, "");
|
|
370
|
+
//# sourceMappingURL=checkpoint-storage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkpoint-storage.js","sourceRoot":"","sources":["../../src/executor/checkpoint-storage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,O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f,CAAC;IACF,CAAC;IAAC,MAAM,CAAC;QACR,iBAAiB;QACjB,OAAO,MAAM,CAAC;IACf,CAAC;AACF,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,UAAkB,EAAU,EAAE,CAC7D,UAAU,CAAC,OAAO,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checkpoint Types
|
|
3
|
+
*
|
|
4
|
+
* Central type definitions for the checkpoint system.
|
|
5
|
+
* Separated from implementation files for clarity and testability.
|
|
6
|
+
*/
|
|
7
|
+
import type { CheckpointStorage, Lock } from "./checkpoint-storage.js";
|
|
8
|
+
/**
|
|
9
|
+
* Checkpoint manager configuration options.
|
|
10
|
+
*/
|
|
11
|
+
export interface CheckpointConfig {
|
|
12
|
+
/** Storage backend for checkpoint data */
|
|
13
|
+
storage: CheckpointStorage;
|
|
14
|
+
/** Concurrency lock for checkpoint saves */
|
|
15
|
+
lock?: Lock;
|
|
16
|
+
/** Worker identity for sharded mode */
|
|
17
|
+
workerIndex?: number;
|
|
18
|
+
/** Total number of workers in sharded mode */
|
|
19
|
+
totalWorkers?: number;
|
|
20
|
+
/** Base checkpoint path (for sharding) */
|
|
21
|
+
basePath?: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Worker identity for sharded checkpoint execution.
|
|
25
|
+
*/
|
|
26
|
+
export interface WorkerIdentity {
|
|
27
|
+
/** Index of this worker (0-based) */
|
|
28
|
+
index: number;
|
|
29
|
+
/** Total number of workers */
|
|
30
|
+
total: number;
|
|
31
|
+
/** Human-readable name */
|
|
32
|
+
name: string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Checkpoint shard information.
|
|
36
|
+
*/
|
|
37
|
+
export interface CheckpointShard {
|
|
38
|
+
/** Path to this shard's checkpoint file */
|
|
39
|
+
path: string;
|
|
40
|
+
/** Worker index that owns this shard */
|
|
41
|
+
workerIndex: number;
|
|
42
|
+
/** Number of completed runs in this shard */
|
|
43
|
+
completedCount: number;
|
|
44
|
+
/** Whether this shard exists and is valid */
|
|
45
|
+
valid: boolean;
|
|
46
|
+
}
|
|
47
|
+
export { type Lock } from "./checkpoint-storage.js";
|
|
48
|
+
//# sourceMappingURL=checkpoint-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkpoint-types.d.ts","sourceRoot":"","sources":["../../src/executor/checkpoint-types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAIvE;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAChC,0CAA0C;IAC1C,OAAO,EAAE,iBAAiB,CAAC;IAE3B,4CAA4C;IAC5C,IAAI,CAAC,EAAE,IAAI,CAAC;IAEZ,uCAAuC;IACvC,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB,8CAA8C;IAC9C,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB,0CAA0C;IAC1C,QAAQ,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC9B,qCAAqC;IACrC,KAAK,EAAE,MAAM,CAAC;IAEd,8BAA8B;IAC9B,KAAK,EAAE,MAAM,CAAC;IAEd,0BAA0B;IAC1B,IAAI,EAAE,MAAM,CAAC;CACb;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC/B,2CAA2C;IAC3C,IAAI,EAAE,MAAM,CAAC;IAEb,wCAAwC;IACxC,WAAW,EAAE,MAAM,CAAC;IAEpB,6CAA6C;IAC7C,cAAc,EAAE,MAAM,CAAC;IAEvB,6CAA6C;IAC7C,KAAK,EAAE,OAAO,CAAC;CACf;AAED,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,yBAAyB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkpoint-types.js","sourceRoot":"","sources":["../../src/executor/checkpoint-types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Experiment Executor
|
|
3
|
+
*
|
|
4
|
+
* Orchestrates experiment execution across SUTs and cases.
|
|
5
|
+
* Handles error isolation, progress reporting, and result collection.
|
|
6
|
+
*/
|
|
7
|
+
import type { CaseDefinition } from "../types/case.js";
|
|
8
|
+
import type { EvaluationResult } from "../types/result.js";
|
|
9
|
+
import type { SutDefinition } from "../types/sut.js";
|
|
10
|
+
/**
|
|
11
|
+
* Configuration for experiment execution.
|
|
12
|
+
*/
|
|
13
|
+
export interface ExecutorConfig {
|
|
14
|
+
/** Continue execution if a single run fails */
|
|
15
|
+
continueOnError: boolean;
|
|
16
|
+
/** Number of repetitions per case (for statistical analysis) */
|
|
17
|
+
repetitions: number;
|
|
18
|
+
/** Random seed base (incremented per repetition) */
|
|
19
|
+
seedBase: number;
|
|
20
|
+
/** Timeout per run in milliseconds (0 = no timeout) */
|
|
21
|
+
timeoutMs: number;
|
|
22
|
+
/** Whether to collect provenance information */
|
|
23
|
+
collectProvenance: boolean;
|
|
24
|
+
/** Number of concurrent runs (1 = sequential) */
|
|
25
|
+
concurrency?: number;
|
|
26
|
+
/** Progress callback */
|
|
27
|
+
onProgress?: (progress: ExecutionProgress) => void;
|
|
28
|
+
/** Per-run callback (can be async) */
|
|
29
|
+
onResult?: (result: EvaluationResult) => void | Promise<void>;
|
|
30
|
+
/** Enable memory monitoring (default: true) */
|
|
31
|
+
monitorMemory?: boolean;
|
|
32
|
+
/** Memory warning threshold in MB (default: 1024) */
|
|
33
|
+
memoryWarningThresholdMb?: number;
|
|
34
|
+
/** Memory critical threshold in MB (default: 2048) */
|
|
35
|
+
memoryCriticalThresholdMb?: number;
|
|
36
|
+
/** Abort execution at critical memory level (default: false) */
|
|
37
|
+
abortOnMemoryCritical?: boolean;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Default executor configuration.
|
|
41
|
+
*/
|
|
42
|
+
export declare const DEFAULT_EXECUTOR_CONFIG: ExecutorConfig;
|
|
43
|
+
/**
|
|
44
|
+
* Execution progress report.
|
|
45
|
+
*/
|
|
46
|
+
export interface ExecutionProgress {
|
|
47
|
+
/** Total planned runs */
|
|
48
|
+
total: number;
|
|
49
|
+
/** Completed runs */
|
|
50
|
+
completed: number;
|
|
51
|
+
/** Failed runs */
|
|
52
|
+
failed: number;
|
|
53
|
+
/** Current SUT */
|
|
54
|
+
currentSut?: string;
|
|
55
|
+
/** Current case */
|
|
56
|
+
currentCase?: string;
|
|
57
|
+
/** Current repetition */
|
|
58
|
+
currentRepetition?: number;
|
|
59
|
+
/** Elapsed time in milliseconds */
|
|
60
|
+
elapsedMs: number;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Execution summary returned after completion.
|
|
64
|
+
*/
|
|
65
|
+
export interface ExecutionSummary {
|
|
66
|
+
/** Total runs attempted */
|
|
67
|
+
totalRuns: number;
|
|
68
|
+
/** Successful runs */
|
|
69
|
+
successfulRuns: number;
|
|
70
|
+
/** Failed runs */
|
|
71
|
+
failedRuns: number;
|
|
72
|
+
/** Total elapsed time */
|
|
73
|
+
elapsedMs: number;
|
|
74
|
+
/** Results collected */
|
|
75
|
+
results: EvaluationResult[];
|
|
76
|
+
/** Errors encountered */
|
|
77
|
+
errors: {
|
|
78
|
+
runId: string;
|
|
79
|
+
error: string;
|
|
80
|
+
}[];
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Execution plan for a single run.
|
|
84
|
+
*/
|
|
85
|
+
export interface PlannedRun {
|
|
86
|
+
/** Deterministic run ID */
|
|
87
|
+
runId: string;
|
|
88
|
+
/** SUT to execute */
|
|
89
|
+
sutId: string;
|
|
90
|
+
/** Case to run against */
|
|
91
|
+
caseId: string;
|
|
92
|
+
/** Repetition number */
|
|
93
|
+
repetition: number;
|
|
94
|
+
/** Random seed */
|
|
95
|
+
seed: number;
|
|
96
|
+
/** Configuration overrides */
|
|
97
|
+
config?: Record<string, unknown>;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Experiment executor.
|
|
101
|
+
*
|
|
102
|
+
* @template TInput - The resource type (e.g., Graph, Dataset)
|
|
103
|
+
* @template TInputs - The algorithm inputs type
|
|
104
|
+
* @template TResult - The algorithm result type
|
|
105
|
+
*/
|
|
106
|
+
export declare class Executor<TInput = unknown, TInputs = unknown, TResult = unknown> {
|
|
107
|
+
private readonly config;
|
|
108
|
+
private readonly inputCache;
|
|
109
|
+
private readonly memoryMonitor?;
|
|
110
|
+
constructor(config?: Partial<ExecutorConfig>);
|
|
111
|
+
/**
|
|
112
|
+
* Plan execution runs without executing.
|
|
113
|
+
*
|
|
114
|
+
* @param suts - SUTs to execute
|
|
115
|
+
* @param cases - Cases to run against
|
|
116
|
+
* @returns Array of planned runs
|
|
117
|
+
*/
|
|
118
|
+
plan(suts: SutDefinition<TInputs, TResult>[], cases: CaseDefinition<TInput, TInputs>[]): PlannedRun[];
|
|
119
|
+
/**
|
|
120
|
+
* Execute all planned runs.
|
|
121
|
+
*
|
|
122
|
+
* @param suts - SUTs to execute
|
|
123
|
+
* @param cases - Cases to run against
|
|
124
|
+
* @param metricsExtractor - Function to extract metrics from result
|
|
125
|
+
* @param plannedRuns - Optional pre-filtered planned runs (for parallel workers)
|
|
126
|
+
* @returns Execution summary with all results
|
|
127
|
+
*/
|
|
128
|
+
execute(suts: SutDefinition<TInputs, TResult>[], cases: CaseDefinition<TInput, TInputs>[], metricsExtractor: (result: TResult) => Record<string, number>, plannedRuns?: PlannedRun[]): Promise<ExecutionSummary>;
|
|
129
|
+
/**
|
|
130
|
+
* Execute runs sequentially (original behavior).
|
|
131
|
+
* @param plannedRuns
|
|
132
|
+
* @param sutMap
|
|
133
|
+
* @param caseMap
|
|
134
|
+
* @param metricsExtractor
|
|
135
|
+
* @param startTime
|
|
136
|
+
* @internal
|
|
137
|
+
*/
|
|
138
|
+
private executeSequential;
|
|
139
|
+
/**
|
|
140
|
+
* Execute runs in parallel with a concurrency limit.
|
|
141
|
+
* @param plannedRuns
|
|
142
|
+
* @param sutMap
|
|
143
|
+
* @param caseMap
|
|
144
|
+
* @param metricsExtractor
|
|
145
|
+
* @param startTime
|
|
146
|
+
* @param concurrency
|
|
147
|
+
* @internal
|
|
148
|
+
*/
|
|
149
|
+
private executeParallel;
|
|
150
|
+
/**
|
|
151
|
+
* Execute a single run.
|
|
152
|
+
* @param run
|
|
153
|
+
* @param sutDef
|
|
154
|
+
* @param caseDef
|
|
155
|
+
* @param metricsExtractor
|
|
156
|
+
*/
|
|
157
|
+
private executeRun;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Create a default executor with standard configuration.
|
|
161
|
+
* @param config
|
|
162
|
+
*/
|
|
163
|
+
export declare const createExecutor: <TInput = unknown, TInputs = unknown, TResult = unknown>(config?: Partial<ExecutorConfig>) => Executor<TInput, TInputs, TResult>;
|
|
164
|
+
//# sourceMappingURL=executor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../../src/executor/executor.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,OAAO,KAAK,EAAE,cAAc,EAAa,MAAM,kBAAkB,CAAC;AAClE,OAAO,KAAK,EAAqB,gBAAgB,EAAc,MAAM,oBAAoB,CAAC;AAC1F,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAIrD;;GAEG;AACH,MAAM,WAAW,cAAc;IAC9B,+CAA+C;IAC/C,eAAe,EAAE,OAAO,CAAC;IAEzB,gEAAgE;IAChE,WAAW,EAAE,MAAM,CAAC;IAEpB,oDAAoD;IACpD,QAAQ,E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