Refine routing geometry checks and streamline documentation

Report coincident terminals and unusable seeds per net, update custom bend handling and verification, and cover the revised behavior with regression tests.

Shorten the user and developer guides around reader tasks and keep the illustrated routing walkthrough and reference links easy to find.
This commit is contained in:
Jan Petykiewicz 2026-11-29 23:12:28 -08:00
commit eac083a37d

View file

@ -1,28 +1,41 @@
# Route a layout
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.
- [Run the single-net quick start](../../README.md#route-a-net)
## 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.** 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)`. Automatic mode is the default. Before using a placement recipe, [check the net's result](tune-and-troubleshoot.md#read-the-result).
Choose a coordinate unit fine enough for your layout. `Port` rounds coordinates to integers. Use the direction of travel at both ports (0° east, 90° north).
```python
from shapely.geometry import box
from inire import NetSpec, Port, RoutingProblem, route
net = NetSpec("input", Port(10, 20, 0), Port(90, 20, 0), width=2)
problem = RoutingProblem(
bounds=(0, 0, 100, 80),
nets=(net,),
static_obstacles=(box(40, 40, 60, 60),),
clearance=2,
)
result = route(problem).results_by_net["input"]
```
- [Check the result](tune-and-troubleshoot.md#read-the-result)
- [Set allowed bend radii](api-reference.md#searchoptions)
- [Layout input types and defaults](api-reference.md#routingproblem)
<a id="connect-a-preplaced-crossing"></a>
## Route between placed crossings
1. **Place the crossing cells.** Keep each cell's physical footprint and internal connections in your layout. Get the port positions and headings in board coordinates after applying placement and rotation.
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 your 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.
1. Place both cells and transform their ports into board coordinates.
2. Use the cells' routing keepouts or cut port openings in copies of their footprints.
3. Add a net for each external connection. A route entering B's west-facing port travels east, so its target heading is 0.
![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.
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.
The shaded keepouts have 12-unit openings in the dashed cell footprints. A straight approach needs 10 units (width 2 plus clearance 4 on each side).
```python
from shapely.geometry import box
@ -63,13 +76,13 @@ result = run.results_by_net[net_id]
assert result.is_valid
```
When assembling the layout, check the port joins and clearance against the actual placed-cell geometry. Inire verifies the external route against the keepouts you supplied.
Check joins and clearance against the full cells when assembling the layout.
For declared port widths and transition cells, see [Check placed optical ports](fabrication.md#check-placed-optical-ports).
- [Port widths and transition cells](fabrication.md#check-placed-optical-ports)
## Save a placement recipe
After checking `result.is_valid`, use `result.as_seed()` to get the ordered moves. Keep the effective net, the component settings, and your coordinate unit with the recipe. The effective net records the resolved terminal positions and headings and the route width.
Keep a verified route's resolved net, ordered moves, component settings, and coordinate unit. This snippet uses `result` and `options` from the crossing example.
```python
if not result.is_valid:
@ -78,18 +91,16 @@ if not result.is_valid:
placement = (result.effective_net, result.as_seed(), options.search)
```
The example uses the `options` from the crossing example. If you called `route(problem)`, use `RoutingOptions().search`.
For a run with default options, use `RoutingOptions().search`.
Place the first move at the effective start port and each subsequent move at the previous move's end port. For explicit placements, read the `move_spec`, `start_port`, and `end_port` of each component in `result.path`. Use the same width, radii, tangent extensions, and custom outlines that the router checked.
Your layout tool realizes the components and writes the layout. Choose widths and clearance with enough margin for any downstream rounding. Inire's verification describes the supplied geometry in routing units. Use `result.locked_geometry` to inspect the polygons it checked or reserve them in a later routing run.
Place each move at the previous move's endpoint, starting at the resolved start port. For explicit placements, read `move_spec`, `start_port`, and `end_port` from `result.path`. Use `result.locked_geometry` to compare your layout against the checked polygons, allowing for the writer's rounding.
## 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. Search can follow a partial seed from the first iteration and can leave it to find another approach. To build a hint from turns and straights, see the [path seed reference](api-reference.md#path-seeds).
- **Hold a route fixed.** Check `result.is_valid`, then use `FixedRoute.from_result(result)` and pass it in `fixed_routes` alongside the remaining nets. The next run respects it as a distinct net, including at zero clearance.
- **Allow changes.** Pass `initial_paths={net_id: result.as_seed()}`. Search can follow or leave the [seed](api-reference.md#path-seeds).
- **Hold the route fixed.** Pass `FixedRoute.from_result(result)` in `fixed_routes`. It blocks contact with other nets even at zero clearance.
When terminal headings are inferred, use the effective net with the saved moves to replay the same placement.
Replay the crossing example with its resolved net and saved moves. Reuse `problem` and `options` from that example.
```python
from dataclasses import replace
@ -140,6 +151,6 @@ assert detour.is_valid
detour_placement = (detour.effective_net, detour.as_seed(), options.search)
```
For imported metal or waveguide polygons that belong to an existing net, use `FixedRoute("existing_net", imported_polygons)`. Supply polygons in board coordinates. For other artwork that blocks routing, use `static_obstacles`.
For imported artwork in board coordinates, use `FixedRoute("existing_net", imported_polygons)` if it belongs to a net. Use `static_obstacles` for other keepouts.
To compare the two paths on a plot, see the [fixed-route example](../../examples/README.md#route-around-fixed-geometry).
- [Fixed-route example and plot](../../examples/README.md#route-around-fixed-geometry)