gdsfactory / kfactory

gdsfactory with a klayout backend
https://gdsfactory.github.io/kfactory/
MIT License
28 stars 10 forks source link

Add smart routing #295

Closed sebastian-goeldi closed 2 months ago

sebastian-goeldi commented 2 months ago

Allow general bundle routing

image

@joamatab

TODO:

sebastian-goeldi commented 2 months ago

(Current) usage:

from functools import partial

from random import randint

import kfactory as kf

ps: list[kf.Port] = []
pe: list[kf.Port] = []

c = kf.KCell()

for angle in [-1, 0, 1, 2]:
    for xi in range(5):
        ts = (
            kf.kdb.Trans(angle, False, 0, 0)
            * kf.kdb.Trans(100_000, -50_000)
            * kf.kdb.Trans(randint(0, 100), randint(0, 100) + xi * 10_000)
        )
        ps.append(
            c.create_port(
                name="i" + str((angle + 1) * 5 + xi),
                trans=ts,
                width=1000,
                layer=kf.kcl.layout.layer(1, 0),
            )
        )
        te = kf.kdb.Trans(2, False, 250_000, 50_000 * angle) * kf.kdb.Trans(
            randint(0, 100), randint(0, 100) - xi * 10_000
        )
        pe.append(
            c.create_port(
                name="o" + str((angle + 1) * 5 + xi),
                trans=te,
                width=1000,
                layer=kf.kcl.layout.layer(1, 0),
            )
        )

b = kf.cells.circular.bend_circular(width=1, radius=10, layer=kf.kcl.layer(1, 0))
s = partial(kf.cells.straight.straight_dbu, width=1000, layer=kf.kcl.layer(1, 0))

routers = kf.routing.manhattan.route_smart(
    start_ports=ps, end_ports=pe, bend90_radius=10_000, separation=2000
)

for p1, p2, router in zip(ps, pe, routers):
    kf.routing.optical.place90(
        c, p1=p1, p2=p2, pts=router.start.pts, straight_factory=s, bend90_cell=b
    )

c.show()
joamatab commented 2 months ago

i tested it in a few cases and found some issues

image

sebastian-goeldi commented 2 months ago

Can you show the whole thing here and what you were trying to connect?

Depending on that, You might need to change the call a bit. This is not necessarily intended to just allow you to connect all components (because it makes strong assumptions about the order of ports) and the target needs to be a bank per bundle. If start and endports per bundle overlap, it will likely cause issues.

sebastian-goeldi commented 2 months ago

Also collision detection isn't built-in yet. That's the next step.

sebastian-goeldi commented 2 months ago

Collision detection:

image

By default kfactory will raise a RuntimeError and send the cell plus lyrdb with errors to klive. Detection is on all port layers or they can be defined in route_bundle