Show stress and Terminal-Bench layouts in the examples gallery

This commit is contained in:
Jan Petykiewicz 2026-11-27 10:16:12 -08:00
commit 4a91df39da
19 changed files with 556 additions and 2 deletions

View file

@ -43,4 +43,5 @@ If you're new to Inire, start with the [single-net quick start](README.md#route-
## Examples
See how bends, locks, and congestion affect the routes in the [runnable examples](examples/README.md).
- See how bends, locks, and congestion affect individual routes in the [basic examples](examples/README.md).
- Compare the boards, ports, and verified results for multi-net layouts in the [advanced examples](examples/advanced.md).

View file

@ -18,6 +18,15 @@
Run `python -m scripts.render_documentation_figures --output-dir /tmp/inire-figures` to preview changes. Compare the port labels, keepouts, path, and caption against the published example. Run the script without `--output-dir` to regenerate the figures in `docs/figures`.
### Refresh the advanced example gallery
After changing a stress fixture or the nine-net board, export the inputs again and regenerate the [advanced example figures](../examples/advanced.md). The exporter checks that the saved data reproduces the benchmark geometry and public-default options.
```sh
python -m scripts.export_advanced_examples
python examples/advanced_layouts.py --output-dir docs/figures
```
## Development history
To recover the inputs, metrics, or rationale behind an earlier routing decision, use the [routing development archive](../archive/routing/README.md).

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 70 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

View file

