Datasets:
Formats:
csv
Languages:
English
Size:
1K - 10K
Tags:
arxiv-artifact
reproducibility
research-artifact
computer-science
computer-logic
formal-methods
License:
| from __future__ import annotations | |
| import argparse | |
| import json | |
| import sys | |
| from pathlib import Path | |
| from .audit import corrupted_detector_drift, radius_ablation, replay_audit | |
| from .datasets import DATASET_NAMES, adapter_status | |
| from .edits import EDIT_TYPES | |
| from .pipeline import RunConfig, run_pipeline, run_pipeline_for_clips, validate_csv | |
| from .plots import make_figures | |
| from .queue import add_job, init_queue, read_jobs, run_next | |
| from .real_plots import make_real_video_figures | |
| from .real_video import download_real_videos, load_real_video_clips, write_real_feature_tables | |
| from .detectors import detector_clips | |
| from .hf_benchmarks import download_hf_benchmark_videos | |
| from .robustness import make_robustness_figures, run_robustness_atlas | |
| from .sweeps import run_sweep | |
| from .sweep_plots import make_sweep_figures | |
| def main(argv: list[str] | None = None) -> int: | |
| parser = argparse.ArgumentParser(description="Proof-carrying multimodal timelines") | |
| sub = parser.add_subparsers(dest="command", required=True) | |
| smoke = sub.add_parser("smoke", help="run minimal end-to-end pipeline") | |
| _add_run_args(smoke, default_output="runs/smoke", default_clips=6, default_edits="none,audio_shift,crop", default_repeats=1) | |
| small = sub.add_parser("run-small", help="run small defect atlas") | |
| _add_run_args(small, default_output="runs/run-small", default_clips=10, default_edits=",".join(EDIT_TYPES), default_repeats=4) | |
| real_data = sub.add_parser("download-real", help="download small public real MP4s") | |
| real_data.add_argument("--output", type=Path, default=Path("data/real_videos")) | |
| hf_data = sub.add_parser("download-benchmark", help="download a bounded public HF benchmark video subset") | |
| hf_data.add_argument("--dataset", choices=["youcook2", "ave"], required=True) | |
| hf_data.add_argument("--output", type=Path, required=True) | |
| hf_data.add_argument("--limit", type=int, default=80) | |
| hf_data.add_argument("--force", action="store_true") | |
| real = sub.add_parser("run-real", help="run certificates on decoded real MP4s") | |
| _add_run_args(real, default_output="runs/real-video", default_clips=15, default_edits=",".join(EDIT_TYPES), default_repeats=128) | |
| real.add_argument("--video-root", type=Path, default=Path("data/real_videos")) | |
| real.add_argument("--feature-output", type=Path, default=None) | |
| detector = sub.add_parser("run-detector", help="run CLIP/AST detector atoms on real MP4s") | |
| _add_run_args(detector, default_output="runs/detector-video", default_clips=15, default_edits=",".join(EDIT_TYPES), default_repeats=512) | |
| detector.add_argument("--video-root", type=Path, default=Path("data/real_videos")) | |
| detector.add_argument("--detector-output", type=Path, default=None) | |
| sweep = sub.add_parser("run-sweep", help="run dense parameterized perturbation sweeps") | |
| sweep.add_argument("--input-run", choices=["real", "detector"], default="detector") | |
| sweep.add_argument("--output", type=Path, default=Path("runs/sweep-detector")) | |
| sweep.add_argument("--video-root", type=Path, default=Path("data/real_videos")) | |
| sweep.add_argument("--clips", type=int, default=15) | |
| sweep.add_argument("--use-gpu", default="auto", choices=["auto", "cpu", "cuda", "gpu"]) | |
| sweep.add_argument("--stress-repeats", type=int, default=512) | |
| figures = sub.add_parser("figures", help="create manuscript figures") | |
| figures.add_argument("--input", type=Path, default=Path("runs/run-small/traces.csv")) | |
| figures.add_argument("--output", type=Path, default=Path("figures")) | |
| real_figures = sub.add_parser("real-figures", help="create real-video frame/timeline figures") | |
| real_figures.add_argument("--video", type=Path, default=Path("data/real_videos/sample-20s-360p.mp4")) | |
| real_figures.add_argument("--traces", type=Path, default=Path("runs/real-video/traces.csv")) | |
| real_figures.add_argument("--output", type=Path, default=Path("figures")) | |
| real_figures.add_argument("--use-gpu", default="auto", choices=["auto", "cpu", "cuda", "gpu"]) | |
| sweep_figures = sub.add_parser("sweep-figures", help="create sweep heatmap and perturbation figures") | |
| sweep_figures.add_argument("--traces", type=Path, default=Path("runs/sweep-detector/sweep_traces.csv")) | |
| sweep_figures.add_argument("--metrics", type=Path, default=Path("runs/sweep-detector/sweep_metrics.json")) | |
| sweep_figures.add_argument("--output", type=Path, default=Path("figures")) | |
| validate = sub.add_parser("validate", help="validate a trace CSV") | |
| validate.add_argument("--input", type=Path, required=True) | |
| status = sub.add_parser("adapter-status", help="report local real dataset adapter status") | |
| status.add_argument("--root", type=Path, default=Path("data/raw")) | |
| qi = sub.add_parser("queue-init", help="initialize GPU queue") | |
| qi.add_argument("--path", type=Path, default=Path("runs/gpu_jobs.jsonl")) | |
| qa = sub.add_parser("queue-add", help="add a GPU queue job") | |
| qa.add_argument("--path", type=Path, default=Path("runs/gpu_jobs.jsonl")) | |
| qa.add_argument("--name", required=True) | |
| qa.add_argument("--command", dest="job_command", required=True) | |
| qa.add_argument("--cwd", default=".") | |
| ql = sub.add_parser("queue-list", help="list GPU queue jobs") | |
| ql.add_argument("--path", type=Path, default=Path("runs/gpu_jobs.jsonl")) | |
| qr = sub.add_parser("queue-run-next", help="run the next queued job") | |
| qr.add_argument("--path", type=Path, default=Path("runs/gpu_jobs.jsonl")) | |
| qr.add_argument("--log-dir", type=Path, default=Path("runs/gpu_queue_logs")) | |
| replay = sub.add_parser("replay-audit", help="independently replay certificates for a run directory") | |
| replay.add_argument("--run", type=Path, default=Path("runs/run-small")) | |
| replay.add_argument("--output", type=Path) | |
| radius = sub.add_parser("radius-ablation", help="evaluate formulas across radius settings from windows.jsonl") | |
| radius.add_argument("--run", type=Path, default=Path("runs/run-small")) | |
| radius.add_argument("--output", type=Path, default=Path("runs/run-small/radius_ablation.csv")) | |
| radius.add_argument("--radii", default="0,1,2,4,8") | |
| drift = sub.add_parser("corrupted-drift", help="compare oracle-like and corrupted atom traces") | |
| drift.add_argument("--run", type=Path, default=Path("runs/run-small")) | |
| drift.add_argument("--output", type=Path, default=Path("runs/run-small/corrupted_detector_drift.csv")) | |
| robust = sub.add_parser("robustness-atlas", help="aggregate detector-threshold/radius certificate stability atlas") | |
| robust.add_argument("--run", type=Path, default=Path("runs/run-small")) | |
| robust.add_argument("--output", type=Path, default=Path("runs/robustness-atlas")) | |
| robust.add_argument("--thresholds", type=int, default=64) | |
| robust.add_argument("--radii", default="0,1,2,3,4,5,6,7,8") | |
| robust.add_argument("--use-gpu", default="auto", choices=["auto", "cpu", "cuda", "gpu"]) | |
| robust.add_argument("--sample-limit", type=int, default=None) | |
| robust.add_argument("--unstable-limit", type=int, default=200) | |
| robust_fig = sub.add_parser("robustness-figures", help="create certificate stability phase-diagram figure") | |
| robust_fig.add_argument("--input", type=Path, default=Path("runs/robustness-atlas")) | |
| robust_fig.add_argument("--output", type=Path, default=Path("figures")) | |
| args = parser.parse_args(argv) | |
| if args.command in {"smoke", "run-small"}: | |
| metrics = _run_from_args(args) | |
| print(json.dumps(metrics, indent=2, sort_keys=True)) | |
| return 0 | |
| if args.command == "download-real": | |
| paths = download_real_videos(args.output) | |
| print(json.dumps([str(path) for path in paths], indent=2)) | |
| return 0 | |
| if args.command == "download-benchmark": | |
| paths = download_hf_benchmark_videos(args.dataset, args.output, limit=args.limit, force=args.force) | |
| print(json.dumps([str(path) for path in paths], indent=2)) | |
| return 0 | |
| if args.command == "run-real": | |
| edits = [edit.strip() for edit in args.edits.split(",") if edit.strip()] | |
| clips = load_real_video_clips(args.video_root, limit=args.clips, use_gpu=args.use_gpu) | |
| paths = [clip.media_path for clip in clips if clip.media_path is not None] | |
| feature_output = args.feature_output or (args.output / "features") | |
| write_real_feature_tables(paths, feature_output, use_gpu=args.use_gpu) | |
| config = RunConfig( | |
| output=args.output, | |
| data_root=args.data_root, | |
| fixture_root=args.fixture_root, | |
| datasets=["real_public_mp4"], | |
| clips=args.clips, | |
| edits=edits, | |
| use_gpu=args.use_gpu, | |
| stress_repeats=max(1, args.stress_repeats), | |
| ) | |
| metrics = run_pipeline_for_clips(config, clips) | |
| print(json.dumps(metrics, indent=2, sort_keys=True)) | |
| return 0 | |
| if args.command == "run-detector": | |
| edits = [edit.strip() for edit in args.edits.split(",") if edit.strip()] | |
| detector_output = args.detector_output or (args.output / "detector") | |
| clips = detector_clips(args.video_root, detector_output, limit=args.clips, use_gpu=args.use_gpu) | |
| config = RunConfig( | |
| output=args.output, | |
| data_root=args.data_root, | |
| fixture_root=args.fixture_root, | |
| datasets=["real_public_mp4_detector"], | |
| clips=args.clips, | |
| edits=edits, | |
| use_gpu=args.use_gpu, | |
| stress_repeats=max(1, args.stress_repeats), | |
| ) | |
| metrics = run_pipeline_for_clips(config, clips) | |
| print(json.dumps(metrics, indent=2, sort_keys=True)) | |
| return 0 | |
| if args.command == "run-sweep": | |
| if args.input_run == "detector": | |
| clips = detector_clips(args.video_root, args.output / "detector", limit=args.clips, use_gpu=args.use_gpu) | |
| else: | |
| clips = load_real_video_clips(args.video_root, limit=args.clips, use_gpu=args.use_gpu) | |
| metrics = run_sweep(clips, args.output, use_gpu=args.use_gpu, repeats=max(1, args.stress_repeats)) | |
| print(json.dumps(metrics, indent=2, sort_keys=True)) | |
| return 0 | |
| if args.command == "figures": | |
| paths = make_figures(args.input, args.output) | |
| print(json.dumps(paths, indent=2, sort_keys=True)) | |
| return 0 | |
| if args.command == "real-figures": | |
| paths = make_real_video_figures(args.video, args.traces, args.output, use_gpu=args.use_gpu) | |
| print(json.dumps(paths, indent=2, sort_keys=True)) | |
| return 0 | |
| if args.command == "sweep-figures": | |
| paths = make_sweep_figures(args.traces, args.metrics, args.output) | |
| print(json.dumps(paths, indent=2, sort_keys=True)) | |
| return 0 | |
| if args.command == "validate": | |
| errors = validate_csv(args.input) | |
| if errors: | |
| for error in errors: | |
| print(error, file=sys.stderr) | |
| return 1 | |
| print(f"{args.input} valid") | |
| return 0 | |
| if args.command == "adapter-status": | |
| print(json.dumps(adapter_status(args.root), indent=2, sort_keys=True)) | |
| return 0 | |
| if args.command == "queue-init": | |
| init_queue(args.path) | |
| print(args.path) | |
| return 0 | |
| if args.command == "queue-add": | |
| job = add_job(args.path, args.name, args.job_command, cwd=args.cwd) | |
| print(json.dumps(job, indent=2, sort_keys=True)) | |
| return 0 | |
| if args.command == "queue-list": | |
| print(json.dumps(read_jobs(args.path), indent=2, sort_keys=True)) | |
| return 0 | |
| if args.command == "queue-run-next": | |
| job = run_next(args.path, args.log_dir) | |
| print(json.dumps(job, indent=2, sort_keys=True)) | |
| return 0 | |
| if args.command == "replay-audit": | |
| print(json.dumps(replay_audit(args.run, args.output), indent=2, sort_keys=True)) | |
| return 0 | |
| if args.command == "radius-ablation": | |
| radii = [int(item.strip()) for item in args.radii.split(",") if item.strip()] | |
| print(json.dumps(radius_ablation(args.run, args.output, radii), indent=2, sort_keys=True)) | |
| return 0 | |
| if args.command == "corrupted-drift": | |
| print(json.dumps(corrupted_detector_drift(args.run, args.output), indent=2, sort_keys=True)) | |
| return 0 | |
| if args.command == "robustness-atlas": | |
| radii = [int(item.strip()) for item in args.radii.split(",") if item.strip()] | |
| metrics = run_robustness_atlas( | |
| args.run, | |
| args.output, | |
| thresholds=args.thresholds, | |
| radii=radii, | |
| use_gpu=args.use_gpu, | |
| sample_limit=args.sample_limit, | |
| unstable_limit=args.unstable_limit, | |
| ) | |
| print(json.dumps(metrics, indent=2, sort_keys=True)) | |
| return 0 | |
| if args.command == "robustness-figures": | |
| print(json.dumps(make_robustness_figures(args.input, args.output), indent=2, sort_keys=True)) | |
| return 0 | |
| raise AssertionError(args.command) | |
| def _add_run_args(parser: argparse.ArgumentParser, default_output: str, default_clips: int, default_edits: str, default_repeats: int) -> None: | |
| parser.add_argument("--output", type=Path, default=Path(default_output)) | |
| parser.add_argument("--data-root", type=Path, default=Path("data/raw")) | |
| parser.add_argument("--fixture-root", type=Path, default=Path("data/fixtures")) | |
| parser.add_argument("--datasets", default=",".join(DATASET_NAMES)) | |
| parser.add_argument("--clips", type=int, default=default_clips) | |
| parser.add_argument("--edits", default=default_edits) | |
| parser.add_argument("--use-gpu", default="auto", choices=["auto", "cpu", "cuda", "gpu"]) | |
| parser.add_argument("--stress-repeats", type=int, default=default_repeats) | |
| def _run_from_args(args: argparse.Namespace) -> dict: | |
| edits = [edit.strip() for edit in args.edits.split(",") if edit.strip()] | |
| datasets = [dataset.strip() for dataset in args.datasets.split(",") if dataset.strip()] | |
| config = RunConfig( | |
| output=args.output, | |
| data_root=args.data_root, | |
| fixture_root=args.fixture_root, | |
| datasets=datasets, | |
| clips=args.clips, | |
| edits=edits, | |
| use_gpu=args.use_gpu, | |
| stress_repeats=max(1, args.stress_repeats), | |
| ) | |
| return run_pipeline(config) | |
| if __name__ == "__main__": | |
| raise SystemExit(main()) | |