inire/DOCS.md

11 KiB

Inire API and tuning guide

Start with route(problem). It uses automatic routing with the default options. Import public types from inire. The implementation modules under inire.router and inire.geometry can change between releases. Quick start

Describe a layout

Use RoutingProblem to describe a single routing layer. Use the same unit for bounds, coordinates, widths, spacing, and radii. Ports snap to the integer grid. Their headings are degrees counterclockwise from east and must be multiples of 90 after rounding. A target heading gives the direction of travel at arrival.

Input Meaning
bounds Board outline as (xmin, ymin, xmax, ymax).
nets NetSpec(net_id, start, target, width=2.0) objects with unique IDs and Port(x, y, r) terminals. Defaults to an empty tuple.
static_obstacles Shapely polygons for keepouts. Defaults to an empty tuple. For a preplaced crossing, provide access to its ports and route each external leg as a net.
initial_paths Mapping from net IDs to PathSeed objects. Defaults to an empty mapping.
clearance Required spacing between physical shapes. Defaults to 2.0.
safety_zone_radius Tolerance for very small obstacle intersections at ports during search. Defaults to 0.0021.

Incremental routing with locked geometry

Reuse the physical polygons of valid routes as static obstacles in the next run. The next run applies its own clearance to those polygons.

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
)
second = route(replace(next_problem, static_obstacles=next_problem.static_obstacles + locked))

Initial paths with PathSeed

Use result.as_seed() to replay a path for the same net, or construct a PathSeed from StraightSeed, Bend90Seed, and SBendSeed segments. The router materializes seeds from each net's start port with the current geometry settings. It can use partial seeds as hints and reroute nets as needed. Use static obstacles when a route must remain fixed. Locked paths example

Read the result

route(problem, options=..., iteration_callback=...) returns a RoutingRunResult. Read results_by_net[net_id] and check is_valid before exporting a path. The outcome is completed, colliding, partial, or unroutable. A path can reach the requested port and still fail clearance or board containment. The per-net report gives physical length and collision counts.

A live callback receives (iteration_index, results_by_net) after each completed congestion iteration. In automatic mode, indices increase across attempts and each callback sees the nets in that attempt. Callback counts and net sets depend on which attempts run. Use the returned result for final verified routes. Diagnostics and metrics

Topological routing

Set RoutingOptions(topology=TopologyOptions(mode=...)) when you need a particular mode.

Mode When to use it
"automatic" The default. Chooses from constructive planners and detailed search stages based on the layout.
"off" Run the lattice router directly. Useful for custom bends and controlled comparisons.
"guide" Add corridor waypoints and a soft guidance cost to lattice search.
"seed" Try to realize and verify corridor paths before the detailed router completes the layout.
"bundle" Construct tracks for supported ordered rectangular bundles. Unsupported layouts or failed verification raise ValueError.

guide and seed require constrained triangulation from Shapely 2.1 with GEOS 3.10 or newer. Caller-supplied seeds take precedence. Nets without corridors can still use lattice search. In bundle mode, use a circular bend radius enabled for both bends and S-bends. Enable heading inference only when the supplied terminals are points with flexible headings. Topology algorithms and bundle example

Automatic routing

Automatic routing verifies planner candidates and keeps the best coverage it finds. The near-port probe uses at most 100 nodes per search and two congestion iterations with the standard arc proxy, subject to any smaller caller limits. Alternate proxies use the configured iteration budget. The wider initial pass can use up to 500 nodes per search and the configured iteration limit. When coverage remains below the routing bound, a lattice fallback can use the configured search ceiling. Automatic uses lattice directly for custom bend geometry or when constrained triangulation is unavailable.

run.automatic reports verified_net_ids, the selected planner, its stages, and the upper bound max_routed. A cut with finite capacity or conflicting fixed ports can make that bound smaller than the requested net count. Detailed traces describe the selected attempt. Counters and stage timings include work done in other attempts. Automatic stage order · Report fields

Tune a run

Start with the process constraints in SearchOptions and the layout's clearance. If routing stops early, inspect the returned net outcomes and the automatic routing bound before increasing budgets. Set SearchOptions(node_limit=500) to cap each search at 500 expansions. The entire run may do several searches per net. If refinement dominates runtime, try RefinementOptions(max_windows_per_net=1). Compare verified net IDs and paths as well as time.

