Grid snapping#

GDS represents points as integers where each point corresponds to a database unit (DBU). Typically, in most foundries, the default DBU is set to 1 nanometer (1nm).

gdsfactory snaps ports to the grid by default to avoid grid snapping errors which are common in layout designs.

Example of grid snapping errors.

import gdsfactory as gf

nm = 1e-3

wg1 = gf.Component()
wg1.add_polygon(
    [(0, 0), (1.4 * nm, 0), (1.4 * nm, 1 * nm), (0, 1 * nm)], layer=(1, 0)
)  # rounds to 1 nm

wg1.add_polygon(
    [(0, 3 * nm), (1.6 * nm, 3 * nm), (1.6 * nm, 4 * nm), (0, 4 * nm)], layer=(1, 0)
)  # rounds to 2 nm

wg1.plot()
../_images/c6ba6bd54af6555b2940b575bb2e8f378aefb5af188c3a906c3d4c9919a65f0c.png

⚠️ Warning: Manhattan Orientations#

It’s crucial to always maintain ports with Manhattan orientations (0, 90, 180, 270 degrees). Non-Manhattan ports can lead to ports snapping off the grid, resulting in 1nm gaps in your layouts, which can be detrimental to the design’s integrity.

Although gdsfactory provides functions to connect and route component ports that are off-grid or have non-Manhattan orientations, this feature is disabled by default for safety reasons.

Note: If you intend to create off-grid ports and non-Manhattan connections, you must enable this feature manually. This should be done with caution and a thorough understanding of the potential implications on your design.

c = gf.Component()
w1 = c << gf.c.straight(length=4 * nm, width=4 * nm)
w1.drotate(45)

w2 = c << gf.c.straight(length=4 * nm, width=4 * nm)
w2.connect("o1", w1["o2"])
c  # in this case ports overlap by an extra nm because of the rotation, instead of connecting them with no overlap
../_images/2d8f8331c3a51fc2ae1448ec92593143b0d7440b61d7b7d84f06e42b5af34a87.png
c = gf.Component()
w1 = c << gf.components.straight(length=4 * nm, width=4 * nm)
w1.drotate(30)

w2 = c << gf.components.straight(length=4 * nm, width=4 * nm)
w2.connect("o1", w1["o2"])
c  # in this case ports have a 1nm gap error because of the rotation
../_images/694001eec226e4c672a27d91f0497b2e59592f99ee91f436980291fdeeb9249e.png

Fix Non manhattan connections#

The GDS format often has issues with non-manhattan shapes, due to the rounding of vertices to a unit grid and to downstream tools (i.e. DRC) which often tend to assume cell references only have rotations at 90 degree intervals.

To fix it, you can insert them as virtual instances.

For example:

import gdsfactory as gf

nm = 1e-3
c = gf.Component()
w = gf.components.straight(length=4 * nm, width=4 * nm)
w1 = c.create_vinst(w)
w1.rotate(30)

w2 = c.create_vinst(w)
w2.connect("o1", w1["o2"])
c
../_images/202e80fcd7ebfb3403d1b440c28d1a904aeafd1cd4055bffd80a2baa7f66ccb4.png
import gdsfactory as gf


@gf.cell(check_instances="none")
def demo_non_manhattan():
    c = gf.Component("bend")
    b = c << gf.components.bend_circular(angle=30)
    s = c << gf.components.straight(length=5)
    s.connect("o1", b.ports["o2"])
    return c


c1 = demo_non_manhattan()
c1
../_images/56805a0ac70278744ad44028eca227eb85a22db73835959cd2ca70578346e3a8.png

if you zoom in between the bends you will see a notch between waveguides due to non-manhattan connection between the bends.

gap

Solution#

import gdsfactory as gf


@gf.vcell
def snap_bends() -> gf.ComponentAllAngle:
    c = gf.ComponentAllAngle()
    b = gf.c.bend_euler_all_angle(angle=37)
    b1 = c << b
    b2 = c << b
    b2.connect("o1", b1.ports["o2"])
    c.add_port("o1", port=b1.ports["o1"])
    c.add_port("o2", port=b2.ports["o2"])
    return c


c = snap_bends()
c
../_images/fb3f74fcff86f7a7dead5dea2d1814332f3daa8df84de13a8563c8b8e3b16b8e.png
c.show()

If you zoom in the connection you will see now a perfect connection.

no gap