Clarify routing documentation and refresh example figures

This commit is contained in:
Jan Petykiewicz 2026-11-27 11:59:22 -08:00
commit ab97281df3
3 changed files with 128 additions and 121 deletions

View file

@ -8,14 +8,14 @@ Import these types from `inire`. To see how the inputs fit together in a runnabl
route(problem, *, options=None, iteration_callback=None) -> RoutingRunResult
```
Omitting `options` uses `RoutingOptions()`. To observe live congestion iterations, pass a callable accepting `(index, results_by_net)`. The index increases across automatic attempts. Each callback sees the nets in its current attempt. Use the returned result for final coverage.
Omitting `options` uses `RoutingOptions()`. To observe progress, pass a callable accepting `(index, results_by_net)`. Each call reports one completed congestion iteration on the nets in that attempt. Automatic mode keeps increasing the index across attempts. Check the returned result for final coverage, including on runs that finish without a callback.
## Layout inputs
### Ports and nets
- `Port(x, y, r)` snaps coordinates to the integer grid and normalizes the heading `r` in degrees. Heading 0 points east and 90 points north. The heading must be a multiple of 90 after rounding.
- `NetSpec(net_id, start, target, width=2.0)` uses a unique ID and two ports. The target heading is the direction of arrival.
- `Port(x, y, r)` rounds coordinates to integers. The heading `r` is in degrees, with 0 east, 90 north, 180 west, and 270 south. The rounded angle must be a multiple of 90 and is wrapped to the range 0–359.
- `NetSpec(net_id, start, target, width=2.0)` uses a unique ID and two ports. Set the start heading to the direction of departure and the target heading to the direction of arrival.
### RoutingProblem
@ -28,7 +28,7 @@ The fields below appear in constructor order. Use one layout unit for coordinate
| `static_obstacles` | `()` | Shapely polygons that define keepouts. |
| `initial_paths` | Empty mapping | Net IDs mapped to `PathSeed` objects. |
| `clearance` | `2.0` | Required spacing between physical shapes. |
| `safety_zone_radius` | `0.0021` | Tolerance for very small obstacle intersections at ports during search. |
| `safety_zone_radius` | `0.0021` | Tolerance for small obstacle intersections at a move's endpoints during search. |
## Path seeds
@ -39,11 +39,11 @@ The fields below appear in constructor order. Use one layout unit for coordinate
| Value | Read it for |
| --- | --- |
| `RoutingRunResult.results_by_net` | A mapping from net ID to `RoutingResult`. |
| `RoutingResult.is_valid` and `outcome` | Final validity and a status of `completed`, `colliding`, `partial`, or `unroutable`. |
| `RoutingResult.is_valid` and `outcome` | `is_valid` is true when the outcome is `completed`. Read `outcome` to distinguish success, a failed geometry check (`colliding`), a path that stopped short (`partial`), or an empty path (`unroutable`). |
| `RoutingResult.path` | Ordered path components from the source to the last reached state. An unroutable result has an empty path. |
| `RoutingResult.reached_target` | Whether the path reached the target port with its required heading. |
| `RoutingResult.reached_target` | Whether the path reached the target position and heading. With heading inference, the check uses the chosen heading. Read `is_valid` for the result of geometry verification. |
| `RoutingResult.report` | `total_length` in layout units plus static, dynamic, and self-collision counts. `out_of_bounds` records a board containment failure when checked. |
| `RoutingResult.locked_geometry` and `as_seed()` | Physical polygons for export or fixed obstacles, and the move sequence for reuse as a seed. |
| `RoutingResult.locked_geometry` and `as_seed()` | Physical polygons and the sequence of moves, respectively. Check validity before exporting polygons or using them as keepouts. |
| `RoutingRunResult.automatic` | In automatic mode, the selected planner, verified IDs, stage history, and any capacity or port-conflict bound. `None` for explicit modes. |
| `RoutingRunResult.topology` and `metrics` | Corridor counts and seed work when reported by the selected worker, plus work counters across the run. |
@ -67,9 +67,9 @@ To read a route's polygons and write them to a test file, follow the [geometry e
| 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. |
| `min_straight_length` | `5.0` | Minimum length for regular forward moves in lattice search. |
| `max_straight_length` | `2000.0` | Maximum distance the forward scan uses to propose straight moves in lattice search. |
| `greedy_h_weight` | `1.5` | Weight on the estimated cost still needed to reach the target. Lower values give more influence to the cost of the path so far. |
| `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. |
@ -86,7 +86,7 @@ The search objective scores path length, components, and proximity. Increasing a
| 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. |
| `bend_penalty` | `250.0` | Additional cost of a 90-degree bend. Smaller radii incur a larger surcharge when this penalty is positive. |
| `sbend_penalty` | `500.0` | Additional cost of an S-bend. |
| `danger_weight` | `1.0` | Weight of the obstacle proximity cost. |
@ -100,7 +100,7 @@ Increase the iteration limit when later reroutes might resolve conflicts. Adjust
| `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"` | Start from input order or sort by terminal Manhattan distance with `"shortest"` or `"longest"`. |
| `net_order` | `"user"` | Start from input order or sort by the sum of the horizontal and vertical distances between ports with `"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. |
@ -111,7 +111,7 @@ Increase the iteration limit when later reroutes might resolve conflicts. Adjust
| --- | --- | --- |
| `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. |
| `max_windows_per_net` | `4` | Maximum number of path sections to try replacing per net across improvement rounds. Use `1` for a shorter pass or `None` to remove this limit. |
### TopologyOptions
@ -120,11 +120,11 @@ For a layout that repeatedly stops short at an opening, `guide` can suggest a pa
| Field | Default | Effect |
| --- | --- | --- |
| `mode` | `"automatic"` | Select a [routing mode](tune-and-troubleshoot.md#choose-a-routing-mode). |
| `max_corridors` | `3` | Limit alternative corridors per net. |
| `max_corridors` | `3` | Maximum proposed passages 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. |
| `infer_terminal_headings` | `False` | Let automatic or bundle mode choose headings for supported layouts with flexible port directions. Automatic preserves caller headings when initial paths are supplied. |
| `automatic_cost` | `"selective"` | Try a second column-planning pass based on route cost when the first pass chains short S-bends. Use `"always"` to try both passes or `"never"` to plan by span 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
@ -135,8 +135,8 @@ The flags default to `False`.
| --- | --- |
| `capture_expanded` | Plot the states explored by search. |
| `capture_iteration_trace` | Attribute search work to individual nets and iterations. |
| `capture_conflict_trace` | Find overlapping pairs of routes. |
| `capture_frontier_trace` | Examine pruning near a final overlap. |
| `capture_conflict_trace` | Find pairs of routes with clearance conflicts. |
| `capture_frontier_trace` | See why search pruned moves near a final route conflict. |
| `capture_pre_pair_frontier_trace` | Inspect the routing state before pair-local repair. |
For the corresponding result fields and a worked trace, see the [developer diagnostics](../routing-diagnostics.md#traces).

View file

@ -5,10 +5,10 @@ To get a result you can experiment with, run the [single-net quick start](../../
## Define the inputs
1. **Choose a coordinate unit.** Inire snaps port coordinates to an integer grid. Choose a unit fine enough to preserve narrow gaps, and use it for widths, radii, clearance, and bounds too.
2. **Set source and target headings.** Heading 0 points east and 90 points north. The source heading points along the launch. The target heading points along the arrival. If your device library labels the target port with its outward heading, reverse it by 180 degrees.
2. **Set source and target headings.** A heading is the direction the waveguide travels as it leaves its source or enters its target. Heading 0 points east and 90 points north. If a device labels a target port by the direction it faces outward, reverse that heading by 180 degrees. For example, a waveguide entering a west-facing port travels east, so its target heading is 0.
3. **Add a net for each connection.** Give each `NetSpec` a unique ID and the guide width. Use your process's allowed bend radii in [`SearchOptions`](api-reference.md#searchoptions).
4. **Set the board and keepouts.** Pass the board rectangle as `bounds`, Shapely polygons as `static_obstacles`, and the required physical spacing as `clearance`. For the defaults and accepted inputs, see [`RoutingProblem`](api-reference.md#routingproblem).
5. **Route and check.** Call `route(problem, options=options)` with automatic mode for a general layout. Before exporting, [check each net's result](tune-and-troubleshoot.md#read-the-result).
5. **Route and check.** Call `route(problem, options=options)`. Automatic mode is the default. Before exporting, [check each net's result](tune-and-troubleshoot.md#read-the-result).
<a id="connect-a-preplaced-crossing"></a>
@ -18,7 +18,7 @@ To get a result you can experiment with, run the [single-net quick start](../../
2. **Reserve routing keepouts around the cells.** Use the device's routing keepout if supplied. Otherwise, start from its footprint and make local openings at the ports you're connecting. Keep the full physical cell in the exported layout.
3. **Route the external connections.** Give Inire one net per connection between devices. The example connects A's east port to B's west port. B's arrival heading points east into the cell.
![Two offset rectangular crossing cells with finite footprints. The solid external waveguide leaves A's east port and enters B's west port. Small cutouts in the shaded keepouts allow port access.](../figures/placed-crossing.png)
![Two rectangular crossing cells at different heights. A waveguide runs from the opening on A's right edge to the opening on B's left edge. Both port arrows point east.](../figures/placed-crossing.png)
The dashed outlines show the full footprints of crossings A and B. The shaded keepouts leave a port opening on each facing edge. The external waveguide leaves A at `(80, 75)` and enters B at `(260, 115)`. Both arrows point east.
@ -67,7 +67,7 @@ Before export, check the port joins and clearance against the actual placed-cell
## Export verified geometry
Use `result.locked_geometry` to pass a verified net's physical polygons to a layout writer. For a test file, continue from the quick start or the crossing example and write the polygons as WKT in the layout's coordinate unit.
Use `result.locked_geometry` to pass a verified net's physical polygons to a layout writer. To inspect the coordinates in a text file, continue from the quick start or the crossing example and write the polygons as well-known text (WKT). Keep track of your coordinate unit when importing the file into another tool.
```python
from pathlib import Path
@ -86,7 +86,7 @@ For a multi-net layout, apply the validity check to every net you intend to expo
## Reuse an existing route
- **Give the router a route it can move.** Put `result.as_seed()` in `initial_paths` under the net's ID. A seed uses the current start port, width, and geometry settings. A partial seed can suggest an approach. To build a hint from turns and straights, see the [path seed reference](api-reference.md#path-seeds).
- **Hold a route fixed.** Add `result.locked_geometry` to `static_obstacles` while routing other nets. The next run applies its own clearance.
- **Hold a route fixed.** Check `result.is_valid`, then add `result.locked_geometry` to `static_obstacles` while routing other nets. The next run applies its own clearance to those polygons.
Route a straight net, then use its polygons as keepouts in a second routing problem. The second net has to detour around one end of the fixed route.

View file

@ -1,22 +1,22 @@
# Tune and troubleshoot a route
Start with the net's outcome. It tells you whether to examine the port approach, an overlap, or the search budget.
Start with `run.results_by_net[net_id].outcome`. It distinguishes a path that stopped short from one that reached its target and failed a geometry check.
## Read the result
| `result.outcome` | What to inspect |
| --- | --- |
| `completed` | The path reached its target and passed verification. Read its length in `report.total_length` and follow the [geometry export steps](route-a-layout.md#export-verified-geometry). |
| `colliding` | The path reached its target. Check the collision counts in `result.report` to see whether it overlaps a keepout, another route, or itself. For automatic routing, also check `report.out_of_bounds`. |
| `partial` | Locate `result.path[-1].end_port` on the board and check the next turn and radius. If that approach fits, compare search limits. |
| `colliding` | The path reached its target and failed verification. Check `result.report` for keepout clearance, conflicts with another route, or self-overlap. In automatic mode, also check `report.out_of_bounds`. |
| `partial` | Read the position and heading of `result.path[-1].end_port`. Check room for the path to continue from that heading. If the next turn fits, compare search limits. |
| `unroutable` | The path is empty. Check the launch heading and room for the first straight or bend. |
Check `is_valid` before exporting. With explicit `off`, `guide`, or `seed` mode, also check that the physical polygons fit the board if your export requires containment. Automatic mode includes that check in candidate verification.
## Why a net stopped short
1. **Check whether automatic routing hit a bound.** Compare the verified count with `run.automatic.max_routed`. If the count reaches a bound below the requested total, use `capacity_limit` to locate the passage to widen or `port_conflicts` to find the ports to move.
2. **Check the next approach.** Follow a partial route from its endpoint toward the target. Check the width, clearance, allowed turns, and final heading against the physical layout. When none of the allowed bends fits, change the port approach or the available space.
1. **Check the coverage bound in automatic mode.** Compare the verified count with `run.automatic.max_routed`. If the bound is below the requested total, `capacity_limit` can identify a cut with too few tracks and `port_conflicts` can identify pairs of nets whose ports are too close. If the count falls below the bound, check the approaches and search limits as well.
2. **Check the next approach.** Follow a partial route from its last heading toward the target heading. Check whether the allowed turns fit with the guide width and clearance. If the approach requires a turn larger than the available space, reposition the port or give the turn more room.
3. **Compare two search limits.** If the geometry looks feasible, rerun with a larger `search.node_limit` and compare the path endpoint and verified count. The limit applies per search. One run can search the same net several times. Look up the default and related fields in [`SearchOptions`](api-reference.md#searchoptions).
![Two panels of the same obstacle layout. At a three-node search limit the dashed path stops before the obstacles. At 500 nodes the solid path curves around them and arrives at the target.](../figures/partial-and-complete.png)
@ -28,23 +28,23 @@ At three nodes per search the dashed path ends before the first keepout. At 500
Set `TopologyOptions(mode=...)` and pass it as `topology` in `RoutingOptions`.
- **`automatic`.** Start here. Inire chooses from constructive planners and search stages and keeps the best verified coverage it finds.
- **`off`.** Isolate lattice search or work with custom physical bend geometry.
- **`guide`.** Use suggested corridors when a detour looks promising and the router needs freedom to leave the corridor to turn.
- **`seed`.** Try to realize a verified starting path inside a corridor before the detailed search.
- **`bundle`.** Route supported ordered rectangular bundles. Use a circular radius enabled for both bends and S-bends. Unsupported layouts and invalid schedules raise `ValueError`.
- **`off`.** Run lattice search directly to measure what search can do without corridor suggestions.
- **`guide`.** Suggest a passage through free space. Search can leave it to make a turn.
- **`seed`.** Try to build a valid starting path inside the suggested passage before the detailed search.
- **`bundle`.** Route supported ordered rectangular bundles with an empty `initial_paths` mapping. Use circular physical bends. The smallest 90-degree bend radius must be a positive integer and must also appear in `sbend_radii`. Unsupported layouts and invalid schedules raise `ValueError`.
### Mode requirements
- Guide and seed modes require constrained triangulation from Shapely 2.1 with GEOS 3.10 or newer. Caller-supplied seeds take precedence, and nets without a corridor can use ordinary lattice search.
- Enable `infer_terminal_headings` for point terminals with flexible headings. Preserve fixed headings when a device requires a specific arrival direction.
- In automatic mode, smaller initial budgets make the first attempts cheaper. If coverage remains below the bound, a lattice fallback can use your configured ceiling. Automatic also uses lattice for custom bend geometry or when constrained triangulation is unavailable.
- In guide and seed modes, nets without a corridor can use ordinary lattice search. A caller-supplied seed takes precedence over a generated one. These modes require Shapely 2.1 or later with GEOS 3.10 or later for [constrained triangulation](https://shapely.readthedocs.io/en/2.1.2/reference/shapely.constrained_delaunay_triangles.html).
- Use `infer_terminal_headings` with automatic or bundle mode if your ports may change direction and the layout supports bundle planning. For the same board with fixed and flexible headings, see the [nine-net example](../../examples/advanced.md#nine-net-terminal-bench-board).
- Automatic mode starts with smaller budgets and can retry with your configured ceiling if coverage remains below the bound. It runs lattice search directly for custom physical bends or polygonal search proxies, or when constrained triangulation is unavailable.
## Choose the next setting
| Observation | Next comparison |
| --- | --- |
| Multiple routes reach their ports and collide with one another | Change `net_order` or `max_iterations` one at a time. Compare which nets remain unresolved. See the accepted values in [`CongestionOptions`](api-reference.md#congestionoptions). |
| Valid routes use too many small bends | Increase `bend_penalty`. Compare bend counts and physical lengths to see whether a straighter path needs a longer detour. See [`ObjectiveWeights`](api-reference.md#objectiveweights). |
| Valid routes use too many turns | Increase `bend_penalty` for 90-degree turns or `sbend_penalty` for S-bends. Compare the number of each type and the resulting path length. See [`ObjectiveWeights`](api-reference.md#objectiveweights). |
| Refinement dominates runtime | Try `max_windows_per_net=1`. Compare runtime, cost, and verified paths before adopting the smaller limit. See [`RefinementOptions`](api-reference.md#refinementoptions). |
For a shorter refinement pass, derive the new settings from the `options` already used for the layout.