KLayout
KLayout is an open-source tool for layout visualization, editing, DRC, and LVS. It supports multiple layout formats (GDSII, OASIS, DEF, LEF) and provides both a GUI and scripting APIs (Python and Ruby). KLayout is widely used for physical verification and design inspection in open-source flows.
Key features
- View, edit, and merge GDSII, OASIS, and DEF/LEF files.
- Design Rule Check (DRC) and Layout-vs-Schematic (LVS) verification.
- Layer mapping and hierarchical inspection of standard-cell designs.
- Scripting via Python or Ruby (batch and GUI modes).
- Integration with Magic, Netgen, Xschem, and OpenROAD.
- Compatible with open-source PDKs such as Sky130, GF180, and IHP-SG13G2.
Typical workflow integration
| Step | Role of KLayout | Input | Output |
|---|---|---|---|
| During PnR (digital) | Inspect DEF/GDS generated by OpenROAD | .def, .gds, .lef | Visualization, geometry check |
| During layout (analog) | Edit and overlay cells, verify geometry | .gds, .mag, .oas | Corrected GDS |
| For sign-off | Run DRC/LVS scripts from open PDKs | .gds + .spice | DRC/LVS reports |
Launching KLayout
GUI mode
klayout &Command-line mode (batch)
klayout -b -r scripts/drc_check.lydrc -rd layout=mychip.gds -rd report=reports/drc.lyrdbOptions
| Option | Description |
|---|---|
-b | Batch mode (no GUI) |
-r | Run a DRC/LVS or macro script |
-rd | Define runtime variables accessible in the script |
-nc | Skip configuration loading |
-zz | Start with empty layout |
File formats and conversions
| Task | Command / Menu | Description |
|---|---|---|
| Import DEF/LEF | File → Import → LEF/DEF | Convert digital layouts from OpenROAD |
| Merge layouts | Tools → Merge Cells | Combine multiple GDS files |
| Save to OASIS | File → Save As... | Smaller binary output |
| Export layer map | File → Layer Properties... → Export | Save or reuse color map configuration |
Running DRC in KLayout
KLayout includes a built-in DRC engine that uses a Ruby or Python syntax to define rules.
Example DRC script (Ruby)
scripts/drc_check.lydrc
report("DRC report")
layout = Layout::read($layout)
top = layout.top_cell
# Example rules (using micron units)
metal1 = input(1, 0)
metal1.space(0.3.um).output("M1 spacing violation")
metal1.width(0.3.um).output("M1 min width violation")
report.save($report)Run it:
klayout -b -r scripts/drc_check.lydrc \
-rd layout=results/chip.gds \
-rd report=reports/drc.lyrdbOutputs:
- reports/drc.lyrdb – viewable directly in KLayout (Tools → Marker Browser)
- On-screen DRC markers (colored overlay on the layout)
Running LVS in KLayout
KLayout can perform schematic-to-layout comparison using its LVS plugin. It supports SPICE and Verilog netlists.
Example LVS command
klayout -b -r scripts/lvs_run.lylvs \
-rd layout=layout/chip.gds \
-rd schematic=netlists/chip.spice \
-rd setup=tech/sky130A_setup.lvs \
-rd report=reports/lvs.lyrdbTypical setup file:
provided in $PDK_ROOT/$pdk/libs.tech/klayout/lvs/.
Outputs:
- lvs.lyrdb — LVS report file (viewable in KLayout)
- lvs.log — textual summary of matched/unmatched nets/devices
Scripting with Python
KLayout includes a full Python API (pya). You can automate DRC checks, GDS merges, or layout inspection.
Example: generate a layout snapshot
import pya
layout = pya.Layout()
layout.read("results/chip.gds")
top = layout.top_cell()
bbox = top.bbox()
print(f"Top cell: {top.name}, Bounding box: {bbox}")Run:
klayout -b -r myscript.pyVisualization and debugging tips
- Use “Layer Properties” (Ctrl+L) to toggle layer visibility and colors.
- Hierarchy browser (Ctrl+H) shows cell hierarchy and instances.
- Use “Measure” (M key) to check distances or width violations.
- For dense designs, enable “Low-res mode” to speed up rendering.
- Export screenshots (File → Save Screenshot) for documentation.
Integration with open tools
| Tool | Purpose |
|---|---|
| OpenROAD | View routed GDS or DEF; check PDN, congestion, or macro placement |
| Magic | Cross-check layout (GDS ↔ MAG) |
| Netgen | Use same LVS setup file for cross-tool consistency |
| Xschem | Generate SPICE schematic netlists for LVS comparison |
| Ngspice | Post-layout simulation after extraction |
| Open-PDKs | Provide layer maps, DRC/LVS rules, and setup scripts for KLayout |
Example sign-off flow using KLayout
| Step | Tool | Output |
|---|---|---|
| Routing | OpenROAD | chip.def / chip.gds |
| GDS inspection | KLayout | visual check |
| DRC check | KLayout | drc.lyrdb |
| LVS comparison | KLayout / Netgen | lvs.lyrdb |
| Sign-off export | KLayout | final chip.gds |
Best practices
- Always use the PDK-provided DRC/LVS setup files.
- Keep a consistent layer mapping across Magic and KLayout.
- Validate GDS output from OpenROAD before tape-out.
- Save marker reports (.lyrdb) — they are lightweight and easy to share.
- Automate recurring checks with Python batch scripts.
- Use “Diff mode” (Tools → Layout Diff) to compare two GDS revisions.