Separate user guides, benchmarks, and routing internals

This commit is contained in:
Jan Petykiewicz 2026-11-26 21:14:29 -08:00
commit e4d5952677

164
DOCS.md
View file

@ -1,162 +1,36 @@
# Inire API and tuning guide
<a id="inire-api-and-tuning-guide"></a>
Start with `route(problem)`. It uses automatic routing with the default options. Import public types from `inire`. The implementation modules under `inire.router` and `inire.geometry` can change between releases. [Quick start](README.md#route-a-net)
# User guide
Get a [first route running](README.md#route-a-net), then use these guides for your own layout.
## Describe a layout
Use `RoutingProblem` to describe a single routing layer. Use the same unit for bounds, coordinates, widths, spacing, and radii. Choose the unit before converting device ports so integer snapping preserves narrow gaps. Headings are degrees counterclockwise from east and must be multiples of 90 after rounding. If your device library describes port headings pointing out of a device, reverse that heading for a target so it follows the waveguide into the device.
| Input | Meaning |
| --- | --- |
| `bounds` | Board outline as `(xmin, ymin, xmax, ymax)`. |
| `nets` | `NetSpec(net_id, start, target, width=2.0)` objects with unique IDs and `Port(x, y, r)` terminals. Defaults to an empty tuple. |
| `static_obstacles` | Shapely polygons for keepouts. Defaults to an empty tuple. |
| `initial_paths` | Mapping from net IDs to `PathSeed` objects. Defaults to an empty mapping. |
| `clearance` | Required spacing between physical shapes. Defaults to `2.0`. |
| `safety_zone_radius` | Tolerance for very small obstacle intersections at ports during search. Defaults to `0.0021`. |
For a preplaced crossing, route the connections to and from its four ports. Keep the internal crossing geometry in the device and leave access openings in its keepout. This lets the router verify clearance around the placed cell while treating each external leg as a separate connection. [Crossing benchmark fixtures](docs/topological-routing.md#benchmark-corpus)
### Incremental routing with locked geometry
Reuse the physical polygons of valid routes as static obstacles in the next run. The next run applies its own clearance to those polygons.
```python
from dataclasses import replace
from inire import route
first = route(first_problem)
locked = tuple(
polygon
for result in first.results_by_net.values()
if result.is_valid
for polygon in result.locked_geometry
)
second = route(replace(next_problem, static_obstacles=next_problem.static_obstacles + locked))
```
### Initial paths with PathSeed
Use `result.as_seed()` when you want a subsequent run to start from an existing route and still be free to move it. You can also build a `PathSeed` from `StraightSeed`, `Bend90Seed`, and `SBendSeed` segments to suggest an approach. Seeds start at the net's current start port and use the current width and geometry settings. For a route that must remain fixed, use its physical polygons as obstacles. [Locked paths example](examples/03_locked_paths.py)
- [Route a layout](docs/user/route-a-layout.md) covers units, port headings, widths, and keepouts.
- [Connect a preplaced crossing](docs/user/route-a-layout.md#connect-a-preplaced-crossing) shows where to place the ports and how to split the external nets.
- [Reuse an existing route](docs/user/route-a-layout.md#reuse-an-existing-route) explains fixed routes and movable seeds.
## Read the result
`route(problem, options=..., iteration_callback=...)` returns a `RoutingRunResult`. Check `results_by_net[net_id].is_valid` before exporting any path. With explicit `off`, `guide`, or `seed` mode, also check the physical polygons against the board if your export requires containment. Automatic mode includes that check in its candidate verification.
| Outcome | What to inspect |
| --- | --- |
| `completed` | Use `report.total_length` to compare physical length. Use `locked_geometry` for the physical polygons or `as_seed()` for the move sequence. |
| `colliding` | The path reached its target. Check `report` for static, dynamic, or self-collisions, or a failed automatic board containment check. |
| `partial` | Inspect where the returned path ends. An awkward launch or arrival can leave too little room to turn, even when the ports look close in plan view. |
| `unroutable` | There is no returned path. Check the start heading and access to the first straight or bend. The outcome alone does not establish that the net is impossible. |
A live callback receives `(iteration_index, results_by_net)` after each completed congestion iteration. In automatic mode, indices increase across attempts and each callback sees the nets in that attempt. Callback counts and net sets depend on which attempts run. Use the returned result for final verified routes. [Diagnostics and metrics](docs/routing-diagnostics.md)
- [Interpret the result](docs/user/tune-and-troubleshoot.md#read-the-result) before exporting physical paths.
- [Diagnose an unfinished net](docs/user/tune-and-troubleshoot.md#why-a-net-stopped-short) and decide whether to change the layout or try another search.
## Topological routing
Set `RoutingOptions(topology=TopologyOptions(mode=...))` when you need a particular mode.
| Mode | When to use it |
| --- | --- |
| `"automatic"` | Start here for general routing. Inire tries different strategies and keeps the best verified coverage it finds. |
| `"off"` | Isolate detailed lattice search when testing custom bend geometry or comparing the effect of corridor planning. |
| `"guide"` | Try this when obstacles suggest a useful detour and the search needs freedom to leave it to make a turn. |
| `"seed"` | Try this when finding a usable route around the obstacles is the main difficulty and a verified starting route could help. |
| `"bundle"` | Use for supported ordered rectangular bundles, such as the Terminal-Bench point-terminal example. Unsupported layouts and invalid schedules raise `ValueError`. |
`guide` and `seed` require constrained triangulation from Shapely 2.1 with GEOS 3.10 or newer. Caller-supplied seeds take precedence. Nets without corridors can still use lattice search. In bundle mode, use a circular bend radius enabled for both bends and S-bends. Enable heading inference only when the supplied terminals are points with flexible headings. [Topology algorithms and bundle example](docs/topological-routing.md)
### Automatic routing
The first search stages use smaller budgets. If they leave nets unresolved, a later lattice search can use your configured ceiling. Lowering that ceiling limits each search, and can prevent a difficult net from completing. Automatic uses lattice directly for custom bend geometry or when constrained triangulation is unavailable. [Automatic stage order and budgets](docs/architecture.md#automatic-routing)
Compare `len(run.automatic.verified_net_ids)` with `max_routed`. If the verified count already reaches a bound below the requested count, examine `capacity_limit` or `port_conflicts` to find the geometric constraint. More search cannot add a route past that bound. A verified count below the bound leaves room to investigate the search or geometry. [Read a routing report](docs/routing-diagnostics.md#automatic-reports)
[Choose a routing mode](docs/user/tune-and-troubleshoot.md#choose-a-routing-mode) for automatic selection, lattice search, guide, seed, or ordered bundles.
## Tune a run
Set the layout clearance and allowed radii from your process constraints first. Then change one setting at a time on the same layout and check the affected nets as well as the elapsed time.
[Choose a setting to try](docs/user/tune-and-troubleshoot.md#choose-the-next-setting), or open the [API reference](docs/user/api-reference.md) for signatures and defaults.
| If you see | Try |
| --- | --- |
| The router reaches a reported capacity bound | Move the conflicting ports or make more room in the bottleneck. For a mixed-width passage, check the room at the approach and through the turns. |
| A net remains partial below the bound despite plausible turn room | Try a larger `search.node_limit` and check whether that net completes. The limit applies per search. One run may search for the same net several times. |
| Several nets reach their targets and collide with one another | Compare a different `congestion.net_order` or raise `max_iterations` so the router can look for separate paths. Static obstacle collisions call for a geometry check first. |
| All nets route but refinement takes most of the time | Try `refinement.max_windows_per_net=1` and compare the resulting paths. |
| All nets route but carry too many small bends | Try a higher `objective.bend_penalty`. Compare bend counts and physical lengths to see whether straighter routes need longer detours. |
## Examples
To try the shorter refinement pass, derive the new settings from the `options` you already use for the layout.
[Browse the visual examples](examples/README.md) for locked paths, bend geometry, congestion, and partial results.
```python
from dataclasses import replace
from inire import route
## Moved reference sections
faster_refinement = replace(options, refinement=replace(options.refinement, max_windows_per_net=1))
run = route(problem, options=faster_refinement)
```
### SearchOptions
| Field | Default | Effect |
| --- | --- | --- |
| `node_limit` | `1_000_000` | Per-search expansion ceiling. Automatic uses smaller budgets for its initial stages. |
| `min_straight_length` | `5.0` | Minimum single straight length. |
| `max_straight_length` | `2000.0` | Maximum single straight length. |
| `greedy_h_weight` | `1.5` | Weight for the A* heuristic. Lower values give the path cost more influence. |
| `bend_radii` | `(50.0, 100.0)` | Permitted radii for 90-degree bends. |
| `sbend_radii` | `(10.0,)` | Permitted S-bend radii. |
| `sbend_offsets` | `None` | Set permitted lateral offsets explicitly, or let search suggest offsets. A compact S-bend needs a nonzero offset with magnitude less than twice its radius. |
| `bend_collision_type` | `"arc"` | Search proxy, one of `"arc"`, `"bbox"`, or `"clipped_bbox"`. The legacy polygon form defines both shapes unless split geometry is supplied. |
| `bend_proxy_geometry` | `None` | Override the proxy. A custom polygon proxy by itself keeps the standard physical arc and emits a warning. |
| `bend_physical_geometry` | `None` | Override the physical geometry with `"arc"` or a polygon. A custom physical polygon also supplies the default proxy when the collision type is `"arc"`. |
| `bend_clip_margin` | `None` | Optional legacy shrink margin for `"clipped_bbox"`. The default uses the eight-point proxy. |
| `visibility_guidance` | `"tangent_corner"` | Choose tangent candidates, exact corner visibility with `"exact_corner"`, or no visibility suggestions with `"off"`. |
### ObjectiveWeights
The search objective scores path length, components, and proximity. Increasing a component penalty makes routes with more of that component less attractive. Refinement can use its own objective.
| Field | Default | Effect |
| --- | --- | --- |
| `unit_length_cost` | `1.0` | Cost per unit of path length. |
| `bend_penalty` | `250.0` | Additional cost of a 90-degree bend, scaled by radius. |
| `sbend_penalty` | `500.0` | Additional cost of an S-bend. |
| `danger_weight` | `1.0` | Weight of the obstacle proximity cost. |
### CongestionOptions
Increase the iteration limit when later reroutes might resolve conflicts. Adjust the initial penalty or multiplier when nets keep competing for the same space.
| Field | Default | Effect |
| --- | --- | --- |
| `max_iterations` | `10` | Maximum congestion iterations per attempt. Automatic's initial probe may use fewer. |
| `base_penalty` | `100.0` | Initial penalty for overlapping other routes. |
| `multiplier` | `1.5` | Scale the penalty between unresolved iterations. |
| `use_tiered_strategy` | `True` | Allow a cheaper bend proxy in the first iteration when applicable. |
| `net_order` | `"user"` | Route in input order or use `"shortest"` or `"longest"`. |
| `warm_start_enabled` | `True` | Build greedy seeds before congestion iterations. |
| `shuffle_nets` | `False` | Shuffle routing order between iterations. |
| `seed` | `None` | Random seed for shuffled ordering. |
### RefinementOptions
| Field | Default | Effect |
| --- | --- | --- |
| `enabled` | `True` | Try geometric improvements after routing. |
| `objective` | `None` | Use another `ObjectiveWeights` value for refinement, or reuse the search objective. |
| `max_windows_per_net` | `4` | Maximum candidate windows per net across improvement rounds. Use `1` for a shorter pass or `None` for unlimited windows. |
### TopologyOptions
| Field | Default | Effect |
| --- | --- | --- |
| `mode` | `"automatic"` | Select a [routing mode](#topological-routing). |
| `max_corridors` | `3` | Limit alternative corridors per net. |
| `guide_strength` | `0.75` | Maximum added guidance cost per unit length. Zero keeps the suggested moves without adding cost. |
| `seed_node_limit` | `600` | Total seed-search expansions per net, capped by the active search limit. |
| `infer_terminal_headings` | `False` | Allow heading inference for bundle-style point terminals. Automatic preserves caller headings when initial paths are supplied. |
| `automatic_cost` | `"selective"` | Re-score column layouts when they chain short S-bends. Use `"always"` for both passes or `"never"` for span scoring alone. |
| `automatic_length_weights` | `None` | Optional straight, 90-degree bend, and S-bend length multipliers for automatic candidate selection. The default uses the search objective. |
### DiagnosticsOptions
The flags default to `False`. Use `capture_expanded` to plot explored states or `capture_iteration_trace` to attribute search work per net and iteration. For clearance conflicts, `capture_conflict_trace` reports overlapping pairs, `capture_frontier_trace` examines prunes near final hotspots, and `capture_pre_pair_frontier_trace` examines the state before pair-local repair. [Trace fields and examples](docs/routing-diagnostics.md#traces)
- <a id="incremental-routing-with-locked-geometry"></a><a id="initial-paths-with-pathseed"></a>[Fixed routes and path seeds](docs/user/route-a-layout.md#reuse-an-existing-route)
- <a id="automatic-routing"></a>[Automatic routing and other modes](docs/user/tune-and-troubleshoot.md#choose-a-routing-mode)
- <a id="searchoptions"></a>[SearchOptions](docs/user/api-reference.md#searchoptions) and <a id="objectiveweights"></a>[ObjectiveWeights](docs/user/api-reference.md#objectiveweights)
- <a id="congestionoptions"></a>[CongestionOptions](docs/user/api-reference.md#congestionoptions) and <a id="refinementoptions"></a>[RefinementOptions](docs/user/api-reference.md#refinementoptions)
- <a id="topologyoptions"></a>[TopologyOptions](docs/user/api-reference.md#topologyoptions) and <a id="diagnosticsoptions"></a>[DiagnosticsOptions](docs/user/api-reference.md#diagnosticsoptions)