Separate user guides, benchmarks, and routing internals
This commit is contained in:
parent
24559bb6aa
commit
e4d5952677
3 changed files with 846 additions and 270 deletions
123
docs/user/api-reference.md
Normal file
123
docs/user/api-reference.md
Normal file
|
|
@ -0,0 +1,123 @@
|
|||
# Public API reference
|
||||
|
||||
Import the types on this page from `inire`. The [layout guide](route-a-layout.md) shows how to assemble a problem and the [tuning guide](tune-and-troubleshoot.md) explains which settings to try.
|
||||
|
||||
## Route a problem
|
||||
|
||||
```text
|
||||
route(problem, *, options=None, iteration_callback=None) -> RoutingRunResult
|
||||
```
|
||||
|
||||
Omitting `options` uses `RoutingOptions()`. To observe live congestion iterations, pass a callable accepting `(index, results_by_net)`. The index increases across automatic attempts. Each callback sees the nets in its current attempt. Use the returned result for final coverage.
|
||||
|
||||
## Layout inputs
|
||||
|
||||
- `Port(x, y, r)` snaps coordinates to the integer grid and normalizes the heading in degrees. Heading 0 points east and 90 points north. The heading must be a multiple of 90 after rounding.
|
||||
- `NetSpec(net_id, start, target, width=2.0)` uses a unique ID and two ports. The target heading is the direction of arrival.
|
||||
- `RoutingProblem` describes one routing layer. Use one unit for distances, coordinates, widths, and radii.
|
||||
|
||||
| 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. |
|
||||
| `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`. |
|
||||
|
||||
## Path seeds
|
||||
|
||||
`PathSeed(segments)` holds an ordered tuple of `StraightSeed(length)`, `Bend90Seed(radius, direction)`, and `SBendSeed(offset, radius)` moves. Bend directions are `"CW"` and `"CCW"`. A seed is materialized from the net's current start port using its width and the run's geometry options. [Seed and lock workflows](route-a-layout.md#reuse-an-existing-route)
|
||||
|
||||
## Results
|
||||
|
||||
| Value | Read it for |
|
||||
| --- | --- |
|
||||
| `RoutingRunResult.results_by_net` | A mapping from net ID to `RoutingResult`. |
|
||||
| `RoutingResult.is_valid` and `outcome` | Final validity and a status of `completed`, `colliding`, `partial`, or `unroutable`. |
|
||||
| `RoutingResult.reached_target` and `report` | Arrival status, physical length, and collision details. |
|
||||
| `RoutingResult.locked_geometry` and `as_seed()` | Physical polygons for export or fixed obstacles, and the move sequence for reuse as a seed. |
|
||||
| `RoutingRunResult.automatic` | In automatic mode, the selected planner, the verified IDs, stage history, and any capacity or port-conflict bound. |
|
||||
| `RoutingRunResult.topology` and `metrics` | Corridor counts and seed work when reported by the selected worker, plus work counters across the run. |
|
||||
|
||||
See [how to read the result](tune-and-troubleshoot.md#read-the-result) for export checks and [developer diagnostics](../routing-diagnostics.md) for reports and traces.
|
||||
|
||||
## Options and defaults
|
||||
|
||||
`RoutingOptions` accepts six option groups. Each group uses the defaults in its table when omitted.
|
||||
|
||||
| Group | Type |
|
||||
| --- | --- |
|
||||
| `search` | [SearchOptions](#searchoptions) |
|
||||
| `objective` | [ObjectiveWeights](#objectiveweights) |
|
||||
| `congestion` | [CongestionOptions](#congestionoptions) |
|
||||
| `refinement` | [RefinementOptions](#refinementoptions) |
|
||||
| `topology` | [TopologyOptions](#topologyoptions) |
|
||||
| `diagnostics` | [DiagnosticsOptions](#diagnosticsoptions) |
|
||||
|
||||
### 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](tune-and-troubleshoot.md#choose-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](../routing-diagnostics.md#traces)
|
||||
51
docs/user/route-a-layout.md
Normal file
51
docs/user/route-a-layout.md
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
# 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. [Input fields](api-reference.md#layout-inputs)
|
||||
5. **Run and check.** Call `route(problem, options=options)` and check each `result.is_valid`. Start with automatic mode for general layouts. [Read the result](tune-and-troubleshoot.md#read-the-result)
|
||||
|
||||
## Connect a preplaced crossing
|
||||
|
||||
- Place the device and reserve its keepout first.
|
||||
- Leave openings in the keepout at the physical ports.
|
||||
- Define the external legs as separate nets. The placed cell supplies the internal connections.
|
||||
|
||||

|
||||
|
||||
Each leg meets a port at the end of an access slot. The dashed links show the device's internal connections schematically. The four external paths come from Inire's `crossing-single` fixture. [Crossing fixtures](../benchmark-fixtures.md#preplaced-crossings)
|
||||
|
||||
## 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.
|
||||
- **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,
|
||||
))
|
||||
```
|
||||
|
||||
See the [locked-path example](../../examples/README.md#route-around-fixed-geometry) for the resulting detour and the [seed reference](api-reference.md#path-seeds) for building a hint by hand.
|
||||
64
docs/user/tune-and-troubleshoot.md
Normal file
64
docs/user/tune-and-troubleshoot.md
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
# Tune and troubleshoot a route
|
||||
|
||||
Check whether the layout can fit the connection before spending more search time. Start with the per-net result and change one setting at a time.
|
||||
|
||||
## Read the result
|
||||
|
||||
| `result.outcome` | What to inspect |
|
||||
| --- | --- |
|
||||
| `completed` | The path reached its target and passed verification. Use `locked_geometry` for physical polygons and `report.total_length` for length. |
|
||||
| `colliding` | The path reached its target. Read `report` for static, dynamic, or self-collisions and any automatic board containment failure. |
|
||||
| `partial` | Inspect where the path ends. Check the next turn, available radius, and search limit. |
|
||||
| `unroutable` | No path was returned. Check the launch heading and room for the first straight or bend. |
|
||||
|
||||
Check `is_valid` before exporting. With explicit `off`, `guide`, or `seed` mode, also check that the physical polygons fit the board if your export requires containment. Automatic mode includes that check in candidate verification. [Result fields](api-reference.md#results)
|
||||
|
||||
## Why a net stopped short
|
||||
|
||||
1. **Check for a geometric bound.** If the automatic run reaches `max_routed` below the requested count, read `capacity_limit` or `port_conflicts`. Make more room at the reported cut or move conflicting ports.
|
||||
2. **Check the port and turn geometry.** For static or self-collisions, inspect physical clearance and bend room. For dynamic collisions, inspect the routes that compete for the same space.
|
||||
3. **Check the search budget.** If the verified count is below the bound and the geometry looks feasible, try raising a small `search.node_limit`. The limit is per search. A run can try the same net several times.
|
||||
|
||||

|
||||
|
||||
Both runs use the best-effort example's ports, obstacles, radii, and iteration settings. At three nodes per search, the dashed path stops before the obstacles. At 500, the solid path reaches the westbound target. [Runnable best-effort example](../../examples/09_unroutable_best_effort.py)
|
||||
|
||||
## Choose a routing mode
|
||||
|
||||
Set `TopologyOptions(mode=...)` and pass it as `topology` in `RoutingOptions`.
|
||||
|
||||
- **`automatic`.** Start here. Inire chooses from constructive planners and search stages and keeps the best verified coverage it finds.
|
||||
- **`off`.** Isolate lattice search or work with custom physical bend geometry.
|
||||
- **`guide`.** Use suggested corridors when a detour looks promising and the router needs freedom to leave the corridor to turn.
|
||||
- **`seed`.** Try to realize a verified starting path inside a corridor before the detailed search.
|
||||
- **`bundle`.** Route supported ordered rectangular bundles. Use a circular radius enabled for both bends and S-bends. Unsupported layouts and invalid schedules raise `ValueError`.
|
||||
|
||||
- Guide and seed modes require constrained triangulation from Shapely 2.1 with GEOS 3.10 or newer. Caller-supplied seeds take precedence, and nets without a corridor can use ordinary lattice search.
|
||||
- Enable `infer_terminal_headings` for point terminals with flexible headings. Preserve fixed headings when a device requires a specific arrival direction.
|
||||
- In automatic mode, smaller initial budgets make the first attempts cheaper. If coverage remains below the bound, a lattice fallback can use your configured ceiling. Automatic also uses lattice for custom bend geometry or when constrained triangulation is unavailable. [Automatic stage order](../architecture.md#automatic-routing)
|
||||
|
||||
## Choose the next setting
|
||||
|
||||
| Observation | Next comparison |
|
||||
| --- | --- |
|
||||
| Multiple routes reach their ports and collide with one another | Try a different `congestion.net_order` or allow more `max_iterations`. Compare the unresolved IDs. |
|
||||
| Valid routes use too many small bends | Increase `objective.bend_penalty`. Compare bend counts and physical lengths to see whether a straighter path needs a longer detour. |
|
||||
| Refinement dominates runtime | Try `refinement.max_windows_per_net=1`. Compare the verified paths and cost before adopting the smaller limit. |
|
||||
|
||||
For a shorter refinement pass, derive the new settings from the `options` already used for the layout.
|
||||
|
||||
```python
|
||||
from dataclasses import replace
|
||||
from inire import route
|
||||
|
||||
short_pass = replace(
|
||||
options.refinement,
|
||||
max_windows_per_net=1,
|
||||
)
|
||||
faster_refinement = replace(
|
||||
options, refinement=short_pass,
|
||||
)
|
||||
run = route(problem, options=faster_refinement)
|
||||
```
|
||||
|
||||
[Option defaults](api-reference.md#options-and-defaults) · [Deeper diagnostics](../routing-diagnostics.md)
|
||||
Loading…
Reference in a new issue