diff --git a/.github/workflows/flow.yml b/.github/workflows/flow.yml index 031e917..98848e4 100644 --- a/.github/workflows/flow.yml +++ b/.github/workflows/flow.yml @@ -44,6 +44,8 @@ jobs: python benchmarks/verify_fixtures.py python benchmarks/test_generate_headline_summary.py python benchmarks/test_disparity_regression_policy.py + python benchmarks/test_generate_operation_rows.py + python benchmarks/generate_operation_rows.py --check python benchmarks/test_config_equivalence.py python benchmarks/test_rank_optimization_stages.py python benchmarks/publish_headline_v2.py --check @@ -68,6 +70,8 @@ jobs: benchmarks/test_config_equivalence.py \ benchmarks/test_disparity_regression_policy.py \ benchmarks/publish_headline_v2.py \ + benchmarks/generate_operation_rows.py \ + benchmarks/test_generate_operation_rows.py \ benchmarks/validate_execution_substrate.py python - <<'PY' import json diff --git a/.github/workflows/remaining-issues.yml b/.github/workflows/remaining-issues.yml index 5b822cc..7c2cdd5 100644 --- a/.github/workflows/remaining-issues.yml +++ b/.github/workflows/remaining-issues.yml @@ -236,6 +236,7 @@ jobs: python benchmarks/refresh_derived_evidence.py - name: Sync published claims to the frozen artifact run: | + python benchmarks/generate_operation_rows.py python benchmarks/validate_published_claims.py --fix python benchmarks/validate_published_claims.py - name: Commit generated evidence if changed diff --git a/.gitignore b/.gitignore index dcd7bb7..f10c39d 100644 --- a/.gitignore +++ b/.gitignore @@ -32,6 +32,7 @@ docs/disparity-report.json docs/disparity-history.json docs/scaled-ci-history.json docs/estimator-comparison.json +docs/operation-rows.json # Raw ESTIMATOR| capture from the generated wide benchmark; the joined result # is benchmarks/estimator_comparison.json. diff --git a/benchmarks/README.md b/benchmarks/README.md index ee0a185..23f7d74 100644 --- a/benchmarks/README.md +++ b/benchmarks/README.md @@ -303,6 +303,24 @@ of it found a heap-buffer-overflow in `_solve_lstsq_qr`, which assumed a design has at least as many rows as columns; RANSAC reaches it by fitting 5 sampled rows against the 10 features of diabetes. +## Operation rows + +The canonical result classifies an estimator and dataset from fit plus +prediction time. [`operation_rows.json`](operation_rows.json) lists each timed +operation on its own: `fit`, and the prediction stage, which is `predict` for +every estimator except PCA where it is `transform`. Each row has the median and +IQR of both implementations, the speedup, a status, the parity status that +makes the row eligible, and a tracking issue when the operation loses. + +`predict_proba`, `decision_function` and the other operations of a benchmarked +estimator are not timed separately. They appear with status `not measured`. + +[`operation_loss_issues.json`](operation_loss_issues.json) maps each losing +operation to its focused issue. `generate_operation_rows.py` rebuilds the file +from `headline_result_v2.json`, and `--check` fails when the committed file +differs from that build. The #478 exit criterion is evaluated here: +`every_measured_operation_wins` is true only when no timed operation loses. + ## Pages publication [`publish_headline_v2.py`](publish_headline_v2.py) validates the committed canonical benchmark and architecture map, then copies the JSON artifacts into `docs/` for the static site. The public benchmark and architecture pages render those artifacts directly instead of embedding hand-maintained timing claims. diff --git a/benchmarks/generate_operation_rows.py b/benchmarks/generate_operation_rows.py new file mode 100644 index 0000000..27b7d99 --- /dev/null +++ b/benchmarks/generate_operation_rows.py @@ -0,0 +1,179 @@ +#!/usr/bin/env python3 +"""Write one row per estimator operation from the canonical headline result. + +headline_result_v2.json classifies an estimator and dataset from fit plus +prediction time. A total can be a Flow win while one of its operations loses, +so this file lists each timed operation on its own: median, IQR, speedup and +status for both implementations. Totals stay in the headline result as the +secondary view. + +Timed operations: `fit` for every row, and the prediction stage, which is +`predict` for every estimator except PCA where it is `transform`. +`predict_proba` and `decision_function` (and `transform` or `predict` where an +estimator has both) are not timed by the headline benchmark. They are listed +with status "not measured" so no operation of a benchmarked estimator is +silently absent. + +An operation row is eligible when the headline row's parity status is eligible. +The prediction stage is timed on the model that each implementation fitted in +the same process, so it needs the fit state to be parity-eligible too, and the +one parity status covers both. + +Each operation that loses carries a tracking issue from +operation_loss_issues.json. `--check` fails when the committed file differs +from what the committed headline result produces. +""" +from __future__ import annotations + +import argparse +import hashlib +import json +import sys +from pathlib import Path + +from generate_headline_summary import ELIGIBLE_PARITY, TIE_RELATIVE_THRESHOLD +from rank_optimization_opportunities import HEADLINE_TO_SKLEARN + +ROOT = Path(__file__).resolve().parents[1] +BENCH = ROOT / "benchmarks" +UNTIMED_OPERATIONS = ("predict", "transform", "predict_proba", "decision_function") +UNTIMED_REASON = "not timed separately by the headline benchmark; shares the prediction stage kernel" + + +def prediction_operation(algorithm: str) -> str: + return "transform" if algorithm == "PCA" else "predict" + + +def status_of(row: dict, sklearn_ms, flow_ms) -> tuple[str, float | None]: + if row.get("parity_status") not in ELIGIBLE_PARITY: + return "parity unresolved", None + sk = float(sklearn_ms or 0.0) + fl = float(flow_ms or 0.0) + if row.get("measurement_status") != "resolved" or sk <= 0.0 or fl <= 0.0: + return "measurement unresolved", None + speedup = sk / fl + if abs(sk - fl) / max(sk, fl) <= TIE_RELATIVE_THRESHOLD: + return "tie", speedup + return ("flow win" if fl < sk else "sklearn win"), speedup + + +def build(result_bytes: bytes, inventory: list[dict], issues: dict[str, int]) -> dict: + result = json.loads(result_bytes) + rows: list[dict] = [] + for h in result["rows"]: + algorithm, dataset = h["algorithm"], h["dataset"] + estimator = HEADLINE_TO_SKLEARN.get(algorithm, algorithm) + timed = ( + ("fit", "fit", "sklearn_fit_ms", "flow_fit_ms", "sklearn_fit_iqr_ms", "flow_fit_iqr_ms"), + (prediction_operation(algorithm), "prediction", "sklearn_pred_ms", "flow_pred_ms", + "sklearn_pred_iqr_ms", "flow_pred_iqr_ms"), + ) + for operation, stage, sk_key, fl_key, sk_iqr, fl_iqr in timed: + status, speedup = status_of(h, h.get(sk_key), h.get(fl_key)) + key = f"{algorithm}/{dataset}/{operation}" + rows.append({ + "id": key, + "algorithm": algorithm, + "sklearn_estimator": estimator, + "dataset": dataset, + "operation": operation, + "stage": stage, + "sklearn_median_ms": h.get(sk_key), + "flow_median_ms": h.get(fl_key), + "sklearn_iqr_ms": h.get(sk_iqr), + "flow_iqr_ms": h.get(fl_iqr), + "speedup": speedup, + "status": status, + "parity_status": h.get("parity_status"), + "prerequisites_met": h.get("parity_status") in ELIGIBLE_PARITY and h.get("measurement_status") == "resolved", + "tracking_issue": issues.get(key) if status == "sklearn win" else None, + }) + timed_ops = {r["operation"] for r in rows if r["algorithm"] == algorithm and r["dataset"] == dataset} + available = {r["operation"] for r in inventory if r["estimator"] == estimator} + for operation in UNTIMED_OPERATIONS: + if operation in available and operation not in timed_ops: + rows.append({ + "id": f"{algorithm}/{dataset}/{operation}", + "algorithm": algorithm, + "sklearn_estimator": estimator, + "dataset": dataset, + "operation": operation, + "stage": "prediction", + "sklearn_median_ms": None, + "flow_median_ms": None, + "sklearn_iqr_ms": None, + "flow_iqr_ms": None, + "speedup": None, + "status": "not measured", + "parity_status": h.get("parity_status"), + "prerequisites_met": False, + "tracking_issue": None, + "note": UNTIMED_REASON, + }) + + measured = [r for r in rows if r["status"] != "not measured"] + by_status = {s: sum(r["status"] == s for r in rows) for s in + ("flow win", "sklearn win", "tie", "parity unresolved", "measurement unresolved", "not measured")} + losses = [r for r in rows if r["status"] == "sklearn win"] + by_operation: dict[str, dict] = {} + for r in rows: + c = by_operation.setdefault(r["operation"], {"rows": 0, "flow_wins": 0, "sklearn_wins": 0, "ties": 0, "not_measured": 0}) + c["rows"] += 1 + c["flow_wins"] += r["status"] == "flow win" + c["sklearn_wins"] += r["status"] == "sklearn win" + c["ties"] += r["status"] == "tie" + c["not_measured"] += r["status"] == "not measured" + counts = { + "operation_rows": len(rows), + "measured_operations": len(measured), + "flow_wins": by_status["flow win"], + "sklearn_wins": by_status["sklearn win"], + "ties": by_status["tie"], + "parity_unresolved": by_status["parity unresolved"], + "measurement_unresolved": by_status["measurement unresolved"], + "not_measured": by_status["not measured"], + "losses_without_tracking_issue": sum(r["tracking_issue"] is None for r in losses), + "by_operation": by_operation, + } + return { + "schema_version": 1, + "timing_unit": "ms", + "tie_relative_threshold": TIE_RELATIVE_THRESHOLD, + "source_result_sha256": hashlib.sha256(result_bytes).hexdigest(), + "environment_id": result.get("environment_id"), + "exit_criterion": "every measured operation row is a Flow win; totals do not count", + "every_measured_operation_wins": bool(measured) and len(measured) == by_status["flow win"], + "counts": counts, + "rows": rows, + } + + +def main() -> int: + ap = argparse.ArgumentParser() + ap.add_argument("--result", type=Path, default=BENCH / "headline_result_v2.json") + ap.add_argument("--inventory", type=Path, default=BENCH / "sklearn_execution_inventory.json") + ap.add_argument("--issues", type=Path, default=BENCH / "operation_loss_issues.json") + ap.add_argument("--output", type=Path, default=BENCH / "operation_rows.json") + ap.add_argument("--check", action="store_true", help="fail when the committed output differs from a fresh build") + args = ap.parse_args() + + inventory = json.loads(args.inventory.read_text())["rows"] + issues = json.loads(args.issues.read_text())["issues"] + doc = build(args.result.read_bytes(), inventory, issues) + text = json.dumps(doc, indent=2) + "\n" + c = doc["counts"] + if args.check: + if not args.output.exists() or args.output.read_text() != text: + print(f"{args.output.name} does not match {args.result.name}. Run: python benchmarks/generate_operation_rows.py") + return 1 + print(f"operation rows match the headline result: {c['flow_wins']} wins, {c['sklearn_wins']} losses, " + f"{c['ties']} ties over {c['measured_operations']} measured operations") + return 0 + args.output.write_text(text) + print(f"{c['flow_wins']} wins, {c['sklearn_wins']} losses, {c['ties']} ties over {c['measured_operations']} measured " + f"operations; {c['not_measured']} untimed; {c['losses_without_tracking_issue']} losses without an issue") + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/benchmarks/operation_loss_issues.json b/benchmarks/operation_loss_issues.json new file mode 100644 index 0000000..0bbc8a0 --- /dev/null +++ b/benchmarks/operation_loss_issues.json @@ -0,0 +1,6 @@ +{ + "comment": "Focused issue for each operation that loses to scikit-learn. Key is algorithm/dataset/operation.", + "issues": { + "LinearSVC/digits/predict": 518 + } +} diff --git a/benchmarks/operation_rows.json b/benchmarks/operation_rows.json new file mode 100644 index 0000000..64e2858 --- /dev/null +++ b/benchmarks/operation_rows.json @@ -0,0 +1,1029 @@ +{ + "schema_version": 1, + "timing_unit": "ms", + "tie_relative_threshold": 0.02, + "source_result_sha256": "466fd432d26dd8042a24425290d5c09ff749b3c504b137930334d97b7bb397be", + "environment_id": "8f11a9c3927a0fee", + "exit_criterion": "every measured operation row is a Flow win; totals do not count", + "every_measured_operation_wins": false, + "counts": { + "operation_rows": 56, + "measured_operations": 38, + "flow_wins": 37, + "sklearn_wins": 1, + "ties": 0, + "parity_unresolved": 0, + "measurement_unresolved": 0, + "not_measured": 18, + "losses_without_tracking_issue": 0, + "by_operation": { + "fit": { + "rows": 19, + "flow_wins": 19, + "sklearn_wins": 0, + "ties": 0, + "not_measured": 0 + }, + "predict": { + "rows": 18, + "flow_wins": 17, + "sklearn_wins": 1, + "ties": 0, + "not_measured": 0 + }, + "predict_proba": { + "rows": 10, + "flow_wins": 0, + "sklearn_wins": 0, + "ties": 0, + "not_measured": 10 + }, + "decision_function": { + "rows": 6, + "flow_wins": 0, + "sklearn_wins": 0, + "ties": 0, + "not_measured": 6 + }, + "transform": { + "rows": 3, + "flow_wins": 1, + "sklearn_wins": 0, + "ties": 0, + "not_measured": 2 + } + } + }, + "rows": [ + { + "id": "LogisticRegression/iris/fit", + "algorithm": "LogisticRegression", + "sklearn_estimator": "LogisticRegression", + "dataset": "iris", + "operation": "fit", + "stage": "fit", + "sklearn_median_ms": 2.33989094, + "flow_median_ms": 0.127223998, + "sklearn_iqr_ms": 0.00226838, + "flow_iqr_ms": 0.003358006, + "speedup": 18.391899144688097, + "status": "flow win", + "parity_status": "approximately equivalent", + "prerequisites_met": true, + "tracking_issue": null + }, + { + "id": "LogisticRegression/iris/predict", + "algorithm": "LogisticRegression", + "sklearn_estimator": "LogisticRegression", + "dataset": "iris", + "operation": "predict", + "stage": "prediction", + "sklearn_median_ms": 0.0800641953, + "flow_median_ms": 0.004827, + "sklearn_iqr_ms": 0.0001028789, + "flow_iqr_ms": 0.000417, + "speedup": 16.58674027346178, + "status": "flow win", + "parity_status": "approximately equivalent", + "prerequisites_met": true, + "tracking_issue": null + }, + { + "id": "LogisticRegression/iris/predict_proba", + "algorithm": "LogisticRegression", + "sklearn_estimator": "LogisticRegression", + "dataset": "iris", + "operation": "predict_proba", + "stage": "prediction", + "sklearn_median_ms": null, + "flow_median_ms": null, + "sklearn_iqr_ms": null, + "flow_iqr_ms": null, + "speedup": null, + "status": "not measured", + "parity_status": "approximately equivalent", + "prerequisites_met": false, + "tracking_issue": null, + "note": "not timed separately by the headline benchmark; shares the prediction stage kernel" + }, + { + "id": "LogisticRegression/iris/decision_function", + "algorithm": "LogisticRegression", + "sklearn_estimator": "LogisticRegression", + "dataset": "iris", + "operation": "decision_function", + "stage": "prediction", + "sklearn_median_ms": null, + "flow_median_ms": null, + "sklearn_iqr_ms": null, + "flow_iqr_ms": null, + "speedup": null, + "status": "not measured", + "parity_status": "approximately equivalent", + "prerequisites_met": false, + "tracking_issue": null, + "note": "not timed separately by the headline benchmark; shares the prediction stage kernel" + }, + { + "id": "LinearSVC/iris/fit", + "algorithm": "LinearSVC", + "sklearn_estimator": "LinearSVC", + "dataset": "iris", + "operation": "fit", + "stage": "fit", + "sklearn_median_ms": 0.549966297, + "flow_median_ms": 0.104854003, + "sklearn_iqr_ms": 0.005824781, + "flow_iqr_ms": 7.7001e-05, + "speedup": 5.2450672484101535, + "status": "flow win", + "parity_status": "approximately equivalent", + "prerequisites_met": true, + "tracking_issue": null + }, + { + "id": "LinearSVC/iris/predict", + "algorithm": "LinearSVC", + "sklearn_estimator": "LinearSVC", + "dataset": "iris", + "operation": "predict", + "stage": "prediction", + "sklearn_median_ms": 0.0802341914, + "flow_median_ms": 0.000949, + "sklearn_iqr_ms": 0.0006929648, + "flow_iqr_ms": 0.00012, + "speedup": 84.54603940990516, + "status": "flow win", + "parity_status": "approximately equivalent", + "prerequisites_met": true, + "tracking_issue": null + }, + { + "id": "LinearSVC/iris/decision_function", + "algorithm": "LinearSVC", + "sklearn_estimator": "LinearSVC", + "dataset": "iris", + "operation": "decision_function", + "stage": "prediction", + "sklearn_median_ms": null, + "flow_median_ms": null, + "sklearn_iqr_ms": null, + "flow_iqr_ms": null, + "speedup": null, + "status": "not measured", + "parity_status": "approximately equivalent", + "prerequisites_met": false, + "tracking_issue": null, + "note": "not timed separately by the headline benchmark; shares the prediction stage kernel" + }, + { + "id": "KernelSVC_RBF/iris/fit", + "algorithm": "KernelSVC_RBF", + "sklearn_estimator": "SVC", + "dataset": "iris", + "operation": "fit", + "stage": "fit", + "sklearn_median_ms": 0.591600656, + "flow_median_ms": 0.167482004, + "sklearn_iqr_ms": 0.00451925, + "flow_iqr_ms": 0.008451, + "speedup": 3.5323237235685334, + "status": "flow win", + "parity_status": "approximately equivalent", + "prerequisites_met": true, + "tracking_issue": null + }, + { + "id": "KernelSVC_RBF/iris/predict", + "algorithm": "KernelSVC_RBF", + "sklearn_estimator": "SVC", + "dataset": "iris", + "operation": "predict", + "stage": "prediction", + "sklearn_median_ms": 0.101745219, + "flow_median_ms": 0.025976, + "sklearn_iqr_ms": 0.000526344, + "flow_iqr_ms": 0.000390999, + "speedup": 3.9168932476131815, + "status": "flow win", + "parity_status": "approximately equivalent", + "prerequisites_met": true, + "tracking_issue": null + }, + { + "id": "KernelSVC_RBF/iris/predict_proba", + "algorithm": "KernelSVC_RBF", + "sklearn_estimator": "SVC", + "dataset": "iris", + "operation": "predict_proba", + "stage": "prediction", + "sklearn_median_ms": null, + "flow_median_ms": null, + "sklearn_iqr_ms": null, + "flow_iqr_ms": null, + "speedup": null, + "status": "not measured", + "parity_status": "approximately equivalent", + "prerequisites_met": false, + "tracking_issue": null, + "note": "not timed separately by the headline benchmark; shares the prediction stage kernel" + }, + { + "id": "KernelSVC_RBF/iris/decision_function", + "algorithm": "KernelSVC_RBF", + "sklearn_estimator": "SVC", + "dataset": "iris", + "operation": "decision_function", + "stage": "prediction", + "sklearn_median_ms": null, + "flow_median_ms": null, + "sklearn_iqr_ms": null, + "flow_iqr_ms": null, + "speedup": null, + "status": "not measured", + "parity_status": "approximately equivalent", + "prerequisites_met": false, + "tracking_issue": null, + "note": "not timed separately by the headline benchmark; shares the prediction stage kernel" + }, + { + "id": "DecisionTree/iris/fit", + "algorithm": "DecisionTree", + "sklearn_estimator": "DecisionTreeClassifier", + "dataset": "iris", + "operation": "fit", + "stage": "fit", + "sklearn_median_ms": 0.498908172, + "flow_median_ms": 0.035741001, + "sklearn_iqr_ms": 0.006084641, + "flow_iqr_ms": 0.000322, + "speedup": 13.958987102795469, + "status": "flow win", + "parity_status": "approximately equivalent", + "prerequisites_met": true, + "tracking_issue": null + }, + { + "id": "DecisionTree/iris/predict", + "algorithm": "DecisionTree", + "sklearn_estimator": "DecisionTreeClassifier", + "dataset": "iris", + "operation": "predict", + "stage": "prediction", + "sklearn_median_ms": 0.0606443086, + "flow_median_ms": 0.001046, + "sklearn_iqr_ms": 0.0005438105, + "flow_iqr_ms": 9.7e-05, + "speedup": 57.97735047801147, + "status": "flow win", + "parity_status": "approximately equivalent", + "prerequisites_met": true, + "tracking_issue": null + }, + { + "id": "DecisionTree/iris/predict_proba", + "algorithm": "DecisionTree", + "sklearn_estimator": "DecisionTreeClassifier", + "dataset": "iris", + "operation": "predict_proba", + "stage": "prediction", + "sklearn_median_ms": null, + "flow_median_ms": null, + "sklearn_iqr_ms": null, + "flow_iqr_ms": null, + "speedup": null, + "status": "not measured", + "parity_status": "approximately equivalent", + "prerequisites_met": false, + "tracking_issue": null, + "note": "not timed separately by the headline benchmark; shares the prediction stage kernel" + }, + { + "id": "RandomForest/iris/fit", + "algorithm": "RandomForest", + "sklearn_estimator": "RandomForestClassifier", + "dataset": "iris", + "operation": "fit", + "stage": "fit", + "sklearn_median_ms": 7.08113325, + "flow_median_ms": 1.04771697, + "sklearn_iqr_ms": 0.0568885, + "flow_iqr_ms": 0.290257037, + "speedup": 6.75863181828581, + "status": "flow win", + "parity_status": "approximately equivalent", + "prerequisites_met": true, + "tracking_issue": null + }, + { + "id": "RandomForest/iris/predict", + "algorithm": "RandomForest", + "sklearn_estimator": "RandomForestClassifier", + "dataset": "iris", + "operation": "predict", + "stage": "prediction", + "sklearn_median_ms": 0.465911281, + "flow_median_ms": 0.008199, + "sklearn_iqr_ms": 0.000123266, + "flow_iqr_ms": 0.000651, + "speedup": 56.82537882668618, + "status": "flow win", + "parity_status": "approximately equivalent", + "prerequisites_met": true, + "tracking_issue": null + }, + { + "id": "RandomForest/iris/predict_proba", + "algorithm": "RandomForest", + "sklearn_estimator": "RandomForestClassifier", + "dataset": "iris", + "operation": "predict_proba", + "stage": "prediction", + "sklearn_median_ms": null, + "flow_median_ms": null, + "sklearn_iqr_ms": null, + "flow_iqr_ms": null, + "speedup": null, + "status": "not measured", + "parity_status": "approximately equivalent", + "prerequisites_met": false, + "tracking_issue": null, + "note": "not timed separately by the headline benchmark; shares the prediction stage kernel" + }, + { + "id": "GaussianNB/iris/fit", + "algorithm": "GaussianNB", + "sklearn_estimator": "GaussianNB", + "dataset": "iris", + "operation": "fit", + "stage": "fit", + "sklearn_median_ms": 0.458299266, + "flow_median_ms": 0.005032, + "sklearn_iqr_ms": 0.001183953, + "flow_iqr_ms": 0.000343, + "speedup": 91.0769606518283, + "status": "flow win", + "parity_status": "parity verified", + "prerequisites_met": true, + "tracking_issue": null + }, + { + "id": "GaussianNB/iris/predict", + "algorithm": "GaussianNB", + "sklearn_estimator": "GaussianNB", + "dataset": "iris", + "operation": "predict", + "stage": "prediction", + "sklearn_median_ms": 0.0873740117, + "flow_median_ms": 0.000671, + "sklearn_iqr_ms": 0.0009356406, + "flow_iqr_ms": 0.000175, + "speedup": 130.2146225037258, + "status": "flow win", + "parity_status": "parity verified", + "prerequisites_met": true, + "tracking_issue": null + }, + { + "id": "GaussianNB/iris/predict_proba", + "algorithm": "GaussianNB", + "sklearn_estimator": "GaussianNB", + "dataset": "iris", + "operation": "predict_proba", + "stage": "prediction", + "sklearn_median_ms": null, + "flow_median_ms": null, + "sklearn_iqr_ms": null, + "flow_iqr_ms": null, + "speedup": null, + "status": "not measured", + "parity_status": "parity verified", + "prerequisites_met": false, + "tracking_issue": null, + "note": "not timed separately by the headline benchmark; shares the prediction stage kernel" + }, + { + "id": "KMeans/iris/fit", + "algorithm": "KMeans", + "sklearn_estimator": "KMeans", + "dataset": "iris", + "operation": "fit", + "stage": "fit", + "sklearn_median_ms": 4.22115375, + "flow_median_ms": 0.222369, + "sklearn_iqr_ms": 0.01843837, + "flow_iqr_ms": 0.002620995, + "speedup": 18.982653832143868, + "status": "flow win", + "parity_status": "approximately equivalent", + "prerequisites_met": true, + "tracking_issue": null + }, + { + "id": "KMeans/iris/predict", + "algorithm": "KMeans", + "sklearn_estimator": "KMeans", + "dataset": "iris", + "operation": "predict", + "stage": "prediction", + "sklearn_median_ms": 0.0834126797, + "flow_median_ms": 0.001077, + "sklearn_iqr_ms": 0.0001344336, + "flow_iqr_ms": 3.9e-05, + "speedup": 77.4490990714949, + "status": "flow win", + "parity_status": "approximately equivalent", + "prerequisites_met": true, + "tracking_issue": null + }, + { + "id": "KMeans/iris/transform", + "algorithm": "KMeans", + "sklearn_estimator": "KMeans", + "dataset": "iris", + "operation": "transform", + "stage": "prediction", + "sklearn_median_ms": null, + "flow_median_ms": null, + "sklearn_iqr_ms": null, + "flow_iqr_ms": null, + "speedup": null, + "status": "not measured", + "parity_status": "approximately equivalent", + "prerequisites_met": false, + "tracking_issue": null, + "note": "not timed separately by the headline benchmark; shares the prediction stage kernel" + }, + { + "id": "PCA/iris/fit", + "algorithm": "PCA", + "sklearn_estimator": "PCA", + "dataset": "iris", + "operation": "fit", + "stage": "fit", + "sklearn_median_ms": 0.193224453, + "flow_median_ms": 0.007572, + "sklearn_iqr_ms": 0.002061719, + "flow_iqr_ms": 0.000143, + "speedup": 25.518284865293186, + "status": "flow win", + "parity_status": "parity verified", + "prerequisites_met": true, + "tracking_issue": null + }, + { + "id": "PCA/iris/transform", + "algorithm": "PCA", + "sklearn_estimator": "PCA", + "dataset": "iris", + "operation": "transform", + "stage": "prediction", + "sklearn_median_ms": 0.0572420625, + "flow_median_ms": 0.001362, + "sklearn_iqr_ms": 0.0006014414, + "flow_iqr_ms": 0.000327, + "speedup": 42.027946035242294, + "status": "flow win", + "parity_status": "parity verified", + "prerequisites_met": true, + "tracking_issue": null + }, + { + "id": "LogisticRegression/digits/fit", + "algorithm": "LogisticRegression", + "sklearn_estimator": "LogisticRegression", + "dataset": "digits", + "operation": "fit", + "stage": "fit", + "sklearn_median_ms": 12.1236595, + "flow_median_ms": 4.01118994, + "sklearn_iqr_ms": 0.1280435, + "flow_iqr_ms": 0.058334112, + "speedup": 3.0224595896348903, + "status": "flow win", + "parity_status": "approximately equivalent", + "prerequisites_met": true, + "tracking_issue": null + }, + { + "id": "LogisticRegression/digits/predict", + "algorithm": "LogisticRegression", + "sklearn_estimator": "LogisticRegression", + "dataset": "digits", + "operation": "predict", + "stage": "prediction", + "sklearn_median_ms": 0.0979806484, + "flow_median_ms": 0.030834001, + "sklearn_iqr_ms": 0.0005349805, + "flow_iqr_ms": 0.000497999, + "speedup": 3.1776819492222237, + "status": "flow win", + "parity_status": "approximately equivalent", + "prerequisites_met": true, + "tracking_issue": null + }, + { + "id": "LogisticRegression/digits/predict_proba", + "algorithm": "LogisticRegression", + "sklearn_estimator": "LogisticRegression", + "dataset": "digits", + "operation": "predict_proba", + "stage": "prediction", + "sklearn_median_ms": null, + "flow_median_ms": null, + "sklearn_iqr_ms": null, + "flow_iqr_ms": null, + "speedup": null, + "status": "not measured", + "parity_status": "approximately equivalent", + "prerequisites_met": false, + "tracking_issue": null, + "note": "not timed separately by the headline benchmark; shares the prediction stage kernel" + }, + { + "id": "LogisticRegression/digits/decision_function", + "algorithm": "LogisticRegression", + "sklearn_estimator": "LogisticRegression", + "dataset": "digits", + "operation": "decision_function", + "stage": "prediction", + "sklearn_median_ms": null, + "flow_median_ms": null, + "sklearn_iqr_ms": null, + "flow_iqr_ms": null, + "speedup": null, + "status": "not measured", + "parity_status": "approximately equivalent", + "prerequisites_met": false, + "tracking_issue": null, + "note": "not timed separately by the headline benchmark; shares the prediction stage kernel" + }, + { + "id": "LinearSVC/digits/fit", + "algorithm": "LinearSVC", + "sklearn_estimator": "LinearSVC", + "dataset": "digits", + "operation": "fit", + "stage": "fit", + "sklearn_median_ms": 238.195115, + "flow_median_ms": 118.271774, + "sklearn_iqr_ms": 0.554734, + "flow_iqr_ms": 0.214775085, + "speedup": 2.0139641686612393, + "status": "flow win", + "parity_status": "approximately equivalent", + "prerequisites_met": true, + "tracking_issue": null + }, + { + "id": "LinearSVC/digits/predict", + "algorithm": "LinearSVC", + "sklearn_estimator": "LinearSVC", + "dataset": "digits", + "operation": "predict", + "stage": "prediction", + "sklearn_median_ms": 0.106933844, + "flow_median_ms": 0.176237002, + "sklearn_iqr_ms": 0.001332414, + "flow_iqr_ms": 0.002336994, + "speedup": 0.6067615925513757, + "status": "sklearn win", + "parity_status": "approximately equivalent", + "prerequisites_met": true, + "tracking_issue": 518 + }, + { + "id": "LinearSVC/digits/decision_function", + "algorithm": "LinearSVC", + "sklearn_estimator": "LinearSVC", + "dataset": "digits", + "operation": "decision_function", + "stage": "prediction", + "sklearn_median_ms": null, + "flow_median_ms": null, + "sklearn_iqr_ms": null, + "flow_iqr_ms": null, + "speedup": null, + "status": "not measured", + "parity_status": "approximately equivalent", + "prerequisites_met": false, + "tracking_issue": null, + "note": "not timed separately by the headline benchmark; shares the prediction stage kernel" + }, + { + "id": "KernelSVC_RBF/digits/fit", + "algorithm": "KernelSVC_RBF", + "sklearn_estimator": "SVC", + "dataset": "digits", + "operation": "fit", + "stage": "fit", + "sklearn_median_ms": 32.51705, + "flow_median_ms": 29.226963, + "sklearn_iqr_ms": 4.02546, + "flow_iqr_ms": 0.320962906, + "speedup": 1.1125702660245609, + "status": "flow win", + "parity_status": "approximately equivalent", + "prerequisites_met": true, + "tracking_issue": null + }, + { + "id": "KernelSVC_RBF/digits/predict", + "algorithm": "KernelSVC_RBF", + "sklearn_estimator": "SVC", + "dataset": "digits", + "operation": "predict", + "stage": "prediction", + "sklearn_median_ms": 17.52443, + "flow_median_ms": 4.08556509, + "sklearn_iqr_ms": 0.0393515, + "flow_iqr_ms": 0.115680933, + "speedup": 4.289352785712196, + "status": "flow win", + "parity_status": "approximately equivalent", + "prerequisites_met": true, + "tracking_issue": null + }, + { + "id": "KernelSVC_RBF/digits/predict_proba", + "algorithm": "KernelSVC_RBF", + "sklearn_estimator": "SVC", + "dataset": "digits", + "operation": "predict_proba", + "stage": "prediction", + "sklearn_median_ms": null, + "flow_median_ms": null, + "sklearn_iqr_ms": null, + "flow_iqr_ms": null, + "speedup": null, + "status": "not measured", + "parity_status": "approximately equivalent", + "prerequisites_met": false, + "tracking_issue": null, + "note": "not timed separately by the headline benchmark; shares the prediction stage kernel" + }, + { + "id": "KernelSVC_RBF/digits/decision_function", + "algorithm": "KernelSVC_RBF", + "sklearn_estimator": "SVC", + "dataset": "digits", + "operation": "decision_function", + "stage": "prediction", + "sklearn_median_ms": null, + "flow_median_ms": null, + "sklearn_iqr_ms": null, + "flow_iqr_ms": null, + "speedup": null, + "status": "not measured", + "parity_status": "approximately equivalent", + "prerequisites_met": false, + "tracking_issue": null, + "note": "not timed separately by the headline benchmark; shares the prediction stage kernel" + }, + { + "id": "DecisionTree/digits/fit", + "algorithm": "DecisionTree", + "sklearn_estimator": "DecisionTreeClassifier", + "dataset": "digits", + "operation": "fit", + "stage": "fit", + "sklearn_median_ms": 10.4754095, + "flow_median_ms": 6.4688859, + "sklearn_iqr_ms": 0.0412685, + "flow_iqr_ms": 0.013662815, + "speedup": 1.619352955352018, + "status": "flow win", + "parity_status": "approximately equivalent", + "prerequisites_met": true, + "tracking_issue": null + }, + { + "id": "DecisionTree/digits/predict", + "algorithm": "DecisionTree", + "sklearn_estimator": "DecisionTreeClassifier", + "dataset": "digits", + "operation": "predict", + "stage": "prediction", + "sklearn_median_ms": 0.0754109141, + "flow_median_ms": 0.034809999, + "sklearn_iqr_ms": 0.0007692325, + "flow_iqr_ms": 0.002744001, + "speedup": 2.1663578358620463, + "status": "flow win", + "parity_status": "approximately equivalent", + "prerequisites_met": true, + "tracking_issue": null + }, + { + "id": "DecisionTree/digits/predict_proba", + "algorithm": "DecisionTree", + "sklearn_estimator": "DecisionTreeClassifier", + "dataset": "digits", + "operation": "predict_proba", + "stage": "prediction", + "sklearn_median_ms": null, + "flow_median_ms": null, + "sklearn_iqr_ms": null, + "flow_iqr_ms": null, + "speedup": null, + "status": "not measured", + "parity_status": "approximately equivalent", + "prerequisites_met": false, + "tracking_issue": null, + "note": "not timed separately by the headline benchmark; shares the prediction stage kernel" + }, + { + "id": "RandomForest/digits/fit", + "algorithm": "RandomForest", + "sklearn_estimator": "RandomForestClassifier", + "dataset": "digits", + "operation": "fit", + "stage": "fit", + "sklearn_median_ms": 18.7362865, + "flow_median_ms": 12.2515287, + "sklearn_iqr_ms": 0.0804385, + "flow_iqr_ms": 3.04496956, + "speedup": 1.5293019311132985, + "status": "flow win", + "parity_status": "approximately equivalent", + "prerequisites_met": true, + "tracking_issue": null + }, + { + "id": "RandomForest/digits/predict", + "algorithm": "RandomForest", + "sklearn_estimator": "RandomForestClassifier", + "dataset": "digits", + "operation": "predict", + "stage": "prediction", + "sklearn_median_ms": 0.705887656, + "flow_median_ms": 0.253333986, + "sklearn_iqr_ms": 0.006308844, + "flow_iqr_ms": 0.003629982, + "speedup": 2.7863914634809404, + "status": "flow win", + "parity_status": "approximately equivalent", + "prerequisites_met": true, + "tracking_issue": null + }, + { + "id": "RandomForest/digits/predict_proba", + "algorithm": "RandomForest", + "sklearn_estimator": "RandomForestClassifier", + "dataset": "digits", + "operation": "predict_proba", + "stage": "prediction", + "sklearn_median_ms": null, + "flow_median_ms": null, + "sklearn_iqr_ms": null, + "flow_iqr_ms": null, + "speedup": null, + "status": "not measured", + "parity_status": "approximately equivalent", + "prerequisites_met": false, + "tracking_issue": null, + "note": "not timed separately by the headline benchmark; shares the prediction stage kernel" + }, + { + "id": "GaussianNB/digits/fit", + "algorithm": "GaussianNB", + "sklearn_estimator": "GaussianNB", + "dataset": "digits", + "operation": "fit", + "stage": "fit", + "sklearn_median_ms": 0.955796563, + "flow_median_ms": 0.168266997, + "sklearn_iqr_ms": 0.010119219, + "flow_iqr_ms": 0.003013998, + "speedup": 5.680237836537845, + "status": "flow win", + "parity_status": "parity verified", + "prerequisites_met": true, + "tracking_issue": null + }, + { + "id": "GaussianNB/digits/predict", + "algorithm": "GaussianNB", + "sklearn_estimator": "GaussianNB", + "dataset": "digits", + "operation": "predict", + "stage": "prediction", + "sklearn_median_ms": 0.392142016, + "flow_median_ms": 0.081519, + "sklearn_iqr_ms": 0.006483219, + "flow_iqr_ms": 0.000372998, + "speedup": 4.810437026950773, + "status": "flow win", + "parity_status": "parity verified", + "prerequisites_met": true, + "tracking_issue": null + }, + { + "id": "GaussianNB/digits/predict_proba", + "algorithm": "GaussianNB", + "sklearn_estimator": "GaussianNB", + "dataset": "digits", + "operation": "predict_proba", + "stage": "prediction", + "sklearn_median_ms": null, + "flow_median_ms": null, + "sklearn_iqr_ms": null, + "flow_iqr_ms": null, + "speedup": null, + "status": "not measured", + "parity_status": "parity verified", + "prerequisites_met": false, + "tracking_issue": null, + "note": "not timed separately by the headline benchmark; shares the prediction stage kernel" + }, + { + "id": "KMeans/digits/fit", + "algorithm": "KMeans", + "sklearn_estimator": "KMeans", + "dataset": "digits", + "operation": "fit", + "stage": "fit", + "sklearn_median_ms": 32.829742, + "flow_median_ms": 20.6755772, + "sklearn_iqr_ms": 0.812873, + "flow_iqr_ms": 0.071016312, + "speedup": 1.587851293457481, + "status": "flow win", + "parity_status": "approximately equivalent", + "prerequisites_met": true, + "tracking_issue": null + }, + { + "id": "KMeans/digits/predict", + "algorithm": "KMeans", + "sklearn_estimator": "KMeans", + "dataset": "digits", + "operation": "predict", + "stage": "prediction", + "sklearn_median_ms": 0.102131062, + "flow_median_ms": 0.029771, + "sklearn_iqr_ms": 0.001144445, + "flow_iqr_ms": 0.000211998, + "speedup": 3.4305553054986397, + "status": "flow win", + "parity_status": "approximately equivalent", + "prerequisites_met": true, + "tracking_issue": null + }, + { + "id": "KMeans/digits/transform", + "algorithm": "KMeans", + "sklearn_estimator": "KMeans", + "dataset": "digits", + "operation": "transform", + "stage": "prediction", + "sklearn_median_ms": null, + "flow_median_ms": null, + "sklearn_iqr_ms": null, + "flow_iqr_ms": null, + "speedup": null, + "status": "not measured", + "parity_status": "approximately equivalent", + "prerequisites_met": false, + "tracking_issue": null, + "note": "not timed separately by the headline benchmark; shares the prediction stage kernel" + }, + { + "id": "Ridge/diabetes/fit", + "algorithm": "Ridge", + "sklearn_estimator": "Ridge", + "dataset": "diabetes", + "operation": "fit", + "stage": "fit", + "sklearn_median_ms": 0.388972422, + "flow_median_ms": 0.04439, + "sklearn_iqr_ms": 0.002154875, + "flow_iqr_ms": 0.001387998, + "speedup": 8.762613696778553, + "status": "flow win", + "parity_status": "approximately equivalent", + "prerequisites_met": true, + "tracking_issue": null + }, + { + "id": "Ridge/diabetes/predict", + "algorithm": "Ridge", + "sklearn_estimator": "Ridge", + "dataset": "diabetes", + "operation": "predict", + "stage": "prediction", + "sklearn_median_ms": 0.0512225, + "flow_median_ms": 0.001593, + "sklearn_iqr_ms": 0.0005726348, + "flow_iqr_ms": 0.000262, + "speedup": 32.15473948524796, + "status": "flow win", + "parity_status": "approximately equivalent", + "prerequisites_met": true, + "tracking_issue": null + }, + { + "id": "Lasso/diabetes/fit", + "algorithm": "Lasso", + "sklearn_estimator": "Lasso", + "dataset": "diabetes", + "operation": "fit", + "stage": "fit", + "sklearn_median_ms": 0.416835125, + "flow_median_ms": 0.049036, + "sklearn_iqr_ms": 0.003141016, + "flow_iqr_ms": 0.001520001, + "speedup": 8.500593951382656, + "status": "flow win", + "parity_status": "approximately equivalent", + "prerequisites_met": true, + "tracking_issue": null + }, + { + "id": "Lasso/diabetes/predict", + "algorithm": "Lasso", + "sklearn_estimator": "Lasso", + "dataset": "diabetes", + "operation": "predict", + "stage": "prediction", + "sklearn_median_ms": 0.0547876523, + "flow_median_ms": 0.001203, + "sklearn_iqr_ms": 0.0005019356, + "flow_iqr_ms": 0.000194, + "speedup": 45.54252061512884, + "status": "flow win", + "parity_status": "approximately equivalent", + "prerequisites_met": true, + "tracking_issue": null + }, + { + "id": "LinearRegression/diabetes/fit", + "algorithm": "LinearRegression", + "sklearn_estimator": "LinearRegression", + "dataset": "diabetes", + "operation": "fit", + "stage": "fit", + "sklearn_median_ms": 0.350535297, + "flow_median_ms": 0.042238999, + "sklearn_iqr_ms": 0.001480359, + "flow_iqr_ms": 0.000530001, + "speedup": 8.29885426498862, + "status": "flow win", + "parity_status": "parity verified", + "prerequisites_met": true, + "tracking_issue": null + }, + { + "id": "LinearRegression/diabetes/predict", + "algorithm": "LinearRegression", + "sklearn_estimator": "LinearRegression", + "dataset": "diabetes", + "operation": "predict", + "stage": "prediction", + "sklearn_median_ms": 0.0507998848, + "flow_median_ms": 0.000507, + "sklearn_iqr_ms": 0.0007798164, + "flow_iqr_ms": 3.9e-05, + "speedup": 100.19701143984221, + "status": "flow win", + "parity_status": "parity verified", + "prerequisites_met": true, + "tracking_issue": null + }, + { + "id": "KernelRidge_RBF/diabetes/fit", + "algorithm": "KernelRidge_RBF", + "sklearn_estimator": "KernelRidge", + "dataset": "diabetes", + "operation": "fit", + "stage": "fit", + "sklearn_median_ms": 6.00003875, + "flow_median_ms": 1.14915395, + "sklearn_iqr_ms": 0.00080075, + "flow_iqr_ms": 0.018522024, + "speedup": 5.221266262888449, + "status": "flow win", + "parity_status": "parity verified", + "prerequisites_met": true, + "tracking_issue": null + }, + { + "id": "KernelRidge_RBF/diabetes/predict", + "algorithm": "KernelRidge_RBF", + "sklearn_estimator": "KernelRidge", + "dataset": "diabetes", + "operation": "predict", + "stage": "prediction", + "sklearn_median_ms": 0.429176906, + "flow_median_ms": 0.122539997, + "sklearn_iqr_ms": 0.000620625, + "flow_iqr_ms": 0.003957003, + "speedup": 3.5023414110251694, + "status": "flow win", + "parity_status": "parity verified", + "prerequisites_met": true, + "tracking_issue": null + } + ] +} diff --git a/benchmarks/publish_headline_v2.py b/benchmarks/publish_headline_v2.py index 28e73d3..f9030a1 100644 --- a/benchmarks/publish_headline_v2.py +++ b/benchmarks/publish_headline_v2.py @@ -3,6 +3,7 @@ from __future__ import annotations import argparse +import hashlib import json import shutil from pathlib import Path @@ -16,12 +17,14 @@ HISTORY = BENCH / "disparity_history.json" SCALED = BENCH / "scaled_ci_history.json" ESTIMATORS = BENCH / "estimator_comparison.json" +OPERATIONS = BENCH / "operation_rows.json" DOC_RESULT = DOCS / "headline-result-v2.json" DOC_ARCH = DOCS / "architecture-performance-map.json" DOC_DISPARITY = DOCS / "disparity-report.json" DOC_HISTORY = DOCS / "disparity-history.json" DOC_SCALED = DOCS / "scaled-ci-history.json" DOC_ESTIMATORS = DOCS / "estimator-comparison.json" +DOC_OPERATIONS = DOCS / "operation-rows.json" def validate_headline(result: dict) -> None: @@ -93,6 +96,24 @@ def validate_estimators(payload: dict) -> None: raise SystemExit("the estimator comparison must carry the contract it was measured under") +def validate_operations(payload: dict, result: dict) -> None: + rows = payload["rows"] + counts = payload["counts"] + if counts["operation_rows"] != len(rows): + raise SystemExit("operation rows count disagrees with its own rows") + measured = [r for r in rows if r["status"] != "not measured"] + if counts["measured_operations"] != len(measured): + raise SystemExit("operation rows measured count disagrees with its own rows") + if counts["flow_wins"] + counts["sklearn_wins"] + counts["ties"] + counts["parity_unresolved"] + counts["measurement_unresolved"] != len(measured): + raise SystemExit("operation row status counts do not add up to the measured operations") + for h in result["rows"]: + ops = [r for r in measured if r["algorithm"] == h["algorithm"] and r["dataset"] == h["dataset"]] + if sorted(r["stage"] for r in ops) != ["fit", "prediction"]: + raise SystemExit(f"{h['algorithm']}/{h['dataset']} lacks a fit row and a prediction row in operation_rows.json") + if payload["source_result_sha256"] != hashlib.sha256(RESULT.read_bytes()).hexdigest(): + raise SystemExit("operation_rows.json was built from a different headline result") + + def main() -> int: parser = argparse.ArgumentParser() parser.add_argument("--check", action="store_true") @@ -114,6 +135,11 @@ def main() -> int: validate_estimators(estimators) elif not args.check: raise SystemExit("estimator_comparison.json must be present before Pages publication") + operations = json.loads(OPERATIONS.read_text()) if OPERATIONS.exists() else None + if operations is not None: + validate_operations(operations, result) + elif not args.check: + raise SystemExit("operation_rows.json must be generated before Pages publication") scaled = json.loads(SCALED.read_text()) if SCALED.exists() else None if scaled is not None: validate_scaled(scaled) @@ -131,6 +157,7 @@ def main() -> int: shutil.copyfile(HISTORY, DOC_HISTORY) shutil.copyfile(SCALED, DOC_SCALED) shutil.copyfile(ESTIMATORS, DOC_ESTIMATORS) + shutil.copyfile(OPERATIONS, DOC_OPERATIONS) counts = result["counts"] print(f"published evidence: {counts['flow_wins']}/{counts['eligible_comparisons']} Flow wins; {disparity['counts']['rows_with_tracked_disparity']} rows with tracked disparities; {len(history['snapshots'])} history snapshots; scaled matrix over {scaled['counts']['runs']} runs; {estimators['counts']['compared']} estimators ranked") else: diff --git a/benchmarks/test_generate_operation_rows.py b/benchmarks/test_generate_operation_rows.py new file mode 100644 index 0000000..15df2fc --- /dev/null +++ b/benchmarks/test_generate_operation_rows.py @@ -0,0 +1,88 @@ +#!/usr/bin/env python3 +"""Operation rows must expose a losing operation that an estimator total hides. + +Issue #489. The synthetic result below is a Flow win in total (fit 10x, predict +0.5x), which is the shape of LinearSVC Digits in the frozen headline. The +operation rows must list the loss, link its issue, and treat unresolved timings +and parity as unresolved rather than as wins. +""" +from __future__ import annotations + +import json +import subprocess +import sys +import tempfile +from pathlib import Path + +from generate_headline_summary import summarize +from generate_operation_rows import build + +BENCH = Path(__file__).resolve().parent + + +def headline_row(algorithm, dataset, fit_sk, fit_fl, pred_sk, pred_fl, parity="parity verified", measurement="resolved"): + return { + "algorithm": algorithm, "dataset": dataset, "metric": "accuracy", "timing_unit": "ms", + "sklearn_fit_ms": fit_sk, "flow_fit_ms": fit_fl, "sklearn_pred_ms": pred_sk, "flow_pred_ms": pred_fl, + "sklearn_fit_iqr_ms": 0.1, "flow_fit_iqr_ms": 0.1, "sklearn_pred_iqr_ms": 0.01, "flow_pred_iqr_ms": 0.01, + "sklearn_ms": fit_sk + pred_sk, "flow_ms": fit_fl + pred_fl, + "parity_status": parity, "measurement_status": measurement, "comparable": True, "environment_id": "env", + } + + +INVENTORY = [ + {"estimator": "LinearSVC", "operation": op} for op in ("fit", "predict", "decision_function") +] + [{"estimator": "PCA", "operation": op} for op in ("fit", "transform")] + + +def main() -> int: + failures = 0 + + def check(name, ok): + nonlocal failures + print(("PASS " if ok else "FAIL ") + name) + failures += 0 if ok else 1 + + rows = [ + headline_row("LinearSVC", "digits", 200.0, 20.0, 0.10, 0.20), + headline_row("PCA", "iris", 2.0, 1.0, 0.4, 0.2), + headline_row("LinearSVC", "iris", 3.0, 1.0, 0.1, 0.0), + headline_row("LinearSVC", "wine", 3.0, 1.0, 0.1, 0.05, parity="parity unresolved"), + ] + result = summarize(rows) + result_bytes = json.dumps(result).encode() + check("total hides the loss: LinearSVC digits is a total Flow win", + next(r for r in result["rows"] if r["algorithm"] == "LinearSVC" and r["dataset"] == "digits")["classification"] == "flow win") + + doc = build(result_bytes, INVENTORY, {"LinearSVC/digits/predict": 518}) + by_id = {r["id"]: r for r in doc["rows"]} + check("fit row is a win", by_id["LinearSVC/digits/fit"]["status"] == "flow win") + loss = by_id["LinearSVC/digits/predict"] + check("predict loss is listed", loss["status"] == "sklearn win" and abs(loss["speedup"] - 0.5) < 1e-9) + check("predict loss links its issue", loss["tracking_issue"] == 518) + check("PCA prediction stage is transform", "PCA/iris/transform" in by_id and "PCA/iris/predict" not in by_id) + check("zero-resolution predict is unresolved, not a win", by_id["LinearSVC/iris/predict"]["status"] == "measurement unresolved") + check("parity-unresolved row gives unresolved operations", + by_id["LinearSVC/wine/fit"]["status"] == "parity unresolved" and not by_id["LinearSVC/wine/fit"]["prerequisites_met"]) + check("untimed decision_function is listed as not measured", by_id["LinearSVC/digits/decision_function"]["status"] == "not measured") + check("exit criterion is false while a loss exists", doc["every_measured_operation_wins"] is False) + check("loss without an issue is counted", + build(result_bytes, INVENTORY, {})["counts"]["losses_without_tracking_issue"] == 1) + check("rows carry median and IQR for both sides", + all(loss[k] is not None for k in ("sklearn_median_ms", "flow_median_ms", "sklearn_iqr_ms", "flow_iqr_ms"))) + + # The committed file must match the committed result, and a stale one must fail. + committed = subprocess.run([sys.executable, str(BENCH / "generate_operation_rows.py"), "--check"], capture_output=True, text=True) + check("committed operation_rows.json matches the headline result", committed.returncode == 0) + with tempfile.TemporaryDirectory() as tmp: + stale = Path(tmp) / "operation_rows.json" + d = json.loads((BENCH / "operation_rows.json").read_text()) + d["rows"][0]["speedup"] = 123.0 + stale.write_text(json.dumps(d, indent=2) + "\n") + out = subprocess.run([sys.executable, str(BENCH / "generate_operation_rows.py"), "--check", "--output", str(stale)], capture_output=True, text=True) + check("an edited operation_rows.json is rejected", out.returncode == 1) + return 1 if failures else 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/docs/benchmarks.html b/docs/benchmarks.html index f843df0..4477643 100644 --- a/docs/benchmarks.html +++ b/docs/benchmarks.html @@ -36,4 +36,27 @@ "The last column names which side's absolute time moved more when a row's speedup changed by over 10%.

