diff --git a/experiments/nautilus_worker_headroom/README.md b/experiments/nautilus_worker_headroom/README.md new file mode 100644 index 0000000..59bff5a --- /dev/null +++ b/experiments/nautilus_worker_headroom/README.md @@ -0,0 +1,35 @@ +# How much fit time can two-worker scheduling recover? + +Keep the native scheduler on this phase 0a fixture. Across 14 traced fits, an ideal two-worker schedule could save at most **0.39–0.51% of complete fit wall time** with the measured per-proposal service times. The predeclared threshold for a live scheduling experiment was 5%. Even removing the entire submit-to-collection interval would save only 0.65–1.44%. [Phase issue and decision rule](https://github.com/PyAutoLabs/autofit_profiling/issues/28). + +The source was a 5D analytic Gaussian with two persistent likelihood workers, native update interval 200 and logical batches of 100. Fixed and parameter-correlated costs each have three seeds per adapter. The synthetic random-cost case has one. Each row below gives the range across its seeds. All percentages in the last three columns use the full **traced** fit as denominator. + +| Adapter | Cost | Fits | Worker occupancy inside maps | Entire map | Ideal scheduling ceiling | Single-point chunk prediction | +|---|---|---:|---:|---:|---:|---:| +| direct | fixed | 3 | 29.7–32.7% | 0.65–0.72% | 0.44–0.51% | 0.003–0.005% | +| direct | correlated | 3 | 44.1–45.6% | 0.76–0.81% | 0.43–0.44% | 0.013–0.015% | +| direct | random | 1 | 68.3% | 1.38% | 0.44% | 0.033% | +| pyautofit | fixed | 3 | 54.6–56.0% | 0.92–0.96% | 0.41–0.43% | 0.007–0.014% | +| pyautofit | correlated | 3 | 59.0–60.7% | 0.98–1.01% | 0.40–0.41% | 0.010–0.019% | +| pyautofit | random | 1 | 72.6% | 1.44% | 0.39% | 0.023% | + +## Reading the estimates + +Worker occupancy is the sum of elapsed per-proposal service times divided by the capacity of two workers over the observed map interval. It includes time a worker might be descheduled during service. The map occupies a small fraction of the total fit, so even low occupancy can coexist with little wall time to recover. + +For each batch, the replay measures wall time from the common submission timestamp to collection of the ordered results. With two workers and indivisible proposals, the earliest possible completion is bounded below by the longer of the slowest individual service time and half the sum of all service times. Subtracting that floor from the map interval deliberately lets dispatch, queue gaps and collection overhead vanish. The resulting bound is optimistic and can exceed the gain physically attainable by chunk scheduling. Summation uses disjoint map intervals and keeps parent work, proposal order and the complete-batch adaptation boundary fixed. + +The last column compares two zero-overhead queue simulations. Each assigns the next contiguous chunk to the earliest available worker. One uses the native CPython chunk size of 13, the other uses one proposal per chunk. Each simulation reuses the same recorded service intervals and assumes they are independent of assignment. The predicted reductions span 0.003–0.033% of full-fit wall. Actual fine-grained dispatch would incur overhead. The records provide no measured speedup for either a changed scheduler or asynchronous adaptation. + +## Inputs and verification + +The manifest selects all 14 included two-worker traced fits. All 356 logical batches and 35,600 proposal IDs reconciled against the native likelihood counts. The two original compressed examples remain in the baseline results. The other 12 original traces are included in this directory so the full replay runs from a clean checkout. Every input is checked against its compressed SHA-256 in the pinned manifest. The replay also checks timestamp order, nonoverlap, one result per proposal, assignment of contiguous native chunks to individual workers and the two-worker lower bound. [Baseline manifest and controls](../../results/analytic_gaussian/nautilus/pilot_runs.json) · [Per-fit replay including raw nanosecond totals](result.json). + +Run from the producer root with Python 3.10 or later. + +```sh +python3 experiments/nautilus_worker_headroom/replay.py +python3 experiments/nautilus_worker_headroom/replay.py --examples-only +``` + +An optional `--archive PATH` verifies original run-ID directories against the same manifest. The replay starts no workers or samplers. The conclusion applies to the recorded cheap two-worker fits on the shared WSL host. An expensive or more variable target requires its own map share before extrapolation. The phase 0b dimension and accuracy work remains open. [Canonical profiling producer task](https://github.com/PyAutoLabs/PyAutoPulse/blob/main/tasks/autofit_profiling_bootstrap.md). diff --git a/experiments/nautilus_worker_headroom/replay.py b/experiments/nautilus_worker_headroom/replay.py new file mode 100644 index 0000000..ea4ec24 --- /dev/null +++ b/experiments/nautilus_worker_headroom/replay.py @@ -0,0 +1,134 @@ +"""Replay two-worker phase 0a batches using their recorded service times.""" + +import argparse +import gzip +import hashlib +import json +import math +import sys +from pathlib import Path + +ROOT = Path(__file__).resolve().parents[2] +HERE = Path(__file__).resolve().parent +BASELINE = ROOT / "results" / "analytic_gaussian" / "nautilus" +MANIFEST_SHA256 = "7370d4a1a86d216e7c100c1b1f601ec329230bb84a5821ae451870dfbc04ec60" +sys.path.insert(0, str(ROOT / "scripts" / "misc")) + +from profiling.nautilus_trace import reconcile + + +def greedy_makespan(durations, chunk): + """Assign the next contiguous chunk to the first of two available workers.""" + free = [0, 0] + for i in range(0, len(durations), chunk): + worker = 0 if free[0] <= free[1] else 1 + free[worker] += sum(durations[i : i + chunk]) + return max(free) + + +def replay_batch(events): + events = sorted(events, key=lambda e: e["id"][1]) + submits = {e["submit_ns"] for e in events} + collects = {e["collect_ns"] for e in events} + if len(submits) != 1 or len(collects) != 1 or len({e["pid"] for e in events}) != 2: + raise ValueError("Expected one pooled map with two observed workers") + # CPython Pool.map_async defaults to ceil(n / (4 * workers)). + chunk = math.ceil(len(events) / 8) + for i in range(0, len(events), chunk): + if len({e["pid"] for e in events[i : i + chunk]}) != 1: + raise ValueError("Observed assignments split a native-sized chunk") + durations = [e["finish_ns"] - e["start_ns"] for e in events] + window = max(collects) - min(submits) + span = max(e["finish_ns"] for e in events) - min(e["start_ns"] for e in events) + floor = max(max(durations), (sum(durations) + 1) // 2) + native = greedy_makespan(durations, chunk) + single = greedy_makespan(durations, 1) + if not (floor <= span <= window and floor <= min(native, single)): + raise ValueError("Impossible two-worker schedule") + return dict( + map_ns=window, + service_ns=sum(durations), + floor_ns=floor, + edge_ns=window - span, + native_model_ns=native, + single_model_ns=single, + ) + + +def replay(record, compressed): + result, case = record["result"], record["case"] + sha = hashlib.sha256(compressed).hexdigest() + if sha != result["timeline"]["sha256"]: + raise ValueError(f"Wrong timeline for {case['id']}") + trace = json.loads(gzip.decompress(compressed)) + batches = trace["batches"] + by_batch = reconcile(trace["events"], batches) + ordered = sorted(batches, key=lambda b: b["start_ns"]) + if len(by_batch) != len(batches) or any( + a["finish_ns"] > b["start_ns"] for a, b in zip(ordered, ordered[1:]) + ): + raise ValueError("Missing, duplicate or overlapping batch windows") + if len(trace["events"]) != result["n_like"]: + raise ValueError("Proposal count disagrees with native likelihood count") + windows = [replay_batch(by_batch[b["id"]]) for b in ordered] + totals = {key: sum(batch[key] for batch in windows) for key in windows[0]} + wall_ns = result["wall_s"] * 1e9 + if totals["map_ns"] > wall_ns: + raise ValueError("Map windows exceed full fit") + return { + "id": case["id"], + "adapter": case["adapter"], + "cost": case["cost_profile"], + "seed": case["seed"], + "native_update": result["resolved_constructor"]["n_update"], + "source_sha256": sha, + "fit_wall_s": result["wall_s"], + "batches": len(windows), + "proposals": len(trace["events"]), + **totals, + "observed_occupancy_pct": 50 * totals["service_ns"] / totals["map_ns"], + "all_map_pct_fit": 100 * totals["map_ns"] / wall_ns, + "scheduling_ceiling_pct_fit": 100 * (totals["map_ns"] - totals["floor_ns"]) / wall_ns, + "single_vs_native_model_pct_fit": 100 + * (totals["native_model_ns"] - totals["single_model_ns"]) + / wall_ns, + } + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("--archive", type=Path, help="read original run-ID directories") + parser.add_argument( + "--examples-only", action="store_true", help="replay the two original public examples" + ) + args = parser.parse_args() + raw = (BASELINE / "pilot_runs.json").read_bytes() + if hashlib.sha256(raw).hexdigest() != MANIFEST_SHA256: + raise ValueError("Phase 0a manifest changed") + examples = { + hashlib.sha256(p.read_bytes()).hexdigest(): p for p in BASELINE.glob("*-timeline.json.gz") + } + rows = [] + for record in json.loads(raw)["runs"]: + case = record["case"] + if not ( + case.get("included_in_analysis") and case["workers"] == 2 and case["trace"] == "on" + ): + continue + if case["status"] != "success": + raise ValueError(f"Incomplete selected case: {case['id']}") + path = examples.get(record["result"]["timeline"]["sha256"]) + if args.examples_only and path is None: + continue + if args.archive: + path = args.archive / case["id"] / "timeline.json.gz" + elif path is None: + path = HERE / "timelines" / (case["id"] + ".json.gz") + rows.append(replay(record, path.read_bytes())) + if len(rows) != (2 if args.examples_only else 14): + raise ValueError("Unexpected selected case count") + print(json.dumps({"manifest_sha256": MANIFEST_SHA256, "runs": rows}, indent=2, allow_nan=False)) + + +if __name__ == "__main__": + main() diff --git a/experiments/nautilus_worker_headroom/result.json b/experiments/nautilus_worker_headroom/result.json new file mode 100644 index 0000000..cc5e236 --- /dev/null +++ b/experiments/nautilus_worker_headroom/result.json @@ -0,0 +1,299 @@ +{ + "manifest_sha256": "7370d4a1a86d216e7c100c1b1f601ec329230bb84a5821ae451870dfbc04ec60", + "runs": [ + { + "id": "run-013", + "adapter": "direct", + "cost": "correlated", + "seed": 0, + "native_update": 200, + "source_sha256": "2ab0eb562231f43c808bc20154303088c800fdf686c2855f3c7822d8f75885c3", + "fit_wall_s": 10.16088074999999, + "batches": 26, + "proposals": 2600, + "map_ns": 79603052, + "service_ns": 70359589, + "floor_ns": 35179797, + "edge_ns": 27752793, + "native_model_ns": 37018104, + "single_model_ns": 35616108, + "observed_occupancy_pct": 44.194027259155845, + "all_map_pct_fit": 0.7834266926122528, + "scheduling_ceiling_pct_fit": 0.43719886191952445, + "single_vs_native_model_pct_fit": 0.013797977109415454 + }, + { + "id": "run-015", + "adapter": "pyautofit", + "cost": "correlated", + "seed": 0, + "native_update": 200, + "source_sha256": "186411f3a0f73efd2aa2fe71e88cde3235603aae617f834760f447ae464a9f71", + "fit_wall_s": 13.538342188000001, + "batches": 26, + "proposals": 2600, + "map_ns": 132835020, + "service_ns": 156740913, + "floor_ns": 78370461, + "edge_ns": 29086009, + "native_model_ns": 80976974, + "single_model_ns": 78881776, + "observed_occupancy_pct": 58.9983398203275, + "all_map_pct_fit": 0.9811764110803843, + "scheduling_ceiling_pct_fit": 0.40229858459535633, + "single_vs_native_model_pct_fit": 0.015476030749592985 + }, + { + "id": "run-020", + "adapter": "direct", + "cost": "fixed", + "seed": 1, + "native_update": 200, + "source_sha256": "18a3c44671eb93a68f4c676662def44821ada78ecd0b8633e49e1cb8795361d3", + "fit_wall_s": 8.37583185799997, + "batches": 25, + "proposals": 2500, + "map_ns": 60231911, + "service_ns": 35787484, + "floor_ns": 17893749, + "edge_ns": 28463649, + "native_model_ns": 18233260, + "single_model_ns": 17971387, + "observed_occupancy_pct": 29.708076172446198, + "all_map_pct_fit": 0.719115569905704, + "scheduling_ceiling_pct_fit": 0.5054800850564084, + "single_vs_native_model_pct_fit": 0.0031265312441758064 + }, + { + "id": "run-022", + "adapter": "pyautofit", + "cost": "fixed", + "seed": 1, + "native_update": 200, + "source_sha256": "f44e0b01e18e6f3ec96b75d6f69cbd4a1db830ea527bc72db3033cfb6d3028eb", + "fit_wall_s": 11.84903913200003, + "batches": 25, + "proposals": 2500, + "map_ns": 109201536, + "service_ns": 122225476, + "floor_ns": 61112745, + "edge_ns": 25147370, + "native_model_ns": 62463149, + "single_model_ns": 61487280, + "observed_occupancy_pct": 55.963258612040036, + "all_map_pct_fit": 0.9216066786806838, + "scheduling_ceiling_pct_fit": 0.40584549062825964, + "single_vs_native_model_pct_fit": 0.00823584924590658 + }, + { + "id": "run-028", + "adapter": "direct", + "cost": "correlated", + "seed": 1, + "native_update": 200, + "source_sha256": "a65cfa2b261edb42adfb148b8552c97abcf4a0efa126f217f7714dde4d8a1005", + "fit_wall_s": 9.197536860000014, + "batches": 25, + "proposals": 2500, + "map_ns": 70051218, + "service_ns": 61760210, + "floor_ns": 30880113, + "edge_ns": 23002141, + "native_model_ns": 32342350, + "single_model_ns": 31145322, + "observed_occupancy_pct": 44.08218141189208, + "all_map_pct_fit": 0.7616301958478903, + "scheduling_ceiling_pct_fit": 0.42588690424666525, + "single_vs_native_model_pct_fit": 0.01301465836147786 + }, + { + "id": "run-030", + "adapter": "pyautofit", + "cost": "correlated", + "seed": 1, + "native_update": 200, + "source_sha256": "8e2a8fef66ee8ca36415a968c8a01ead87b49a6ad5bc72387019d0887941ee77", + "fit_wall_s": 12.157253817999958, + "batches": 25, + "proposals": 2500, + "map_ns": 121354551, + "service_ns": 143455315, + "floor_ns": 71727666, + "edge_ns": 26883687, + "native_model_ns": 73367837, + "single_model_ns": 72207875, + "observed_occupancy_pct": 59.10586534163024, + "all_map_pct_fit": 0.9982069373292443, + "scheduling_ceiling_pct_fit": 0.4082080192035041, + "single_vs_native_model_pct_fit": 0.009541315969586545 + }, + { + "id": "run-037", + "adapter": "direct", + "cost": "fixed", + "seed": 2, + "native_update": 200, + "source_sha256": "907c1dd5bf4d40a41734ce667059425cabc463e63f194f201b0c31f42ef58c18", + "fit_wall_s": 7.8081241860001, + "batches": 25, + "proposals": 2500, + "map_ns": 55812895, + "service_ns": 34958569, + "floor_ns": 17479288, + "edge_ns": 25272559, + "native_model_ns": 17871051, + "single_model_ns": 17578698, + "observed_occupancy_pct": 31.317645321927845, + "all_map_pct_fit": 0.7148054215130446, + "scheduling_ceiling_pct_fit": 0.49094515003657124, + "single_vs_native_model_pct_fit": 0.003744215550825721 + }, + { + "id": "run-039", + "adapter": "pyautofit", + "cost": "fixed", + "seed": 2, + "native_update": 200, + "source_sha256": "63ce250383af8a7a72370f1d40d22d99e71c300e21bc3f0d008406e84609b77e", + "fit_wall_s": 11.059881896000093, + "batches": 25, + "proposals": 2500, + "map_ns": 102045402, + "service_ns": 111425707, + "floor_ns": 55712860, + "edge_ns": 25796222, + "native_model_ns": 56792627, + "single_model_ns": 56016778, + "observed_occupancy_pct": 54.59614290117648, + "all_map_pct_fit": 0.9226626736123253, + "scheduling_ceiling_pct_fit": 0.4189243830601535, + "single_vs_native_model_pct_fit": 0.007014984493465458 + }, + { + "id": "run-045", + "adapter": "direct", + "cost": "correlated", + "seed": 2, + "native_update": 200, + "source_sha256": "6656df2242d2bfaadee7ddcf7299978c06c40bfb0c671c7a007e6880be813162", + "fit_wall_s": 7.294893395000031, + "batches": 25, + "proposals": 2500, + "map_ns": 59145303, + "service_ns": 53931066, + "floor_ns": 26965541, + "edge_ns": 18707148, + "native_model_ns": 28229734, + "single_model_ns": 27124746, + "observed_occupancy_pct": 45.592010915896395, + "all_map_pct_fit": 0.8107767968280194, + "scheduling_ceiling_pct_fit": 0.4411272414488775, + "single_vs_native_model_pct_fit": 0.015147418065867368 + }, + { + "id": "run-047", + "adapter": "pyautofit", + "cost": "correlated", + "seed": 2, + "native_update": 200, + "source_sha256": "f90bc09c2040eb37826aaa302972cf40ec422dbd03940beeb7c52f8e2b5c9327", + "fit_wall_s": 10.164051028000017, + "batches": 25, + "proposals": 2500, + "map_ns": 102258009, + "service_ns": 124117066, + "floor_ns": 62058538, + "edge_ns": 21204504, + "native_model_ns": 64339486, + "single_model_ns": 62445976, + "observed_occupancy_pct": 60.68818824743595, + "all_map_pct_fit": 1.0060753209355082, + "scheduling_ceiling_pct_fit": 0.39550638706218755, + "single_vs_native_model_pct_fit": 0.018629481441835957 + }, + { + "id": "run-049", + "adapter": "direct", + "cost": "random", + "seed": 0, + "native_update": 200, + "source_sha256": "2651094379638ad8ab114c94209aae941c194d388269cd5419d9685e79f2bfd2", + "fit_wall_s": 8.69011510900009, + "batches": 26, + "proposals": 2600, + "map_ns": 120216275, + "service_ns": 164101550, + "floor_ns": 82050782, + "edge_ns": 21319967, + "native_model_ns": 85453780, + "single_model_ns": 82559237, + "observed_occupancy_pct": 68.252634678624, + "all_map_pct_fit": 1.38336803934272, + "scheduling_ceiling_pct_fit": 0.4391828246379976, + "single_vs_native_model_pct_fit": 0.033308454073320726 + }, + { + "id": "run-051", + "adapter": "pyautofit", + "cost": "random", + "seed": 0, + "native_update": 200, + "source_sha256": "d4edb8c88b8eb6d92029b074b2fd5854f5a14d9583c1ed44b6c23013a2ea8686", + "fit_wall_s": 12.071732818999863, + "batches": 26, + "proposals": 2600, + "map_ns": 173283040, + "service_ns": 251655204, + "floor_ns": 125827608, + "edge_ns": 24328801, + "native_model_ns": 129249769, + "single_model_ns": 126485896, + "observed_occupancy_pct": 72.61391651485339, + "all_map_pct_fit": 1.4354446258723312, + "scheduling_ceiling_pct_fit": 0.39311201392155776, + "single_vs_native_model_pct_fit": 0.022895412294495973 + }, + { + "id": "run-005-pin2", + "adapter": "direct", + "cost": "fixed", + "seed": 0, + "native_update": 200, + "source_sha256": "be78621446d9681636ab694094990353d915dd7c650ca1556df48fa8886abaf7", + "fit_wall_s": 8.812195279999969, + "batches": 26, + "proposals": 2600, + "map_ns": 57691974, + "service_ns": 37737672, + "floor_ns": 18868844, + "edge_ns": 23926535, + "native_model_ns": 19430960, + "single_model_ns": 18988999, + "observed_occupancy_pct": 32.70617157249637, + "all_map_pct_fit": 0.6546833356148708, + "scheduling_ceiling_pct_fit": 0.4405613898288479, + "single_vs_native_model_pct_fit": 0.005015333704679335 + }, + { + "id": "run-007-pin2", + "adapter": "pyautofit", + "cost": "fixed", + "seed": 0, + "native_update": 200, + "source_sha256": "a16fef1127c24f651962f507cc3cdfa84f14207d7e12b8358244ede75986de58", + "fit_wall_s": 12.138249642000005, + "batches": 26, + "proposals": 2600, + "map_ns": 116780804, + "service_ns": 130278630, + "floor_ns": 65139321, + "edge_ns": 27464730, + "native_model_ns": 67263876, + "single_model_ns": 65514245, + "observed_occupancy_pct": 55.77912873420532, + "all_map_pct_fit": 0.962089324608405, + "scheduling_ceiling_pct_fit": 0.42544423226651557, + "single_vs_native_model_pct_fit": 0.014414195222563533 + } + ] +} diff --git a/experiments/nautilus_worker_headroom/timelines/run-005-pin2.json.gz b/experiments/nautilus_worker_headroom/timelines/run-005-pin2.json.gz new file mode 100644 index 0000000..33181ce Binary files /dev/null and b/experiments/nautilus_worker_headroom/timelines/run-005-pin2.json.gz differ diff --git a/experiments/nautilus_worker_headroom/timelines/run-007-pin2.json.gz b/experiments/nautilus_worker_headroom/timelines/run-007-pin2.json.gz new file mode 100644 index 0000000..519552b Binary files /dev/null and b/experiments/nautilus_worker_headroom/timelines/run-007-pin2.json.gz differ diff --git a/experiments/nautilus_worker_headroom/timelines/run-020.json.gz b/experiments/nautilus_worker_headroom/timelines/run-020.json.gz new file mode 100644 index 0000000..007cbf1 Binary files /dev/null and b/experiments/nautilus_worker_headroom/timelines/run-020.json.gz differ diff --git a/experiments/nautilus_worker_headroom/timelines/run-022.json.gz b/experiments/nautilus_worker_headroom/timelines/run-022.json.gz new file mode 100644 index 0000000..87fff33 Binary files /dev/null and b/experiments/nautilus_worker_headroom/timelines/run-022.json.gz differ diff --git a/experiments/nautilus_worker_headroom/timelines/run-028.json.gz b/experiments/nautilus_worker_headroom/timelines/run-028.json.gz new file mode 100644 index 0000000..f5a7dad Binary files /dev/null and b/experiments/nautilus_worker_headroom/timelines/run-028.json.gz differ diff --git a/experiments/nautilus_worker_headroom/timelines/run-030.json.gz b/experiments/nautilus_worker_headroom/timelines/run-030.json.gz new file mode 100644 index 0000000..c87eb62 Binary files /dev/null and b/experiments/nautilus_worker_headroom/timelines/run-030.json.gz differ diff --git a/experiments/nautilus_worker_headroom/timelines/run-037.json.gz b/experiments/nautilus_worker_headroom/timelines/run-037.json.gz new file mode 100644 index 0000000..b27c778 Binary files /dev/null and b/experiments/nautilus_worker_headroom/timelines/run-037.json.gz differ diff --git a/experiments/nautilus_worker_headroom/timelines/run-039.json.gz b/experiments/nautilus_worker_headroom/timelines/run-039.json.gz new file mode 100644 index 0000000..63277f4 Binary files /dev/null and b/experiments/nautilus_worker_headroom/timelines/run-039.json.gz differ diff --git a/experiments/nautilus_worker_headroom/timelines/run-045.json.gz b/experiments/nautilus_worker_headroom/timelines/run-045.json.gz new file mode 100644 index 0000000..3769063 Binary files /dev/null and b/experiments/nautilus_worker_headroom/timelines/run-045.json.gz differ diff --git a/experiments/nautilus_worker_headroom/timelines/run-047.json.gz b/experiments/nautilus_worker_headroom/timelines/run-047.json.gz new file mode 100644 index 0000000..3241542 Binary files /dev/null and b/experiments/nautilus_worker_headroom/timelines/run-047.json.gz differ diff --git a/experiments/nautilus_worker_headroom/timelines/run-049.json.gz b/experiments/nautilus_worker_headroom/timelines/run-049.json.gz new file mode 100644 index 0000000..8e73123 Binary files /dev/null and b/experiments/nautilus_worker_headroom/timelines/run-049.json.gz differ diff --git a/experiments/nautilus_worker_headroom/timelines/run-051.json.gz b/experiments/nautilus_worker_headroom/timelines/run-051.json.gz new file mode 100644 index 0000000..905b1ca Binary files /dev/null and b/experiments/nautilus_worker_headroom/timelines/run-051.json.gz differ