Rewrite routing documentation for users and developers
This commit is contained in:
parent
8fdb42122e
commit
2b02c6eae9
1 changed files with 296 additions and 1193 deletions
|
|
@ -1,61 +1,41 @@
|
|||
# Architecture Overview
|
||||
# Router architecture
|
||||
|
||||
`inire` is a single-package Python router with a small stable API at the package root and a larger semi-private implementation under `inire.geometry` and `inire.router`.
|
||||
The supported entry point is [`inire.route`](../DOCS.md). Automatic mode selects among planner candidates and search attempts. Explicit modes run one worker through [`route_once`](../inire/router/_stack.py). Each worker builds its own collision world, obstacle-proximity map, cost evaluator, A* context, and negotiated-congestion driver.
|
||||
|
||||
## Stable Surface
|
||||
## Automatic routing
|
||||
|
||||
- The supported entrypoint is `route(problem, options=...)`.
|
||||
- Stable public types live at the package root and include `RoutingProblem`, `RoutingOptions`, `NetSpec`, `Port`, `RoutingResult`, and `RoutingRunResult`.
|
||||
- Deep imports such as `inire.router._router.PathFinder` and `inire.geometry.collision.RoutingWorld` are intentionally accessible for advanced workflows, but they are unstable.
|
||||
[`_automatic.py`](../inire/router/_automatic.py) controls stage order. [`_routing_policy.py`](../inire/router/_routing_policy.py) owns lock ordering, residual problems, and trial eligibility.
|
||||
|
||||
## Current Module Layout
|
||||
1. **Bound coverage.** Count disjoint conflicting fixed-port pairs and test applicable vertical cuts. A cut estimates how many tracks fit through the available openings. The smaller bound limits the number of nets the run is trying to verify. Compatible unseeded point-terminal inputs may use inferred headings.
|
||||
2. **Try constructive layouts.** Ordered bundles, bundle turnarounds, compact port jogs, column schedules, and local S-bends can produce paths before search. Column scheduling assigns ordered tracks to openings and checks adjacent transitions with the actual widths. Selective cost scoring tries weighted transitions when the span pass finds a layout with fragmented short shifts. A constructed layout goes through the ordinary seed materializer and verifier.
|
||||
3. **Probe, then widen.** Short shifts in both axes may get a guide pass first. Column jogs can assign lanes and stagger 90-degree turns before the probe. The near-port probe uses up to 100 nodes per search and **two congestion iterations** with the standard arc proxy, respecting smaller caller limits. Alternate proxies retain the configured iteration budget. Direct passes reserve safe straight links, check whether the remaining ports are connected, and can change the lock order. A narrow unlocked probe can test whether a straight reservation blocks a nearby exit. A one-net residual can try a four-turn dogleg and two-net boards can try paired perimeter routes. The wider lookahead uses the smaller of 500 nodes and the caller's ceiling, with the configured iteration limit. Live callbacks and shuffled ordering affect the placement of some early stages.
|
||||
4. **Recover unresolved nets.** Freeze verified incumbents as static geometry when the remaining ports stay connected. If hard locks disconnect the residual, pass the incumbents as movable seeds. For some unresolved shared portals, retry with different joint lane assignments. Complete locked candidates and improved joint retries get a whole-layout check. If needed, try whole-layout seed and lattice search, followed by a lattice retry at the caller's ceiling.
|
||||
5. **Select and refine.** More verified net IDs wins. Lower cost breaks ties between candidates with identical verified IDs. Locally checked paths remain ineligible until their required layout check passes. If enabled, refine the selected layout and accept a replacement that preserves the verified ID set and improves the score.
|
||||
|
||||
- `inire/model.py`: Immutable request and option dataclasses.
|
||||
- `inire/results.py`: Immutable routing results plus the per-run `RouteMetrics` snapshot.
|
||||
- `inire/seeds.py`: Serializable path-seed primitives.
|
||||
- `inire/geometry/primitives.py`: Integer Manhattan ports and small transform helpers.
|
||||
- `inire/geometry/components.py`: `Straight`, `Bend90`, and `SBend` geometry generation.
|
||||
- `inire/geometry/collision.py`: Routing-world collision, congestion, ray-cast, and path-verification logic.
|
||||
- `inire/geometry/static_obstacle_index.py` and `inire/geometry/dynamic_path_index.py`: Spatial-index management for static obstacles and routed paths, including dynamic per-object indices, per-net grid occupancy, congestion grid membership, and per-net dynamic envelopes.
|
||||
- `inire/router/_search.py`, `_astar_moves.py`, `_astar_admission.py`, `_astar_types.py`: The state-lattice A* search loop and move admission pipeline.
|
||||
- `inire/router/_router.py`: The negotiated-congestion driver and refinement orchestration.
|
||||
- `inire/router/_congestion_policy.py` contains the iteration review, reroute selection, and stopping rules. `_route_traces.py` formats diagnostics from the driver’s collected data.
|
||||
- `inire/router/_pair_local.py` searches for replacements in a separate routing world. The driver installs and verifies proposed replacements and restores the incumbent layout when a candidate is rejected.
|
||||
- `inire/router/_automatic.py` selects and verifies planner candidates for the default public routing mode. It retries at the configured lattice search ceiling when the first pass falls short of the routing bound.
|
||||
- `inire/router/_capacity.py` calculates vertical cut bounds and disjoint fixed-port conflicts for the automatic router.
|
||||
- `inire/router/_topology.py` builds alternative corridors through triangulated free space and ranks portal lanes using capacity, route overlap, and estimated turn clearance.
|
||||
- `inire/router/_bundle.py` constructs ordered routes from rectangular barriers and terminal order for the opt-in bundle mode. `_waypoints.py` compiles its turns and S-bends into physical path seeds.
|
||||
- `inire/router/refiner.py`: Post-route path simplification for completed paths.
|
||||
- `inire/router/cost.py` and `inire/router/danger_map.py`: Search scoring and obstacle-proximity biasing.
|
||||
- `inire/utils/visualization.py`: Plotting and diagnostics helpers.
|
||||
Automatic uses the lattice worker directly for custom physical or polygonal proxy bends and when constrained triangulation is unavailable. [Topology planning](topological-routing.md) describes corridor ranking and seed realization.
|
||||
|
||||
## Routing Stack
|
||||
## Detailed search and congestion
|
||||
|
||||
The public `route()` function dispatches automatic planner selection and explicit modes. Both use `route_once()` in `inire/router/_stack.py` to run a single mode and collect its diagnostics. Each attempt builds a routing stack composed of:
|
||||
The search key is an integer `(x, y, heading)` port. [Move generation](../inire/router/_astar_moves.py) proposes variable-length straights, 90-degree bends, and S-bends. Ray casts, visible corners, and corridor waypoints supply additional straight endpoints. [Admission](../inire/router/_astar_admission.py) checks state dominance, cost bounds, and collisions before enqueuing a move. [The search loop](../inire/router/_search.py) ranks candidates by accumulated cost plus a weighted heuristic. When an attempt runs out of budget, it can return the partial path with the best remaining heuristic.
|
||||
|
||||
1. `RoutingWorld` for collision state.
|
||||
2. `DangerMap` for static-obstacle proximity costs.
|
||||
3. `CostEvaluator` for move scoring and heuristic support.
|
||||
4. `AStarContext` for caches and search configuration.
|
||||
5. `PathFinder` for negotiated congestion, rip-up/reroute, and refinement.
|
||||
[`PathFinder`](../inire/router/_router.py) materializes caller seeds, plans corridors when requested, and can bootstrap with greedy warm starts. During routing it removes a net's old geometry, searches with the current collision state, and installs the new result. The first pass can use a cheaper bend proxy. Later iterations raise the congestion penalty to give routes an incentive to separate.
|
||||
|
||||
The search state is a snapped Manhattan `(x, y, r)` port. From each state the router expands straight segments, 90-degree bends, and compact S-bends, then validates candidates against static geometry, dynamic congestion, and optional self-collision checks.
|
||||
At each iteration boundary, the driver rechecks reached-target paths against the installed geometry. It saves the layout with the most completed nets, then the fewest conflict edges and dynamic collisions. [Congestion policy](../inire/router/_congestion_policy.py) chooses which nets to reroute and stops on completed or stalled layouts. Late iterations with a small all-reached conflict graph can reroute just the conflicting set and carry forward expensive incumbents. After restoring the best snapshot, [pair-local search](../inire/router/_pair_local.py) tries both orders for an eligible final conflict pair with the other nets frozen. The driver verifies the proposed replacement in the live world and restores the incumbents if it fails.
|
||||
|
||||
When enabled, topological planning runs before the first iteration. The lattice uses its waypoint suggestions during search. Seed mode additionally realizes and verifies paths inside candidate corridors before handing them off for negotiated routing and refinement.
|
||||
## Geometry, verification, and refinement
|
||||
|
||||
## Notes On Current Behavior
|
||||
The [collision world](../inire/geometry/collision.py) manages raw, clearance-adjusted, and width-specific static geometry. Dynamic paths use a grid and net envelopes to narrow candidate sets before exact polygon checks. [Static](../inire/geometry/static_obstacle_index.py) and [dynamic](../inire/geometry/dynamic_path_index.py) indices own their geometry and caches. The [danger map](../inire/router/danger_map.py) samples obstacle boundaries in a KD-tree. The [visibility planner](../inire/router/visibility.py) builds a lazy static corner index for tangent guidance and a separate graph for exact-corner queries.
|
||||
|
||||
- Static obstacles and routed paths are treated as single-layer geometry; automatic crossings are not supported.
|
||||
- The danger-map implementation uses sampled obstacle-boundary points and a KD-tree, not a dense distance-transform grid.
|
||||
- The visibility subsystem keeps a lazy static corner index for default `tangent_corner` guidance and only builds the exact corner-to-corner graph on demand for `exact_corner` queries.
|
||||
- `use_tiered_strategy` can swap in a cheaper bend proxy on the first congestion iteration.
|
||||
- Negotiated congestion now re-verifies every reached-target path at the end of each iteration against the final installed dynamic geometry, and it stops early if the conflict graph stalls for consecutive iterations.
|
||||
- In the late all-reached low-edge regime, negotiated congestion reroutes only the current conflict set instead of all nets. The heaviest remaining late reroutes can be capped and carried forward by restoring their incumbent reached-target paths when more search would just churn before pair-local repair.
|
||||
- After best-snapshot restoration, the router runs a bounded pair-local scratch reroute on final two-net reached-target conflict pairs. That repair phase clones static obstacles from the live collision world, treats all outside-pair geometry as fixed blockers, tries both pair orders, and only keeps the result if whole-set reverify improves.
|
||||
- Final `RoutingResult` validity is determined by explicit post-route verification, not only by search-time pruning.
|
||||
Search may use proxy geometry. Verification uses physical components, checks static and dynamic clearance and self-collisions, and adds board containment to automatic trial verification. A mitred static buffer can overestimate clearance near corners. Physical distance resolves those candidates. Locked geometry exposes the unbuffered polygons so the receiving problem can apply its own clearance.
|
||||
|
||||
## Performance Visibility
|
||||
[`PathRefiner`](../inire/router/refiner.py) proposes shorter or cheaper replacements in windows of the selected path. With a finite window limit above one it tries bend-ended windows first, longest within each group. The one-window and unlimited modes use longest-first ordering. It scores candidate moves before building polygons. For a verified incumbent it checks the changed window against the board's collision world and the unchanged route. Final verification accounts for the installed result.
|
||||
|
||||
`RoutingRunResult.metrics` includes both A* counters and index/cache/verification counters. The committed example-corpus baseline for those counters is tracked in `docs/performance.md` and `docs/performance_baseline.json`.
|
||||
## Implementation map
|
||||
|
||||
The [topological routing experiment](topological-routing.md) compares soft corridor guidance and corridor-first seed generation with the state-lattice baseline. The [refactor plan](routing-refactor-plan.md) documents the exact parity command for checking implementation changes against a baseline.
|
||||
| Responsibility | Source |
|
||||
| --- | --- |
|
||||
| Public inputs, outputs, and seed types | [Model](../inire/model.py), [results](../inire/results.py), [seeds](../inire/seeds.py) |
|
||||
| Planner implementations | [Bundles](../inire/router/_bundle.py), [columns](../inire/router/_columns.py), [compact links](../inire/router/_compact.py), [perimeter detours](../inire/router/_perimeter.py) |
|
||||
| Bounds and corridor allocation | [Capacity](../inire/router/_capacity.py), [topology](../inire/router/_topology.py) |
|
||||
| Physical paths and scoring | [Components](../inire/geometry/components.py), [seed materialization](../inire/router/_seed_materialization.py), [cost](../inire/router/cost.py) |
|
||||
| Diagnostics formatting | [Trace formatters](../inire/router/_route_traces.py), [benchmark tools](routing-diagnostics.md) |
|
||||
|
|
|
|||
Loading…
Reference in a new issue