Skip to content

Commit 58915ad

Browse files
committed
Publish benchmark summaries and charts to GitHub PRs
1 parent f0a7628 commit 58915ad

6 files changed

Lines changed: 862 additions & 1 deletion

File tree

‎README.md‎

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,72 @@ are saved every 15 seconds in a sibling `console.progress.log` (or
278278
only print start and finish summaries. These are status updates, not an estimated
279279
completion percentage.
280280

281+
## Publishing benchmark results to a PR
282+
283+
A suite can post one results comment after its final comparison report. Add an
284+
explicit target (the repository is always on github.com):
285+
286+
```yaml
287+
inputs:
288+
pr:
289+
type: integer
290+
required: true
291+
minimum: 1
292+
publish:
293+
github:
294+
repository: ActivitySim/activitysim
295+
pr: ${pr}
296+
baseline: main
297+
```
298+
299+
`baseline` names a run in `runs` and defaults to the first run. The posting target
300+
is independent of source selection: use `pr: ${pr}` in an ActivitySim source
301+
mapping to benchmark that PR's pinned head as well. See
302+
[`examples/sandag-pr.yaml`](examples/sandag-pr.yaml) for a complete example with a
303+
pinned baseline; adjust its model/data paths and baseline commit for your model.
304+
305+
```bash
306+
abench examples/sandag-pr.yaml --set pr=1110
307+
# Run benchmarks, but only generate the local comment and charts:
308+
abench examples/sandag-pr.yaml --set pr=1110 --publish-dry-run
309+
# Inspect or publish retained results without rerunning benchmarks:
310+
abench publish /path/to/suite-output --dry-run
311+
abench publish /path/to/suite-output
312+
```
313+
314+
Publication requires GitHub CLI 2.99 or newer with `gh pr comment --attach`, an
315+
authenticated account, and repository write access for image uploads. Use
316+
`gh auth login --hostname github.com` (OAuth), or a classic personal access token
317+
through `GH_TOKEN`. Other token types and GitHub Enterprise Server image uploads
318+
are not supported by this first release. `gh` remains optional for ordinary runs
319+
and publication dry runs. Authentication and PR access are checked before asset
320+
preparation or benchmark execution when publication is enabled; validation and
321+
prepare-only commands do not publish. Tokens are never written to experiment
322+
metadata or passed into benchmark containers.
323+
324+
The comment contains elapsed time and peak memory, percentage changes against the
325+
baseline for valid runs with matching comparison settings, run settings, source
326+
commits, memory traces, and component-runtime charts. Invalid runs have no change
327+
claims and are excluded from the runtime chart; unstarted runs are identified.
328+
PR head/base commits are recorded at startup, and a head change during execution
329+
is noted when posting. These are observations, not statistical significance tests.
330+
331+
The `publication/` directory retains `comment.md`, `memory.svg`, `runtimes.svg`,
332+
and `state.json` with the comment ID/URL and publication status. The exact upload
333+
body is retained as `upload.md`. A retry searches for the suite's unique comment
334+
marker before posting; a recorded successful publication is a no-op. Independent
335+
suite executions get separate comments. Simultaneous publication of the same
336+
output directory is blocked. Partial uploads can leave unused GitHub attachments,
337+
but the local reports are retained and a retry can complete the comment.
338+
339+
A posting error fails the command and prints the retry command. If the benchmark
340+
also failed, its failure remains primary and the publication error is printed
341+
separately. The full HTML/JSON comparison remains local; this release uploads only
342+
the summary and SVG figures, not raw logs, model data, or the interactive HTML.
343+
Images must fit GitHub's 10 MB attachment limit, and summaries are limited to
344+
60,000 characters. Publication transport tests simulate GitHub; a live attachment
345+
smoke test should use a designated test PR, never a production PR by default.
346+
281347
## Run controls
282348

283349
- `--single-process` (default), or `--multiprocess --processes N`. The count applies

‎examples/sandag-pr.yaml‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Run from any directory: abench /path/to/abench/examples/sandag-pr.yaml
2+
schema_version: 1
3+
# Publishing is opt-in through this block. Use --publish-dry-run to preview locally.
4+
publish:
5+
github:
6+
repository: ActivitySim/activitysim
7+
pr: ${pr}
8+
baseline: main
9+
inputs:
10+
pr:
11+
type: integer
12+
required: true
13+
minimum: 1
14+
description: ActivitySim PR to benchmark and comment on
15+
households:
16+
type: integer
17+
default: 28365
18+
minimum: 0
19+
description: Households to sample from benchmarking-data; 0 uses all
20+
processes:
21+
type: integer
22+
default: 4
23+
minimum: 1
24+
warmup_households:
25+
type: integer
26+
default: 5000
27+
minimum: 1
28+
vars:
29+
model: ../../sandag-abm3-example
30+
activitysim_main: 5c6fae24a91a57a2d6dfc2e1dbe062a61d94545a
31+
output_root: ../experiments/sandag-pr${pr}-${timestamp}
32+
defaults:
33+
model_dir: ${model}
34+
profile: sandag
35+
data_dir: ${model}/benchmarking-data
36+
config_overlay: ["${model}/configs_explicit_chunk"]
37+
multiprocess: true
38+
processes: ${processes}
39+
sharrow: true
40+
households: ${households}
41+
# Cache misses in the measured run trigger a retry using the compiled flows.
42+
warmup_households: ${warmup_households}
43+
memory: 80g
44+
shm_size: 8g
45+
platform: linux/arm64
46+
sources:
47+
- sharrow=ActivitySim/sharrow@fc175b27d8e0c5d202721c67d96b050e6117b235
48+
runs:
49+
main:
50+
label: SANDAG main — explicit chunking
51+
sources:
52+
- activitysim=ActivitySim/activitysim@${activitysim_main}
53+
candidate:
54+
label: SANDAG PR${pr} — explicit chunking
55+
sources:
56+
- name: activitysim
57+
repository: ActivitySim/activitysim
58+
pr: ${pr}

‎src/abench/cli.py‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def positive(value):
6060
def parser():
6161
p = argparse.ArgumentParser(
6262
description=__doc__,
63-
epilog="Named experiments: abench experiments.yaml [--set NAME=VALUE]; preflight: abench validate experiments.yaml [--set NAME=VALUE]; data only: abench prepare experiments.yaml",
63+
epilog="Named experiments: abench experiments.yaml [--set NAME=VALUE]; preflight: abench validate experiments.yaml [--set NAME=VALUE]; data only: abench prepare experiments.yaml; publish retained results: abench publish OUTPUT_DIRECTORY [--dry-run]",
6464
)
6565
p.add_argument("--version", action="version", version=f"abench {__version__}")
6666
p.add_argument("--model-dir", type=Path, default=Path.cwd())
@@ -233,6 +233,19 @@ def container_phase(spec, output, data, image, phase_name):
233233
def main(argv=None):
234234
p = parser()
235235
argv = list(sys.argv[1:] if argv is None else argv)
236+
if argv and argv[0] == "publish":
237+
from .publishing import publish
238+
239+
publish_parser = argparse.ArgumentParser(prog="abench publish")
240+
publish_parser.add_argument("output_directory", type=Path)
241+
publish_parser.add_argument(
242+
"--dry-run",
243+
action="store_true",
244+
help="generate the local bundle without GitHub access",
245+
)
246+
options = publish_parser.parse_args(argv[1:])
247+
publish(options.output_directory, dry_run=options.dry_run)
248+
return 0
236249
# A file invocation stays separate from model profiles and ordinary flags.
237250
candidate = argv[1:] if argv and argv[0] in ("run", "validate", "prepare") else argv
238251
if (
@@ -272,6 +285,11 @@ def main(argv=None):
272285
action="store_true",
273286
help="use defaults and --set values without prompting (required inputs must be supplied)",
274287
)
288+
suite_parser.add_argument(
289+
"--publish-dry-run",
290+
action="store_true",
291+
help="run benchmarks and prepare the comment and charts without publishing",
292+
)
275293
suite_args = suite_parser.parse_args(candidate)
276294
interactive = not suite_args.non_interactive and sys.stdin.isatty()
277295
selected = select_experiment(suite_args.experiment_file, interactive)
@@ -282,6 +300,7 @@ def main(argv=None):
282300
validate_only=argv[0] == "validate",
283301
assignments=suite_args.set,
284302
interactive=interactive,
303+
**({"publish_dry_run": True} if suite_args.publish_dry_run else {}),
285304
)
286305
action = argv.pop(0) if argv and argv[0] in ("run", "report", "validate") else "run"
287306
args = p.parse_args(argv)

