Prefer bend-ended windows in default path refinement

This commit is contained in:
Jan Petykiewicz 2026-11-26 15:25:21 -08:00
commit 8af08a537e
4 changed files with 27 additions and 20 deletions

View file

@ -121,9 +121,9 @@ Use `RoutingProblem.initial_paths` to provide semantic per-net seeds. Seeds are
| :-- | :-- | :-- | | :-- | :-- | :-- |
| `enabled` | `True` | Enable post-route refinement. | | `enabled` | `True` | Enable post-route refinement. |
| `objective` | `None` | Optional override objective for refinement. `None` reuses the search objective. | | `objective` | `None` | Optional override objective for refinement. `None` reuses the search objective. |
| `max_windows_per_net` | `24` | Maximum candidate windows attempted per net, shared across improvement rounds. Use `1` for a faster pass or `None` to remove the window limit. | | `max_windows_per_net` | `4` | Maximum candidate windows attempted per net, shared across improvement rounds. Use `1` for a faster pass or `None` to remove the window limit. |
The refiner scores candidate moves from their ports and lengths before building polygons. When the incumbent is valid in the current collision world, it verifies the replacement window against obstacles, other nets, and the unchanged parts of its own path. The router verifies the final layout in full. With a finite limit greater than one, the refiner tries windows with a bend at each end first, then those with one bend at an end, and finally the rest. Within each group it tries the longest windows first. A limit of one and unlimited refinement use longest-first ordering across all windows. The refiner scores candidate moves from their ports and lengths before building polygons. When the incumbent is valid in the current collision world, it verifies the replacement window against obstacles, other nets, and the unchanged parts of its own path. The router verifies the final layout in full.
## Topological Routing ## Topological Routing

View file

@ -323,6 +323,8 @@ With public defaults, the earlier runs on the alternating doglegs, width-key pas
Before the new fallbacks, the proposed four-window refinement order and guarded 500-node first pass matched the original stress baseline at the matched budget. On the seeded return-shelf diagnostic, bend-first ordering found the same cost improvement on its first window that the prior order found on its second, with different geometry. Before the new fallbacks, the proposed four-window refinement order and guarded 500-node first pass matched the original stress baseline at the matched budget. On the seeded return-shelf diagnostic, bend-first ordering found the same cost improvement on its first window that the prior order found on its second, with different geometry.
Four bend-first windows are now the default. A full comparison against the 24-window longest-first baseline matched verified IDs, bounds, and both per-net costs on all 67 boards in both profiles. Fixed-heading Terminal-Bench used different geometry at the same scores. Single-window and unlimited refinement keep longest-first ordering.
### External and fallback benchmarks ### External and fallback benchmarks
`--case external` runs six fixed-placement problems from two public sources. The fixtures preserve net IDs and device locations, with optical ports snapped to a 0.1 µm lattice and expressed relative to the imported board. Device boxes become obstacles with outward access cutouts at the selected ports. The timed runs start from empty initial paths. The converted inputs are checked into the repo so benchmark runs work offline. [Fixture data](../inire/tests/data/external_routing_benchmarks.json) `--case external` runs six fixed-placement problems from two public sources. The fixtures preserve net IDs and device locations, with optical ports snapped to a 0.1 µm lattice and expressed relative to the imported board. Device boxes become obstacles with outward access cutouts at the selected ports. The timed runs start from empty initial paths. The converted inputs are checked into the repo so benchmark runs work offline. [Fixture data](../inire/tests/data/external_routing_benchmarks.json)

View file

@ -101,7 +101,7 @@ class CongestionOptions:
class RefinementOptions: class RefinementOptions:
enabled: bool = True enabled: bool = True
objective: ObjectiveWeights | None = None objective: ObjectiveWeights | None = None
max_windows_per_net: int | None = 24 max_windows_per_net: int | None = 4
def __post_init__(self) -> None: def __post_init__(self) -> None:
limit = self.max_windows_per_net limit = self.max_windows_per_net

View file

@ -2,7 +2,7 @@ from __future__ import annotations
import math import math
from dataclasses import dataclass from dataclasses import dataclass
from itertools import chain from itertools import accumulate, chain
from typing import TYPE_CHECKING, Any from typing import TYPE_CHECKING, Any
from inire.geometry.component_overlap import components_overlap from inire.geometry.component_overlap import components_overlap
@ -264,21 +264,26 @@ class PathRefiner:
def _iter_refinement_windows(self, start: Port, path: Sequence[ComponentResult]) -> Iterator[tuple[int, int]]: def _iter_refinement_windows(self, start: Port, path: Sequence[ComponentResult]) -> Iterator[tuple[int, int]]:
ports = self._path_ports(start, path) ports = self._path_ports(start, path)
min_radius = min(self.context.options.search.bend_radii, default=0.0) min_radius = min(self.context.options.search.bend_radii, default=0.0)
bends = [component.move_type == "bend90" for component in path]
bend_counts = tuple(accumulate(bends, initial=0))
limit = self.context.options.refinement.max_windows_per_net
# Keep the original order for a single attempt and for unlimited refinement.
edge_counts = (2, 1, 0) if limit is not None and limit > 1 else (None,)
for window_size in range(len(path), 0, -1): for edge_count in edge_counts:
for window_size in range(len(path), 3, -1):
for start_idx in range(len(path) - window_size + 1): for start_idx in range(len(path) - window_size + 1):
end_idx = start_idx + window_size end_idx = start_idx + window_size
window = path[start_idx:end_idx] if bend_counts[end_idx] - bend_counts[start_idx] < 4:
bend_count = sum(1 for comp in window if comp.move_type == "bend90") continue
if bend_count < 4: if edge_count is not None and bends[start_idx] + bends[end_idx - 1] != edge_count:
continue continue
window_start = ports[start_idx] window_start = ports[start_idx]
window_end = ports[end_idx] window_end = ports[end_idx]
if window_start.r != window_end.r: if window_start.r != window_end.r:
continue continue
local_dx, _ = self._to_local(window_start, window_end) local_dx, _ = self._to_local(window_start, window_end)
if local_dx < 4.0 * min_radius - 0.01: if local_dx >= 4.0 * min_radius - 0.01:
continue
yield start_idx, end_idx yield start_idx, end_idx
def _try_refine_window( def _try_refine_window(