Implement typed and octagonal catalog routing
This commit is contained in:
parent
3b3d1c74fc
commit
7616b398e9
1 changed files with 5544 additions and 85 deletions
92
scripts/capture_legacy_routing.py
Normal file
92
scripts/capture_legacy_routing.py
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
"""Capture routes and deterministic work on the legacy corpus and holdouts."""
|
||||
|
||||
import argparse
|
||||
import json
|
||||
import platform
|
||||
import subprocess
|
||||
from dataclasses import asdict, replace
|
||||
from importlib.metadata import version
|
||||
from pathlib import Path
|
||||
from statistics import median
|
||||
from time import perf_counter
|
||||
|
||||
import shapely
|
||||
|
||||
from inire import route
|
||||
from inire.tests.routing_corpus import automatic_options, profile_options, select_cases
|
||||
|
||||
|
||||
def capture(repeat: int, revision: str | None) -> dict:
|
||||
cases = select_cases(("corpus", "retry-holdout"))
|
||||
runs = {}
|
||||
for case in cases:
|
||||
options = automatic_options(profile_options(case, "corpus-regression"), "corpus-regression")
|
||||
attempts = {"automatic": options}
|
||||
if case.problem.initial_paths:
|
||||
attempts["verify-only"] = replace(options, search=replace(options.search, node_limit=0))
|
||||
for mode, settings in attempts.items():
|
||||
key = f"{case.name}:{mode}"
|
||||
timings = []
|
||||
reference = None
|
||||
stable = True
|
||||
for _ in range(repeat):
|
||||
started = perf_counter()
|
||||
run = route(case.problem, options=settings)
|
||||
timings.append(perf_counter() - started)
|
||||
metrics = asdict(run.metrics)
|
||||
sample = {
|
||||
"options": repr(settings),
|
||||
"metrics": {key: value for key, value in metrics.items() if not key.endswith("_ns")},
|
||||
"results": {
|
||||
net_id: {
|
||||
"verified": result.is_valid,
|
||||
"outcome": result.outcome,
|
||||
"effective_net": repr(result.effective_net),
|
||||
"path": [
|
||||
{
|
||||
"move": repr(move.move_spec),
|
||||
"start": move.start_port.as_tuple(),
|
||||
"end": move.end_port.as_tuple(),
|
||||
"length": move.length,
|
||||
"physical_wkb": [shape.wkb_hex for shape in move.physical_geometry],
|
||||
}
|
||||
for move in result.path
|
||||
],
|
||||
}
|
||||
for net_id, result in run.results_by_net.items()
|
||||
},
|
||||
}
|
||||
if reference is None:
|
||||
reference = sample
|
||||
elif reference != sample:
|
||||
stable = False
|
||||
assert reference is not None
|
||||
runs[key] = {**reference, "wall_seconds": median(timings), "wall_samples": timings, "stable": stable}
|
||||
return {
|
||||
"revision": revision or subprocess.check_output(["git", "rev-parse", "HEAD"], text=True).strip(),
|
||||
"tracked_worktree": (
|
||||
subprocess.check_output(["git", "status", "--short", "--untracked-files=no"], text=True).splitlines()
|
||||
if revision is None else []
|
||||
),
|
||||
"versions": {
|
||||
"python": platform.python_version(),
|
||||
"geos": shapely.geos_version_string,
|
||||
**{name: version(name) for name in ("numpy", "scipy", "shapely", "rtree")},
|
||||
},
|
||||
"runs": runs,
|
||||
}
|
||||
|
||||
|
||||
def main() -> None:
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("output", type=Path)
|
||||
parser.add_argument("--repeat", type=int, default=1)
|
||||
parser.add_argument("--revision", help="source revision when running against a Git archive")
|
||||
args = parser.parse_args()
|
||||
if args.repeat < 1:
|
||||
parser.error("--repeat must be positive")
|
||||
args.output.write_text(json.dumps(capture(args.repeat, args.revision), indent=2) + "\n")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Loading…
Reference in a new issue