more bend work; bounds constrain edges
This commit is contained in:
parent
4714bed9a8
commit
58873692d6
15 changed files with 251 additions and 124 deletions
29
DOCS.md
29
DOCS.md
|
|
@ -7,22 +7,22 @@ This document describes the user-tunable parameters for the `inire` auto-router.
|
|||
The `AStarRouter` is the core pathfinding engine. It can be configured directly through its constructor.
|
||||
|
||||
| Parameter | Type | Default | Description |
|
||||
| :--- | :--- | :--- | :--- |
|
||||
| :-------------------- | :------------ | :----------------- | :------------------------------------------------------------------------------------ |
|
||||
| `node_limit` | `int` | 1,000,000 | Maximum number of states to explore per net. Increase for very complex paths. |
|
||||
| `straight_lengths` | `list[float]` | `[1.0, 5.0, 25.0]` | Discrete step sizes for straight waveguides (µm). Larger steps speed up search in open space. |
|
||||
| `bend_radii` | `list[float]` | `[10.0]` | Available radii for 90-degree turns (µm). Multiple values allow the router to pick the best fit. |
|
||||
| `straight_lengths` | `list[float]` | `[1.0, 5.0, 25.0]` | Discrete step sizes for straight waveguides (µm). Larger steps speed up search. |
|
||||
| `bend_radii` | `list[float]` | `[10.0]` | Available radii for 90-degree turns (µm). Multiple values allow best-fit selection. |
|
||||
| `sbend_offsets` | `list[float]` | `[-5, -2, 2, 5]` | Lateral offsets for parametric S-bends (µm). |
|
||||
| `sbend_radii` | `list[float]` | `[10.0]` | Available radii for S-bends (µm). |
|
||||
| `snap_to_target_dist`| `float` | 20.0 | Distance (µm) at which the router attempts an exact bridge to the target port. |
|
||||
| `snap_to_target_dist` | `float` | 20.0 | Distance (µm) at which the router attempts an exact bridge to the target port. |
|
||||
| `bend_penalty` | `float` | 50.0 | Flat cost added for every 90-degree bend. Higher values favor straight lines. |
|
||||
| `sbend_penalty` | `float` | 100.0 | Flat cost added for every S-bend. Usually higher than `bend_penalty`. |
|
||||
| `bend_collision_type`| `str` | `"arc"` | Collision model for bends: `"arc"`, `"bbox"`, or `"clipped_bbox"`. |
|
||||
| `bend_clip_margin` | `float` | 10.0 | Margin (µm) for the `"clipped_bbox"` collision model. |
|
||||
| `bend_collision_type` | `str` | `"arc"` | Collision model for bends: `"arc"`, `"bbox"`, or `"clipped_bbox"`. |
|
||||
| `bend_clip_margin` | `float` | 10.0 | Extra space (µm) around the waveguide before the bounding box corners are clipped. |
|
||||
|
||||
### Bend Collision Models
|
||||
* `"arc"`: High-fidelity model following the exact curved waveguide geometry.
|
||||
* `"bbox"`: Conservative model using the axis-aligned bounding box of the bend. Fast but blocks more space.
|
||||
* `"clipped_bbox"`: A middle ground that uses the bounding box but clips corners that are far from the waveguide.
|
||||
* `"clipped_bbox"`: A middle ground that starts with the bounding box but applies 45-degree linear cuts to the inner and outer corners. The `bend_clip_margin` defines the extra safety distance from the waveguide edge to the cut line.
|
||||
|
||||
---
|
||||
|
||||
|
|
@ -31,10 +31,10 @@ The `AStarRouter` is the core pathfinding engine. It can be configured directly
|
|||
The `CostEvaluator` defines the "goodness" of a path.
|
||||
|
||||
| Parameter | Type | Default | Description |
|
||||
| :--- | :--- | :--- | :--- |
|
||||
| :------------------- | :------ | :--------- | :--------------------------------------------------------------------------------------- |
|
||||
| `unit_length_cost` | `float` | 1.0 | Cost per µm of wire length. |
|
||||
| `greedy_h_weight` | `float` | 1.1 | Heuristic weight. `1.0` is optimal; higher values (e.g., `1.5`) are faster but may produce longer paths. |
|
||||
| `congestion_penalty`| `float` | 10,000.0 | Multiplier for overlaps in the multi-net Negotiated Congestion loop. |
|
||||
| `greedy_h_weight` | `float` | 1.1 | Heuristic weight. `1.0` is optimal; higher values (e.g. `1.5`) speed up search. |
|
||||
| `congestion_penalty` | `float` | 10,000.0 | Multiplier for overlaps in the multi-net Negotiated Congestion loop. |
|
||||
|
||||
---
|
||||
|
||||
|
|
@ -43,18 +43,18 @@ The `CostEvaluator` defines the "goodness" of a path.
|
|||
The `PathFinder` orchestrates multi-net routing using the Negotiated Congestion algorithm.
|
||||
|
||||
| Parameter | Type | Default | Description |
|
||||
| :--- | :--- | :--- | :--- |
|
||||
| :------------------------ | :------ | :------ | :-------------------------------------------------------------------------------------- |
|
||||
| `max_iterations` | `int` | 10 | Maximum number of rip-up and reroute iterations to resolve congestion. |
|
||||
| `base_congestion_penalty` | `float` | 100.0 | Starting penalty for overlaps. This value is multiplied by `1.5` each iteration if congestion persists. |
|
||||
| `base_congestion_penalty` | `float` | 100.0 | Starting penalty for overlaps. Multiplied by `1.5` each iteration if congestion remains.|
|
||||
|
||||
---
|
||||
|
||||
## 4. CollisionEngine Parameters
|
||||
|
||||
| Parameter | Type | Default | Description |
|
||||
| :--- | :--- | :--- | :--- |
|
||||
| :------------------- | :------ | :--------- | :------------------------------------------------------------------------------------ |
|
||||
| `clearance` | `float` | (Required) | Minimum required distance between any two waveguides or obstacles (µm). |
|
||||
| `safety_zone_radius`| `float` | 0.0021 | Radius (µm) around ports where collisions are ignored to allow PDK boundary incidence. |
|
||||
| `safety_zone_radius` | `float` | 0.0021 | Radius (µm) around ports where collisions are ignored for PDK boundary incidence. |
|
||||
|
||||
---
|
||||
|
||||
|
|
@ -62,6 +62,7 @@ The `PathFinder` orchestrates multi-net routing using the Negotiated Congestion
|
|||
- **Coordinates**: Micrometers (µm).
|
||||
- **Grid Snapping**: The router internally operates on a **1nm** grid for final ports and a **1µm** lattice for expansion moves.
|
||||
- **Search Space**: Assumptions are optimized for design areas up to **20mm x 20mm**.
|
||||
- **Design Bounds**: The boundary limits defined in `DangerMap` strictly constrain the **physical edges** (dilated geometry) of the waveguide. Any move that would cause the waveguide or its required clearance to extend beyond these bounds is rejected with an infinite cost.
|
||||
|
||||
---
|
||||
|
||||
|
|
|
|||
|
|
@ -74,12 +74,17 @@ Check the `examples/` directory for ready-to-run scripts demonstrating core feat
|
|||
* **`examples/03_locked_paths.py`**: Incremental workflow using `lock_net()` to route around previously fixed paths. Generates `03_locked_paths.png`.
|
||||
* **`examples/04_sbends_and_radii.py`**: Complex paths using parametric S-bends and multiple bend radii. Generates `04_sbends_and_radii.png`.
|
||||
* **`examples/05_orientation_stress.py`**: Stress test for various port orientation combinations (U-turns, opposite directions). Generates `05_orientation_stress.png`.
|
||||
* **`examples/06_bend_collision_models.py`**: Comparison of different collision models for bends (Arc vs. BBox vs. Clipped BBox). Generates `06_bend_collision_models.png`.
|
||||
|
||||
Run an example:
|
||||
```bash
|
||||
python3 examples/01_simple_route.py
|
||||
```
|
||||
|
||||
## Documentation
|
||||
|
||||
Full documentation for all user-tunable parameters, cost functions, and collision models can be found in **[DOCS.md](DOCS.md)**.
|
||||
|
||||
## Architecture
|
||||
|
||||
`inire` operates on a **State-Lattice** defined by $(x, y, \theta)$. From any state, the router expands via three primary "Move" types:
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ def main() -> None:
|
|||
"vertical_up": (Port(45, 10, 90), Port(45, 90, 90)),
|
||||
"vertical_down": (Port(55, 90, 270), Port(55, 10, 270)),
|
||||
}
|
||||
net_widths = {nid: 2.0 for nid in netlist}
|
||||
net_widths = dict.fromkeys(netlist, 2.0)
|
||||
|
||||
# 3. Route with Negotiated Congestion
|
||||
# We increase the base penalty to encourage faster divergence
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ def main() -> None:
|
|||
"bus_2": (Port(10, 60, 0), Port(110, 65, 0)),
|
||||
}
|
||||
print("Phase 1: Routing bus (3 nets)...")
|
||||
results_p1 = pf.route_all(netlist_p1, {nid: 2.0 for nid in netlist_p1})
|
||||
results_p1 = pf.route_all(netlist_p1, dict.fromkeys(netlist_p1, 2.0))
|
||||
|
||||
# Lock all Phase 1 nets
|
||||
path_polys = []
|
||||
|
|
@ -53,7 +53,7 @@ def main() -> None:
|
|||
|
||||
print("Phase 2: Routing crossing nets around locked bus...")
|
||||
# We use a slightly different width for variety
|
||||
results_p2 = pf.route_all(netlist_p2, {nid: 1.5 for nid in netlist_p2})
|
||||
results_p2 = pf.route_all(netlist_p2, dict.fromkeys(netlist_p2, 1.5))
|
||||
|
||||
# 4. Check Results
|
||||
for nid, res in results_p2.items():
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
from shapely.geometry import Polygon
|
||||
|
||||
from inire.geometry.collision import CollisionEngine
|
||||
from inire.geometry.primitives import Port
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ def main() -> None:
|
|||
# Sharp return: output is behind and oriented towards the input
|
||||
"return_loop": (Port(80, 20, 0), Port(40, 10, 180)),
|
||||
}
|
||||
net_widths = {nid: 2.0 for nid in netlist}
|
||||
net_widths = dict.fromkeys(netlist, 2.0)
|
||||
|
||||
# 3. Route
|
||||
results = pf.route_all(netlist, net_widths)
|
||||
|
|
|
|||
BIN
examples/06_bend_collision_models.png
Normal file
BIN
examples/06_bend_collision_models.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 43 KiB |
70
examples/06_bend_collision_models.py
Normal file
70
examples/06_bend_collision_models.py
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
from shapely.geometry import Polygon
|
||||
|
||||
from inire.geometry.collision import CollisionEngine
|
||||
from inire.geometry.primitives import Port
|
||||
from inire.router.astar import AStarRouter
|
||||
from inire.router.cost import CostEvaluator
|
||||
from inire.router.danger_map import DangerMap
|
||||
from inire.router.pathfinder import PathFinder
|
||||
from inire.utils.visualization import plot_routing_results
|
||||
|
||||
|
||||
def main() -> None:
|
||||
print("Running Example 06: Bend Collision Models...")
|
||||
|
||||
# 1. Setup Environment
|
||||
# Give room for 10um bends near the edges
|
||||
bounds = (-20, -20, 170, 170)
|
||||
engine = CollisionEngine(clearance=2.0)
|
||||
danger_map = DangerMap(bounds=bounds)
|
||||
|
||||
# Create three scenarios with identical obstacles
|
||||
# We'll space them out vertically
|
||||
obs_arc = Polygon([(40, 110), (60, 110), (60, 130), (40, 130)])
|
||||
obs_bbox = Polygon([(40, 60), (60, 60), (60, 80), (40, 80)])
|
||||
obs_clipped = Polygon([(40, 10), (60, 10), (60, 30), (40, 30)])
|
||||
|
||||
obstacles = [obs_arc, obs_bbox, obs_clipped]
|
||||
for obs in obstacles:
|
||||
engine.add_static_obstacle(obs)
|
||||
danger_map.precompute(obstacles)
|
||||
|
||||
# We'll run three separate routers since collision_type is a router-level config
|
||||
evaluator = CostEvaluator(engine, danger_map)
|
||||
|
||||
# Scenario 1: Standard 'arc' model (High fidelity)
|
||||
router_arc = AStarRouter(evaluator, bend_collision_type="arc")
|
||||
netlist_arc = {"arc_model": (Port(10, 120, 0), Port(90, 140, 90))}
|
||||
|
||||
# Scenario 2: 'bbox' model (Conservative axis-aligned box)
|
||||
router_bbox = AStarRouter(evaluator, bend_collision_type="bbox")
|
||||
netlist_bbox = {"bbox_model": (Port(10, 70, 0), Port(90, 90, 90))}
|
||||
|
||||
# Scenario 3: 'clipped_bbox' model (Balanced)
|
||||
router_clipped = AStarRouter(evaluator, bend_collision_type="clipped_bbox", bend_clip_margin=1.0)
|
||||
netlist_clipped = {"clipped_model": (Port(10, 20, 0), Port(90, 40, 90))}
|
||||
|
||||
# 2. Route each scenario
|
||||
print("Routing Scenario 1 (Arc)...")
|
||||
res_arc = PathFinder(router_arc, evaluator).route_all(netlist_arc, {"arc_model": 2.0})
|
||||
|
||||
print("Routing Scenario 2 (BBox)...")
|
||||
res_bbox = PathFinder(router_bbox, evaluator).route_all(netlist_bbox, {"bbox_model": 2.0})
|
||||
|
||||
print("Routing Scenario 3 (Clipped BBox)...")
|
||||
res_clipped = PathFinder(router_clipped, evaluator).route_all(netlist_clipped, {"clipped_model": 2.0})
|
||||
|
||||
# 3. Combine results for visualization
|
||||
all_results = {**res_arc, **res_bbox, **res_clipped}
|
||||
all_netlists = {**netlist_arc, **netlist_bbox, **netlist_clipped}
|
||||
|
||||
# 4. Visualize
|
||||
# Note: plot_routing_results will show the 'collision geometry' used by the router
|
||||
# since that's what's stored in res.path[i].geometry
|
||||
fig, ax = plot_routing_results(all_results, obstacles, bounds, netlist=all_netlists)
|
||||
fig.savefig("examples/06_bend_collision_models.png")
|
||||
print("Saved plot to examples/06_bend_collision_models.png")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
@ -3,8 +3,7 @@ from __future__ import annotations
|
|||
from typing import TYPE_CHECKING
|
||||
|
||||
import rtree
|
||||
from shapely.geometry import Point, Polygon
|
||||
from shapely.ops import unary_union
|
||||
from shapely.geometry import Polygon
|
||||
from shapely.prepared import prep
|
||||
|
||||
if TYPE_CHECKING:
|
||||
|
|
@ -131,17 +130,14 @@ class CollisionEngine:
|
|||
ix_minx, ix_miny, ix_maxx, ix_maxy = intersection.bounds
|
||||
|
||||
is_near_start = False
|
||||
if start_port:
|
||||
if (abs(ix_minx - start_port.x) < self.safety_zone_radius and abs(ix_maxx - start_port.x) < self.safety_zone_radius and
|
||||
if start_port and (abs(ix_minx - start_port.x) < self.safety_zone_radius and abs(ix_maxx - start_port.x) < self.safety_zone_radius and
|
||||
abs(ix_miny - start_port.y) < self.safety_zone_radius and abs(ix_maxy - start_port.y) < self.safety_zone_radius):
|
||||
is_near_start = True
|
||||
|
||||
is_near_end = False
|
||||
if end_port:
|
||||
if (abs(ix_minx - end_port.x) < self.safety_zone_radius and abs(ix_maxx - end_port.x) < self.safety_zone_radius and
|
||||
if end_port and (abs(ix_minx - end_port.x) < self.safety_zone_radius and abs(ix_maxx - end_port.x) < self.safety_zone_radius and
|
||||
abs(ix_miny - end_port.y) < self.safety_zone_radius and abs(ix_maxy - end_port.y) < self.safety_zone_radius):
|
||||
is_near_end = True
|
||||
|
||||
if is_near_start or is_near_end:
|
||||
continue
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from typing import NamedTuple, Literal, Union
|
||||
from typing import NamedTuple, Literal, Any
|
||||
|
||||
import numpy as np
|
||||
from shapely.geometry import Polygon, box
|
||||
|
|
@ -87,6 +87,9 @@ def _apply_collision_model(
|
|||
arc_poly: Polygon,
|
||||
collision_type: Literal["arc", "bbox", "clipped_bbox"] | Polygon,
|
||||
radius: float,
|
||||
width: float,
|
||||
cx: float = 0.0,
|
||||
cy: float = 0.0,
|
||||
clip_margin: float = 10.0
|
||||
) -> list[Polygon]:
|
||||
"""Applies the specified collision model to an arc geometry."""
|
||||
|
|
@ -104,8 +107,49 @@ def _apply_collision_model(
|
|||
return [bbox]
|
||||
|
||||
if collision_type == "clipped_bbox":
|
||||
safe_zone = arc_poly.buffer(clip_margin)
|
||||
return [bbox.intersection(safe_zone)]
|
||||
res_poly = bbox
|
||||
|
||||
# Determine quadrant signs from arc centroid relative to center
|
||||
# This ensures we always cut 'into' the box correctly
|
||||
ac = arc_poly.centroid
|
||||
sx = 1.0 if ac.x >= cx else -1.0
|
||||
sy = 1.0 if ac.y >= cy else -1.0
|
||||
|
||||
r_out_cut = radius + width / 2.0 + clip_margin
|
||||
r_in_cut = radius - width / 2.0 - clip_margin
|
||||
|
||||
corners = [(minx, miny), (minx, maxy), (maxx, miny), (maxx, maxy)]
|
||||
for px, py in corners:
|
||||
dx, dy = px - cx, py - cy
|
||||
dist = np.sqrt(dx**2 + dy**2)
|
||||
|
||||
if dist > r_out_cut:
|
||||
# Outer corner: remove part furthest from center
|
||||
# We want minimum distance to line to be r_out_cut
|
||||
d_cut = r_out_cut * np.sqrt(2)
|
||||
elif r_in_cut > 0 and dist < r_in_cut:
|
||||
# Inner corner: remove part closest to center
|
||||
# We want maximum distance to line to be r_in_cut
|
||||
d_cut = r_in_cut
|
||||
else:
|
||||
continue
|
||||
|
||||
# The cut line is sx*(x-cx) + sy*(y-cy) = d_cut
|
||||
# sx*x + sy*y = sx*cx + sy*cy + d_cut
|
||||
val = cx * sx + cy * sy + d_cut
|
||||
|
||||
try:
|
||||
p1 = (px, py)
|
||||
p2 = (px, (val - sx * px) / sy)
|
||||
p3 = ((val - sy * py) / sx, py)
|
||||
|
||||
triangle = Polygon([p1, p2, p3])
|
||||
if triangle.is_valid and triangle.area > 1e-9:
|
||||
res_poly = res_poly.difference(triangle)
|
||||
except ZeroDivisionError:
|
||||
continue
|
||||
|
||||
return [res_poly]
|
||||
|
||||
return [arc_poly]
|
||||
|
||||
|
|
@ -135,7 +179,9 @@ class Bend90:
|
|||
end_port = Port(ex, ey, float((start_port.orientation + turn_angle) % 360))
|
||||
|
||||
arc_polys = _get_arc_polygons(cx, cy, radius, width, t_start, t_end, sagitta)
|
||||
collision_polys = _apply_collision_model(arc_polys[0], collision_type, radius, clip_margin)
|
||||
collision_polys = _apply_collision_model(
|
||||
arc_polys[0], collision_type, radius, width, cx, cy, clip_margin
|
||||
)
|
||||
|
||||
return ComponentResult(geometry=collision_polys, end_port=end_port, length=radius * np.pi / 2.0)
|
||||
|
||||
|
|
@ -181,5 +227,13 @@ class SBend:
|
|||
arc2 = _get_arc_polygons(cx2, cy2, radius, width, ts2, te2, sagitta)[0]
|
||||
combined_arc = unary_union([arc1, arc2])
|
||||
|
||||
collision_polys = _apply_collision_model(combined_arc, collision_type, radius, clip_margin)
|
||||
if collision_type == "clipped_bbox":
|
||||
col1 = _apply_collision_model(arc1, collision_type, radius, width, cx1, cy1, clip_margin)
|
||||
col2 = _apply_collision_model(arc2, collision_type, radius, width, cx2, cy2, clip_margin)
|
||||
collision_polys = [unary_union(col1 + col2)]
|
||||
else:
|
||||
collision_polys = _apply_collision_model(
|
||||
combined_arc, collision_type, radius, width, 0, 0, clip_margin
|
||||
)
|
||||
|
||||
return ComponentResult(geometry=collision_polys, end_port=end_port, length=2 * radius * theta)
|
||||
|
|
|
|||
|
|
@ -189,7 +189,7 @@ class AStarRouter:
|
|||
lengths = self.config.straight_lengths
|
||||
if dist < 5.0:
|
||||
fine_steps = [0.1, 0.5]
|
||||
lengths = sorted(list(set(lengths + fine_steps)))
|
||||
lengths = sorted(set(lengths + fine_steps))
|
||||
|
||||
for length in lengths:
|
||||
res = Straight.generate(current.port, length, net_width)
|
||||
|
|
|
|||
|
|
@ -1,10 +1,8 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass, field
|
||||
from typing import Literal, TYPE_CHECKING, Any
|
||||
from typing import Literal, Any
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from shapely.geometry import Polygon
|
||||
|
||||
|
||||
@dataclass
|
||||
|
|
|
|||
|
|
@ -74,11 +74,18 @@ class CostEvaluator:
|
|||
_ = net_width # Unused
|
||||
total_cost = length * self.unit_length_cost
|
||||
|
||||
# 1. Hard Collision check (Static obstacles)
|
||||
# 1. Hard Collision & Boundary Check
|
||||
# We buffer by the full clearance to ensure distance >= clearance
|
||||
hard_dilation = self.collision_engine.clearance
|
||||
for poly in geometry:
|
||||
dilated_poly = poly.buffer(hard_dilation)
|
||||
|
||||
# Boundary Check: Physical edges must stay within design bounds
|
||||
minx, miny, maxx, maxy = dilated_poly.bounds
|
||||
if not (self.danger_map.is_within_bounds(minx, miny) and
|
||||
self.danger_map.is_within_bounds(maxx, maxy)):
|
||||
return 1e15 # Out of bounds is impossible
|
||||
|
||||
if self.collision_engine.is_collision_prebuffered(dilated_poly, start_port=start_port, end_port=end_port):
|
||||
return 1e15 # Impossible cost for hard collisions
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,4 @@
|
|||
import numpy as np
|
||||
import pytest
|
||||
from shapely.geometry import Point
|
||||
|
||||
from inire.geometry.components import Bend90, SBend, Straight
|
||||
from inire.geometry.primitives import Port, rotate_port, translate_port
|
||||
|
|
|
|||
|
|
@ -3,8 +3,7 @@ from __future__ import annotations
|
|||
import numpy as np
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
from shapely.geometry import Point, Polygon
|
||||
from shapely.ops import unary_union
|
||||
from shapely.geometry import Polygon
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from inire.geometry.primitives import Port
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue