Route the 40-net photonic floorplan with verified constructive candidates
This commit is contained in:
parent
ee41dc600a
commit
0183a91e9c
2 changed files with 555 additions and 55 deletions
|
|
@ -6,7 +6,8 @@ import argparse
|
|||
import json
|
||||
import platform
|
||||
import resource
|
||||
from dataclasses import asdict, dataclass, field
|
||||
from dataclasses import asdict, dataclass, field, replace
|
||||
from itertools import pairwise
|
||||
from math import fsum, pi, sqrt
|
||||
from statistics import median
|
||||
from time import perf_counter
|
||||
|
|
@ -15,12 +16,15 @@ from shapely.affinity import scale
|
|||
from shapely.geometry import Polygon, box
|
||||
|
||||
from inire import NetSpec, ObjectiveWeights, Port, RefinementOptions, RoutingOptions, RoutingProblem, SearchOptions, TopologyOptions, route
|
||||
from inire._catalog import BendVariant, Catalog, FixedVariant, Grid, Move, MoveEvaluator, Orientation, Pose, Profile, StraightVariant
|
||||
from inire._catalog import (
|
||||
HEADING_STEPS, BendVariant, Catalog, FixedVariant, Grid, Move, MoveEvaluator, Orientation, Pose, Profile, StraightVariant,
|
||||
)
|
||||
from inire._catalog_timing import DelayModel
|
||||
from inire.router._catalog_guidance import AutomaticGrid, CoarseGuidance
|
||||
from inire.router._catalog_layout import CatalogNet, LayoutSettings, route_layout
|
||||
from inire.router._catalog_matching import MatchGroup
|
||||
from inire.router._catalog_verify import replay_moves, verify_path
|
||||
from scripts.catalog_floorplan import BLOCKS, COMPONENTS, NET_BANKS, STEPPED_BLOCKS
|
||||
|
||||
|
||||
@dataclass(frozen=True, slots=True)
|
||||
|
|
@ -80,7 +84,53 @@ def corpus_lanes(name: str) -> ScaleCase:
|
|||
)
|
||||
|
||||
|
||||
def floorplan_case() -> ScaleCase:
|
||||
"""Build unseeded port pairs and rounded Manhattan references from authored waypoints."""
|
||||
grid = Grid((0, 0), 100, 1e-9)
|
||||
radius_um = 10
|
||||
cardinal_headings = {step: heading for heading, step in HEADING_STEPS.items() if heading % 90 == 0}
|
||||
nets: dict[str, CatalogNet] = {}
|
||||
references: dict[str, tuple[Move, ...]] = {}
|
||||
for bank, paths in NET_BANKS.items():
|
||||
for index, points in enumerate(paths, 1):
|
||||
name = f"{bank}-{index}"
|
||||
deltas = [(x1 - x0, y1 - y0) for (x0, y0), (x1, y1) in pairwise(points)]
|
||||
directions = [((dx > 0) - (dx < 0), (dy > 0) - (dy < 0)) for dx, dy in deltas]
|
||||
headings = [cardinal_headings[direction] for direction in directions]
|
||||
source, destination = points[0], points[-1]
|
||||
nets[name] = CatalogNet(
|
||||
Pose(1000 * source[0], 1000 * source[1], headings[0], "4"),
|
||||
Pose(1000 * destination[0], 1000 * destination[1], headings[-1], "4"),
|
||||
)
|
||||
recipe: list[Move] = []
|
||||
for segment, (dx, dy) in enumerate(deltas):
|
||||
has_corner = segment < len(deltas) - 1
|
||||
# Each rounded corner uses one radius of the incoming and outgoing straights.
|
||||
length = abs(dx) + abs(dy) - radius_um * (int(segment > 0) + int(has_corner))
|
||||
if length < 0:
|
||||
raise ValueError(f"Reference bend exceeds its setback on {name}")
|
||||
if length:
|
||||
recipe.append(Move("4-straight", steps=1000 * length // grid.pitch))
|
||||
if has_corner:
|
||||
travel, onward = directions[segment:segment + 2]
|
||||
turn = travel[0] * onward[1] - travel[1] * onward[0]
|
||||
if not turn:
|
||||
raise ValueError(f"Reference corner must be a quarter turn on {name}")
|
||||
radius = 1000 * radius_um
|
||||
offset = (radius * (travel[0] + onward[0]), radius * (travel[1] + onward[1]))
|
||||
recipe.append(Move("left-90" if turn > 0 else "right-90", displacement=offset))
|
||||
references[name] = tuple(recipe)
|
||||
|
||||
obstacles = (
|
||||
*(box(*(1000 * coordinate for coordinate in block)) for block in (*BLOCKS, *COMPONENTS)),
|
||||
*(Polygon([(1000 * x, 1000 * y) for x, y in block]) for block in STEPPED_BLOCKS),
|
||||
)
|
||||
return ScaleCase(grid, box(0, 0, 5_000_000, 5_000_000), nets, obstacles, references)
|
||||
|
||||
|
||||
def scale_case(name: str) -> ScaleCase:
|
||||
if name == "floorplan":
|
||||
return floorplan_case()
|
||||
if name in ("tuning", "retry"):
|
||||
return timing_case(name)
|
||||
if name in ("corpus-lanes", "corpus-open-lanes"):
|
||||
|
|
@ -137,7 +187,7 @@ def catalog(mode: str, case: str) -> Catalog:
|
|||
(Polygon(((0, -2000), (10_000, -2500), (10_000, 2500), (0, 2000))),),
|
||||
(("a", "b"), ("b", "a")), (Orientation(), Orientation(180)), 0.01, 10_000,
|
||||
)
|
||||
if case in ("constrained", "diagonal-savings", "tuning"):
|
||||
if case in ("floorplan", "constrained", "diagonal-savings", "tuning"):
|
||||
variants["left-90"] = BendVariant("4", 90, 10_000, 0.01, sagitta=30)
|
||||
variants["right-90"] = BendVariant("4", -90, 10_000, 0.01, sagitta=30)
|
||||
if mode == "octagonal":
|
||||
|
|
@ -172,11 +222,22 @@ def verify_references(case: ScaleCase, technology: Catalog) -> None:
|
|||
raise AssertionError(f"Invalid reference for {name}: {error}")
|
||||
|
||||
|
||||
def bank_order_key(net: CatalogNet) -> tuple[int, int, bool, int, int]:
|
||||
"""Group by heading and put the outside of each lateral fan-out first."""
|
||||
start, target = net.start, net.target
|
||||
dx, dy = HEADING_STEPS[start.heading]
|
||||
start_side = dx * start.y - dy * start.x
|
||||
shift = dx * target.y - dy * target.x - start_side
|
||||
side = (shift > 0) - (shift < 0)
|
||||
return start.heading, target.heading, shift != 0, side, -side * start_side
|
||||
|
||||
|
||||
def run_catalog(case: ScaleCase, technology: Catalog, args: argparse.Namespace) -> tuple[dict, float]:
|
||||
settings = LayoutSettings(
|
||||
case.board, case.obstacles, clearance=case.clearance, node_limit=args.node_limit, refinement=not args.no_refinement,
|
||||
guidance=None if args.guide_pitch is None else CoarseGuidance(args.guide_pitch),
|
||||
retry_independent=not args.no_independent_retry,
|
||||
constructive=args.constructive,
|
||||
)
|
||||
start = perf_counter()
|
||||
grid = case.grid
|
||||
|
|
@ -231,7 +292,10 @@ def run_native(case: ScaleCase, args: argparse.Namespace) -> tuple[dict, float]:
|
|||
rate = pitch * case.grid.meters_per_unit * 100
|
||||
radius = 10_000 / pitch
|
||||
options = RoutingOptions(
|
||||
search=SearchOptions(node_limit=args.node_limit, max_straight_length=50_000, bend_radii=(radius,), sbend_radii=()),
|
||||
search=SearchOptions(
|
||||
node_limit=args.node_limit, max_straight_length=50_000, bend_radii=(radius,), sbend_radii=(),
|
||||
terminal_jog_limit=args.native_jog_limit,
|
||||
),
|
||||
objective=ObjectiveWeights(unit_length_cost=rate, bend_penalty=(0.01 - radius * pi / 2 * rate) * sqrt(radius / 10), danger_weight=0),
|
||||
topology=TopologyOptions(mode="off"),
|
||||
refinement=RefinementOptions(enabled=not args.no_refinement),
|
||||
|
|
@ -271,31 +335,46 @@ def main() -> None:
|
|||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--mode", choices=("native", "manhattan", "typed", "octagonal"), default="typed")
|
||||
parser.add_argument(
|
||||
"--case", default="aligned",
|
||||
"--case", default="floorplan", help="routing fixture (default: floorplan)",
|
||||
choices=(
|
||||
"aligned", "constrained", "diagonal-savings", "diagonal", "off-coarse", "tuning", "retry", "corpus-lanes", "corpus-open-lanes",
|
||||
"floorplan", "aligned", "constrained", "diagonal-savings", "diagonal", "off-coarse", "tuning", "retry",
|
||||
"corpus-lanes", "corpus-open-lanes",
|
||||
),
|
||||
)
|
||||
parser.add_argument("--guide-pitch", type=int, help="coarse pitch in nanometers")
|
||||
parser.add_argument("--auto-pitch", type=int, help="preferred pitch for automatic grid selection in nanometers")
|
||||
parser.add_argument("--repeat", type=int, default=3)
|
||||
parser.add_argument("--node-limit", type=int, default=1000)
|
||||
parser.add_argument("--net-order", choices=("input", "bank"), help="order for routing nets (floorplan defaults to bank order)")
|
||||
parser.add_argument("--native-jog-limit", type=int, help="two-turn launch attempts per native warm start")
|
||||
parser.add_argument("--constructive", action=argparse.BooleanOptionalAction, help="try constructive catalog routes first")
|
||||
parser.add_argument("--no-refinement", action="store_true")
|
||||
parser.add_argument("--no-independent-retry", action="store_true")
|
||||
parser.add_argument("--geometry", action="store_true")
|
||||
args = parser.parse_args()
|
||||
if args.repeat < 1:
|
||||
parser.error("--repeat must be positive")
|
||||
if args.native_jog_limit is not None and (args.mode != "native" or args.native_jog_limit < 0):
|
||||
parser.error("--native-jog-limit requires native mode and a nonnegative limit")
|
||||
if args.case == "diagonal" and args.mode != "octagonal":
|
||||
parser.error("The native-diagonal terminal case requires octagonal mode")
|
||||
if args.mode == "native" and (
|
||||
args.guide_pitch is not None or args.auto_pitch is not None
|
||||
or args.case not in ("constrained", "aligned", "diagonal-savings", "corpus-lanes", "corpus-open-lanes")
|
||||
or args.case not in ("floorplan", "constrained", "aligned", "diagonal-savings", "corpus-lanes", "corpus-open-lanes")
|
||||
):
|
||||
parser.error("Native mode needs a case with cardinal terminals on the explicit grid")
|
||||
case = scale_case(args.case)
|
||||
technology = catalog(args.mode, args.case)
|
||||
verify_references(case, technology)
|
||||
if args.net_order is None:
|
||||
args.net_order = "bank" if args.case == "floorplan" else "input"
|
||||
if args.net_order == "bank":
|
||||
names = sorted(case.nets, key=lambda name: bank_order_key(case.nets[name]))
|
||||
case = replace(case, nets={name: case.nets[name] for name in names})
|
||||
if args.mode == "native" and args.native_jog_limit is None:
|
||||
args.native_jog_limit = 48 if args.case == "floorplan" else 0
|
||||
if args.constructive is None:
|
||||
args.constructive = args.case == "floorplan" and args.mode != "native"
|
||||
samples = []
|
||||
measurements = {}
|
||||
for _ in range(args.repeat):
|
||||
|
|
|
|||
98
scripts/catalog_floorplan.py
Normal file
98
scripts/catalog_floorplan.py
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
"""Synthetic photonic floorplan for the catalog routing scale benchmark."""
|
||||
|
||||
# Coordinates in micrometers. Each bank lists source-to-destination waypoint sequences.
|
||||
NET_BANKS = {
|
||||
"west-launch": (
|
||||
((180, 430), (1080, 430)),
|
||||
((180, 454), (1520, 454)),
|
||||
((180, 478), (740, 478), (740, 518), (1660, 518)),
|
||||
((180, 502), (675, 502), (675, 548), (1660, 548)),
|
||||
((180, 526), (610, 526), (610, 588), (1660, 588)),
|
||||
((180, 550), (545, 550), (545, 628), (1660, 628)),
|
||||
((180, 574), (478, 574), (478, 668), (1660, 668)),
|
||||
((180, 598), (414, 598), (414, 711), (1520, 711)),
|
||||
),
|
||||
"shared-trunk": (
|
||||
((260, 1160), (1090, 1160), (1090, 1288), (2140, 1288)),
|
||||
((260, 1198), (1010, 1198), (1010, 1302), (2140, 1302)),
|
||||
((260, 1236), (930, 1236), (930, 1316), (2140, 1316)),
|
||||
((260, 1274), (850, 1274), (850, 1330), (2140, 1330)),
|
||||
((260, 1312), (775, 1312), (775, 1344), (2140, 1344)),
|
||||
((260, 1358), (2140, 1358)),
|
||||
),
|
||||
"east-output": (
|
||||
((2570, 2025), (3790, 2025), (3790, 1977), (4190, 1977), (4190, 2025), (4780, 2025)),
|
||||
((2670, 2050), (4780, 2050)),
|
||||
((2740, 2080), (3510, 2080), (3510, 2110), (4780, 2110)),
|
||||
((2740, 2110), (3420, 2110), (3420, 2160), (4780, 2160)),
|
||||
((2740, 2140), (3330, 2140), (3330, 2210), (4780, 2210)),
|
||||
),
|
||||
"east-feedback": (
|
||||
((4710, 2570), (2880, 2570)),
|
||||
((4710, 2606), (2470, 2606)),
|
||||
((4710, 2642), (3790, 2642), (3790, 2702), (2470, 2702)),
|
||||
((4710, 2678), (3860, 2678), (3860, 2752), (2470, 2752)),
|
||||
((4710, 2714), (3930, 2714), (3930, 2802), (2470, 2802)),
|
||||
),
|
||||
"north-monitor": (
|
||||
((608, 2110), (608, 4560)),
|
||||
((648, 2110), (648, 4560)),
|
||||
((688, 2110), (688, 3210), (752, 3210), (752, 4560)),
|
||||
((728, 2110), (728, 3080), (797, 3080), (797, 4560)),
|
||||
((768, 2110), (768, 2950), (842, 2950), (842, 4560)),
|
||||
((808, 2230), (808, 2880), (895, 2880), (895, 4560)),
|
||||
),
|
||||
"south-access": (
|
||||
((2970, 1730), (2970, 240)),
|
||||
((3030, 1730), (3030, 240)),
|
||||
((3100, 1660), (3100, 1080), (3170, 1080), (3170, 240)),
|
||||
((3160, 1660), (3160, 1180), (3230, 1180), (3230, 240)),
|
||||
((3220, 1660), (3220, 1280), (3290, 1280), (3290, 240)),
|
||||
((3530, 1050), (3530, 720)),
|
||||
),
|
||||
"upper-transfer": (
|
||||
((2700, 3300), (3890, 3300), (3890, 4440)),
|
||||
((2700, 3365), (3790, 3365), (3790, 4470)),
|
||||
((2700, 3430), (3690, 3430), (3690, 4500)),
|
||||
((2700, 3495), (3590, 3495), (3590, 4530)),
|
||||
),
|
||||
}
|
||||
|
||||
# Large keepouts reserve device, electronics, and thermal regions.
|
||||
BLOCKS = (
|
||||
(1220, 955, 1610, 1282),
|
||||
(1250, 1364, 1660, 1745),
|
||||
(1800, 435, 2240, 815),
|
||||
(2050, 1480, 2520, 1830),
|
||||
(2560, 675, 2840, 1210),
|
||||
(1870, 2960, 2360, 3370),
|
||||
(2900, 3650, 3435, 3960),
|
||||
(4190, 3180, 4530, 3530),
|
||||
(3970, 1135, 4420, 1470),
|
||||
(3320, 2280, 3590, 2510),
|
||||
(1110, 2510, 1430, 2930),
|
||||
(1140, 3730, 1470, 4170),
|
||||
(1960, 3970, 2310, 4235),
|
||||
(113, 1590, 420, 1850),
|
||||
)
|
||||
# Local device and pad banks are regular within each cluster and vary between clusters.
|
||||
COMPONENTS = (
|
||||
(100, 268, 165, 394), (100, 416, 160, 494), (98, 510, 160, 573), (105, 594, 160, 671),
|
||||
(165, 1125, 238, 1214), (171, 1234, 238, 1312), (169, 1332, 238, 1401),
|
||||
(4788, 1954, 4880, 2054), (4788, 2070, 4880, 2190), (4788, 2206, 4880, 2270),
|
||||
(4730, 2485, 4820, 2589), (4730, 2600, 4820, 2700), (4730, 2712, 4820, 2770),
|
||||
(512, 4580, 625, 4670), (639, 4580, 701, 4670), (716, 4580, 817, 4670), (832, 4580, 924, 4670),
|
||||
(2910, 115, 3005, 221), (3018, 115, 3122, 221), (3135, 115, 3232, 221), (3245, 115, 3320, 221),
|
||||
(3480, 4560, 3610, 4690), (3626, 4540, 3730, 4690), (3744, 4520, 3945, 4690),
|
||||
(1580, 2380, 1672, 2494), (1695, 2398, 1777, 2512), (1805, 2388, 1889, 2502),
|
||||
(2510, 2980, 2610, 3180), (2640, 2930, 2824, 3130), (2870, 2912, 2980, 3090),
|
||||
(4020, 375, 4170, 490), (4200, 410, 4330, 610), (4375, 505, 4490, 650), (4530, 580, 4630, 680),
|
||||
(3890, 2005, 4090, 2039),
|
||||
(3490, 1080, 3580, 1210), (3500, 533, 3640, 678), (3700, 654, 3820, 866),
|
||||
(595, 1940, 682, 2070), (700, 1955, 787, 2070), (801, 1990, 886, 2150),
|
||||
(1700, 4630, 1800, 4755), (1830, 4600, 1950, 4755), (1980, 4555, 2150, 4730),
|
||||
)
|
||||
STEPPED_BLOCKS = (
|
||||
((800, 759), (1150, 759), (1150, 925), (1020, 925), (1020, 1025), (800, 1025)),
|
||||
((3950, 3820), (4420, 3820), (4420, 4180), (4140, 4180), (4140, 4330), (3950, 4330)),
|
||||
)
|
||||
Loading…
Reference in a new issue