go to a tunable 5um grid

This commit is contained in:
jan 2026-03-11 09:37:54 -07:00
commit 91256cbcf9
21 changed files with 222 additions and 233 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 84 KiB

After

Width:  |  Height:  |  Size: 78 KiB

Before After
Before After

View file

@ -26,8 +26,8 @@ def main() -> None:
# Precompute the danger map (distance field) for heuristics
danger_map.precompute([obstacle])
evaluator = CostEvaluator(engine, danger_map)
router = AStarRouter(evaluator)
evaluator = CostEvaluator(engine, danger_map, bend_penalty=50.0, sbend_penalty=150.0)
router = AStarRouter(evaluator, snap_size=1.0, straight_lengths=[1.0, 5.0, 25.0], bend_radii=[10.0])
pf = PathFinder(router, evaluator)
# 2. Define Netlist

Binary file not shown.

Before

Width:  |  Height:  |  Size: 122 KiB

After

Width:  |  Height:  |  Size: 85 KiB

Before After
Before After

View file

@ -16,8 +16,8 @@ def main() -> None:
danger_map = DangerMap(bounds=bounds)
danger_map.precompute([])
evaluator = CostEvaluator(engine, danger_map)
router = AStarRouter(evaluator)
evaluator = CostEvaluator(engine, danger_map, bend_penalty=50.0, sbend_penalty=150.0)
router = AStarRouter(evaluator, snap_size=1.0, straight_lengths=[1.0, 5.0, 25.0], bend_radii=[10.0])
pf = PathFinder(router, evaluator)
# 2. Define Netlist

Binary file not shown.

Before

Width:  |  Height:  |  Size: 133 KiB

After

Width:  |  Height:  |  Size: 75 KiB

Before After
Before After

View file