"; host.innerHTML=html; }).catch(()=>{}); -fetch('scaled-ci-history.json').then(r=>r.json()).then(h=>{const c=h.counts,tb=document.getElementById('scaled-rows');document.getElementById('scaled-summary').textContent=`Across ${c.runs} consecutive CI runs, Flow wins ${c.rows_won_in_every_run} of the ${c.rows} rows in every one of them. The remaining ${c.rows_lost_in_at_least_one_run} dipped below 1x in at least one run, and every one of those is at 1000 samples.`;h.rows.slice().sort((a,b)=>a.median_speedup-b.median_speedup).forEach(r=>{const tr=document.createElement('tr');const cells=[[r.algorithm.replace(/_/g,' '),''],[r.rows,'num'],[r.features,'num'],[`${r.runs_won} / ${r.runs_observed}`,r.runs_won===r.runs_observed?'num win':'num loss'],[`${r.median_speedup.toFixed(2)}x`,'num'],[`${r.min_speedup.toFixed(2)} to ${r.max_speedup.toFixed(2)}`,'num']];cells.forEach(([t,cl])=>{const td=document.createElement('td');if(cl)td.className=cl;td.textContent=t;tr.appendChild(td)});tb.appendChild(tr)})});fetch('estimator-comparison.json').then(r=>r.json()).then(e=>{const c=e.counts;const byStatus=t=>e.rows.filter(r=>r.status===t).length;document.getElementById('est-ranked').textContent=c.compared;document.getElementById('est-wins').textContent=`${c.flow_wins} / ${c.compared}`;document.getElementById('est-shape').textContent=byStatus('different_shape');document.getElementById('est-only').textContent=byStatus('flow_only');document.getElementById('est-note').textContent=e.note||'';const stub=e.rows.filter(r=>r.status==='simplified');if(stub.length){document.getElementById('est-excluded').textContent=`${stub.length} more are excluded from the count because the implementation's own comments call it simplified: ${stub.map(r=>r.flow_estimator.replace(/_/g,' ')).join(', ')}. `+`Timing a stand-in against scikit-learn's algorithm compares two different things, and three of those four would otherwise have been the widest wins on the page.`}const tb=document.getElementById('est-rows');e.rows.filter(r=>r.status==='ok'&&r.speedup!=null).sort((a,b)=>a.speedup-b.speedup).forEach(r=>{const tr=document.createElement('tr');const cells=[[r.flow_estimator.replace(/_/g,' '),''],[r.sklearn_estimator,''],[r.flow_ms.toFixed(3),'num'],[r.sklearn_ms.toFixed(3),'num'],[`${r.speedup.toFixed(2)}x`,r.speedup>=1?'num win':'num loss']];cells.forEach(([t,cl])=>{const td=document.createElement('td');if(cl)td.className=cl;td.textContent=t;tr.appendChild(td)});tb.appendChild(tr)})}); \ No newline at end of file +fetch('scaled-ci-history.json').then(r=>r.json()).then(h=>{const c=h.counts,tb=document.getElementById('scaled-rows');document.getElementById('scaled-summary').textContent=`Across ${c.runs} consecutive CI runs, Flow wins ${c.rows_won_in_every_run} of the ${c.rows} rows in every one of them. The remaining ${c.rows_lost_in_at_least_one_run} dipped below 1x in at least one run, and every one of those is at 1000 samples.`;h.rows.slice().sort((a,b)=>a.median_speedup-b.median_speedup).forEach(r=>{const tr=document.createElement('tr');const cells=[[r.algorithm.replace(/_/g,' '),''],[r.rows,'num'],[r.features,'num'],[`${r.runs_won} / ${r.runs_observed}`,r.runs_won===r.runs_observed?'num win':'num loss'],[`${r.median_speedup.toFixed(2)}x`,'num'],[`${r.min_speedup.toFixed(2)} to ${r.max_speedup.toFixed(2)}`,'num']];cells.forEach(([t,cl])=>{const td=document.createElement('td');if(cl)td.className=cl;td.textContent=t;tr.appendChild(td)});tb.appendChild(tr)})});fetch('estimator-comparison.json').then(r=>r.json()).then(e=>{const c=e.counts;const byStatus=t=>e.rows.filter(r=>r.status===t).length;document.getElementById('est-ranked').textContent=c.compared;document.getElementById('est-wins').textContent=`${c.flow_wins} / ${c.compared}`;document.getElementById('est-shape').textContent=byStatus('different_shape');document.getElementById('est-only').textContent=byStatus('flow_only');document.getElementById('est-note').textContent=e.note||'';const stub=e.rows.filter(r=>r.status==='simplified');if(stub.length){document.getElementById('est-excluded').textContent=`${stub.length} more are excluded from the count because the implementation's own comments call it simplified: ${stub.map(r=>r.flow_estimator.replace(/_/g,' ')).join(', ')}. `+`Timing a stand-in against scikit-learn's algorithm compares two different things, and three of those four would otherwise have been the widest wins on the page.`}const tb=document.getElementById('est-rows');e.rows.filter(r=>r.status==='ok'&&r.speedup!=null).sort((a,b)=>a.speedup-b.speedup).forEach(r=>{const tr=document.createElement('tr');const cells=[[r.flow_estimator.replace(/_/g,' '),''],[r.sklearn_estimator,''],[r.flow_ms.toFixed(3),'num'],[r.sklearn_ms.toFixed(3),'num'],[`${r.speedup.toFixed(2)}x`,r.speedup>=1?'num win':'num loss']];cells.forEach(([t,cl])=>{const td=document.createElement('td');if(cl)td.className=cl;td.textContent=t;tr.appendChild(td)});tb.appendChild(tr)})}); + \ No newline at end of file