Skip to content

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

StepRole of KLayoutInputOutput
During PnR (digital)Inspect DEF/GDS generated by OpenROAD.def, .gds, .lefVisualization, geometry check
During layout (analog)Edit and overlay cells, verify geometry.gds, .mag, .oasCorrected GDS
For sign-offRun DRC/LVS scripts from open PDKs.gds + .spiceDRC/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.lyrdb

Options

OptionDescription
-bBatch mode (no GUI)
-rRun a DRC/LVS or macro script
-rdDefine runtime variables accessible in the script
-ncSkip configuration loading
-zzStart with empty layout

File formats and conversions

TaskCommand / MenuDescription
Import DEF/LEFFile → Import → LEF/DEFConvert digital layouts from OpenROAD
Merge layoutsTools → Merge CellsCombine multiple GDS files
Save to OASISFile → Save As...Smaller binary output
Export layer mapFile → Layer Properties... → ExportSave 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.lyrdb

Outputs:

  • 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.lyrdb

Typical 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.py

Visualization 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

ToolPurpose
OpenROADView routed GDS or DEF; check PDN, congestion, or macro placement
MagicCross-check layout (GDS ↔ MAG)
NetgenUse same LVS setup file for cross-tool consistency
XschemGenerate SPICE schematic netlists for LVS comparison
NgspicePost-layout simulation after extraction
Open-PDKsProvide layer maps, DRC/LVS rules, and setup scripts for KLayout

Example sign-off flow using KLayout

StepToolOutput
RoutingOpenROADchip.def / chip.gds
GDS inspectionKLayoutvisual check
DRC checkKLayoutdrc.lyrdb
LVS comparisonKLayout / Netgenlvs.lyrdb
Sign-off exportKLayoutfinal 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.

Further reading