Tie routing documentation to user and developer workflows

This commit is contained in:
Jan Petykiewicz 2026-11-27 10:15:54 -08:00
commit 2c7a7ea90a

View file

@ -1,16 +1,14 @@
# Route a layout
Start with the [first route](../../README.md#route-a-net), then replace the example ports and add your layout's constraints.
To get a result you can experiment with, run the [single-net quick start](../../README.md#route-a-net). To route your own design, set up the board and connections in the order below.
## 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.
3. **Add a net for each connection.** Give each `NetSpec` a unique ID and the guide width. Set your process limits through `SearchOptions` and choose the required clearance on `RoutingProblem`.
4. **Add keepouts.** Supply Shapely polygons in `static_obstacles` and use `bounds` for the board rectangle. Leave enough access at the ports for the guide and its permitted bends.
5. **Run and check.** Call `route(problem, options=options)`. Start with automatic mode for general layouts and [check each net before export](tune-and-troubleshoot.md#read-the-result).
For the constructor signatures and field defaults, see the [layout input reference](api-reference.md#layout-inputs).
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).
<a id="connect-a-preplaced-crossing"></a>
@ -22,9 +20,9 @@ For the constructor signatures and field defaults, see the [layout input referen
![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)
Dashed outlines show the complete device footprints. Shading shows the keepouts passed to Inire. The external route connects the two port markers. The arrow at each marker shows the heading.
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.
Inire applies `clearance` around the supplied keepout polygons. A straight approach of width `w` between two keepout edges needs at least `w + 2 * clearance` of open width. Leave room for any turn near the port and check the opening after snapping the port to the grid.
Each opening is 12 units wide. A straight approach of width 2 with clearance 4 on each side needs `2 + 2 * 4 = 10` units between keepout edges. Leave extra room for any turn near a port, and check the opening after snapping the port to the grid.
```python
from shapely.geometry import box
@ -59,40 +57,61 @@ problem = RoutingProblem(
search = SearchOptions(
bend_radii=(25,), sbend_radii=(25,),
)
opts = RoutingOptions(search=search)
run = route(problem, options=opts)
options = RoutingOptions(search=search)
run = route(problem, options=options)
result = run.results_by_net[net_id]
assert result.is_valid
```
Before export, check the port joins and clearance against the actual placed-cell geometry. Inire verifies the external route against the keepouts you supplied.
## 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.
```python
from pathlib import Path
from shapely.geometry import GeometryCollection
if not result.is_valid:
raise ValueError(f"{result.net_id}: {result.outcome}")
geometry = GeometryCollection(result.locked_geometry)
Path("route.wkt").write_text(geometry.wkt + "\n", encoding="utf-8")
```
For a multi-net layout, apply the validity check to every net you intend to export. If a route is short or colliding, use its outcome to choose the [next troubleshooting check](tune-and-troubleshoot.md#read-the-result).
## 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.
To reuse the verified routes from a first problem as fixed obstacles, add them to a second problem that contains the remaining nets.
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.
```python
from dataclasses import replace
from inire import route
from inire import (
NetSpec, Port, RoutingOptions,
RoutingProblem, SearchOptions, 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
bounds = (0, -50, 100, 50)
options = RoutingOptions(search=SearchOptions(bend_radii=(10,)))
first = RoutingProblem(
bounds=bounds,
nets=(NetSpec("fixed", Port(10, 0, 0), Port(90, 0, 0)),),
)
obstacles = (
next_problem.static_obstacles
+ locked
fixed = route(first, options=options).results_by_net["fixed"]
assert fixed.is_valid
second = RoutingProblem(
bounds=bounds,
nets=(NetSpec("detour", Port(50, -20, 90), Port(50, 20, 90)),),
static_obstacles=fixed.locked_geometry,
)
second = route(replace(
next_problem,
static_obstacles=obstacles,
))
detour = route(second, options=options).results_by_net["detour"]
assert detour.is_valid
```
To see the second route detour around a fixed path, run the [locked-path example](../../examples/README.md#route-around-fixed-geometry).
To compare the two paths on a plot, see the [fixed-route example](../../examples/README.md#route-around-fixed-geometry).