@ -1,3 +1,5 @@
from shapely.geometry import Polygon
from inire.geometry.collision import CollisionEngine
from inire.geometry.primitives import Port
from inire.router.astar import AStarRouter
@ -8,63 +10,51 @@ from inire.utils.visualization import plot_routing_results
def main() -> None:
print("Running Example 03: Locked Paths (Incremental Routing - Bus Scenario)...")
print("Running Example 03: Locked Paths...")
# 1. Setup Environment
bounds = (0, 0, 120, 120)
bounds = (0, 0, 100, 100)
engine = CollisionEngine(clearance=2.0)
danger_map = DangerMap(bounds=bounds)
danger_map.precompute([]) # Start with empty space
danger_map.precompute([])
evaluator = CostEvaluator(engine, danger_map, greedy_h_weight=1.2)
router = AStarRouter(evaluator, node_limit=200000)
evaluator = CostEvaluator(engine, danger_map, bend_penalty=50.0, sbend_penalty=150.0)
router = AStarRouter(evaluator, snap_size=1.0, straight_lengths=[1.0, 5.0, 25.0], bend_radii=[10.0])
pf = PathFinder(router, evaluator)
# 2. Phase 1: Route a "Bus" of 3 parallel nets
# We give them a small jog to make the locked geometry more interesting
netlist_p1 = {
"bus_0": (Port(10, 40, 0), Port(110, 45, 0)),
"bus_1": (Port(10, 50, 0), Port(110, 55, 0)),
"bus_2": (Port(10, 60, 0), Port(110, 65, 0)),
# 2. Add a 'Pre-routed' net and lock it
# Net 'fixed' goes right through the middle
fixed_start = Port(10, 50, 0)
fixed_target = Port(90, 50, 0)
print("Routing initial net...")
res_fixed = router.route(fixed_start, fixed_target, net_width=2.0)
if res_fixed:
# 3. Lock this net! It now behaves like a static obstacle
geoms = [comp.geometry[0] for comp in res_fixed]
engine.add_path("locked_net", geoms)
engine.lock_net("locked_net")
print("Initial net locked as static obstacle.")
# Update danger map to reflect the new static obstacle
danger_map.precompute(list(engine.static_geometries.values()))
# 4. Route a new net that must detour around the locked one
netlist = {
"detour_net": (Port(50, 10, 90), Port(50, 90, 90)),
}
print("Phase 1: Routing bus (3 nets)...")
results_p1 = pf.route_all(netlist_p1, dict.fromkeys(netlist_p1, 2.0))
net_widths = {"detour_net": 2.0}
# Lock all Phase 1 nets
path_polys = []
for nid, res in results_p1.items():
if res.is_valid:
print(f" Locking {nid}...")
engine.lock_net(nid)
path_polys.extend([p for comp in res.path for p in comp.geometry])
else:
print(f" Warning: {nid} failed to route correctly.")
# Update danger map with the newly locked geometry
print("Updating DangerMap with locked paths...")
danger_map.precompute(path_polys)
# 3. Phase 2: Route secondary nets that must navigate around the locked bus
# These nets cross the bus vertically.
netlist_p2 = {
"cross_left": (Port(30, 10, 90), Port(30, 110, 90)),
"cross_right": (Port(80, 110, 270), Port(80, 10, 270)), # Top to bottom
}
print("Phase 2: Routing crossing nets around locked bus...")
# We use a slightly different width for variety
results_p2 = pf.route_all(netlist_p2, dict.fromkeys(netlist_p2, 1.5))
# 4. Check Results
for nid, res in results_p2.items():
status = "Success" if res.is_valid else "Failed"
print(f" {nid:12}: {status}, collisions={res.collisions}")
print("Routing detour net around locked path...")
results = pf.route_all(netlist, net_widths)
# 5. Visualize
all_results = {**results_p1, **results_p2}
all_netlists = {**netlist_p1, **netlist_p2}
fig, ax = plot_routing_results(all_results, [], bounds, netlist=all_netlists)
# Add the locked net back to results for display
from inire.router.pathfinder import RoutingResult
display_results = {**results, "locked_net": RoutingResult("locked_net", res_fixed or [], True, 0)}
fig, ax = plot_routing_results(display_results, list(engine.static_geometries.values()), bounds, netlist=netlist)
fig.savefig("examples/03_locked_paths.png")
print("Saved plot to examples/03_locked_paths.png")

View file

@ -1,4 +1,3 @@
from inire.geometry.collision import CollisionEngine
from inire.geometry.primitives import Port
from inire.router.astar import AStarRouter
@ -23,15 +22,14 @@ def main() -> None:
danger_map,
unit_length_cost=1.0,
greedy_h_weight=1.5,
bend_penalty=10.0,
sbend_penalty=20.0,
)
# We want a 45 degree switchover for S-bend.
# Offset O = 2 * R * (1 - cos(theta))
# If R = 10, O = 5.86
router = AStarRouter(
evaluator,
node_limit=50000,
snap_size=1.0,
bend_radii=[10.0, 30.0],
sbend_offsets=[5.0], # Use a simpler offset
sbend_radii=[10.0],

View file

@ -11,42 +11,31 @@ def main() -> None:
print("Running Example 05: Orientation Stress Test...")
# 1. Setup Environment
# Give some breathing room (-20 to 120) for U-turns and flips (R=10)
bounds = (-20, -20, 120, 120)
bounds = (0, 0, 200, 200)
engine = CollisionEngine(clearance=2.0)
danger_map = DangerMap(bounds=bounds)
danger_map.precompute([])
evaluator = CostEvaluator(engine, danger_map, greedy_h_weight=1.1)
router = AStarRouter(evaluator, node_limit=100000)
router.config.bend_collision_type = "clipped_bbox"
router.config.bend_clip_margin = 1.0
evaluator = CostEvaluator(engine, danger_map, bend_penalty=50.0, sbend_penalty=150.0)
router = AStarRouter(evaluator, snap_size=1.0, straight_lengths=[1.0, 5.0, 25.0], bend_radii=[10.0])
pf = PathFinder(router, evaluator)
# 2. Define Netlist with various orientation challenges
# 2. Define Netlist: Complex orientation challenges
netlist = {
# Opposite directions: requires two 90-degree bends to flip orientation
"opposite": (Port(10, 80, 0), Port(90, 80, 180)),
# 90-degree turn: standard L-shape
"turn_90": (Port(10, 60, 0), Port(40, 90, 90)),
# Output behind input: requires a full U-turn
"behind": (Port(80, 40, 0), Port(20, 40, 0)),
# Sharp return: output is behind and oriented towards the input
"return_loop": (Port(80, 20, 0), Port(40, 10, 180)),
"u_turn": (Port(50, 100, 0), Port(30, 100, 180)),
"loop": (Port(150, 50, 90), Port(150, 40, 90)),
"zig_zag": (Port(20, 20, 0), Port(180, 180, 0)),
}
net_widths = dict.fromkeys(netlist, 2.0)
net_widths = {nid: 2.0 for nid in netlist}
# 3. Route
print("Routing complex orientation nets...")
results = pf.route_all(netlist, net_widths)
# 4. Check Results
for nid, res in results.items():
status = "Success" if res.is_valid else "Failed"
total_len = sum(comp.length for comp in res.path) if res.path else 0
print(f" {nid:12}: {status}, total_length={total_len:.1f}")
print(f" {nid}: {status}")
# 5. Visualize
fig, ax = plot_routing_results(results, [], bounds, netlist=netlist)

View file

@ -30,18 +30,18 @@ def main() -> None:
danger_map.precompute(obstacles)
# We'll run three separate routers since collision_type is a router-level config
evaluator = CostEvaluator(engine, danger_map)
evaluator = CostEvaluator(engine, danger_map, bend_penalty=50.0, sbend_penalty=150.0)
# Scenario 1: Standard 'arc' model (High fidelity)
router_arc = AStarRouter(evaluator, bend_collision_type="arc")
router_arc = AStarRouter(evaluator, snap_size=1.0, straight_lengths=[1.0, 5.0, 25.0], bend_radii=[10.0], 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")
router_bbox = AStarRouter(evaluator, snap_size=1.0, straight_lengths=[1.0, 5.0, 25.0], bend_radii=[10.0], 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)
router_clipped = AStarRouter(evaluator, snap_size=1.0, straight_lengths=[1.0, 5.0, 25.0], bend_radii=[10.0], 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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 77 KiB

After

Width:  |  Height:  |  Size: 130 KiB

Before After
Before After

View file

@ -9,17 +9,16 @@ from inire.utils.visualization import plot_routing_results
from shapely.geometry import box
def main() -> None:
print("Running Example 07: Fan-Out (5 Nets)...")
print("Running Example 07: Fan-Out (10 Nets, 50um Radius, 5um Grid)...")
# 1. Setup Environment
# Small area for fast and reliable demonstration
bounds = (0, 0, 100, 100)
engine = CollisionEngine(clearance=2.0)
bounds = (0, 0, 1000, 1000)
engine = CollisionEngine(clearance=6.0)
# Wide bottleneck at x=50, 60um gap (from y=20 to y=80)
# Bottleneck at x=500, 200um gap
obstacles = [
box(50, 0, 55, 20),
box(50, 80, 55, 100),
box(450, 0, 550, 400),
box(450, 600, 550, 1000),
]
for obs in obstacles:
engine.add_static_obstacle(obs)
@ -29,32 +28,28 @@ def main() -> None:
evaluator = CostEvaluator(engine, danger_map, greedy_h_weight=1.5)
# Increase node_limit for more complex search
router = AStarRouter(evaluator, node_limit=50000)
pf = PathFinder(router, evaluator, max_iterations=2)
router = AStarRouter(evaluator, node_limit=50000, snap_size=5.0)
pf = PathFinder(router, evaluator, max_iterations=10)
# 2. Define Netlist: Fan-Out Configuration
# 2. Define Netlist
netlist = {}
num_nets = 10
start_x = 10
# Bundle centered at y=50, 4um pitch
start_y_base = 50 - (num_nets * 4.0) / 2.0
start_x = 50
start_y_base = 500 - (num_nets * 10.0) / 2.0
end_x = 90
end_y_base = 10
end_y_pitch = 80.0 / (num_nets - 1)
end_x = 950
end_y_base = 100
end_y_pitch = 800.0 / (num_nets - 1)
for i in range(num_nets):
sy = start_y_base + i * 4.0
ey = end_y_base + i * end_y_pitch
net_id = f"net_{i:02d}"
netlist[net_id] = (Port(start_x, sy, 0), Port(end_x, ey, 0))
sy = round((start_y_base + i * 10.0) / 5.0) * 5.0
ey = round((end_y_base + i * end_y_pitch) / 5.0) * 5.0
netlist[f"net_{i:02d}"] = (Port(start_x, sy, 0), Port(end_x, ey, 0))
net_widths = {nid: 2.0 for nid in netlist}
# 3. Route
print(f"Routing {len(netlist)} nets through 60um bottleneck...")
print(f"Routing {len(netlist)} nets through 200um bottleneck...")
results = pf.route_all(netlist, net_widths)
# 4. Check Results

View file

@ -1,4 +1,5 @@
from shapely.geometry import Polygon
from inire.geometry.collision import CollisionEngine
from inire.geometry.primitives import Port
from inire.router.astar import AStarRouter
@ -7,60 +8,47 @@ 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 08: Custom Bend Geometry Models...")
def main() -> None:
print("Running Example 08: Custom Bend Geometry...")
# 1. Setup Environment
bounds = (0, 0, 150, 150)
engine = CollisionEngine(clearance=2.0)
# Static obstacle to force specific bend paths
obstacle = Polygon([(60, 40), (90, 40), (90, 110), (60, 110)])
engine.add_static_obstacle(obstacle)
danger_map = DangerMap(bounds=bounds)
danger_map.precompute([obstacle])
evaluator = CostEvaluator(engine, danger_map)
danger_map.precompute([])
# We will route three nets, each with a DIFFERENT collision model
# To do this cleanly with the current architecture, we'll use one router
# but change its config per route call (or use tiered escalation in PathFinder).
# Since AStarRouter.route now accepts bend_collision_type, we can do it directly.
router = AStarRouter(evaluator)
evaluator = CostEvaluator(engine, danger_map, bend_penalty=50.0, sbend_penalty=150.0)
router = AStarRouter(evaluator, snap_size=1.0, straight_lengths=[1.0, 5.0, 25.0], bend_radii=[10.0])
pf = PathFinder(router, evaluator)
# 2. Define Netlist
netlist = {
"model_arc": (Port(10, 130, 0), Port(130, 100, -90)),
"model_bbox": (Port(10, 80, 0), Port(130, 50, -90)),
"model_clipped": (Port(10, 30, 0), Port(130, 10, -90)),
"custom_bend": (Port(20, 20, 0), Port(100, 100, 90)),
}
net_widths = {nid: 2.0 for nid in netlist}
net_widths = {"custom_bend": 2.0}
# Manual routing to specify different models per net
results = {}
print("Routing with 'arc' model...")
results["model_arc"] = pf.router.route(netlist["model_arc"][0], netlist["model_arc"][1], 2.0,
net_id="model_arc", bend_collision_type="arc")
print("Routing with 'bbox' model...")
results["model_bbox"] = pf.router.route(netlist["model_bbox"][0], netlist["model_bbox"][1], 2.0,
net_id="model_bbox", bend_collision_type="bbox")
print("Routing with 'clipped_bbox' model...")
results["model_clipped"] = pf.router.route(netlist["model_clipped"][0], netlist["model_clipped"][1], 2.0,
net_id="model_clipped", bend_collision_type="clipped_bbox")
# 3. Route with standard arc first
print("Routing with standard arc...")
results_std = pf.route_all(netlist, net_widths)
# Wrap in RoutingResult for visualization
from inire.router.pathfinder import RoutingResult
final_results = {
nid: RoutingResult(nid, path if path else [], path is not None, 0)
for nid, path in results.items()
}
# 4. Define a custom 'trapezoid' bend model
# (Just for demonstration - we override the collision model during search)
custom_poly = Polygon([(0, 0), (20, 0), (20, 20), (0, 20)]) # Oversized box
print("Routing with custom collision model...")
# Override bend_collision_type with a literal Polygon
router_custom = AStarRouter(evaluator, snap_size=1.0, straight_lengths=[1.0, 5.0, 25.0], bend_radii=[10.0], bend_collision_type=custom_poly)
results_custom = PathFinder(router_custom, evaluator, use_tiered_strategy=False).route_all(
{"custom_model": netlist["custom_bend"]}, {"custom_model": 2.0}
)
fig, ax = plot_routing_results(final_results, [obstacle], bounds, netlist=netlist)
# 5. Visualize
all_results = {**results_std, **results_custom}
fig, ax = plot_routing_results(all_results, [], bounds, netlist=netlist)
fig.savefig("examples/08_custom_bend_geometry.png")
print("Saved plot to examples/08_custom_bend_geometry.png")
if __name__ == "__main__":
main()

View file

@ -3,42 +3,55 @@ 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, RoutingResult
from inire.router.pathfinder import PathFinder
from inire.utils.visualization import plot_routing_results
from shapely.geometry import box
def main() -> None:
print("Running Example 09: Unroutable Nets & Best Effort Display...")
print("Running Example 09: Best-Effort (Unroutable Net)...")
# 1. Setup Environment
bounds = (0, 0, 100, 100)
engine = CollisionEngine(clearance=2.0)
# A large obstacle that completely blocks the target port
blocking_obs = box(40, 0, 60, 100)
engine.add_static_obstacle(blocking_obs)
danger_map = DangerMap(bounds=bounds)
danger_map.precompute([blocking_obs])
evaluator = CostEvaluator(engine, danger_map)
# Use a low node limit to fail quickly
router = AStarRouter(evaluator, node_limit=5000)
netlist = {
"blocked_net": (Port(10, 50, 0), Port(90, 50, 180))
}
print("Routing blocked net (expecting failure)...")
# Manually call route with return_partial=True
path = router.route(netlist["blocked_net"][0], netlist["blocked_net"][1], 2.0,
net_id="blocked_net", return_partial=True)
# Wrap in RoutingResult. Even if path is returned, is_valid=False
results = {
"blocked_net": RoutingResult("blocked_net", path if path else [], False, 1)
}
# Create a 'cage' that completely blocks the target
cage = [
box(70, 30, 75, 70), # Left wall
box(70, 70, 95, 75), # Top wall
box(70, 25, 95, 30), # Bottom wall
]
for obs in cage:
engine.add_static_obstacle(obs)
fig, ax = plot_routing_results(results, [blocking_obs], bounds, netlist=netlist)
danger_map = DangerMap(bounds=bounds)
danger_map.precompute(cage)
evaluator = CostEvaluator(engine, danger_map, bend_penalty=50.0, sbend_penalty=150.0)
# Use a low node limit to fail faster
router = AStarRouter(evaluator, node_limit=2000, snap_size=1.0, straight_lengths=[1.0, 5.0, 25.0], bend_radii=[10.0])
# Enable partial path return
pf = PathFinder(router, evaluator)
# 2. Define Netlist: start outside, target inside the cage
netlist = {
"trapped_net": (Port(10, 50, 0), Port(85, 50, 0)),
}
net_widths = {"trapped_net": 2.0}
# 3. Route
print("Routing net into a cage (should fail and return partial)...")
results = pf.route_all(netlist, net_widths)
# 4. Check Results
res = results["trapped_net"]
if not res.is_valid:
print(f"Net failed to route as expected. Partial path length: {len(res.path)} segments.")
else:
print("Wait, it found a way in? Check the cage geometry!")
# 5. Visualize
fig, ax = plot_routing_results(results, cage, bounds, netlist=netlist)
fig.savefig("examples/09_unroutable_best_effort.png")
print("Saved plot to examples/09_unroutable_best_effort.png")