add_route_astar finds a path from one port to another that avoids the listed obstacle layers — useful when you don't want to dictate the route shape but the wire has to navigate around existing components (waveguides, bond pads, MMIs, fences, …).

This is optical routing, so we route on a waveguide cross-section and use bend_euler for the bends — sharp corners would scatter the mode and break the loss budget. The bend radius must be ≥ the PDK's minimum; here we use 5 µm for gdsfactory.gpdk.

The grid the A* algorithm searches over is set by grid_unit (in dbu). A finer grid finds tighter paths but costs more solve time; coarser is faster but can miss valid routes through narrow gaps.

clearance (µm) inflates each obstacle polygon before the search, so the route stays at least clearance away from every obstacle edge. With clearance=0 (default) the route can share an edge with an obstacle (zero-area "touch"), which reads visually as overlap in klayout. Set it to ~1 µm or so to leave a clean gap.

Imports

import gdsfactory as gf
from gdsfactory.gpdk import PDK

import doroutes as dr

PDK.activate()

Single Route on a Test Field

dr.pcells.field1() is a small example layout with in and out named instances and a handful of waveguide stubs scattered between them as obstacles — a stand-in for the kind of crowded floorplan you might be routing through. A* finds a path on the WG (waveguide) layer that doesn't cross any of those obstacles.

c = gf.Component()
ref = c << dr.pcells.field1()
dr.add_route_astar(
    component=c,
    start=ref.ports["o1"],  # routable end of field1's "in" sub-instance
    stop=ref.ports["o2"],  # routable end of field1's "out" sub-instance
    straight="straight",
    bend={"component": "bend_euler", "settings": {"radius": 5}},
    layers=["WG"],  # obstacles to avoid
    grid_unit=500,  # A* grid pitch (dbu) — smaller = tighter paths, more solve time
    clearance=0.5,  # leave 1 µm gap between the route body and every obstacle edge
)
dr.util.show_cell(c)
API key for organization 'DoPlayDo' found.

Next steps