diff --git a/docs/benchmark-fixtures.md b/docs/benchmark-fixtures.md index 2e4e87d..932a9ee 100644 --- a/docs/benchmark-fixtures.md +++ b/docs/benchmark-fixtures.md @@ -3,6 +3,23 @@ - [Benchmark cases](benchmarks.md#choose-a-case) - [Corpus registry and profiles](../inire/tests/routing_corpus.py) +## Micron-scale routing cases + +The `expanded` group adds 72 deterministic, unseeded boards with independently constructed reference routes. The authored grid units are 10, 100, 250, 500, and 1000 nm. Bend radii span 10–100 µm and trace widths span 1–20 µm. The comparison script records `grid_nm` for these boards. Convert benchmark-weighted lengths to microns by multiplying by `grid_nm / 1000`. + +| Group | Boards | Coverage | +| --- | ---: | --- | +| `geometry-corners` | 32 | Exact four-bend spans, tight returns and paired routes, exact-span S-bend slots, mixed widths, and saturated or overloaded apertures. | +| `complex-layouts` | 24 | Serial aperture banks with opposing tracks, concave and fixed-route keepouts, and staggered crossing arrays. | +| `search-challenges` | 8 | Alternating comb walls that force repeated turns and exercise search-budget exhaustion. | +| `scaling` | 8 | Banks and crossing arrays of up to 256 nets, obstacle fields with up to 320 keepouts, and a 240-net board with 240 keepouts and four blocked approaches. | + +The 72 reference layouts run in pytest. The corner and complex groups and seven scaling boards also have unseeded coverage assertions at the regression budget. Use `--case search-challenges` or `--case scaling` with an explicit budget to measure search and coverage on the harder boards. For scaling comparisons, use the same grid, mode, and budget and collect repeated timings with `--repeat`. + +To exercise the low-budget fallbacks on tight geometry, run `--case geometry-corners --profile corpus-regression --mode automatic --nodes 1 --seed-nodes 1 --iterations 1`. + +- [Fixture definitions](../inire/tests/routing_expanded_benchmarks.py) + ## Complex-routing example 1 Use `complex-routing-example-1` to test fixed eastbound arrival and `complex-routing-example-1-point-terminals` to test heading inference. diff --git a/docs/benchmarks.md b/docs/benchmarks.md index 22a18eb..ecc7a25 100644 --- a/docs/benchmarks.md +++ b/docs/benchmarks.md @@ -17,11 +17,12 @@ Expect `3/4 valid`. All four nets need to cross a vertical cut where the opening | If you are changing | Use `--case` | | --- | --- | -| Overall coverage | `corpus` runs the regression suite. | +| Overall coverage | `corpus` runs all benchmark boards, including the search and scaling workloads. | | Ordered tracks, shared gates, and barrier layouts | `all` includes the fixed-heading complex-routing example 1. Use `corpus` for the full regression suite. | | Seeds, custom bend geometry, and fallback behavior | `broad` includes caller seeds, custom bends, imported layouts, and held-out boards. | | Ports on placed devices | `crossings` exercises external legs to preplaced crossing cells. | | Lock ordering, tight turns, and competing passages | `stress` runs known-feasible folded returns, competing locks, and shared passages. | +| Tight geometry, complex layouts, search limits, or scaling | `expanded` runs 72 additional boards. Use `geometry-corners`, `complex-layouts`, `search-challenges`, or `scaling` to focus on one group. | | A retry tuned on the regression corpus | `retry-holdout` tests related but separate return shelves, bypasses, and competing trunks. | List cases with `python -m scripts.compare_topological_routing --list`. Start with the smallest case that exhibits the behavior. @@ -38,7 +39,7 @@ List cases with `python -m scripts.compare_topological_routing --list`. Start wi Both budget profiles use benchmark weights when selecting an automatic candidate. A stage can use a smaller budget, and a net can be searched more than once. Match the profile, options, and worker count when measuring a change. -### Run the full regression corpus +### Run the full benchmark corpus ```sh python -m scripts.compare_topological_routing \ diff --git a/inire/tests/routing_benchmark_case.py b/inire/tests/routing_benchmark_case.py index 2ddb1b2..2390d4c 100644 --- a/inire/tests/routing_benchmark_case.py +++ b/inire/tests/routing_benchmark_case.py @@ -21,6 +21,7 @@ class BenchmarkCase: options: RoutingOptions reference_paths: tuple[tuple[str, PathSeed], ...] = () expected_routed: int | None = None + grid_nm: int | None = None @property def routing_bound(self) -> int: diff --git a/inire/tests/routing_corpus.py b/inire/tests/routing_corpus.py index d308cd9..15daa56 100644 --- a/inire/tests/routing_corpus.py +++ b/inire/tests/routing_corpus.py @@ -16,6 +16,7 @@ from inire.tests.routing_benchmarks import ( FALLBACK_BENCHMARK_CASES, VALIDATION_BENCHMARK_CASES, ) +from inire.tests.routing_expanded_benchmarks import COMPLEX_CASES, CORNER_CASES, SCALING_CASES, SCALING_REGRESSION_CASES, SEARCH_CASES from inire.tests.stress_routing_benchmarks import STRESS_BENCHMARK_CASES from inire.tests.terminal_bench_scenario import LENGTH_COST @@ -27,7 +28,9 @@ if TYPE_CHECKING: BROAD_CASES = (*VALIDATION_BENCHMARK_CASES, *FALLBACK_BENCHMARK_CASES, *EXTERNAL_BENCHMARK_CASES) -CORPUS_CASES = (*BENCHMARK_CASES, *BROAD_CASES, *CROSSING_BENCHMARK_CASES, *STRESS_BENCHMARK_CASES) +_STANDARD_CASES = (*BENCHMARK_CASES, *BROAD_CASES, *CROSSING_BENCHMARK_CASES, *STRESS_BENCHMARK_CASES, *CORNER_CASES, *COMPLEX_CASES) +CORPUS_REGRESSION_CASES = (*_STANDARD_CASES, *SCALING_REGRESSION_CASES) +CORPUS_CASES = (*_STANDARD_CASES, *SEARCH_CASES, *SCALING_CASES) SNAPSHOT_CASES = tuple( case for case in (*BENCHMARK_CASES, *FALLBACK_BENCHMARK_CASES, *EXTERNAL_BENCHMARK_CASES) if case.name != "terminal-bench" ) @@ -47,6 +50,11 @@ CASE_GROUPS = { "broad": BROAD_CASES, "crossings": CROSSING_BENCHMARK_CASES, "stress": STRESS_BENCHMARK_CASES, + "geometry-corners": CORNER_CASES, + "complex-layouts": COMPLEX_CASES, + "search-challenges": SEARCH_CASES, + "scaling": SCALING_CASES, + "expanded": (*CORNER_CASES, *COMPLEX_CASES, *SEARCH_CASES, *SCALING_CASES), "retry-holdout": RETRY_HOLDOUT_CASES, "corpus": CORPUS_CASES, } diff --git a/inire/tests/routing_expanded_benchmarks.py b/inire/tests/routing_expanded_benchmarks.py new file mode 100644 index 0000000..406ec79 --- /dev/null +++ b/inire/tests/routing_expanded_benchmarks.py @@ -0,0 +1,364 @@ +"""Deterministic micron-scale layouts with independently specified routes.""" + +from __future__ import annotations + +from dataclasses import replace +from itertools import pairwise, product +from typing import TYPE_CHECKING + +from shapely.affinity import scale +from shapely.geometry import Polygon, box + +from inire import Bend90Seed, FixedRoute, NetSpec, PathSeed, Port, SBendSeed, StraightSeed +from inire.tests.routing_crossing_benchmarks import _crossing_grid +from inire.tests.stress_routing_benchmarks import _Track, _wall, _waypoint_case + +if TYPE_CHECKING: + from inire.seeds import PathSegmentSeed + from inire.tests.routing_benchmark_case import BenchmarkCase + + +def _on_grid(case: BenchmarkCase, grid_nm: int) -> BenchmarkCase: + """Convert authored microns to integer layout units before timing the router.""" + assert 1000 % grid_nm == 0 + factor = 1000 // grid_nm + if factor == 1: + return replace(case, grid_nm=grid_nm) + + def port(p: Port) -> Port: + return Port(p.x * factor, p.y * factor, p.r) + + def polygon(shape: Polygon) -> Polygon: + return scale(shape, xfact=factor, yfact=factor, origin=(0, 0)) + + def move(segment: PathSegmentSeed) -> PathSegmentSeed: + if isinstance(segment, StraightSeed): + return StraightSeed(segment.length * factor) + if isinstance(segment, Bend90Seed): + return Bend90Seed(segment.radius * factor, segment.direction) + return SBendSeed(segment.offset * factor, segment.radius * factor) + + problem, options = case.problem, case.options + assert not problem.initial_paths + xmin, ymin, xmax, ymax = problem.bounds + scaled_problem = replace( + problem, + bounds=(xmin * factor, ymin * factor, xmax * factor, ymax * factor), + nets=tuple(NetSpec(net.net_id, port(net.start), port(net.target), net.width * factor) for net in problem.nets), + static_obstacles=tuple(polygon(shape) for shape in problem.static_obstacles), + fixed_routes=tuple(FixedRoute(route.net_id, tuple(polygon(shape) for shape in route.polygons)) for route in problem.fixed_routes), + clearance=problem.clearance * factor, + safety_zone_radius=problem.safety_zone_radius * factor, + self_clearance=problem.self_clearance * factor, + ) + search = options.search + offsets = search.sbend_offsets + scaled_options = replace( + options, + search=replace( + search, + bend_radii=tuple(r * factor for r in search.bend_radii), + sbend_radii=tuple(r * factor for r in search.sbend_radii), + sbend_offsets=None if offsets is None else tuple(offset * factor for offset in offsets), + min_straight_length=search.min_straight_length * factor, + max_straight_length=search.max_straight_length * factor, + proximity_range=search.proximity_range * factor, + ), + # Component scoring divides the bend surcharge by the square root of the radius. + objective=replace( + options.objective, + bend_penalty=options.objective.bend_penalty * factor**1.5, + sbend_penalty=options.objective.sbend_penalty * factor**1.5, + ), + congestion=replace(options.congestion, base_penalty=options.congestion.base_penalty * factor), + ) + reference = tuple((net_id, PathSeed(tuple(move(segment) for segment in seed.segments))) for net_id, seed in case.reference_paths) + return replace(case, problem=scaled_problem, options=scaled_options, reference_paths=reference, grid_nm=grid_nm) + + +def _forward(name: str, r: int, width: int, slack: int, *, grid: int = 1000, edge_clutter: bool = False) -> BenchmarkCase: + start, y, finish = 2 * r, 4 * r, 6 * r + slack + height = 8 * r + obstacles = (box(4 * r - r // 5, y - r // 2, 4 * r + r // 5, y + r // 2),) + if edge_clutter: + obstacles += (box(3 * r, 0, 4 * r, r // 3), box(3 * r, height - r // 3, 4 * r, height)) + route = _Track("through", ((start, y), (3 * r, y), (3 * r, y + 2 * r), (finish - r, y + 2 * r), (finish - r, y), (finish, y)), width) + return _on_grid(_waypoint_case( + f"precision-forward-{name}", "Four turns at the tangency limit, with edge clutter or slack to control available lanes", + (0, 0, finish + 2 * r, height), obstacles, (route,), radius=r, clearance=1, + ), grid) + + +def _return(name: str, r: int, width: int, *, tight: bool = False, peer: bool = False, rise: int = 0, grid: int = 1000) -> BenchmarkCase: + start, finish, y, height = 10 * r, 2 * r, 4 * r, 9 * r + right, left, lane = start + r, finish - r, y - 2 * r + board_width = 13 * r + obstacles = (box(4 * r, 0, 5 * r, r // 3), box(6 * r, height - r // 3, 7 * r, height)) + if tight: + edge = width / 2 + 0.25 + obstacles += (box(right + edge, y - r, board_width, y + r), box(0, y + rise - r, left - edge, y + rise + r)) + tracks = (_Track("return", ((start, y), (right, y), (right, lane), (left, lane), (left, y + rise), (finish, y + rise)), width),) + if peer: + tracks += (_Track("through", ((2 * r, 7 * r), (board_width - r, 7 * r)), width=width),) + return _on_grid(_waypoint_case( + f"precision-return-{name}", "East-facing westward return with limited lead room or a neighboring through track", + (0, 0, board_width, height), obstacles, tracks, radius=r, clearance=0, + ), grid) + + +def _sbend_slot(name: str, radius: int, count: int, width: int, *, pitch: int, sign: int = 1, grid: int = 1000) -> BenchmarkCase: + # A 3-4-5 triangle makes these spans exact on every chosen grid. + offset, span = sign * 4 * radius // 5, 8 * radius // 5 + start, turn, end = radius, 3 * radius, 7 * radius + levels = tuple(2 * radius + pitch * i for i in range(count)) + shifted = tuple(y + offset for y in levels) + height = max(*levels, *shifted) + 2 * radius + clearance = 2 + half_slot = width // 2 + clearance + 1 + obstacles = (*_wall(turn - 9, turn - 3, height, tuple((y - half_slot, y + half_slot) for y in levels)), + *_wall(turn + span + 3, turn + span + 9, height, tuple((y - half_slot, y + half_slot) for y in shifted))) + tracks = tuple( + _Track(f"lane_{i}", ((start, a), (turn, a), (turn + span, b), (end, b)), width) + for i, (a, b) in enumerate(zip(levels, shifted, strict=True)) + ) + case = _waypoint_case( + f"precision-sbend-{name}", "Short bank of exact signed S-bends between aligned narrow port slots", + (0, 0, 8 * radius, height), obstacles, tracks, radius=radius, clearance=clearance, + ) + options = replace(case.options, search=replace(case.options.search, bend_radii=(), sbend_offsets=(offset,))) + return _on_grid(replace(case, options=options), grid) + + +def _aperture(name: str, widths: tuple[int, ...], clearance: int, *, extra: int = 0, grid: int = 1000) -> BenchmarkCase: + lower = 32 + cursor = lower + clearance + tracks = [] + for i, width in enumerate(widths): + row = cursor + width // 2 + tracks.append(_Track(f"lane_{i}", ((20, row), (260, row)), width)) + cursor += width + clearance + upper = cursor + height = upper + 64 + case = _waypoint_case( + f"precision-aperture-{name}", "Exact-capacity wall opening with sized trace pitches and optional competing ports", + (0, 0, 280, height), _wall(120, 160, height, ((lower, upper),)), tuple(tracks), radius=10, clearance=clearance, + ) + if extra: + start = upper + 10 + overflow = tuple(NetSpec(f"overflow_{i}", Port(20, start + 10 * i, 0), Port(260, start + 10 * i, 0), widths[0]) for i in range(extra)) + case = replace(case, problem=replace(case.problem, nets=(*case.problem.nets, *overflow)), expected_routed=len(widths)) + return _on_grid(case, grid) + + +def _columns(name: str, count: int, walls: int, radius: int, width: int, *, shift_units: int, grid: int = 1000) -> BenchmarkCase: + rise = shift_units * radius + pitch = width + 14 + wall_pitch = count * (2 * radius + 10) + 4 * radius + 40 + finish = (walls + 1) * wall_pitch + 10 + height = 4 * radius + (walls + 1) * rise + count * pitch + rows = tuple(tuple(2 * radius + bank * rise + track * pitch for track in range(count)) for bank in range(walls + 2)) + obstacles = tuple( + obstacle + for bank in range(1, walls + 1) + for obstacle in _wall(bank * wall_pitch, bank * wall_pitch + 18, height, ((rows[bank][0] - width, rows[bank][-1] + width),)) + ) + tracks = [] + for i, path_rows in enumerate(zip(*rows, strict=True)): + points = [(20, path_rows[0])] + for bank, (low, high) in enumerate(pairwise(path_rows)): + x = bank * wall_pitch + 26 + radius + (count - 1 - i) * (2 * radius + 10) + points.extend(((x, low), (x, high))) + points.append((finish, path_rows[-1])) + tracks.append(_Track(f"lane_{i}", tuple(reversed(points)) if i % 2 else tuple(points), width)) + return _on_grid(_waypoint_case( + f"complex-column-{name}", "Alternating net directions through multiple narrow, ascending aperture banks", + (0, 0, finish + 30, height), obstacles, tuple(tracks), radius=radius, clearance=2, + ), grid) + + +def _residual(name: str, *, width: int, rise: int, fixed: bool, grid: int = 1000) -> BenchmarkCase: + concave = Polygon(((10, 6), (94, 6), (94, 12), (16, 12), (16, 83), (10, 83))) + obstacles = (concave, box(68, 55, 78, 66)) + upper = 60 + rise + tracks = (_Track("trunk", ((26, 60), (42, 60), (42, upper), (105, upper), (105, 60), (138, 60)), width),) + if not fixed: + tracks += (_Track("west_branch", ((6, 75), (6, 114))), _Track("east_rail", ((99, 19), (138, 19)), width=4)) + case = _waypoint_case( + f"complex-residual-{name}", "A dogleg passes through open space inside a concave obstacle's bounding box", + (0, 0, 152, 128), obstacles, tracks, radius=10, clearance=1, + ) + if fixed: + lock = FixedRoute("installed_rail", (box(99, 17, 138, 21),)) + case = replace(case, problem=replace(case.problem, fixed_routes=(lock,))) + return _on_grid(case, grid) + + +def _crossings(name: str, rows: int, columns: int, pitch_x: int, pitch_y: int, *, staggered: bool, grid: int = 1000) -> BenchmarkCase: + return _on_grid(_crossing_grid( + name, f"{rows} by {columns} placed crossing cells with {'staggered' if staggered else 'aligned'} links and opposing port banks", + tuple(160 + pitch_x * col for col in range(columns)), tuple(165 + pitch_y * row for row in range(rows)), staggered=staggered, + ), grid) + + +def _comb(name: str, lanes: int, teeth: int, radius: int, *, grid: int = 1000) -> BenchmarkCase: + pitch = 8 * radius + x_pitch = 5 * radius + finish = (teeth + 1) * x_pitch + width = min(12, radius) + tracks = [] + obstacles = [] + for i in range(lanes): + base = i * pitch + if i: + obstacles.append(box(0, base - 2, finish + 20, base + 2)) + rows = tuple(base + (2 if (j + i) % 2 else 6) * radius for j in range(teeth + 1)) + points = [(radius, rows[0])] + for j, (a, b) in enumerate(pairwise(rows), 1): + x = j * x_pitch - 2 * radius + points.extend(((x, a), (x, b))) + if b > a: + obstacles.append(box(j * x_pitch - radius // 2, base, j * x_pitch + radius // 2, base + 4 * radius)) + else: + obstacles.append(box(j * x_pitch - radius // 2, base + 4 * radius, j * x_pitch + radius // 2, base + pitch)) + points.append((finish, rows[-1])) + tracks.append(_Track(f"lane_{i}", tuple(reversed(points)) if i % 2 else tuple(points), width)) + return _on_grid(_waypoint_case( + f"search-comb-{name}", "Alternating teeth force repeated changes of lane in isolated channels", + (0, 0, finish + 20, lanes * pitch), tuple(obstacles), tuple(tracks), radius=radius, clearance=2, + ), grid) + + +def _port_bank(name: str, count: int, *, obstacles: bool, detours: int = 0, grid: int = 1000) -> BenchmarkCase: + width, clearance, pitch = 4, 2, 10 + straight = count - detours + height = straight * pitch + 20 + detours * 110 + tracks = [ + _Track(f"lane_{i:03}", ((20, y), (560, y)) if i % 2 else ((560, y), (20, y)), width) + for i, y in enumerate(range(10, 10 + straight * pitch, pitch)) + ] + keepouts = [box(160 + 26 * (i % 9), 14 + i * pitch, 195 + 26 * (i % 9), 16 + i * pitch) for i in range(straight)] if obstacles else [] + for i in range(detours): + y = straight * pitch + 50 + 110 * i + points = ((20, y), (100, y), (100, y + 45), (440, y + 45), (440, y), (560, y)) + tracks.append(_Track(f"bypass_{i}", points if i % 2 else tuple(reversed(points)), width)) + keepouts.append(box(190 + 30 * i, y - 10, 260 + 30 * i, y + 10)) + description = f"{count} interleaved eastbound and westbound nets" + if obstacles: + description += " with one keepout per row" + if detours: + description += f" and {detours} obstructed approaches" + return _on_grid(_waypoint_case( + f"scale-bank-{name}", description, (0, 0, 580, height), tuple(keepouts), tuple(tracks), radius=20, clearance=clearance, + ), grid) + + +def _obstacle_field(columns: int, rows: int, count: int, *, grid: int) -> BenchmarkCase: + pitch = 24 + field_end = 140 + pitch * columns + field_base = 64 + height = field_base + pitch * rows + 120 + lanes = tuple(field_base + pitch * i + 10 for i in range(count)) + obstacles = tuple( + box(140 + pitch * col, field_base + pitch * row + col % 3, 152 + pitch * col, field_base + pitch * row + 13 + col % 3) + for col, row in product(range(columns), range(rows)) + ) + # Stagger the turns outside the field so that no vertical leg crosses a peer's occupied row. + tracks = [] + for i, y in enumerate(lanes): + lead = 32 + 22 * i + tail = field_end + 30 + 22 * (count - 1 - i) + lane = 12 + 10 * i + tracks.append(_Track(f"bus_{i}", ((18, y), (lead, y), (lead, lane), (tail, lane), (tail, y), (field_end + 150, y)), 2)) + return _on_grid(_waypoint_case( + f"scale-field-{columns}x{rows}", f"{columns * rows} staggered rectangular obstacles across the straight approaches of {count} buses", + (0, 0, field_end + 170, height), obstacles, tuple(tracks), radius=10, clearance=2, + ), grid) + + +CORNER_CASES = ( + _forward("exact-r10", 10, 1, 0), + _forward("plus-one", 10, 4, 1), + _forward("plus-two", 20, 8, 2, grid=500), + _forward("large-radius", 100, 20, 0), + _forward("board-edges", 20, 4, 0, edge_clutter=True), + _forward("board-edges-fine", 10, 2, 2, grid=100, edge_clutter=True), + _forward("wide-exact", 25, 16, 0, grid=250), + _forward("grid-10nm", 10, 2, 0, grid=10), + _return("exact-pivots", 10, 2, tight=True), + _return("wide-exact-pivots", 20, 10, tight=True), + _return("offset", 25, 4, rise=18), + _return("offset-fine", 10, 3, rise=6, grid=100), + _return("paired", 20, 4, peer=True), + _return("paired-tight", 10, 2, tight=True, peer=True), + _return("paired-wide", 30, 12, peer=True, rise=20, grid=500), + _return("large-radius", 100, 20, tight=True, grid=250), + _sbend_slot("single-r25", 25, 1, 2, pitch=32), + _sbend_slot("single-r50", 50, 1, 6, pitch=32, sign=-1, grid=500), + _sbend_slot("single-r100", 100, 1, 8, pitch=32, grid=250), + _sbend_slot("single-10nm", 25, 1, 2, pitch=32, sign=-1, grid=10), + _sbend_slot("paired", 25, 2, 4, pitch=18, grid=500), + _sbend_slot("paired-down", 25, 2, 4, pitch=16, sign=-1), + _sbend_slot("three", 25, 3, 4, pitch=16), + _sbend_slot("four-wide", 50, 4, 8, pitch=22, sign=-1), + _aperture("pair-exact", (2, 2), 2), + _aperture("four-exact", (4,) * 4, 2, grid=500), + _aperture("six-exact", (2,) * 6, 3), + _aperture("mixed-tight", (2, 8, 4, 12), 2, grid=250), + _aperture("mixed-wide", (16, 4, 20), 3), + _aperture("overloaded-three", (2,) * 3, 3, extra=1), + _aperture("overloaded-five", (4,) * 5, 2, extra=2), + _aperture("overloaded-fine", (2,) * 2, 2, extra=1, grid=100), +) + +COMPLEX_CASES = ( + _columns("3x1", 3, 1, 10, 4, shift_units=3), + _columns("3x2", 3, 2, 10, 4, shift_units=3), + _columns("4x2", 4, 2, 10, 6, shift_units=3), + _columns("4x3", 4, 3, 10, 6, shift_units=3), + _columns("5x2", 5, 2, 15, 6, shift_units=3, grid=500), + _columns("5x3", 5, 3, 15, 8, shift_units=3), + _columns("6x2-wide", 6, 2, 20, 12, shift_units=4), + _columns("6x3", 6, 3, 20, 8, shift_units=4), + _residual("narrow-dogleg", width=2, rise=30, fixed=False), + _residual("wide-dogleg", width=10, rise=44, fixed=False), + _residual("midwidth-fine", width=6, rise=38, fixed=False, grid=250), + _residual("wide-fine", width=12, rise=45, fixed=False, grid=500), + _residual("fixed-rail", width=4, rise=34, fixed=True), + _residual("fixed-rail-wide", width=12, rise=44, fixed=True), + _residual("fixed-rail-fine", width=2, rise=34, fixed=True, grid=100), + _residual("fixed-rail-midwidth", width=8, rise=40, fixed=True, grid=500), + _crossings("complex-crossing-2x2-aligned", 2, 2, 130, 154, staggered=False), + _crossings("complex-crossing-2x3-staggered", 2, 3, 110, 128, staggered=True), + _crossings("complex-crossing-3x2-fine", 3, 2, 118, 132, staggered=True, grid=250), + _crossings("complex-crossing-3x3-uneven-pitch", 3, 3, 108, 147, staggered=True), + _crossings("complex-crossing-3x4-aligned", 3, 4, 108, 97, staggered=False), + _crossings("complex-crossing-3x4-staggered", 3, 4, 102, 116, staggered=True), + _crossings("complex-crossing-4x3-tight", 4, 3, 90, 96, staggered=True), + _crossings("complex-crossing-4x4", 4, 4, 116, 108, staggered=True), +) + +SEARCH_CASES = ( + _comb("1x2", 1, 2, 10), + _comb("1x4", 1, 4, 12), + _comb("2x3", 2, 3, 10), + _comb("2x5-fine", 2, 5, 10, grid=250), + _comb("3x4", 3, 4, 15), + _comb("4x6", 4, 6, 15), + _comb("5x5", 5, 5, 20), + _comb("6x7", 6, 7, 20), +) + +SCALING_REGRESSION_CASES = ( + _crossings("scale-crossing-10x10-aligned", 10, 10, 120, 132, staggered=False), + _crossings("scale-crossing-10x11-staggered", 10, 11, 120, 132, staggered=True), + _port_bank("224", 224, obstacles=False), + _port_bank("256-fine", 256, obstacles=False, grid=100), + _port_bank("216-with-keepouts", 216, obstacles=True), + _obstacle_field(16, 16, 3, grid=1000), + _port_bank("240-with-keepouts", 240, obstacles=True, detours=4, grid=500), +) + +SCALING_CASES = ( + *SCALING_REGRESSION_CASES, + _obstacle_field(20, 16, 4, grid=500), +) diff --git a/inire/tests/test_routing_benchmarks.py b/inire/tests/test_routing_benchmarks.py index a9cea6d..a6d5c74 100644 --- a/inire/tests/test_routing_benchmarks.py +++ b/inire/tests/test_routing_benchmarks.py @@ -23,7 +23,7 @@ from inire.tests.routing_benchmarks import ( EXTERNAL_BENCHMARK_CASES, FALLBACK_BENCHMARK_CASES, ) -from inire.tests.routing_corpus import CASE_GROUPS, CORPUS_CASES, automatic_options, profile_options +from inire.tests.routing_corpus import CASE_GROUPS, CORPUS_CASES, CORPUS_REGRESSION_CASES, automatic_options, profile_options from inire.tests.stress_routing_benchmarks import STRESS_BENCHMARK_CASES from scripts.compare_topological_routing import ( _direct_trials, @@ -41,7 +41,7 @@ def _measure(case, options, strategy): @pytest.mark.routing_corpus @pytest.mark.parametrize( "case", - [pytest.param(case, id=case.name) for case in CORPUS_CASES], + [pytest.param(case, id=case.name) for case in CORPUS_REGRESSION_CASES], ) def test_automatic_reaches_corpus_routing_bound(case) -> None: profile = "corpus-regression" @@ -56,6 +56,40 @@ def test_automatic_reaches_corpus_routing_bound(case) -> None: assert len(verified) == case.routing_bound +def test_expanded_corpus_uses_physical_dimensions_and_has_reference_coverage() -> None: + corpus_names = {case.name for case in CORPUS_CASES} + assert len(corpus_names) == len(CORPUS_CASES) + expanded = CASE_GROUPS["expanded"] + assert 50 <= len(expanded) <= 100 + for case in expanded: + assert case.name in corpus_names + assert case.grid_nm is not None + assert 10 <= case.grid_nm <= 1000 + assert not case.problem.initial_paths + assert len(dict(case.reference_paths)) == case.routing_bound + assert all(1000 <= net.width * case.grid_nm <= 20000 for net in case.problem.nets) + radii = (*case.options.search.bend_radii, *case.options.search.sbend_radii) + assert radii + assert all(10000 <= radius * case.grid_nm <= 100000 for radius in radii) + scaling = CASE_GROUPS["scaling"] + assert any(len(case.problem.nets) >= 200 and len(case.problem.static_obstacles) >= 200 for case in scaling) + assert any(len(case.problem.nets) < 200 <= len(case.problem.static_obstacles) for case in scaling) + assert any(len(case.problem.static_obstacles) < 200 <= len(case.problem.nets) for case in scaling) + + +def test_benchmark_json_records_the_authored_grid(tmp_path, monkeypatch) -> None: + output = tmp_path / "benchmark.json" + monkeypatch.setattr(sys, "argv", [ + "bench", "--case", "precision-sbend-single-10nm", "--profile", "corpus-regression", "--mode", "automatic", "--json", str(output), + ]) + + run_benchmarks() + + [run] = loads(output.read_text())["runs"] + assert run["grid_nm"] == 10 + assert run["options"]["search"]["sbend_radii"] == [2500] + + @pytest.mark.parametrize( "case", [pytest.param(case, id=case.name) for case in (*CORPUS_CASES, *RETRY_HOLDOUT_CASES) if case.reference_paths], diff --git a/scripts/compare_topological_routing.py b/scripts/compare_topological_routing.py index cd963b6..80eb16f 100644 --- a/scripts/compare_topological_routing.py +++ b/scripts/compare_topological_routing.py @@ -302,6 +302,10 @@ def main() -> None: ("external", "External cases"), ("crossings", "Preplaced crossings"), ("stress", "Stress cases"), + ("geometry-corners", "Tight geometry"), + ("complex-layouts", "Complex layouts"), + ("search-challenges", "Search challenges"), + ("scaling", "Large net and keepout counts"), ("retry-holdout", "Retry-policy holdouts"), ): print(f"{title} (--case {group})") @@ -378,6 +382,7 @@ def main() -> None: "case": case.name, "strategy": mode, "requested_mode": mode_options[mode].topology.mode, + "grid_nm": case.grid_nm, "reference_net_ids": [net_id for net_id, _ in case.reference_paths], "options": asdict(mode_options[mode]), "samples": [asdict(sample) for sample in samples[mode]],