inire/docs/user/route-a-layout.md

98 lines
4.8 KiB
Markdown

# Route a layout
Start with the [first route](../../README.md#route-a-net), then replace the example ports and add your layout's constraints.
## 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).
<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 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)
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.
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.
```python
from shapely.geometry import box
from inire import (
NetSpec, Port, RoutingOptions,
RoutingProblem, SearchOptions,
route,
)
# Example footprints and access openings in board coordinates.
a = box(30, 50, 80, 100)
b = box(260, 90, 310, 140)
a_access = box(74, 69, 82, 81)
b_access = box(258, 109, 266, 121)
a_keepout = a.difference(a_access)
b_keepout = b.difference(b_access)
net_id = "A_east_to_B_west"
link = NetSpec(
net_id,
Port(80, 75, 0),
Port(260, 115, 0),
width=2,
)
problem = RoutingProblem(
bounds=(0, 0, 340, 180),
nets=(link,),
static_obstacles=(a_keepout, b_keepout),
clearance=4,
)
search = SearchOptions(
bend_radii=(25,), sbend_radii=(25,),
)
opts = RoutingOptions(search=search)
run = route(problem, options=opts)
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.
## 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.
```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
)
obstacles = (
next_problem.static_obstacles
+ locked
)
second = route(replace(
next_problem,
static_obstacles=obstacles,
))
```
To see the second route detour around a fixed path, run the [locked-path example](../../examples/README.md#route-around-fixed-geometry).