from inire import RefinementOptions, RoutingOptions, SearchOptions, route

options = RoutingOptions(
    search=SearchOptions(node_limit=500, bend_radii=(50,), sbend_radii=(25,)),
    refinement=RefinementOptions(max_windows_per_net=1),
)
run = route(problem, options=options)

SearchOptions

Field Default Effect
node_limit 1_000_000 Per-search expansion ceiling. Automatic uses smaller budgets for its initial stages.
min_straight_length 5.0 Minimum single straight length.
max_straight_length 2000.0 Maximum single straight length.
greedy_h_weight 1.5 Weight for the A* heuristic. Lower values give the path cost more influence.
bend_radii (50.0, 100.0) Permitted radii for 90-degree bends.
sbend_radii (10.0,) Permitted S-bend radii.
sbend_offsets None Set permitted lateral offsets explicitly, or let search suggest offsets. A compact S-bend needs a nonzero offset with magnitude less than twice its radius.
bend_collision_type "arc" Search proxy, one of "arc", "bbox", or "clipped_bbox". The legacy polygon form defines both shapes unless split geometry is supplied.
bend_proxy_geometry None Override the proxy. A custom polygon proxy by itself keeps the standard physical arc and emits a warning.
bend_physical_geometry None Override the physical geometry with "arc" or a polygon. A custom physical polygon also supplies the default proxy when the collision type is "arc".
bend_clip_margin None Optional legacy shrink margin for "clipped_bbox". The default uses the eight-point proxy.
visibility_guidance "tangent_corner" Choose tangent candidates, exact corner visibility with "exact_corner", or no visibility suggestions with "off".

ObjectiveWeights

The search objective scores path length, components, and proximity. Increasing a component penalty makes routes with more of that component less attractive. Refinement can use its own objective.

Field Default Effect
unit_length_cost 1.0 Cost per unit of path length.
bend_penalty 250.0 Additional cost of a 90-degree bend, scaled by radius.
sbend_penalty 500.0 Additional cost of an S-bend.
danger_weight 1.0 Weight of the obstacle proximity cost.

CongestionOptions

Increase the iteration limit when later reroutes might resolve conflicts. Adjust the initial penalty or multiplier when nets keep competing for the same space.

Field Default Effect
max_iterations 10 Maximum congestion iterations per attempt. Automatic's initial probe may use fewer.
base_penalty 100.0 Initial penalty for overlapping other routes.
multiplier 1.5 Scale the penalty between unresolved iterations.
use_tiered_strategy True Allow a cheaper bend proxy in the first iteration when applicable.
net_order "user" Route in input order or use "shortest" or "longest".
warm_start_enabled True Build greedy seeds before congestion iterations.
shuffle_nets False Shuffle routing order between iterations.
seed None Random seed for shuffled ordering.

RefinementOptions

Field Default Effect
enabled True Try geometric improvements after routing.
objective None Use another ObjectiveWeights value for refinement, or reuse the search objective.
max_windows_per_net 4 Maximum candidate windows per net across improvement rounds. Use 1 for a shorter pass or None for unlimited windows.

TopologyOptions

Field Default Effect
mode "automatic" Select a routing mode.
max_corridors 3 Limit alternative corridors per net.
guide_strength 0.75 Maximum added guidance cost per unit length. Zero keeps the suggested moves without adding cost.
seed_node_limit 600 Total seed-search expansions per net, capped by the active search limit.
infer_terminal_headings False Allow heading inference for bundle-style point terminals. Automatic preserves caller headings when initial paths are supplied.
automatic_cost "selective" Re-score column layouts when they chain short S-bends. Use "always" for both passes or "never" for span scoring alone.
automatic_length_weights None Optional straight, 90-degree bend, and S-bend length multipliers for automatic candidate selection. The default uses the search objective.

DiagnosticsOptions

The flags default to False. Use capture_expanded to plot explored states or capture_iteration_trace to attribute search work per net and iteration. For clearance conflicts, capture_conflict_trace reports overlapping pairs, capture_frontier_trace examines prunes near final hotspots, and capture_pre_pair_frontier_trace examines the state before pair-local repair. Trace fields and examples