一键导入
gds-generation
Use when creating GDS layout files programmatically using KLayout's Python API (pya module). Covers cell creation, shape insertion, and file output.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Use when creating GDS layout files programmatically using KLayout's Python API (pya module). Covers cell creation, shape insertion, and file output.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
Use when writing, reading, or understanding KLayout DRC rules (.drc files). Provides KLayout Ruby DSL syntax, common DRC patterns, and reference lookup instructions.
Use when running KLayout DRC evaluation pipelines — executing DRC rules against GDS test files, parsing results, and computing metrics.
Use when inspecting, reading, or modifying existing GDS layout files. Covers reading GDS with KLayout Python API, extracting geometry info, and GDS-to-text conversion.
基于 SOC 职业分类
| name | gds-generation |
| description | Use when creating GDS layout files programmatically using KLayout's Python API (pya module). Covers cell creation, shape insertion, and file output. |
klayout -b -rm script.py # Run script in batch mode
klayout -b -rm script.py -- --arg1 val1 # With arguments (after --)
import pya
import argparse
DBU_UM = 0.001 # Database unit: 1 nm
def um_to_dbu(um_val):
"""Convert micrometers to database units."""
return round(um_val / DBU_UM)
def main():
ly = pya.Layout()
ly.dbu = DBU_UM
top = ly.create_cell("TOP")
# Define layers
li_met1 = ly.layer(pya.LayerInfo(68, 20)) # Metal 1
li_via = ly.layer(pya.LayerInfo(68, 44)) # Via
# Insert shapes (coordinates in DBU = nm)
x0, y0 = um_to_dbu(0), um_to_dbu(0)
x1, y1 = um_to_dbu(10), um_to_dbu(5)
top.shapes(li_met1).insert(pya.Box(x0, y0, x1, y1))
# Write output
ly.write("output.gds")
if __name__ == "__main__":
main()
dbu = 0.001, 1 DBU = 1 nm.um_to_dbu(): Always convert micrometer design values to integer DBU before creating shapes.pya.LayerInfo(layer_number, datatype) — see SKY130 layer reference.pya.Box(x1, y1, x2, y2) for rectangles, pya.Polygon for arbitrary polygons.# Rectangle (Box)
top.shapes(layer).insert(pya.Box(x0, y0, x1, y1))
# Polygon (arbitrary shape)
pts = [pya.Point(x0, y0), pya.Point(x1, y0), pya.Point(x1, y1), pya.Point(x0, y1)]
top.shapes(layer).insert(pya.Polygon(pts))
# Path (wire)
pts = [pya.Point(x0, y0), pya.Point(x1, y1)]
top.shapes(layer).insert(pya.Path(pts, width_dbu))
For DRC testing, generate two sets of GDS files:
def generate_pass_case(ly, top, layer, min_width_um, min_space_um):
"""Two rectangles with sufficient width and spacing."""
w = um_to_dbu(min_width_um * 1.5) # 50% margin
s = um_to_dbu(min_space_um * 1.5)
h = um_to_dbu(2.0)
top.shapes(layer).insert(pya.Box(0, 0, w, h))
top.shapes(layer).insert(pya.Box(w + s, 0, 2*w + s, h))
def generate_fail_case(ly, top, layer, min_width_um, min_space_um):
"""Two rectangles with insufficient spacing."""
w = um_to_dbu(min_width_um * 1.5)
s = um_to_dbu(min_space_um * 0.5) # 50% of minimum = violation
h = um_to_dbu(2.0)
top.shapes(layer).insert(pya.Box(0, 0, w, h))
top.shapes(layer).insert(pya.Box(w + s, 0, 2*w + s, h))
| Mistake | Fix |
|---|---|
| Float coordinates | Always convert to int DBU with um_to_dbu() |
Forgetting ly.dbu = DBU_UM | Set DBU before creating shapes |
| Using wrong layer numbers | Check SKY130 layer reference |
| Shapes at origin overlapping | Offset shapes to avoid unintended intersections |