Skip to content

gdstk backend: close API gaps so the tutorials run - #104

Open
carloscl03 wants to merge 4 commits into
ReaLLMASIC:mainfrom
carloscl03:fix-notebook-backend-imports
Open

gdstk backend: close API gaps so the tutorials run#104
carloscl03 wants to merge 4 commits into
ReaLLMASIC:mainfrom
carloscl03:fix-notebook-backend-imports

Conversation

@carloscl03

Copy link
Copy Markdown

Running the tutorial notebooks under GLAYOUT_BACKEND=gdstk fails almost
immediately — 4 of 14 pass. Two causes, one on each side.

The notebooks bypass the backend selection

from gdsfactory import Component        # 10 notebooks

Under the default backend this resolves to the same class as
glayout.backend.Component, so nobody notices. Under gdstk, gdsfactory's
add_ref() receives a gdstk Component and rejects it:

TypeError: type = <class 'type'> needs to be a Component.

Redirected Component, rectangle, rectangular_ring, boolean and
cell to glayout.backend. Symbols it does not re-export
(text_freetype, array) stay on gdsfactory. Imports only — no cell
content touched.

The gdstk backend is missing parts of the surface

Each of these is used by glayout's own cells or by the tutorials:

before after
movex / movey bare delta destination= too, like move() already had
ref.name read-only assignable (ref.name = "pfet_2")
ref.x / ref.y absent centre accessors, next to the existing xmin/xmax
write_gds filename required, no gdsdir both optional, as in gdsfactory
Component.show absent writes a temp GDS, hands it to klive if reachable

ref.name stores the label on the reference rather than renaming the
target cell — renaming the cell would rename every other placement of it.

Result

tutorial notebooks, GLAYOUT_BACKEND=gdstk:   4/14  ->  10/14

The three BJT tutorials still fail on Component indexing and
add_ref(columns=); those need more than a signature and are left alone.

Notebooks under the default gdsfactory backend are unaffected — the
redirected imports resolve to the same objects.

Worth noting for #100: glayout_opamp.ipynb and GLayout_Cells.ipynb,
which currently time out at 180 s under gdsfactory, complete in 89 s and
53 s under gdstk.

Running the tutorial notebooks under GLAYOUT_BACKEND=gdstk fails almost
immediately: 4 of 14 pass. Two reasons, one on each side.

The notebooks import Component, rectangle, boolean and cell straight from
gdsfactory instead of glayout.backend, so they bypass the backend
selection entirely. Under the default backend both names resolve to the
same class and nobody notices; under gdstk, gdsfactory's add_ref() gets a
gdstk Component and rejects it. Symbols glayout.backend does not re-export
(text_freetype, array) are left on gdsfactory.

The gdstk ComponentReference/Component are also missing pieces of the
gdsfactory surface that glayout's own cells and the tutorials use:

  movex/movey     took a bare delta; move() already accepted destination=
  ref.name        read-only, but cells label placements (ref.name = "pfet_2")
  ref.x / ref.y   had xmin/xmax/ymin/ymax but not the centre accessors
  write_gds       required a filename and ignored gdsdir=
  Component.show  absent

ref.name stores the label on the reference rather than renaming the target
cell, which would rename every other placement of it too.

Tutorial notebooks under gdstk: 4/14 -> 10/14. The three BJT tutorials
still fail (Component indexing, add_ref(columns=)) and are untouched here.
Notebooks under the default gdsfactory backend are unaffected: the imports
resolve to the same objects.
Every vertex of a gdstk-generated layout lands off-grid on gf180. The DRC
reports it on all of them -- 1301 violations on the LIF cell used to check
this, split across contact_OFFGRID x348, via1_OFFGRID x276,
metal1_OFFGRID x252, metal2_OFFGRID x132 and comp_OFFGRID x60.

snap_to_grid() took a bare `nm: int = 1` default. gdsfactory's version reads
the pitch from the active PDK instead:

    nm = int(get_grid_size() * 1000 * grid_factor)

which is 5 nm on gf180. Rounding a 5 nm process to 1 nm produces values like
10.246 where the process wants 10.245, and every one of them is a violation.

Two pieces were missing. Pdk.activate() was a no-op, so nothing recorded
which PDK was active; and grid_size kept the class default of 0.001 because
gdsfactory used to fill it in from its own PDK database on activate. The
real pitch is already in gds_write_settings.precision (5e-9 m on both gf180
and sky130), so activate() now derives grid_size from it and registers the
PDK for snap_to_grid to read. `nm=` still overrides when a caller wants a
specific pitch.

After: 0 of 1228 vertices off-grid, same as the gdsfactory backend, and the
1301 OFFGRID violations are gone. snap_to_2xgrid(10.2463) returns 10.25 on
both backends now. DRC on diff_pair, current_mirror_nfet and
transmission_gate under gdsfactory is unchanged.
move(destination=) traducia respecto al centro del bbox en vez de (0,0),
que es el default de gdsfactory. c_route coloca sus rectangulos de
extension con move(destination=...) seguido de movex relativos, asi que
la ruta se desplazaba medio rectangulo: la neurona LIF salia 32.4 um de
ancho en vez de 29.9 y con 54 violaciones M2.2a de mas.

get_ports_list devolvia el orden del dict; gdsfactory ordena clockwise
(oeste, norte, este, sur). Las celdas buscan puertos por subcadena, asi
que el orden cambia que puerto se enruta.

Con ambos, neurona.ipynb da 1168.6 um2 y 31 violaciones en los dos
backends, identico a gdsfactory.
capmet apuntaba a CAP_MK (117,5), que es solo un marcador. El MIM real es
FuseTop (75,0), que estaba en el archivo pero comentado. Sin dielectrico,
el via_array que deberia contactar la placa superior contactaba la
inferior: 187 via2 uniendo met2 con met3.

Extraido con magic, el cap salia como un unico nodo flotante. Ahora salen
dos placas con capacitancia entre ellas. sky130 ya apuntaba a capm, asi
que gf180 era el caso desviado.

Ademas CAP_MK tiene que envolver al FuseTop (regla MIM.7), asi que
mimcap() dibuja el marcador cuando el pdk mapea capmet_mk.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant