2026-11-26 21:14:29 -08:00
# Route a layout
2026-11-29 23:12:28 -08:00
- [Run the single-net quick start ](../../README.md#route-a-net )
2026-11-26 21:14:29 -08:00
## Define the inputs
2026-11-29 23:12:28 -08:00
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 )
2026-11-26 21:14:29 -08:00
2026-11-26 21:37:05 -08:00
<a id="connect-a-preplaced-crossing"></a>
2026-11-26 21:14:29 -08:00
2026-11-26 21:37:05 -08:00
## Route between placed crossings
2026-11-26 21:14:29 -08:00
2026-11-29 23:12:28 -08:00
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.
2026-11-26 21:14:29 -08:00
2026-11-27 11:59:22 -08:00

2026-11-26 21:37:05 -08:00
2026-11-29 23:12:28 -08:00
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).
2026-11-26 21:37:05 -08:00
```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,),
)
2026-11-27 10:15:54 -08:00
options = RoutingOptions(search=search)
run = route(problem, options=options)
2026-11-26 21:37:05 -08:00
result = run.results_by_net[net_id]
assert result.is_valid
```
2026-11-29 23:12:28 -08:00
Check joins and clearance against the full cells when assembling the layout.
2026-11-26 21:14:29 -08:00
2026-11-29 23:12:28 -08:00
- [Port widths and transition cells ](fabrication.md#check-placed-optical-ports )
2026-11-28 20:42:25 -08:00
2026-11-29 16:36:32 -08:00
## Save a placement recipe
2026-11-27 10:15:54 -08:00
2026-11-29 23:12:28 -08:00
Keep a verified route's resolved net, ordered moves, component settings, and coordinate unit. This snippet uses `result` and `options` from the crossing example.
2026-11-28 20:42:25 -08:00
2026-11-27 10:15:54 -08:00
```python
if not result.is_valid:
2026-11-29 16:36:32 -08:00
raise ValueError(f"Route {result.net_id!r} ended with outcome {result.outcome!r}")
2026-11-27 10:15:54 -08:00
2026-11-29 16:36:32 -08:00
placement = (result.effective_net, result.as_seed(), options.search)
2026-11-27 10:15:54 -08:00
```
2026-11-29 23:12:28 -08:00
For a run with default options, use `RoutingOptions().search` .
2026-11-29 16:36:32 -08:00
2026-11-29 23:12:28 -08:00
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.
2026-11-27 10:15:54 -08:00
2026-11-26 21:14:29 -08:00
## Reuse an existing route
2026-11-29 23:12:28 -08:00
- **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.
2026-11-26 21:14:29 -08:00
2026-11-29 23:12:28 -08:00
Replay the crossing example with its resolved net and saved moves. Reuse `problem` and `options` from that example.
2026-11-28 20:29:40 -08:00
```python
from dataclasses import replace
from inire import RefinementOptions, TopologyOptions, route
chosen = route(problem, options=options)
verified_nets = []
seeds = {}
for net in problem.nets:
result = chosen.results_by_net[net.net_id]
if result.is_valid:
2026-11-29 16:36:32 -08:00
verified_nets.append(result.effective_net)
2026-11-28 20:29:40 -08:00
seeds[net.net_id] = result.as_seed()
replay = route(
replace(problem, nets=tuple(verified_nets), initial_paths=seeds),
options=replace(
options,
search=replace(options.search, node_limit=0),
topology=TopologyOptions(mode="off"),
refinement=RefinementOptions(enabled=False),
),
)
for net in verified_nets:
result = replay.results_by_net[net.net_id]
assert result.is_valid
assert result.locked_geometry == chosen.results_by_net[net.net_id].locked_geometry
```
2026-11-29 00:09:54 -08:00
Route a straight net, then reserve it while routing another net on the same layer. The second net has to detour around one end of the fixed route.
2026-11-26 21:14:29 -08:00
```python
2026-11-29 00:09:54 -08:00
from dataclasses import replace
2026-11-29 00:12:59 -08:00
from inire import FixedRoute, NetSpec, Port, RoutingOptions, RoutingProblem, SearchOptions, route
2026-11-26 21:14:29 -08:00
2026-11-27 10:15:54 -08:00
bounds = (0, -50, 100, 50)
options = RoutingOptions(search=SearchOptions(bend_radii=(10,)))
2026-11-29 00:09:54 -08:00
fixed_net = NetSpec("fixed", Port(10, 0, 0), Port(90, 0, 0))
detour_net = NetSpec("detour", Port(50, -20, 90), Port(50, 20, 90))
problem = RoutingProblem(bounds=bounds, nets=(fixed_net, detour_net), clearance=0)
fixed = route(replace(problem, nets=(fixed_net,)), options=options).results_by_net["fixed"]
2026-11-27 10:15:54 -08:00
2026-11-29 00:12:59 -08:00
remaining = replace(problem, nets=(detour_net,), fixed_routes=(FixedRoute.from_result(fixed),))
2026-11-29 16:36:32 -08:00
detour = route(remaining, options=options).results_by_net["detour"]
assert detour.is_valid
detour_placement = (detour.effective_net, detour.as_seed(), options.search)
2026-11-26 21:14:29 -08:00
```
2026-11-29 23:12:28 -08:00
For imported artwork in board coordinates, use `FixedRoute("existing_net", imported_polygons)` if it belongs to a net. Use `static_obstacles` for other keepouts.
2026-11-29 00:12:59 -08:00
2026-11-29 23:12:28 -08:00
- [Fixed-route example and plot ](../../examples/README.md#route-around-fixed-geometry )