@ -1,6 +1,6 @@
# Routing examples
After [installing Inire](../README.md#install), run the scripts from the repository root. Each saves a PNG beside its source.
After [installing Inire](../README.md#install), run the scripts from the repository root. They save PNGs in the examples directory by default.
```sh
python examples/01_simple_route.py
@ -40,3 +40,7 @@ Follow the short offset to see a single S-bend. The larger shift has room for a
| [Fan-out](07_large_scale_routing.py) | How search states cluster around a bottleneck. The example adjusts the heuristic between iterations through the internal worker. | [Fan-out search overlay](07_large_scale_routing.png) |
In the bend overlays, the dashed outline shows what search uses to screen candidate moves. The solid outline shows the physical bend you can measure for clearance. To interpret an incomplete or colliding path, read `result.outcome` using the [result guide](../docs/user/tune-and-troubleshoot.md#read-the-result).
## Route a challenging layout
Compare each board's inputs with its verified routes in the [advanced gallery](advanced.md). It covers mixed widths, competing passages, preplaced crossings, and both heading configurations of the nine-net Terminal-Bench board.

View file

@ -0,0 +1,253 @@
{
"stress-refine-alternating-doglegs": {
"bounds": [0, 0, 1080, 410],
"clearance": 5,
"bend_radii": [20, 24],
"sbend_radii": [20],
"infer_terminal_headings": false,
"keepouts": [
"POLYGON ((379 0, 379 238, 284 238, 284 0, 379 0))",
"POLYGON ((682 139, 682 410, 594 410, 594 139, 682 139))"
],
"nets": [
["track_0", [34, 147, 0], [1030, 173, 0], 2],
["track_1", [34, 164, 0], [1030, 190, 0], 4],
["track_2", [34, 181, 0], [1030, 207, 0], 3]
]
},
"stress-refine-return-shelf": {
"bounds": [0, 0, 790, 480],
"clearance": 5,
"bend_radii": [20, 27],
"sbend_radii": [20],
"infer_terminal_headings": false,
"keepouts": [
"POLYGON ((502 320, 502 480, 428 480, 428 320, 502 320))",
"POLYGON ((340 145, 340 168, 250 168, 250 145, 340 145))"
],
"nets": [
["folded_return", [640, 155, 0], [555, 230, 0], 2],
["shelf_edge", [201, 272, 0], [595, 272, 0], 4],
["lower_return", [585, 178, 180], [64, 178, 180], 2],
["east_shelf", [675, 438, 180], [610, 438, 180], 2]
]
},
"stress-retry-straight-decoy": {
"bounds": [0, 0, 760, 440],
"clearance": 5,
"bend_radii": [20],
"sbend_radii": [20],
"infer_terminal_headings": false,
"keepouts": [
"POLYGON ((15 222, 15 238, 0 238, 0 222, 15 222))",
"POLYGON ((760 222, 760 238, 745 238, 745 222, 760 222))",
"POLYGON ((282 114, 282 186, 216 186, 216 114, 282 114))",
"POLYGON ((539 114, 539 199, 463 199, 463 114, 539 114))"
],
"nets": [
["trunk", [25, 230, 0], [735, 230, 0], 4],
["branch_west", [326, 144, 90], [326, 339, 90], 2],
["branch_east", [398, 358, 270], [398, 170, 270], 3],
["lower_rail", [58, 79, 0], [708, 79, 0], 2]
]
},
"stress-retry-compact-shift-bank": {
"bounds": [0, 0, 720, 720],
"clearance": 5,
"bend_radii": [20],
"sbend_radii": [20],
"infer_terminal_headings": false,
"keepouts": [
"POLYGON ((720 230, 720 242, 0 242, 0 230, 720 230))",
"POLYGON ((720 389, 720 401, 0 401, 0 389, 720 389))",
"POLYGON ((720 549, 720 561, 0 561, 0 549, 720 549))",
"POLYGON ((202 96, 202 158, 113 158, 113 96, 202 96))",
"POLYGON ((345 264, 345 298, 258 298, 258 264, 345 264))",
"POLYGON ((447 426, 447 460, 337 460, 337 426, 447 426))",
"POLYGON ((402 581, 402 616, 285 616, 285 581, 402 581))"
],
"nets": [
["short", [45, 117, 0], [111, 202, 0], 3],
["middle", [33, 274, 0], [650, 347, 0], 4],
["upper", [56, 445, 0], [670, 513, 0], 2],
["top", [63, 598, 0], [630, 669, 0], 2]
]
},
"stress-retry-mixed-port-bank": {
"bounds": [0, 0, 680, 540],
"clearance": 5,
"bend_radii": [20],
"sbend_radii": [20],
"infer_terminal_headings": false,
"keepouts": [
"POLYGON ((194 53, 194 131, 133 131, 133 53, 194 53))",
"POLYGON ((498 221, 498 291, 452 291, 452 221, 498 221))",
"POLYGON ((624 171, 624 230, 564 230, 564 171, 624 171))",
"POLYGON ((190 185, 339 175, 353 218, 315 283, 199 290, 190 185))",
"POLYGON ((348 302, 348 337, 256 337, 256 302, 348 302))",
"POLYGON ((310 408, 310 443, 108 443, 108 408, 310 408))"
],
"nets": [
["east_compact", [40, 75, 0], [115, 158, 0], 3],
["west_compact", [590, 261, 180], [516, 182, 180], 4],
["turning_exit", [290, 50, 90], [437, 113, 0], 2],
["upper_shift", [40, 315, 0], [450, 395, 0], 2],
["return", [535, 475, 180], [60, 475, 180], 2]
]
},
"stress-passage-width-key": {
"bounds": [0, 0, 1210, 720],
"clearance": 5,
"bend_radii": [20],
"sbend_radii": [20],
"infer_terminal_headings": false,
"keepouts": [
"POLYGON ((492 0, 492 246, 440 246, 440 0, 492 0))",
"POLYGON ((492 260, 492 340, 440 340, 440 260, 492 260))",
"POLYGON ((492 443, 492 720, 440 720, 440 443, 492 443))"
],
"nets": [
["lane_0", [1190, 498, 180], [30, 64, 180], 2],
["lane_1", [30, 81, 0], [1190, 515, 0], 7],
["lane_2", [1190, 533, 180], [30, 99, 180], 4],
["lane_3", [30, 118, 0], [1190, 551, 0], 8],
["lane_4", [30, 135, 0], [1190, 569, 0], 5],
["lane_5", [1190, 587, 180], [30, 153, 180], 6]
]
},
"stress-passage-split-merge": {
"bounds": [0, 0, 1710, 880],
"clearance": 5,
"bend_radii": [20],
"sbend_radii": [20],
"infer_terminal_headings": false,
"keepouts": [
"POLYGON ((470 0, 470 243, 422 243, 422 0, 470 0))",
"POLYGON ((470 293, 470 374, 422 374, 422 293, 470 293))",
"POLYGON ((470 439, 470 880, 422 880, 422 439, 470 439))",
"POLYGON ((982 0, 982 523, 930 523, 930 0, 982 0))",
"POLYGON ((982 618, 982 880, 930 880, 930 618, 982 618))"
],
"nets": [
["lane_0", [1670, 679, 180], [30, 53, 180], 3],
["lane_1", [30, 70, 0], [1670, 697, 0], 5],
["lane_2", [30, 87, 0], [1670, 716, 0], 2],
["lane_3", [1670, 734, 180], [30, 105, 180], 4],
["lane_4", [30, 123, 0], [1670, 752, 0], 6],
["lane_5", [1670, 772, 180], [30, 141, 180], 3]
]
},
"stress-sbend-competing-slots": {
"bounds": [0, 0, 450, 320],
"clearance": 4,
"bend_radii": [25],
"sbend_radii": [25],
"infer_terminal_headings": false,
"keepouts": [
"POLYGON ((120 130, 120 135, 104 135, 104 130, 120 130))",
"POLYGON ((358 166, 358 154, 370 154, 370 140, 356 140, 356 152, 344 152, 344 140, 330 140, 330 154, 342 154, 342 166, 330 166, 330 180, 344 180, 344 168, 356 168, 356 180, 370 180, 370 166, 358 166))"
],
"nets": [
["lower_east", [35, 112, 0], [235, 132, 0], 3],
["upper_west", [235, 141, 180], [35, 121, 180], 3],
["south_access", [330, 52, 90], [350, 146, 90], 2],
["north_access", [350, 174, 90], [330, 284, 90], 2]
]
},
"stress-crossing-off-lattice-slot": {
"bounds": [0, 0, 500, 460],
"clearance": 4,
"bend_radii": [6, 15],
"sbend_radii": [25],
"infer_terminal_headings": false,
"keepouts": [
"POLYGON ((268 236, 268 224, 280 224, 280 210, 266 210, 266 222, 254 222, 254 210, 240 210, 240 224, 252 224, 252 236, 240 236, 240 250, 254 250, 254 238, 266 238, 266 250, 280 250, 280 236, 268 236))",
"POLYGON ((273 272, 273 317, 245 317, 245 272, 273 272))",
"POLYGON ((176 193, 176 214, 145 214, 145 193, 176 193))"
],
"nets": [
["west_odd_shift", [34, 213, 0], [246, 230, 0], 2],
["east_exact_shift", [274, 230, 0], [465, 250, 0], 2],
["north_pocket", [260, 244, 90], [260, 429, 90], 3],
["south_exact_shift", [240, 30, 90], [260, 216, 90], 2]
]
},
"stress-crossings-shared-outside-detour": {
"bounds": [0, 0, 625, 397],
"clearance": 4,
"bend_radii": [20],
"sbend_radii": [25],
"infer_terminal_headings": false,
"keepouts": [
"POLYGON ((228 186, 228 174, 240 174, 240 160, 226 160, 226 172, 214 172, 214 160, 200 160, 200 174, 212 174, 212 186, 200 186, 200 200, 214 200, 214 188, 226 188, 226 200, 240 200, 240 186, 228 186))",
"POLYGON ((363 186, 363 174, 375 174, 375 160, 361 160, 361 172, 349 172, 349 160, 335 160, 335 174, 347 174, 347 186, 335 186, 335 200, 349 200, 349 188, 361 188, 361 200, 375 200, 375 186, 363 186))",
"POLYGON ((415 69, 415 81, 160 81, 160 69, 415 69))",
"POLYGON ((144 216, 144 261, 102 261, 102 216, 144 216))"
],
"nets": [
["west_link", [32, 160, 0], [206, 180, 0], 2],
["device_link", [234, 180, 0], [341, 180, 0], 2],
["east_link", [369, 180, 0], [581, 200, 0], 2],
["west_south", [220, 87, 90], [220, 166, 90], 2],
["east_south", [355, 166, 270], [355, 90, 270], 2],
["west_north", [220, 194, 90], [200, 317, 90], 2],
["east_north", [375, 315, 270], [355, 194, 270], 2],
["outside_lower", [35, 130, 0], [590, 130, 0], 4],
["outside_upper", [589, 353, 180], [33, 353, 180], 2]
]
},
"terminal-bench": {
"bounds": [0, 0, 2500, 1000],
"clearance": 6.0,
"bend_radii": [50.0],
"sbend_radii": [50.0],
"infer_terminal_headings": false,
"keepouts": [
"POLYGON ((550 80, 550 480, 450 480, 450 80, 550 80))",
"POLYGON ((550 520, 550 920, 450 920, 450 520, 550 520))",
"POLYGON ((2010 130, 2010 491.5, 1910 491.5, 1910 130, 2010 130))",
"POLYGON ((2010 510, 2010 851.5, 1910 851.5, 1910 510, 2010 510))",
"POLYGON ((1040 680, 1040 983, 940 983, 940 680, 1040 680))",
"POLYGON ((1080 50, 1080 475, 980 475, 980 50, 1080 50))",
"POLYGON ((1537 18, 1537 620, 1350 620, 1350 18, 1537 18))"
],
"nets": [
["net_00", [12, 460, 0], [2412, 150, 0], 2.0],
["net_01", [12, 470, 0], [2412, 250, 0], 2.0],
["net_02", [12, 480, 0], [2412, 350, 0], 2.0],
["net_03", [12, 490, 0], [902, 900, 0], 2.0],
["net_04", [12, 500, 0], [2412, 500, 0], 2.0],
["net_05", [12, 510, 0], [2412, 650, 0], 2.0],
["net_06", [12, 520, 0], [2412, 750, 0], 2.0],
["net_07", [12, 530, 0], [2412, 850, 0], 2.0],
["net_08", [12, 450, 0], [1112, 991, 0], 2.0]
]
},
"terminal-bench-point-terminals": {
"bounds": [0, 0, 2500, 1000],
"clearance": 6.0,
"bend_radii": [50.0],
"sbend_radii": [50.0],
"infer_terminal_headings": true,
"keepouts": [
"POLYGON ((550 80, 550 480, 450 480, 450 80, 550 80))",
"POLYGON ((550 520, 550 920, 450 920, 450 520, 550 520))",
"POLYGON ((2010 130, 2010 491.5, 1910 491.5, 1910 130, 2010 130))",
"POLYGON ((2010 510, 2010 851.5, 1910 851.5, 1910 510, 2010 510))",
"POLYGON ((1040 680, 1040 983, 940 983, 940 680, 1040 680))",
"POLYGON ((1080 50, 1080 475, 980 475, 980 50, 1080 50))",
"POLYGON ((1537 18, 1537 620, 1350 620, 1350 18, 1537 18))"
],
"nets": [
["net_00", [12, 460, 0], [2412, 150, 0], 2.0],
["net_01", [12, 470, 0], [2412, 250, 0], 2.0],
["net_02", [12, 480, 0], [2412, 350, 0], 2.0],
["net_03", [12, 490, 0], [902, 900, 0], 2.0],
["net_04", [12, 500, 0], [2412, 500, 0], 2.0],
["net_05", [12, 510, 0], [2412, 650, 0], 2.0],
["net_06", [12, 520, 0], [2412, 750, 0], 2.0],
["net_07", [12, 530, 0], [2412, 850, 0], 2.0],
["net_08", [12, 450, 0], [1112, 991, 0], 2.0]
]
}
}

107
examples/advanced.md Normal file
View file

@ -0,0 +1,107 @@
# Advanced routing examples
These layouts exercise the same geometry as the stress tests and the nine-net Terminal-Bench cases. Each run starts with the board, keepouts, and ports. Inire computes all the plotted paths from those inputs.
- [Competing passages](#competing-passages) for mixed widths and opposing headings.
- [Bend and return room](#bend-and-return-room) for alternating detours, short shifts, and branches.
- [Placed crossings](#placed-crossings) for access slots and external detours.
- [Nine-net Terminal-Bench board](#nine-net-terminal-bench-board) for fixed and inferred headings on the same input.
## Run a layout
Select a case by its name below. Repeat `--case` to draw several layouts, or omit it to draw all twelve.
```sh
python examples/advanced_layouts.py \
--case stress-crossings-shared-outside-detour \
--case terminal-bench \
--output-dir /tmp/inire-advanced-routes
```
The [input file](advanced-layouts.json) gives each board's bounds, polygon keepouts in WKT, clearance, and allowed bend and S-bend radii. Each net row contains its ID, source port, target port, and width. Ports are `[x, y, heading_in_degrees]`. The [example script](advanced_layouts.py) builds the `RoutingProblem` and calls `route()` in automatic mode.
In the figures, gray shapes are keepouts. Open circles mark sources and filled squares mark targets. Arrows indicate the direction of travel at those ports. The result panel draws the physical waveguides and reports the number of nets that passed verification.
## Competing passages
### Mixed widths at a slit
In `stress-passage-width-key`, the 2-unit-wide lane uses the lower slit with 5 units of clearance. The other five routes share the upper opening, including nets travelling in the opposite direction.
![Six verified routes through a wall. One thin route uses a low slit while five routes share the upper opening.](../docs/figures/example-stress-passage-width-key.png)
### Staggered openings and one shared passage
In `stress-passage-split-merge`, the first wall offers two openings for three tracks each. The routes turn between the walls to enter the second opening as a six-track bank.
![Six ports on each side of two staggered walls. Three routes use each first opening, then all six pass through the second opening.](../docs/figures/example-stress-passage-split-merge.png)
## Bend and return room
### Alternating doglegs
In `stress-refine-alternating-doglegs`, three eastbound nets pass above a wall rising from the bottom and then below a wall hanging from the top. The staggered turns preserve clearance for three different guide widths.
![Three nested waveguides turn above the first wall and below the second wall.](../docs/figures/example-stress-refine-alternating-doglegs.png)
### Folded return near a shelf
In `stress-refine-return-shelf`, the folded net's target lies west of its source and requires eastbound arrival. Follow its loop below the two neighboring routes in the result panel.
![Four verified paths including an east-facing source that loops below two neighboring paths to reach its east-facing target.](../docs/figures/example-stress-refine-return-shelf.png)
### Trunk that detours around branches
In `stress-retry-straight-decoy`, the straight line between the trunk's ports would cut across both perpendicular branches. The router sends the trunk below the branch ports and above the lower rail.
![Two vertical branches route across the direct line between the trunk ports. A four-turn trunk detour leaves both branches room.](../docs/figures/example-stress-retry-straight-decoy.png)
### Short shifts on separate rows
In `stress-retry-compact-shift-bank`, walls divide the board into four rows. The lowest net has only 66 units of forward travel for an 85-unit lateral shift. Its turns fit beside the keepout on that row.
![Four verified routes on separate rows. The lowest net shifts up sharply over a small forward span.](../docs/figures/example-stress-retry-compact-shift-bank.png)
### Mixed port bank
In `stress-retry-mixed-port-bank`, two compact shifts launch in opposite directions around different keepouts. The lower middle net turns from northbound to eastbound, and the top link runs west.
![Five verified routes around six keepouts, including a westbound link, a perpendicular turn, and compact shifts in opposing directions.](../docs/figures/example-stress-retry-mixed-port-bank.png)
## Placed crossings
The crossing cells are already placed. The board supplies keepouts with slots at their ports, and each routed net represents an external connection. To set up the keepouts for your own devices, follow the [placed crossing walkthrough](../docs/user/route-a-layout.md#route-between-placed-crossings).
### Opposed S-bends beside a crossing
In `stress-sbend-competing-slots`, two links make 20-unit lateral shifts while travelling in opposite directions. Their S-bends fit on opposite sides of the small central keepout while two separate links reach the crossing's north and south ports.
![Two opposed S-bends share the left half of the board. Two more waveguides access a preplaced crossing on the right.](../docs/figures/example-stress-sbend-competing-slots.png)
### Odd offset and a short launch pocket
In `stress-crossing-off-lattice-slot`, the west approach must shift by 17 units and land on a recessed port. It uses a pair of 90-degree bends. The north link turns in a short pocket beside a keepout before straightening toward its target.
![Four routes connect to a crossing. The west link steps up near its launch, and the north link turns around an adjacent keepout.](../docs/figures/example-stress-crossing-off-lattice-slot.png)
### Two crossings with an outside detour
In `stress-crossings-shared-outside-detour`, a straight external link joins the two devices. The long lower route bends around the entire south approach bank, leaving both short vertical links in place.
![Nine verified paths around two crossings. A straight route joins the devices, and a long lower detour passes beneath both approaches.](../docs/figures/example-stress-crossings-shared-outside-detour.png)
## Nine-net Terminal-Bench board
The board has seven keepouts and nine connections out of a tight west-side launch bank. Both examples use 2-unit-wide waveguides, clearance 6, and radius 50 for bends and S-bends. For the upstream board pin and the waypoint export command, see the [Terminal-Bench fixture guide](../docs/benchmark-fixtures.md#automatic-nine-net-terminal-bench-routing).
### Fixed eastbound headings
In `terminal-bench`, both headings on every net are fixed eastbound. Follow `net_08` from the low end of the launch bank around the board. It makes a final turnaround to arrive eastbound at its target near the top edge.
![All nine fixed-heading nets verified. The outer return comes back around and makes an eastbound approach to its top target.](../docs/figures/example-terminal-bench.png)
### Point terminals
In `terminal-bench-point-terminals`, heading inference can change the initial zero headings supplied to `Port`. The setup shows the terminal positions, and the result shows the inferred headings. `net_08` arrives westbound from the east and saves the final turnaround.
![The same nine positions with no headings specified in the setup. All routes verify, and the outer return arrives westbound.](../docs/figures/example-terminal-bench-point-terminals.png)

View file

@ -0,0 +1,131 @@
"""Route and plot the advanced layouts with Inire's public API."""
from __future__ import annotations
import os
from argparse import ArgumentParser
from json import loads
from math import cos, radians, sin
from pathlib import Path
from typing import TYPE_CHECKING
import matplotlib
from shapely import from_wkt, union_all
from shapely.geometry import box
from shapely.plotting import plot_polygon
from inire import NetSpec, Port, RoutingOptions, RoutingProblem, SearchOptions, TopologyOptions, route
if "MPLBACKEND" not in os.environ:
matplotlib.use("Agg")
from matplotlib import pyplot as plt # noqa: E402
from matplotlib.lines import Line2D # noqa: E402
if TYPE_CHECKING:
from matplotlib.axes import Axes
from inire import RoutingRunResult
INPUTS = Path(__file__).with_name("advanced-layouts.json")
COLORS = ("#007189", "#af511b", "#654a99", "#427326", "#b73c62", "#975b2d", "#2f569a", "#734359", "#328179")
def build_problem(layout: dict) -> tuple[RoutingProblem, RoutingOptions]:
"""Create the board, connections, and geometry options from a layout entry."""
problem = RoutingProblem(
bounds=tuple(layout["bounds"]),
static_obstacles=tuple(from_wkt(shape) for shape in layout["keepouts"]),
nets=tuple(NetSpec(name, Port(*start), Port(*target), width) for name, start, target, width in layout["nets"]),
clearance=layout["clearance"],
)
options = RoutingOptions(
search=SearchOptions(bend_radii=tuple(layout["bend_radii"]), sbend_radii=tuple(layout["sbend_radii"])),
topology=TopologyOptions(infer_terminal_headings=layout["infer_terminal_headings"]),
)
return problem, options
def _draw_board(ax: Axes, problem: RoutingProblem) -> None:
x0, y0, x1, y1 = problem.bounds
margin = (x1 - x0) * 0.025
ax.set(xlim=(x0 - margin, x1 + margin), ylim=(y0 - margin, y1 + margin), aspect="equal")
ax.set_axis_off()
plot_polygon(box(*problem.bounds), ax=ax, add_points=False, facecolor="#fbfcfd", edgecolor="#9caeb6", linewidth=0.8)
for shape in problem.static_obstacles:
plot_polygon(shape, ax=ax, add_points=False, facecolor="#d4dde2", edgecolor="#758892", linewidth=0.8)
def _draw_ports(ax: Axes, start: Port, target: Port, color: str, arrow_length: float) -> None:
if arrow_length:
ports = (start, target)
ax.quiver(
[p.x for p in ports], [p.y for p in ports],
[arrow_length * cos(radians(p.r)) for p in ports], [arrow_length * sin(radians(p.r)) for p in ports],
color=color, scale=1, scale_units="xy", angles="xy", width=0.0025, zorder=4,
)
ax.scatter(start.x, start.y, s=19, marker="o", facecolors="white", edgecolors=color, linewidths=1.0, zorder=5)
ax.scatter(target.x, target.y, s=16, marker="s", color=color, linewidths=0.6, zorder=5)
def _plot_case(problem: RoutingProblem, options: RoutingOptions, run: RoutingRunResult, output: Path) -> None:
ratio = (problem.bounds[3] - problem.bounds[1]) / (problem.bounds[2] - problem.bounds[0])
stacked = ratio < 0.45
fig, (setup, result) = plt.subplots(
2 if stacked else 1, 1 if stacked else 2,
figsize=(9.6, (19.2 if stacked else 4.8) * ratio + 1.2),
layout="constrained",
)
for panel in (setup, result):
_draw_board(panel, problem)
verified = sum(route_result.is_valid for route_result in run.results_by_net.values())
setup.set_title("Setup", loc="left", fontsize=13, color="#193447", fontweight="bold")
result.set_title(f"Result · {verified}/{len(problem.nets)} verified", loc="left", fontsize=13, color="#193447", fontweight="bold")
inferred = options.topology.infer_terminal_headings
arrow_length = (problem.bounds[2] - problem.bounds[0]) * 0.025
legend = []
for index, net in enumerate(problem.nets):
color = COLORS[index % len(COLORS)]
legend.append(Line2D([], [], color=color, linewidth=2, label=net.net_id))
routed = run.results_by_net[net.net_id]
_draw_ports(setup, net.start, net.target, color, 0 if inferred else arrow_length)
if routed.path:
plot_polygon(
union_all(routed.locked_geometry), ax=result, add_points=False, facecolor=color, edgecolor=color,
linewidth=0.55, linestyle="-" if routed.is_valid else "--", alpha=1 if routed.is_valid else 0.35, zorder=3,
)
start, target = (routed.path[0].start_port, routed.path[-1].end_port) if inferred and routed.is_valid else (net.start, net.target)
_draw_ports(result, start, target, color, arrow_length if not inferred or routed.is_valid else 0)
columns = 5 if stacked else 4
fig.legend(handles=legend, loc="outside lower center", ncols=columns, fontsize=8.5, frameon=False)
fig.savefig(output, dpi=150, facecolor="white")
plt.close(fig)
def main() -> int:
layouts = loads(INPUTS.read_text(encoding="utf-8"))
parser = ArgumentParser(description=__doc__)
parser.add_argument("--case", action="append", choices=layouts, help="Layout to route. Repeat to select several. Defaults to all.")
parser.add_argument("--output-dir", type=Path, default=INPUTS.parent, help="Directory for the setup and result PNGs.")
args = parser.parse_args()
args.output_dir.mkdir(parents=True, exist_ok=True)
all_verified = True
for name in dict.fromkeys(args.case or layouts):
problem, options = build_problem(layouts[name])
run = route(problem, options=options)
valid = sum(result.is_valid for result in run.results_by_net.values())
print(f"{name}: {valid}/{len(problem.nets)} verified")
if valid != len(problem.nets):
all_verified = False
print(" " + ", ".join(f"{res.net_id}: {res.outcome}" for res in run.results_by_net.values() if not res.is_valid))
_plot_case(problem, options, run, args.output_dir / f"example-{name}.png")
return 0 if all_verified else 1
if __name__ == "__main__":
raise SystemExit(main())

View file

@ -0,0 +1,49 @@
"""Export the advanced example inputs from the canonical benchmark fixtures."""
from argparse import ArgumentParser
from json import dumps
from pathlib import Path
from examples.advanced_layouts import INPUTS, build_problem
from inire.tests.routing_corpus import CASE_GROUPS, profile_options
from inire.tests.stress_routing_benchmarks import STRESS_BENCHMARK_CASES
def main() -> None:
parser = ArgumentParser(description=__doc__)
parser.add_argument("--output", type=Path, default=INPUTS)
args = parser.parse_args()
cases = (*STRESS_BENCHMARK_CASES, *CASE_GROUPS["terminal-bench"], *CASE_GROUPS["terminal-bench-point-terminals"])
entries = []
for case in cases:
problem = case.problem
options = profile_options(case, "public-defaults")
data = {
"bounds": list(problem.bounds),
"clearance": problem.clearance,
"bend_radii": list(options.search.bend_radii),
"sbend_radii": list(options.search.sbend_radii),
"infer_terminal_headings": options.topology.infer_terminal_headings,
"keepouts": [polygon.wkt for polygon in problem.static_obstacles],
"nets": [(net.net_id, net.start.as_tuple(), net.target.as_tuple(), net.width) for net in problem.nets],
}
rebuilt, settings = build_problem(data)
if problem != rebuilt or options != settings:
raise ValueError(f"The advanced example no longer reproduces fixture {case.name}")
# Keep ports and each net on one line so the input file is easy to scan.
lines = [f" {dumps(case.name)}: {{"]
for field in ("bounds", "clearance", "bend_radii", "sbend_radii", "infer_terminal_headings"):
lines.append(f" {dumps(field)}: {dumps(data[field])},")
for field in ("keepouts", "nets"):
values = ",\n".join(f" {dumps(value)}" for value in data[field])
comma = "," if field == "keepouts" else ""
lines.append(f" {dumps(field)}: [\n{values}\n ]{comma}")
entries.append("\n".join((*lines, " }")))
args.output.write_text("{\n" + ",\n".join(entries) + "\n}\n", encoding="utf-8")
if __name__ == "__main__":
main()