Include placed geometry in routing parity snapshots
This commit is contained in:
parent
72f8fbda5a
commit
266aeb6c5e
1 changed files with 49 additions and 14 deletions
|
|
@ -5,11 +5,14 @@ from __future__ import annotations
|
|||
from argparse import ArgumentParser
|
||||
from concurrent.futures import ProcessPoolExecutor
|
||||
from dataclasses import asdict, replace
|
||||
from hashlib import sha256
|
||||
from json import dumps, loads
|
||||
from pathlib import Path
|
||||
from time import perf_counter
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from shapely import to_wkb
|
||||
|
||||
from inire import DiagnosticsOptions, route
|
||||
from inire.results import RouteMetrics
|
||||
from inire.tests.routing_corpus import (
|
||||
|
|
@ -27,7 +30,7 @@ if TYPE_CHECKING:
|
|||
from inire import RoutingResult
|
||||
|
||||
|
||||
SCHEMA_VERSION = 1
|
||||
SCHEMA_VERSION = 2
|
||||
STABLE_COUNTERS = tuple(name for name in RouteMetrics.__dataclass_fields__ if not name.endswith("_ns"))
|
||||
|
||||
|
||||
|
|
@ -39,6 +42,8 @@ def _paths(results: dict[str, RoutingResult]) -> dict:
|
|||
"outcome": result.outcome,
|
||||
"reached_target": result.reached_target,
|
||||
"seed": [{"kind": type(move).__name__, **asdict(move)} for move in result.as_seed().segments],
|
||||
"effective_net": asdict(result.effective_net) if result.effective_net is not None else None,
|
||||
"physical_polygon_hashes": [sha256(wkb).hexdigest() for wkb in to_wkb(result.locked_geometry, byte_order=1)],
|
||||
"report": asdict(result.report),
|
||||
}
|
||||
for net_id, result in results.items()
|
||||
|
|
@ -119,19 +124,24 @@ def _first_difference(expected: object, actual: object, field: str = "") -> str
|
|||
return f"{field} is {expected!r} before and {actual!r} after"
|
||||
|
||||
|
||||
def _read(path: Path) -> dict:
|
||||
def _read(path: Path) -> tuple[int, dict]:
|
||||
payload = loads(path.read_text(encoding="utf-8"))
|
||||
if payload["schema_version"] != SCHEMA_VERSION:
|
||||
version = payload["schema_version"]
|
||||
if version not in (1, SCHEMA_VERSION):
|
||||
raise ValueError(f"Unsupported parity schema in {path}")
|
||||
rows = payload["runs"]
|
||||
by_key = {(row["case"], row["profile"], row["with_callback"], row["with_diagnostics"]): row for row in rows}
|
||||
if len(by_key) != len(rows):
|
||||
raise ValueError(f"Duplicate parity run in {path}")
|
||||
return by_key
|
||||
return version, by_key
|
||||
|
||||
|
||||
def _compare(before: Path, after: Path, allowed_counters: list[str]) -> int:
|
||||
baseline, current = _read(before), _read(after)
|
||||
before_version, baseline = _read(before)
|
||||
after_version, current = _read(after)
|
||||
if before_version != after_version:
|
||||
print(f"Parity schema mismatch ({before_version} and {after_version}). Capture both revisions with the same script version.")
|
||||
return 1
|
||||
for key in sorted(baseline.keys() | current.keys()):
|
||||
label = f"{key[0]} / {key[1]} (callback={key[2]}, diagnostics={key[3]})"
|
||||
if key not in baseline or key not in current:
|
||||
|
|
|
|||
Loading…
Reference in a new issue