5.5 KiB
Route a layout
Define the inputs
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).
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"]
Route between placed crossings
- Place both cells and transform their ports into board coordinates.
- Use the cells' routing keepouts or cut port openings in copies of their footprints.
- Add a net for each external connection. A route entering B's west-facing port travels east, so its target heading is 0.
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).
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,),
)
options = RoutingOptions(search=search)
run = route(problem, options=options)
result = run.results_by_net[net_id]
assert result.is_valid
Check joins and clearance against the full cells when assembling the layout.
Save a placement recipe
Keep a verified route's resolved net, ordered moves, component settings, and coordinate unit. This snippet uses result and options from the crossing example.
if not result.is_valid:
raise ValueError(f"Route {result.net_id!r} ended with outcome {result.outcome!r}")
placement = (result.effective_net, result.as_seed(), options.search)
For a run with default options, use RoutingOptions().search.
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
- Allow changes. Pass
initial_paths={net_id: result.as_seed()}. Search can follow or leave the seed. - Hold the route fixed. Pass
FixedRoute.from_result(result)infixed_routes. It blocks contact with other nets even at zero clearance.
Replay the crossing example with its resolved net and saved moves. Reuse problem and options from that example.
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:
verified_nets.append(result.effective_net)
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
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.
from dataclasses import replace
from inire import FixedRoute, NetSpec, Port, RoutingOptions, RoutingProblem, SearchOptions, route
bounds = (0, -50, 100, 50)
options = RoutingOptions(search=SearchOptions(bend_radii=(10,)))
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"]
remaining = replace(problem, nets=(detour_net,), fixed_routes=(FixedRoute.from_result(fixed),))
detour = route(remaining, options=options).results_by_net["detour"]
assert detour.is_valid
detour_placement = (detour.effective_net, detour.as_seed(), options.search)
For imported artwork in board coordinates, use FixedRoute("existing_net", imported_polygons) if it belongs to a net. Use static_obstacles for other keepouts.
