@tscircuit/autorouting-dataset-01 1.0.26 → 1.0.27
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/dist/cli/index.js +184 -29
- package/package.json +5 -4
package/dist/cli/index.js
CHANGED
|
@@ -5,12 +5,119 @@ import { Command } from "commander";
|
|
|
5
5
|
|
|
6
6
|
// lib/cli/run/register.ts
|
|
7
7
|
import { access, mkdir, writeFile } from "fs/promises";
|
|
8
|
-
import
|
|
8
|
+
import path5 from "path";
|
|
9
9
|
import { fileURLToPath } from "url";
|
|
10
10
|
import kleur from "kleur";
|
|
11
11
|
|
|
12
|
+
// lib/cli/bundleAutorouter.ts
|
|
13
|
+
import path from "path";
|
|
14
|
+
var bundleAutorouter = async (autorouterPath, solverName) => {
|
|
15
|
+
const wrapperCode = `
|
|
16
|
+
import * as AutorouterModule from "${autorouterPath}";
|
|
17
|
+
|
|
18
|
+
// Find the solver constructor
|
|
19
|
+
const solverName = "${solverName}";
|
|
20
|
+
let SolverConstructor = null;
|
|
21
|
+
|
|
22
|
+
// Check direct export by name
|
|
23
|
+
if (AutorouterModule[solverName]) {
|
|
24
|
+
SolverConstructor = AutorouterModule[solverName];
|
|
25
|
+
}
|
|
26
|
+
// Check default export
|
|
27
|
+
else if (AutorouterModule.default) {
|
|
28
|
+
SolverConstructor = AutorouterModule.default;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Check SOLVER_CONSTRUCTOR_LIST array
|
|
32
|
+
if (!SolverConstructor && AutorouterModule.SOLVER_CONSTRUCTOR_LIST) {
|
|
33
|
+
for (const ctor of AutorouterModule.SOLVER_CONSTRUCTOR_LIST) {
|
|
34
|
+
if (ctor.name === solverName) {
|
|
35
|
+
SolverConstructor = ctor;
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Check solverDisplayNameByConstructor map (reverse lookup)
|
|
42
|
+
if (!SolverConstructor && AutorouterModule.solverDisplayNameByConstructor) {
|
|
43
|
+
for (const [ctor, displayName] of AutorouterModule.solverDisplayNameByConstructor) {
|
|
44
|
+
if (displayName === solverName) {
|
|
45
|
+
SolverConstructor = ctor;
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Fallback: check if any export looks like a solver class
|
|
52
|
+
if (!SolverConstructor) {
|
|
53
|
+
for (const [key, value] of Object.entries(AutorouterModule)) {
|
|
54
|
+
if (typeof value === 'function' && value.prototype && key.includes('Pipeline')) {
|
|
55
|
+
SolverConstructor = value;
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Export as ES module
|
|
62
|
+
export { SolverConstructor, solverName };
|
|
63
|
+
export default SolverConstructor;
|
|
64
|
+
`;
|
|
65
|
+
const tempDir = path.dirname(autorouterPath);
|
|
66
|
+
const wrapperPath = path.join(tempDir, "__autorouter_wrapper__.ts");
|
|
67
|
+
await Bun.write(wrapperPath, wrapperCode);
|
|
68
|
+
try {
|
|
69
|
+
const result = await Bun.build({
|
|
70
|
+
entrypoints: [wrapperPath],
|
|
71
|
+
target: "browser",
|
|
72
|
+
minify: false,
|
|
73
|
+
sourcemap: "none",
|
|
74
|
+
external: []
|
|
75
|
+
});
|
|
76
|
+
if (!result.success) {
|
|
77
|
+
const errors = result.logs.map((log) => log.message).join("\n");
|
|
78
|
+
throw new Error(`Bundle failed: ${errors}`);
|
|
79
|
+
}
|
|
80
|
+
const output = result.outputs[0];
|
|
81
|
+
const bundleText = await output.text();
|
|
82
|
+
return bundleText;
|
|
83
|
+
} finally {
|
|
84
|
+
try {
|
|
85
|
+
;
|
|
86
|
+
await Bun.file(wrapperPath).exists() && (await import("fs/promises")).unlink(wrapperPath);
|
|
87
|
+
} catch {
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
|
|
12
92
|
// lib/cli/loadUserAutorouter.ts
|
|
93
|
+
import { readFileSync } from "fs";
|
|
94
|
+
import path2 from "path";
|
|
13
95
|
import { pathToFileURL } from "url";
|
|
96
|
+
var AUTOROUTER_PACKAGE = "@tscircuit/capacity-autorouter";
|
|
97
|
+
var detectPackageInfo = (autorouterPath) => {
|
|
98
|
+
try {
|
|
99
|
+
let searchDir = path2.dirname(autorouterPath);
|
|
100
|
+
while (searchDir !== path2.dirname(searchDir)) {
|
|
101
|
+
try {
|
|
102
|
+
const packageDir = path2.join(
|
|
103
|
+
searchDir,
|
|
104
|
+
"node_modules",
|
|
105
|
+
AUTOROUTER_PACKAGE
|
|
106
|
+
);
|
|
107
|
+
const pkgJsonPath = path2.join(packageDir, "package.json");
|
|
108
|
+
const pkgJson = JSON.parse(readFileSync(pkgJsonPath, "utf-8"));
|
|
109
|
+
return {
|
|
110
|
+
name: AUTOROUTER_PACKAGE,
|
|
111
|
+
version: pkgJson.version
|
|
112
|
+
};
|
|
113
|
+
} catch {
|
|
114
|
+
}
|
|
115
|
+
searchDir = path2.dirname(searchDir);
|
|
116
|
+
}
|
|
117
|
+
} catch {
|
|
118
|
+
}
|
|
119
|
+
return void 0;
|
|
120
|
+
};
|
|
14
121
|
var loadUserAutorouter = async (autorouterPath, requestedSolverName) => {
|
|
15
122
|
let exports;
|
|
16
123
|
try {
|
|
@@ -22,6 +129,7 @@ var loadUserAutorouter = async (autorouterPath, requestedSolverName) => {
|
|
|
22
129
|
`Failed to import autorouter from "${autorouterPath}": ${error.message}`
|
|
23
130
|
);
|
|
24
131
|
}
|
|
132
|
+
let packageInfo;
|
|
25
133
|
let displayNameMap = null;
|
|
26
134
|
for (const [, exportValue] of Object.entries(exports)) {
|
|
27
135
|
if (exportValue instanceof Map) {
|
|
@@ -79,9 +187,11 @@ var loadUserAutorouter = async (autorouterPath, requestedSolverName) => {
|
|
|
79
187
|
`Solver "${requestedSolverName}" not found in "${autorouterPath}". Available solvers: ${availableNames.join(", ") || "(none)"}`
|
|
80
188
|
);
|
|
81
189
|
}
|
|
190
|
+
packageInfo = detectPackageInfo(autorouterPath);
|
|
82
191
|
return {
|
|
83
192
|
solverConstructor: requestedExport.value,
|
|
84
|
-
solverName: requestedSolverName
|
|
193
|
+
solverName: requestedSolverName,
|
|
194
|
+
packageInfo
|
|
85
195
|
};
|
|
86
196
|
}
|
|
87
197
|
if (pipelineExports.length === 0) {
|
|
@@ -104,25 +214,27 @@ var loadUserAutorouter = async (autorouterPath, requestedSolverName) => {
|
|
|
104
214
|
`Export "${preferredExport.name}" is not a class or function. Expected a solver constructor.`
|
|
105
215
|
);
|
|
106
216
|
}
|
|
217
|
+
packageInfo = detectPackageInfo(autorouterPath);
|
|
107
218
|
return {
|
|
108
219
|
solverConstructor,
|
|
109
|
-
solverName: preferredExport.name
|
|
220
|
+
solverName: preferredExport.name,
|
|
221
|
+
packageInfo
|
|
110
222
|
};
|
|
111
223
|
};
|
|
112
224
|
|
|
113
225
|
// scripts/run-benchmark/buildBenchmarkDetailsJson.ts
|
|
114
|
-
import
|
|
226
|
+
import path3 from "path";
|
|
115
227
|
var buildBenchmarkDetailsJson = (inputs) => {
|
|
116
228
|
const { scenarioResultList, scenarioList } = inputs;
|
|
117
229
|
const detailsByScenarioPath = {};
|
|
118
230
|
const simpleRouteJsonByScenarioPath = new Map(
|
|
119
231
|
scenarioList.map((scenario) => [
|
|
120
|
-
|
|
232
|
+
path3.basename(scenario.simpleRouteJsonPath),
|
|
121
233
|
scenario.simpleRouteJson
|
|
122
234
|
])
|
|
123
235
|
);
|
|
124
236
|
for (const scenarioResult of scenarioResultList) {
|
|
125
|
-
const scenarioFileName =
|
|
237
|
+
const scenarioFileName = path3.basename(scenarioResult.simpleRouteJsonPath);
|
|
126
238
|
const simpleRouteJson = simpleRouteJsonByScenarioPath.get(scenarioFileName);
|
|
127
239
|
if (!simpleRouteJson) {
|
|
128
240
|
continue;
|
|
@@ -267,7 +379,7 @@ var generateChartScripts = (result_row_list) => {
|
|
|
267
379
|
|
|
268
380
|
// scripts/run-benchmark/generateHtmlVisualization/generateClientDebuggerScript.ts
|
|
269
381
|
var escapeJsonForHtml = (json) => json.replace(/</g, "\\u003c");
|
|
270
|
-
var generateClientDebuggerScript = (detail_json) => {
|
|
382
|
+
var generateClientDebuggerScript = (detail_json, bundle_filename, solverName) => {
|
|
271
383
|
const detail_json_text = escapeJsonForHtml(JSON.stringify(detail_json));
|
|
272
384
|
const svgsonShim = encodeURIComponent(
|
|
273
385
|
[
|
|
@@ -277,6 +389,12 @@ var generateClientDebuggerScript = (detail_json) => {
|
|
|
277
389
|
"export * from 'https://esm.sh/svgson@5.2.1?target=es2022';"
|
|
278
390
|
].join("")
|
|
279
391
|
);
|
|
392
|
+
const solverImport = bundle_filename ? `import SolverConstructor, { solverName as bundledSolverName } from "./${bundle_filename}";
|
|
393
|
+
const solverConstructors = SolverConstructor ? { [bundledSolverName || "${solverName || "Autorouter"}"]: SolverConstructor } : {};` : `import { AutoroutingPipeline1_OriginalUnravel, AutoroutingPipelineSolver as AutoroutingPipelineSolver2_PortPointPathing } from "https://esm.sh/@tscircuit/capacity-autorouter@latest";
|
|
394
|
+
const solverConstructors = {
|
|
395
|
+
AutoroutingPipelineSolver2_PortPointPathing,
|
|
396
|
+
AutoroutingPipeline1_OriginalUnravel
|
|
397
|
+
};`;
|
|
280
398
|
return `<script>
|
|
281
399
|
window.__benchmark_details = ${detail_json_text};
|
|
282
400
|
</script>
|
|
@@ -297,15 +415,8 @@ var generateClientDebuggerScript = (detail_json) => {
|
|
|
297
415
|
import React, { useMemo } from "react";
|
|
298
416
|
import { createRoot } from "react-dom/client";
|
|
299
417
|
import { GenericSolverDebugger } from "https://esm.sh/@tscircuit/solver-utils@latest/react?external=react,react-dom,svgson";
|
|
300
|
-
import {
|
|
301
|
-
AutoroutingPipeline1_OriginalUnravel,
|
|
302
|
-
AutoroutingPipelineSolver as AutoroutingPipelineSolver2_PortPointPathing
|
|
303
|
-
} from "https://esm.sh/@tscircuit/capacity-autorouter@latest";
|
|
304
418
|
|
|
305
|
-
|
|
306
|
-
AutoroutingPipelineSolver2_PortPointPathing,
|
|
307
|
-
AutoroutingPipeline1_OriginalUnravel
|
|
308
|
-
};
|
|
419
|
+
${solverImport}
|
|
309
420
|
|
|
310
421
|
const modal = document.getElementById("solver-debugger-modal");
|
|
311
422
|
const modalTitle = document.getElementById("solver-debugger-title");
|
|
@@ -717,7 +828,13 @@ var generateWebComponents = () => {
|
|
|
717
828
|
|
|
718
829
|
// scripts/run-benchmark/generateHtmlVisualization/index.ts
|
|
719
830
|
var generateHtmlVisualization = (inputs) => {
|
|
720
|
-
const {
|
|
831
|
+
const {
|
|
832
|
+
summary_json,
|
|
833
|
+
detail_json,
|
|
834
|
+
result_row_list,
|
|
835
|
+
bundle_filename,
|
|
836
|
+
solver_name
|
|
837
|
+
} = inputs;
|
|
721
838
|
return `<!DOCTYPE html>
|
|
722
839
|
<html lang="en">
|
|
723
840
|
<head>
|
|
@@ -737,14 +854,14 @@ var generateHtmlVisualization = (inputs) => {
|
|
|
737
854
|
${generateWebComponents()}
|
|
738
855
|
${generateSolverDebuggerModal()}
|
|
739
856
|
${generateChartScripts(result_row_list)}
|
|
740
|
-
${generateClientDebuggerScript(detail_json)}
|
|
857
|
+
${generateClientDebuggerScript(detail_json, bundle_filename, solver_name)}
|
|
741
858
|
</body>
|
|
742
859
|
</html>`;
|
|
743
860
|
};
|
|
744
861
|
|
|
745
862
|
// scripts/run-benchmark/loadScenarioList.ts
|
|
746
863
|
import { readdir, readFile } from "fs/promises";
|
|
747
|
-
import
|
|
864
|
+
import path4 from "path";
|
|
748
865
|
var loadScenarioList = async (inputs) => {
|
|
749
866
|
const { datasetDirectory, scenarioCountLimit } = inputs;
|
|
750
867
|
const datasetFileList = (await readdir(datasetDirectory)).filter((fileName) => fileName.endsWith(".simple-route.json")).sort();
|
|
@@ -755,7 +872,7 @@ var loadScenarioList = async (inputs) => {
|
|
|
755
872
|
const scenarioList = [];
|
|
756
873
|
for (const fileName of limitedFileList) {
|
|
757
874
|
const scenarioName = fileName.replace(".simple-route.json", "");
|
|
758
|
-
const simpleRouteJsonPath =
|
|
875
|
+
const simpleRouteJsonPath = path4.join(datasetDirectory, fileName);
|
|
759
876
|
const simpleRouteJsonText = await readFile(simpleRouteJsonPath, "utf8");
|
|
760
877
|
const simpleRouteJson = JSON.parse(simpleRouteJsonText);
|
|
761
878
|
scenarioList.push({ scenarioName, simpleRouteJsonPath, simpleRouteJson });
|
|
@@ -1145,8 +1262,8 @@ var runBenchmark = async (inputs) => {
|
|
|
1145
1262
|
// lib/cli/run/register.ts
|
|
1146
1263
|
var findDatasetDirectory = async () => {
|
|
1147
1264
|
const possiblePaths = [
|
|
1148
|
-
|
|
1149
|
-
|
|
1265
|
+
path5.resolve(process.cwd(), "lib/dataset"),
|
|
1266
|
+
path5.resolve(
|
|
1150
1267
|
fileURLToPath(import.meta.url),
|
|
1151
1268
|
"..",
|
|
1152
1269
|
"..",
|
|
@@ -1155,7 +1272,7 @@ var findDatasetDirectory = async () => {
|
|
|
1155
1272
|
"lib",
|
|
1156
1273
|
"dataset"
|
|
1157
1274
|
),
|
|
1158
|
-
|
|
1275
|
+
path5.resolve(
|
|
1159
1276
|
fileURLToPath(import.meta.url),
|
|
1160
1277
|
"..",
|
|
1161
1278
|
"..",
|
|
@@ -1179,15 +1296,24 @@ var registerRun = (program2) => {
|
|
|
1179
1296
|
program2.command("run", { isDefault: true }).description("Run benchmark on an autorouter").argument("<autorouter-path>", "Path to autorouter TypeScript file").argument("[solver-name]", "Specific export name to use as solver").option("-l, --scenario-limit <count>", "Limit number of scenarios to run").option("-o, --output <path>", "Output HTML file path").action(
|
|
1180
1297
|
async (autorouterPath, solverName, options) => {
|
|
1181
1298
|
try {
|
|
1182
|
-
const absolutePath =
|
|
1299
|
+
const absolutePath = path5.resolve(autorouterPath);
|
|
1183
1300
|
console.log(
|
|
1184
1301
|
`${kleur.cyan("Loading autorouter from:")} ${absolutePath}`
|
|
1185
1302
|
);
|
|
1186
|
-
const {
|
|
1303
|
+
const {
|
|
1304
|
+
solverConstructor,
|
|
1305
|
+
solverName: detectedSolverName,
|
|
1306
|
+
packageInfo
|
|
1307
|
+
} = await loadUserAutorouter(absolutePath, solverName);
|
|
1187
1308
|
const finalSolverName = solverName || detectedSolverName;
|
|
1188
1309
|
console.log(
|
|
1189
1310
|
`${kleur.green("\u2713")} Using autorouter: ${kleur.bold(finalSolverName)}`
|
|
1190
1311
|
);
|
|
1312
|
+
if (packageInfo) {
|
|
1313
|
+
console.log(
|
|
1314
|
+
`${kleur.green("\u2713")} From package: ${kleur.cyan(packageInfo.name)}@${packageInfo.version}`
|
|
1315
|
+
);
|
|
1316
|
+
}
|
|
1191
1317
|
solverDisplayNameByConstructor.set(solverConstructor, finalSolverName);
|
|
1192
1318
|
const datasetDirectory = await findDatasetDirectory();
|
|
1193
1319
|
const scenarioCountLimit = options.scenarioLimit ? Number.parseInt(options.scenarioLimit, 10) : null;
|
|
@@ -1223,18 +1349,47 @@ ${kleur.cyan("Running benchmark with")} ${kleur.bold(String(scenarioList.length)
|
|
|
1223
1349
|
scenarioResultList,
|
|
1224
1350
|
scenarioList
|
|
1225
1351
|
});
|
|
1352
|
+
console.log(
|
|
1353
|
+
kleur.cyan("Bundling autorouter for HTML visualization...")
|
|
1354
|
+
);
|
|
1355
|
+
let autorouterBundle = "";
|
|
1356
|
+
let bundleFilename = "";
|
|
1357
|
+
try {
|
|
1358
|
+
autorouterBundle = await bundleAutorouter(
|
|
1359
|
+
absolutePath,
|
|
1360
|
+
finalSolverName
|
|
1361
|
+
);
|
|
1362
|
+
bundleFilename = `${finalSolverName}.bundle.js`;
|
|
1363
|
+
console.log(
|
|
1364
|
+
`${kleur.green("\u2713")} Bundled autorouter (${(autorouterBundle.length / 1024).toFixed(1)} KB)`
|
|
1365
|
+
);
|
|
1366
|
+
} catch (bundleError) {
|
|
1367
|
+
console.warn(
|
|
1368
|
+
kleur.yellow(
|
|
1369
|
+
`Warning: Could not bundle autorouter: ${bundleError instanceof Error ? bundleError.message : String(bundleError)}`
|
|
1370
|
+
)
|
|
1371
|
+
);
|
|
1372
|
+
}
|
|
1226
1373
|
const htmlText = generateHtmlVisualization({
|
|
1227
1374
|
summary_json: summaryJson,
|
|
1228
1375
|
detail_json: detailJson,
|
|
1229
|
-
result_row_list: resultRowList
|
|
1376
|
+
result_row_list: resultRowList,
|
|
1377
|
+
bundle_filename: bundleFilename,
|
|
1378
|
+
solver_name: finalSolverName
|
|
1230
1379
|
});
|
|
1231
|
-
const outputDir =
|
|
1380
|
+
const outputDir = path5.resolve("results");
|
|
1232
1381
|
await mkdir(outputDir, { recursive: true });
|
|
1233
|
-
const outputPath = options.output ?
|
|
1382
|
+
const outputPath = options.output ? path5.resolve(options.output) : path5.join(outputDir, `${finalSolverName}.html`);
|
|
1383
|
+
if (autorouterBundle && bundleFilename) {
|
|
1384
|
+
const bundlePath = path5.join(outputDir, bundleFilename);
|
|
1385
|
+
await writeFile(bundlePath, autorouterBundle);
|
|
1386
|
+
console.log(
|
|
1387
|
+
`${kleur.green("\u2713")} Bundle written to: ${kleur.cyan(bundlePath)}`
|
|
1388
|
+
);
|
|
1389
|
+
}
|
|
1234
1390
|
await writeFile(outputPath, htmlText);
|
|
1235
1391
|
console.log(
|
|
1236
|
-
`
|
|
1237
|
-
${kleur.green("\u2713")} HTML results written to: ${kleur.cyan(outputPath)}`
|
|
1392
|
+
`${kleur.green("\u2713")} HTML results written to: ${kleur.cyan(outputPath)}`
|
|
1238
1393
|
);
|
|
1239
1394
|
process.exit(0);
|
|
1240
1395
|
} catch (error) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tscircuit/autorouting-dataset-01",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.27",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "lib/dataset/index.ts",
|
|
6
6
|
"bin": {
|
|
@@ -39,7 +39,6 @@
|
|
|
39
39
|
"kleur": "^4.1.5"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"tsup": "^8.2.4",
|
|
43
42
|
"@biomejs/biome": "^2.3.13",
|
|
44
43
|
"@tsci/imrishabh18.TB6612FNG": "^0.1.0",
|
|
45
44
|
"@tsci/seveibar.PICO": "^0.1.0",
|
|
@@ -55,10 +54,12 @@
|
|
|
55
54
|
"@tscircuit/core": "^0.0.1005",
|
|
56
55
|
"@tscircuit/footprints": "^0.0.21",
|
|
57
56
|
"@tscircuit/math-utils": "^0.0.33",
|
|
57
|
+
"@tscircuit/solver-utils": "^0.0.14",
|
|
58
|
+
"@types/bun": "^1.3.9",
|
|
58
59
|
"@types/react": "^19.2.9",
|
|
59
60
|
"circuit-json": "^0.0.371",
|
|
61
|
+
"graphics-debug": "^0.0.79",
|
|
60
62
|
"tscircuit": "^0.0.1168",
|
|
61
|
-
"
|
|
62
|
-
"graphics-debug": "^0.0.79"
|
|
63
|
+
"tsup": "^8.2.4"
|
|
63
64
|
}
|
|
64
65
|
}
|