forked from tscircuit/tscircuit-autorouter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbenchmark.sh
More file actions
executable file
·283 lines (252 loc) · 8.66 KB
/
Copy pathbenchmark.sh
File metadata and controls
executable file
·283 lines (252 loc) · 8.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
#!/usr/bin/env bash
set -euo pipefail
SOLVER_NAME=""
SCENARIO_LIMIT=""
EFFORT=""
SAMPLE_TIMEOUT=""
SAMPLE_NUMBERS=""
INCLUDE_ASSIGNABLE=false
DATASET="dataset01"
DEFAULT_SOLVER_NAME="AutoroutingPipelineSolver9_PreloadedTraceGraph"
PIPELINE_ID=""
NETWORKED_COLD_HOT=false
resolve_pipeline_solver_name() {
case "$1" in
1) echo "AutoroutingPipeline1_OriginalUnravel" ;;
2) echo "AutoroutingPipelineSolver2_PortPointPathing" ;;
3) echo "AutoroutingPipelineSolver3_HgPortPointPathing" ;;
4) echo "AutoroutingPipelineSolver4" ;;
5) echo "AutoroutingPipelineSolver5" ;;
6) echo "AutoroutingPipelineSolver6" ;;
7) echo "AutoroutingPipelineSolver7_MultiGraph" ;;
9) echo "AutoroutingPipelineSolver9_PreloadedTraceGraph" ;;
9net|9NET) echo "AutoroutingPipelineSolver9_Networked" ;;
10) echo "AutoroutingPipelineSolver10_BgaFanout" ;;
krt|KRT) echo "KrtAutoroutingPipelineSolver" ;;
*)
echo "Unknown pipeline: $1" >&2
exit 1
;;
esac
}
default_concurrency() {
getconf _NPROCESSORS_ONLN 2>/dev/null || nproc 2>/dev/null || echo 4
}
CONCURRENCY_WAS_SET=false
if [ -n "${BENCHMARK_CONCURRENCY:-}" ]; then
CONCURRENCY="$BENCHMARK_CONCURRENCY"
CONCURRENCY_WAS_SET=true
else
CONCURRENCY="$(default_concurrency)"
fi
get_solvers() {
INCLUDE_ASSIGNABLE="$INCLUDE_ASSIGNABLE" bun --eval '
import { readFileSync } from "node:fs"
import { join } from "node:path"
// Use autorouter-pipelines/index.ts as the source of truth for benchmarkable solvers
const pipelinesIndex = readFileSync(join(process.cwd(), "lib", "autorouter-pipelines", "index.ts"), "utf8")
const pipelineNames = new Set()
for (const match of pipelinesIndex.matchAll(/export\s*\{([\s\S]*?)\}\s*from/g)) {
const exportEntries = match[1].split(",").map((entry) => entry.trim()).filter(Boolean)
for (const entry of exportEntries) {
const localName = entry.split(/\s+as\s+/)[0]?.trim()
if (localName) pipelineNames.add(localName)
}
}
// Resolve aliases from lib/index.ts
const libIndex = readFileSync(join(process.cwd(), "lib", "index.ts"), "utf8")
const solvers = [...pipelineNames].flatMap(name => {
const aliasMatches = [...libIndex.matchAll(new RegExp(name + "\\s+as\\s+(\\w+)", "g"))].map(match => match[1])
return [name, ...aliasMatches]
})
const uniqueSolvers = [...new Set(solvers)]
const includeAssignable = process.env.INCLUDE_ASSIGNABLE === "true"
const filtered = includeAssignable ? uniqueSolvers : uniqueSolvers.filter(name => !name.includes("Assignable"))
filtered.push("KrtAutoroutingPipelineSolver")
console.log(filtered.join("\n"))
' 2>/dev/null || true
}
print_help() {
cat <<'EOF'
Usage:
./benchmark.sh [solver-name|all] [scenario-limit] [--concurrency N] [--effort N] [--sample-timeout DURATION] [--sample N] [--dataset NAME] [--include-assignable]
./benchmark.sh [--solver NAME] [--pipeline ID] [--limit N] [--concurrency N] [--effort N] [--sample-timeout DURATION] [--sample N] [--dataset NAME] [--include-assignable]
Options:
--solver NAME Run only one solver (same as first positional arg)
--pipeline ID Run a pipeline alias (1-7, 9, 9net, 10, or krt). 9net runs cold then hot against hd-cache2.
--limit N Run only first N scenarios (same as second positional arg)
--scenario-limit N Backward-compatible alias for --limit
--concurrency N Number of Bun workers used per solver, or "auto"
--effort N Override scenario effort multiplier
--sample-timeout D Override per-sample timeout directly; otherwise timeout is 300s + 60s * effort
--sample N Run one 1-based sample number from the dataset order
--sample-numbers L Run comma-separated 1-based sample numbers
--dataset NAME Dataset to benchmark: 1/dataset01 (default), zdwiel, 5/srj05, 11/srj11, 12/srj12, 13/srj13, 14/srj14, 15/srj15, 16/srj16, 18/srj18, 19/srj19, 20/srj20, 21/srj21, 23/srj23, 24/srj24, 27/srj27, 28/srj28, or 29/srj29
--include-assignable Include assignable pipelines (excluded by default)
-h, --help Show this help
Defaults:
Running ./benchmark.sh with no parameters benchmarks only AutoroutingPipelineSolver9_PreloadedTraceGraph.
Use "all" to benchmark every available solver.
Examples:
./benchmark.sh
./benchmark.sh AutoroutingPipelineSolver9_PreloadedTraceGraph
./benchmark.sh all 20 --concurrency auto
./benchmark.sh --solver AutoroutingPipelineSolver9_PreloadedTraceGraph --effort 2
./benchmark.sh --solver AutoroutingPipelineSolver9_PreloadedTraceGraph --sample-timeout 90s
./benchmark.sh --pipeline 10 --dataset 29 --sample 1
./benchmark.sh --pipeline 10 --dataset 29 --limit 5
./benchmark.sh --sample-numbers 120,139,148 --concurrency 8 --sample-timeout 120s
./benchmark.sh --solver AutoroutingPipelineSolver9_PreloadedTraceGraph --scenario-limit 20
./benchmark.sh --solver AutoroutingPipelineSolver9_PreloadedTraceGraph --dataset zdwiel --scenario-limit 20
./benchmark.sh --pipeline 4
./benchmark.sh --pipeline 5
./benchmark.sh --pipeline 6
./benchmark.sh --pipeline 7
./benchmark.sh --pipeline 9
./benchmark.sh --pipeline 9net --dataset 18
./benchmark.sh --pipeline 10 --dataset 29
./benchmark.sh --pipeline krt
./benchmark.sh --solver AutoroutingPipelineSolver9_PreloadedTraceGraph --dataset srj05 --scenario-limit 20
./benchmark.sh --dataset 11 --scenario-limit 20
./benchmark.sh --dataset 12 --scenario-limit 10
./benchmark.sh --dataset 13
./benchmark.sh --dataset 14
./benchmark.sh --dataset 15
./benchmark.sh --dataset 16
./benchmark.sh --dataset 18
./benchmark.sh --dataset 19
./benchmark.sh --dataset 20
./benchmark.sh --dataset 21
./benchmark.sh --dataset 23
./benchmark.sh --dataset 24
./benchmark.sh --dataset 27
./benchmark.sh --dataset 28
./benchmark.sh --dataset 29 --pipeline 10
./benchmark.sh --include-assignable
EOF
SOLVERS="$(get_solvers)"
if [ -n "$SOLVERS" ]; then
echo ""
echo "Available solvers:"
while IFS= read -r solver; do
[ -n "$solver" ] && echo " - $solver"
done <<EOF
$SOLVERS
EOF
fi
}
if [ "${1:-}" != "" ] && [[ "${1}" != --* ]]; then
SOLVER_NAME="$1"
shift
fi
if [ "${1:-}" != "" ] && [[ "${1}" != --* ]]; then
SCENARIO_LIMIT="$1"
shift
fi
while [ "$#" -gt 0 ]; do
case "$1" in
-h|--help)
print_help
exit 0
;;
--solver)
SOLVER_NAME="${2:-}"
shift 2
;;
--pipeline)
PIPELINE_ID="${2:-}"
shift 2
;;
--limit|--scenario-limit)
SCENARIO_LIMIT="${2:-}"
shift 2
;;
--concurrency)
CONCURRENCY="${2:-}"
CONCURRENCY_WAS_SET=true
if [ "$CONCURRENCY" = "auto" ]; then
CONCURRENCY="$(default_concurrency)"
fi
shift 2
;;
--effort)
EFFORT="${2:-}"
shift 2
;;
--sample-timeout)
SAMPLE_TIMEOUT="${2:-}"
shift 2
;;
--sample|--sample-numbers)
SAMPLE_NUMBERS="${2:-}"
shift 2
;;
--dataset)
DATASET="${2:-}"
shift 2
;;
--include-assignable)
INCLUDE_ASSIGNABLE=true
shift
;;
*)
echo "Unknown argument: $1"
echo "Run ./benchmark.sh --help for usage"
exit 1
;;
esac
done
if [ -n "$PIPELINE_ID" ]; then
SOLVER_NAME="$(resolve_pipeline_solver_name "$PIPELINE_ID")"
case "$PIPELINE_ID" in
9net|9NET) NETWORKED_COLD_HOT=true ;;
esac
fi
if [ "$NETWORKED_COLD_HOT" = true ]; then
if [ -n "$EFFORT" ] && [ "$EFFORT" != "1" ]; then
echo "Pipeline 9net only supports --effort 1" >&2
exit 1
fi
if [ -z "${HD_CACHE2_CACHE_VERSION:-}" ]; then
echo "Pipeline 9net requires HD_CACHE2_CACHE_VERSION" >&2
exit 1
fi
fi
if [ "$CONCURRENCY_WAS_SET" = false ] && [ "$SOLVER_NAME" = "AutoroutingPipelineSolver7_MultiGraph" ]; then
case "$DATASET" in
18|srj18|dataset18|dataset-srj18)
if [ "$CONCURRENCY" -gt 4 ]; then
CONCURRENCY=4
fi
;;
esac
fi
CMD=(bun "scripts/benchmark/index.ts" "--concurrency" "$CONCURRENCY")
if [ "$NETWORKED_COLD_HOT" = true ]; then
CMD+=("--networked-cold-hot")
fi
if [ -z "$SOLVER_NAME" ]; then
SOLVER_NAME="$DEFAULT_SOLVER_NAME"
fi
if [ -n "$SOLVER_NAME" ] && [ "$SOLVER_NAME" != "_" ] && [ "$SOLVER_NAME" != "all" ]; then
CMD+=("--solver" "$SOLVER_NAME")
fi
if [ -n "$SCENARIO_LIMIT" ]; then
CMD+=("--scenario-limit" "$SCENARIO_LIMIT")
fi
if [ -n "$EFFORT" ]; then
CMD+=("--effort" "$EFFORT")
fi
if [ -n "$SAMPLE_TIMEOUT" ]; then
CMD+=("--sample-timeout" "$SAMPLE_TIMEOUT")
fi
if [ -n "$SAMPLE_NUMBERS" ]; then
CMD+=("--sample-numbers" "$SAMPLE_NUMBERS")
fi
if [ -n "$DATASET" ]; then
CMD+=("--dataset" "$DATASET")
fi
if [ "$INCLUDE_ASSIGNABLE" != true ]; then
CMD+=("--exclude-assignable")
fi
"${CMD[@]}"