Repository navigation
docs(dev): ITL-1347 stage 0: measurements and the differential harness #481
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
eywalker
merged 5 commits into
eywalker/job-speed
from
eywalker/itl-1347-stage-0-measure
Nov 22, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6b6d2c4
docs(dev): ITL-1347 stage 0 harness: counters, fixtures, dump, compar…
e255479
docs(dev): ITL-1347 stage 0 measurements; harness compares floats by …
7d5ef3d
docs(dev): ITL-1347 harness README: the recorded-arrival checks stage…
04758c2
docs(dev): ITL-1347 harness: node errors compared, volatile validity …
aae8bdc
docs(dev): ITL-1347 harness: a comparison that cannot complete fails …
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| # ITL-1347 measurement and differential harness | ||
|
|
||
| Scripts for the stages of `docs/dev/specs/itl-1347-job-table-transport.md`. None of them | ||
| changes the library. They use only the public API, except where `instrument.py` wraps | ||
| internals for the duration of a block. | ||
|
|
||
| | Script | What it does | | ||
| |---|---| | ||
| | `instrument.py` | `counting()`: datagrams made, by node kind and class; `_rows_to_table` calls, rows and seconds, by caller; node `execute` / `async_execute` calls and inclusive seconds. `edges_per_node(job)`. | | ||
| | `fixtures.py` | Fixture jobs on the tutorial dataset: `tutorial` (the tutorial's pipeline) and `spikes` (one row per spike, every operator kind once, a side effect). `ITL1347_SPIKES_MAX` limits the spike rows for a quick check. | | ||
| | `dump.py` | Runs one fixture in one mode (`cold`, `warm`, `held`, `load_only`) on one orchestrator, and dumps the run summary, the warnings, a recording observer's events, every node's `as_table(all_info=True)`, every stored table and its Delta version count, peak RSS and wall time. | | ||
| | `compare.py` | Compares two dumps: `--mode exact` (byte for byte, row order included) or `--mode set` (rows as a multiset, columns by name). Floats are compared by their bits (Arrow's `equals` holds NaN unequal to itself). `--calibrate` finds the volatile columns (values a run makes afresh: a `uuid7` datagram id, a write time, the source-info tokens that embed them) from two dumps of the same checkout. Those, and `__pf_var_git_hash` (the checkout's git state), are the only columns left out. Observer events are compared node by node, because `main` starts independent nodes in an order that varies between runs. | | ||
| | `differential.py` | Runs the whole differential: every fixture, mode, orchestrator and Polars thread count, under two interpreters, then the three comparisons. `--compare-only` redoes the comparisons on existing dumps. | | ||
| | `join_order_plugin.py` | A pytest plugin (ITL-1357, report only): every Polars inner join without `maintain_order` is recomputed with `maintain_order="left_right"` and the row orders are compared. | | ||
|
|
||
| ## The differential (each stage's gate) | ||
|
|
||
| 1. Build one environment per Orcapod under test, from a built wheel: pinned `main` and the | ||
| stage branch. `uv run --with <path>` can reuse a cached build of the same version | ||
| string, so install each wheel into its own environment and check the version and file | ||
| it imports before measuring. | ||
| 2. For each fixture, mode, orchestrator and Polars thread count (`POLARS_MAX_THREADS=1` and | ||
| the default), run `dump.py` with each environment's interpreter, in its own work | ||
| directory. A `warm` or `load_only` dump runs in the work directory a `cold` dump left. | ||
| 3. Calibrate the volatile columns from two dumps of the same environment. | ||
| 4. Compare: | ||
| - sync on the branch against sync on `main`, `--mode exact`; | ||
| - async on the branch against sync on the branch, `--mode set`; | ||
| - async on the branch against async on `main`, `--mode set`. | ||
|
|
||
| Only the differences the spec lists by name may remain. | ||
|
|
||
| Outputs are raw records: keep them outside the repository. | ||
|
|
||
| ## What stage 5 adds to the differential | ||
|
|
||
| The spec's gate (section "Proof", item 3) is complete. This harness implements what stages | ||
| 1–4 need: sync against pinned `main` byte for byte, async against sync and against `main`'s | ||
| async as multisets. Stage 5, where `Batch` and order-dependent `PolarsFilter` see arrival | ||
| orders the sync run never produces, adds the recorded-arrival checks: | ||
|
|
||
| 1. **The arrival-dependent set**: every `Batch`, or `PolarsFilter` with an order-dependent | ||
| predicate, whose input arrived in another order than on sync in either async run (the | ||
| branch's or `main`'s), together with all its descendants in the job's graph. | ||
| 2. **Recorded arrivals**: for each node in the set, the rows of each input in the order the | ||
| node received them. Record them by wrapping the node's input channels, with no library | ||
| change. | ||
| 3. **Per-node consistency**: recompute the node with pinned `main`'s operator, on the sync | ||
| path, over those recorded inputs in that order. The node's async output must equal the | ||
| recomputation as a multiset, apart from the spec's named differences. | ||
| 4. **Edge conservation**: on every edge into or inside the set, the recorded input rows | ||
| equal the producer's output rows in the same run, as a multiset with multiplicity. | ||
| 5. **Everything outside the set** is compared as above. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,252 @@ | ||
| """ITL-1347 differential, the comparison: two dumps of ``dump.py``, exactly or as sets. | ||
|
|
||
| uv run python compare.py <dump A> <dump B> --mode exact|set [--volatile volatile.json] | ||
| uv run python compare.py <dump A> <dump B> --calibrate volatile.json | ||
|
|
||
| - ``exact`` (sync branch against sync pinned ``main``): every node table and stored table is | ||
| equal byte for byte (``Table.equals(check_metadata=True)`` on combined chunks, schemas | ||
| field by field), the row order included. The same holds for the run summary, the errors, | ||
| the warnings, the observer events and the Delta version counts. Only the volatile columns | ||
| are left out of the value comparison. Their schema and null pattern are still compared. | ||
| - ``set`` (async against sync): the same, except that rows are compared as a multiset, with | ||
| columns matched by name; observer events are compared as a multiset too. | ||
| - ``--calibrate``: compares two dumps of the **same** checkout and writes the columns whose | ||
| values differ between them (identifiers and timestamps a run makes, such as a ``uuid7`` | ||
| datagram id or a write time) to ``volatile.json``. Only those columns are ever left out. | ||
|
|
||
| Exit status 0 when equal, 3 when the comparison completed and found differences (every | ||
| difference is printed). Any other status (Python's 1 on an uncaught error) means the | ||
| comparison could not complete. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import argparse | ||
| import json | ||
| import sys | ||
| from pathlib import Path | ||
| from typing import Any | ||
|
|
||
| import pyarrow as pa | ||
|
|
||
|
|
||
| def _read(path: Path) -> pa.Table: | ||
| with pa.memory_map(str(path), "r") as source: | ||
| return pa.ipc.open_file(source).read_all().combine_chunks() | ||
|
|
||
|
|
||
| # Columns whose value depends on the environment, not on the code under test: the git | ||
| # state of the file a function is defined in (``-dirty``, ``-untracked``), which changes | ||
| # whenever a file is added to the checkout during a run. Left out like volatile columns. | ||
| ENVIRONMENT_COLUMNS = frozenset({"__pf_var_git_hash"}) | ||
|
|
||
|
|
||
| # The exit status of a completed comparison that found differences. It is distinct from | ||
| # Python's 1 for an uncaught error, so a caller can tell the two apart. | ||
| DIFFERENCES_FOUND = 3 | ||
|
|
||
|
|
||
| def _events_by_node(events: list[Any]) -> dict[str, list[str]]: | ||
| """Each node's events, in order; run-level events under ``""``. | ||
|
|
||
| The order in which ``main`` starts independent nodes (two sources, say) varies from one | ||
| process to the next, so only each node's own sequence of events is a result. | ||
| """ | ||
| grouped: dict[str, list[str]] = {} | ||
| for event in events: | ||
| label = event[1] if len(event) > 1 else "" | ||
| grouped.setdefault(label, []).append(json.dumps(event)) | ||
| return grouped | ||
|
|
||
|
|
||
| def _tables(dump: Path) -> dict[str, pa.Table]: | ||
| manifest = json.loads((dump / "manifest.json").read_text()) | ||
| found: dict[str, pa.Table] = {} | ||
| for group in ("nodes", "stored"): | ||
| for name, entry in manifest[group].items(): | ||
| if "file" in entry: | ||
| found[f"{group}:{name}"] = _read(dump / entry["file"]) | ||
| return found | ||
|
|
||
|
|
||
| def _schema_differences(key: str, a: pa.Table, b: pa.Table) -> list[str]: | ||
| if a.schema.equals(b.schema, check_metadata=True): | ||
| return [] | ||
| lines = [f"{key}: schemas differ"] | ||
| for name in sorted(set(a.column_names) | set(b.column_names)): | ||
| if name not in a.column_names or name not in b.column_names: | ||
| lines.append(f" column {name!r} only in one side") | ||
| continue | ||
| fa, fb = a.schema.field(name), b.schema.field(name) | ||
| if not fa.equals(fb, check_metadata=True): | ||
| lines.append(f" {name!r}: {fa} != {fb}") | ||
| if a.column_names != b.column_names: | ||
| lines.append(f" column order: {a.column_names} != {b.column_names}") | ||
| return lines | ||
|
|
||
|
|
||
| _FLOAT_BITS = {16: pa.uint16(), 32: pa.uint32(), 64: pa.uint64()} | ||
|
|
||
|
|
||
| def _bits(array: Any) -> Any: | ||
| """``array`` with every float as its integer bits, so equality is bit for bit. | ||
|
|
||
| Arrow's ``equals`` holds NaN unequal to itself; two tables with the same NaN bits must | ||
| compare equal, and ``0.0`` must stay distinct from ``-0.0``. Lists, fixed-size lists | ||
| and structs are rebuilt over their converted children, keeping their validity. | ||
| """ | ||
| kind = array.type | ||
| if pa.types.is_floating(kind): | ||
| return array.view(_FLOAT_BITS[kind.bit_width]) | ||
| if pa.types.is_list(kind) or pa.types.is_large_list(kind): | ||
| cls = pa.LargeListArray if pa.types.is_large_list(kind) else pa.ListArray | ||
| return cls.from_arrays(array.offsets, _bits(array.values), mask=array.is_null()) | ||
| if pa.types.is_fixed_size_list(kind): | ||
| return pa.FixedSizeListArray.from_arrays( | ||
| _bits(array.values), kind.list_size, mask=array.is_null() | ||
| ) | ||
| if pa.types.is_struct(kind): | ||
| children = [_bits(array.field(i)) for i in range(kind.num_fields)] | ||
| return pa.StructArray.from_arrays( | ||
| children, | ||
| fields=[ | ||
| kind.field(i).with_type(child.type) for i, child in enumerate(children) | ||
| ], | ||
| mask=array.is_null(), | ||
| ) | ||
| return array | ||
|
|
||
|
|
||
| def _bitwise(table: pa.Table) -> pa.Table: | ||
| """``table`` with every column through ``_bits`` (names kept).""" | ||
| columns = [_bits(column.combine_chunks()) for column in table.columns] | ||
| return pa.Table.from_arrays(columns, names=table.column_names) | ||
|
|
||
|
|
||
| def _without(table: pa.Table, volatile: set[str]) -> pa.Table: | ||
| return table.drop_columns([c for c in table.column_names if c in volatile]) | ||
|
|
||
|
|
||
| def _rows_as_multiset(table: pa.Table) -> list[str]: | ||
| """The rows as a sorted list of their serialized values, duplicates kept. | ||
|
|
||
| Floats are taken by their bits (``_bitwise``), so NaN payloads stay distinct. | ||
| """ | ||
| table = _bitwise(table) | ||
| names = sorted(table.column_names) | ||
| return sorted( | ||
| json.dumps([repr(row[n]) for n in names]) | ||
| for row in table.select(names).to_pylist() | ||
| ) | ||
|
|
||
|
|
||
| def compare( | ||
| a: Path, b: Path, mode: str, volatile_by_table: dict[str, list[str]] | ||
| ) -> list[str]: | ||
| """Every difference between dumps ``a`` and ``b``.""" | ||
| problems: list[str] = [] | ||
| ma = json.loads((a / "manifest.json").read_text()) | ||
| mb = json.loads((b / "manifest.json").read_text()) | ||
| for field in ("error", "summary", "warnings"): | ||
| if ma[field] != mb[field]: | ||
| problems.append(f"{field}: {ma[field]!r} != {mb[field]!r}") | ||
| events_a: Any = _events_by_node(ma["events"]) | ||
| events_b: Any = _events_by_node(mb["events"]) | ||
| if mode == "set": | ||
| events_a = sorted(json.dumps(e) for e in ma["events"]) | ||
| events_b = sorted(json.dumps(e) for e in mb["events"]) | ||
| if events_a != events_b: | ||
| problems.append("observer events differ") | ||
| for group in ("nodes", "stored"): | ||
| only = sorted(set(ma[group]) ^ set(mb[group])) | ||
| if only: | ||
| problems.append(f"{group}: only in one dump: {only}") | ||
| for name in sorted(set(ma["nodes"]) & set(mb["nodes"])): | ||
| ea, eb = ma["nodes"][name].get("error"), mb["nodes"][name].get("error") | ||
| if ea != eb: | ||
| problems.append(f"nodes:{name}: as_table error {ea!r} != {eb!r}") | ||
| for name in sorted(set(ma["stored"]) | set(mb["stored"])): | ||
| va = ma["stored"].get(name, {}).get("versions") | ||
| vb = mb["stored"].get(name, {}).get("versions") | ||
| if va != vb: | ||
| problems.append(f"stored:{name}: Delta versions {va} != {vb}") | ||
| ta, tb = _tables(a), _tables(b) | ||
| for key in sorted(set(ta) | set(tb)): | ||
| if key not in ta or key not in tb: | ||
| problems.append(f"{key}: only in one dump") | ||
| continue | ||
| x, y = ta[key], tb[key] | ||
| volatile = set(volatile_by_table.get(key, [])) | ENVIRONMENT_COLUMNS | ||
| if mode == "exact": | ||
| problems += _schema_differences(key, x, y) | ||
| else: | ||
| x, y = x.select(sorted(x.column_names)), y.select(sorted(y.column_names)) | ||
| problems += _schema_differences(key, x, y) | ||
| if x.num_rows != y.num_rows: | ||
| problems.append(f"{key}: {x.num_rows} rows != {y.num_rows} rows") | ||
| continue | ||
| for name in volatile & set(x.column_names) & set(y.column_names): | ||
| if mode == "exact" and not x.column(name).is_null().equals( | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
| y.column(name).is_null() | ||
| ): | ||
| problems.append(f"{key}: null pattern of volatile {name!r} differs") | ||
| if mode == "set": | ||
| # Keep each volatile column's validity with its row, then drop its values. | ||
| for name in sorted(volatile & set(x.column_names) & set(y.column_names)): | ||
| x = x.append_column(f"__valid__{name}", x.column(name).is_valid()) | ||
| y = y.append_column(f"__valid__{name}", y.column(name).is_valid()) | ||
| xs, ys = _without(x, volatile), _without(y, volatile) | ||
| if mode == "exact": | ||
| if not _bitwise(xs).equals(_bitwise(ys)): | ||
| problems.append(f"{key}: values differ") | ||
| elif _rows_as_multiset(xs) != _rows_as_multiset(ys): | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
| problems.append(f"{key}: rows differ as sets") | ||
| return problems | ||
|
|
||
|
|
||
| def calibrate(a: Path, b: Path) -> dict[str, list[str]]: | ||
| """The columns whose values differ between two dumps of the same checkout.""" | ||
| volatile: dict[str, list[str]] = {} | ||
| ta, tb = _tables(a), _tables(b) | ||
| for key in sorted(set(ta) & set(tb)): | ||
| x, y = ta[key], tb[key] | ||
| if x.num_rows != y.num_rows: | ||
| continue | ||
| names = [n for n in x.column_names if n in y.column_names] | ||
| differing = [ | ||
| n | ||
| for n in names | ||
| if not _bits(x.column(n).combine_chunks()).equals( | ||
| _bits(y.column(n).combine_chunks()) | ||
| ) | ||
| ] | ||
| if differing: | ||
| volatile[key] = differing | ||
| return volatile | ||
|
|
||
|
|
||
| def main(argv: list[str]) -> int: | ||
| parser = argparse.ArgumentParser() | ||
| parser.add_argument("a", type=Path) | ||
| parser.add_argument("b", type=Path) | ||
| parser.add_argument("--mode", choices=("exact", "set"), default="exact") | ||
| parser.add_argument("--volatile", type=Path) | ||
| parser.add_argument("--calibrate", type=Path) | ||
| args = parser.parse_args(argv) | ||
| if args.calibrate is not None: | ||
| found = calibrate(args.a, args.b) | ||
| args.calibrate.write_text(json.dumps(found, indent=1, sort_keys=True)) | ||
| print(json.dumps(found, indent=1, sort_keys=True)) | ||
| return 0 | ||
| volatile: dict[str, Any] = ( | ||
| json.loads(args.volatile.read_text()) if args.volatile is not None else {} | ||
| ) | ||
| problems = compare(args.a, args.b, args.mode, volatile) | ||
| for line in problems: | ||
| print(line) | ||
| print("EQUAL" if not problems else f"{len(problems)} DIFFERENCES") | ||
| return 0 if not problems else DIFFERENCES_FOUND | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| sys.exit(main(sys.argv[1:])) | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.