‎src/abench/experiments.py‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import yaml
1010

11+
from . import publishing
1112
from .assets import plan_assets, prepare_assets
1213
from .common import write_json
1314
from .inputs import resolve_inputs
@@ -196,6 +197,7 @@ def read_suite(path):
196197
"runs",
197198
"output_root",
198199
"data_assets",
200+
"publish",
199201
}
200202
if unknown:
201203
raise ValueError(f"unknown experiment file fields: {sorted(unknown)}")
@@ -218,6 +220,7 @@ def load_suite(path, assignments=(), interactive=False):
218220
runs = document.get("runs")
219221
if not isinstance(runs, dict) or not runs:
220222
raise ValueError("runs must be a nonempty mapping of run names to options")
223+
publishing.configuration(document.get("publish"), runs)
221224
output = document.get("output_root")
222225
if not isinstance(output, str) or not output:
223226
raise ValueError("output_root must be a path")
@@ -261,6 +264,7 @@ def run_suite(
261264
prepare_only=False,
262265
assignments=(),
263266
interactive=False,
267+
publish_dry_run=False,
264268
):
265269
"""Preflight every run, execute serially, and preserve partial failure reports."""
266270
plan = load_suite(path, assignments=assignments, interactive=interactive)
@@ -271,6 +275,11 @@ def run_suite(
271275
flush=True,
272276
)
273277
root = Path(plan["output_root"])
278+
publish_config = publishing.configuration(
279+
plan["configuration"].get("publish"), [r["name"] for r in plan["runs"]]
280+
)
281+
if publish_config and not (validate_only or prepare_only or publish_dry_run):
282+
plan["publication_pr"] = publishing.preflight(publish_config)
274283
if not validate_only:
275284
if plan["data_assets"]:
276285
print("Preparing input data (checking shared cache)…", flush=True)
@@ -293,6 +302,7 @@ def run_suite(
293302
(root / "experiments.yaml").write_text(plan["original_yaml"])
294303
write_json(root / "suite.json", plan)
295304
completed = []
305+
failed = False
296306
try:
297307
for number, run in enumerate(plan["runs"], 1):
298308
print(
@@ -306,9 +316,21 @@ def run_suite(
306316
if (Path(run["output_dir"]) / "experiment.json").is_file():
307317
completed.append(Path(run["output_dir"]))
308318
if code:
319+
failed = True
309320
return code
321+
except BaseException:
322+
failed = True
323+
raise
310324
finally:
311325
if completed:
312326
report(completed, root / "comparison.html")
313327
print(f"Comparison: {root / 'comparison.html'}", flush=True)
328+
if publish_config:
329+
try:
330+
publishing.publish(root, dry_run=publish_dry_run)
331+
except (ValueError, OSError) as error:
332+
if not failed:
333+
raise
334+
# Keep the model failure primary, but never hide a posting failure.
335+
print(f"Publication failed: {error}", flush=True)
314336
return 0

0 commit comments

Comments
 (0)