2026-03-10 21:55:54 -07:00
|
|
|
import numpy as np
|
2026-03-12 23:50:25 -07:00
|
|
|
import time
|
2026-03-10 21:55:54 -07:00
|
|
|
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
|
2026-03-12 23:50:25 -07:00
|
|
|
from inire.utils.visualization import plot_routing_results, plot_danger_map, plot_expanded_nodes
|
2026-03-10 21:55:54 -07:00
|
|
|
from shapely.geometry import box
|
|
|
|
|
|
|
|
|
|
def main() -> None:
|
2026-03-11 09:37:54 -07:00
|
|
|
print("Running Example 07: Fan-Out (10 Nets, 50um Radius, 5um Grid)...")
|
2026-03-10 21:55:54 -07:00
|
|
|
|
|
|
|
|
# 1. Setup Environment
|
2026-03-11 09:37:54 -07:00
|
|
|
bounds = (0, 0, 1000, 1000)
|
|
|
|
|
engine = CollisionEngine(clearance=6.0)
|
2026-03-10 21:55:54 -07:00
|
|
|
|
2026-03-11 09:37:54 -07:00
|
|
|
# Bottleneck at x=500, 200um gap
|
2026-03-10 21:55:54 -07:00
|
|
|
obstacles = [
|
2026-03-11 09:37:54 -07:00
|
|
|
box(450, 0, 550, 400),
|
|
|
|
|
box(450, 600, 550, 1000),
|
2026-03-10 21:55:54 -07:00
|
|
|
]
|
|
|
|
|
for obs in obstacles:
|
|
|
|
|
engine.add_static_obstacle(obs)
|
|
|
|
|
|
|
|
|
|
danger_map = DangerMap(bounds=bounds)
|
|
|
|
|
danger_map.precompute(obstacles)
|
|
|
|
|
|
|
|
|
|
evaluator = CostEvaluator(engine, danger_map, greedy_h_weight=1.5)
|
|
|
|
|
|
2026-03-12 23:50:25 -07:00
|
|
|
router = AStarRouter(evaluator, node_limit=5000, snap_size=10.0)
|
|
|
|
|
pf = PathFinder(router, evaluator, max_iterations=20, base_congestion_penalty=500.0)
|
2026-03-10 21:55:54 -07:00
|
|
|
|
2026-03-11 09:37:54 -07:00
|
|
|
# 2. Define Netlist
|
2026-03-10 21:55:54 -07:00
|
|
|
netlist = {}
|
|
|
|
|
num_nets = 10
|
2026-03-11 09:37:54 -07:00
|
|
|
start_x = 50
|
|
|
|
|
start_y_base = 500 - (num_nets * 10.0) / 2.0
|
2026-03-10 21:55:54 -07:00
|
|
|
|
2026-03-11 09:37:54 -07:00
|
|
|
end_x = 950
|
|
|
|
|
end_y_base = 100
|
|
|
|
|
end_y_pitch = 800.0 / (num_nets - 1)
|
2026-03-10 21:55:54 -07:00
|
|
|
|
|
|
|
|
for i in range(num_nets):
|
2026-03-11 09:37:54 -07:00
|
|
|
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))
|
2026-03-10 21:55:54 -07:00
|
|
|
|
|
|
|
|
net_widths = {nid: 2.0 for nid in netlist}
|
|
|
|
|
|
2026-03-12 23:50:25 -07:00
|
|
|
def iteration_callback(idx, current_results):
|
|
|
|
|
print(f" Iteration {idx} finished. Successes: {sum(1 for r in current_results.values() if r.is_valid)}/{len(netlist)}")
|
|
|
|
|
# fig, ax = plot_routing_results(current_results, obstacles, bounds, netlist=netlist)
|
|
|
|
|
# plot_danger_map(danger_map, ax=ax)
|
|
|
|
|
# fig.savefig(f"examples/07_iteration_{idx:02d}.png")
|
|
|
|
|
# import matplotlib.pyplot as plt
|
|
|
|
|
# plt.close(fig)
|
|
|
|
|
|
2026-03-10 21:55:54 -07:00
|
|
|
# 3. Route
|
2026-03-11 09:37:54 -07:00
|
|
|
print(f"Routing {len(netlist)} nets through 200um bottleneck...")
|
2026-03-12 23:50:25 -07:00
|
|
|
import cProfile, pstats
|
|
|
|
|
profiler = cProfile.Profile()
|
|
|
|
|
profiler.enable()
|
|
|
|
|
t0 = time.perf_counter()
|
|
|
|
|
results = pf.route_all(netlist, net_widths, store_expanded=True, iteration_callback=iteration_callback)
|
|
|
|
|
t1 = time.perf_counter()
|
|
|
|
|
profiler.disable()
|
|
|
|
|
stats = pstats.Stats(profiler).sort_stats('tottime')
|
|
|
|
|
stats.print_stats(20)
|
|
|
|
|
print(f"Routing took {t1-t0:.4f}s")
|
2026-03-10 21:55:54 -07:00
|
|
|
|
|
|
|
|
# 4. Check Results
|
|
|
|
|
success_count = sum(1 for res in results.values() if res.is_valid)
|
|
|
|
|
print(f"Routed {success_count}/{len(netlist)} nets successfully.")
|
2026-03-12 23:50:25 -07:00
|
|
|
|
|
|
|
|
for nid, res in results.items():
|
|
|
|
|
if not res.is_valid:
|
|
|
|
|
print(f" FAILED: {nid}")
|
|
|
|
|
else:
|
|
|
|
|
types = [move.move_type for move in res.path]
|
|
|
|
|
from collections import Counter
|
|
|
|
|
counts = Counter(types)
|
|
|
|
|
print(f" {nid}: {len(res.path)} segments, {dict(counts)}")
|
2026-03-10 21:55:54 -07:00
|
|
|
|
|
|
|
|
# 5. Visualize
|
|
|
|
|
fig, ax = plot_routing_results(results, obstacles, bounds, netlist=netlist)
|
2026-03-12 23:50:25 -07:00
|
|
|
|
|
|
|
|
# Overlay Danger Map
|
|
|
|
|
plot_danger_map(danger_map, ax=ax)
|
|
|
|
|
|
|
|
|
|
# Overlay Expanded Nodes from last routed net (as an example)
|
|
|
|
|
if pf.router.last_expanded_nodes:
|
|
|
|
|
print(f"Plotting {len(pf.router.last_expanded_nodes)} expanded nodes for the last net...")
|
|
|
|
|
plot_expanded_nodes(pf.router.last_expanded_nodes, ax=ax, color='blue', alpha=0.1)
|
|
|
|
|
|
2026-03-10 21:55:54 -07:00
|
|
|
fig.savefig("examples/07_large_scale_routing.png")
|
|
|
|
|
print("Saved plot to examples/07_large_scale_routing.png")
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
main()
|