Skip to main content

Updated 4 min readPython EDA

Python for EDA automation

Python for EDA automation with working examples: wrapping Calibre runs, reading OASIS with KLayout, driving Virtuoso via skillbridge, and farm scripts.

By the SkyCadEda engineering teamHow these notes are written

  • Python EDA
  • Scripting
  • Automation
  • PCell
  • PDK

ShareLinkedInX

On this page

Python in EDA is the layer around the tools. The tools themselves are scripted in Tcl or, in Virtuoso, SKILL; Python launches them, checks inputs, parses their reports, moves data between formats and feeds dashboards. Tcl is not vendor-locked (Synopsys, Cadence digital and Siemens tools all use it), but each tool embeds its own interpreter and command set, so a script written for one tool does not run in another. Python is where you write the code that has to work across all of them. The examples below are small and real, and each one is a pattern you can extend.

Run a tool and fail on real errors

The most common Python job in a CAD flow is wrapping a batch run: create a run directory, call the tool, keep the log, and turn the result into an exit code. This wrapper runs Calibre DRC and reads the summary report named by the deck's DRC SUMMARY REPORT statement.

import re, subprocess, sys
from pathlib import Path

RULE = re.compile(r"^RULECHECK\s+(\S+)\s.*?"
                  r"TOTAL Result Count\s*=\s*(\d+)")

def run_drc(runset: Path, rundir: Path, summary: str):
    rundir.mkdir(parents=True, exist_ok=True)
    log = rundir / "drc.log"
    with log.open("w") as fh:
        rc = subprocess.run(
            ["calibre", "-drc", "-hier", "-turbo",
             str(runset.resolve())],
            cwd=rundir, stdout=fh,
            stderr=subprocess.STDOUT).returncode
    if rc != 0:
        sys.exit(f"calibre exited {rc}; see {log}")
    fails = {}
    for line in (rundir / summary).read_text().splitlines():
        m = RULE.match(line)
        if m and int(m[2]) > 0:
            fails[m[1]] = int(m[2])
    return fails

if __name__ == "__main__":
    fails = run_drc(Path("rules.svrf"), Path("run/drc"),
                    "drc.sum")
    for rule, n in sorted(fails.items()):
        print(f"{n:6d}  {rule}")
    sys.exit(1 if fails else 0)

The summary format can differ slightly between Calibre versions, so keep a real summary from your version as a pytest fixture for the regex. The same shape (run, keep the log, parse, exit code) works for IC Validator, Pegasus, StarRC or a PrimeTime batch run.

Read GDSII and OASIS

OASIS is a binary stream format; XML libraries cannot read it. The KLayout Python module (pip install klayout, no GUI needed) reads both GDSII and OASIS. This counts shapes per layer/datatype under the top cell, a quick check that a streamed file contains what you expect:

import klayout.db as db

ly = db.Layout()
ly.read("top.oas")
top = ly.top_cell()
print(top.name, "dbu =", ly.dbu)

for li in ly.layer_indexes():
    it = top.begin_shapes_rec(li)
    n = 0
    while not it.at_end():
        n += 1
        it.next()
    if n:
        print(f"{str(ly.get_info(li)):>8}  {n}")

For writing layout, gdstk (the successor to gdspy, which is now in maintenance mode) and gdsfactory are the usual choices; KLayout can also write both formats.

Drive Virtuoso from Python

skillbridge is an open-source package that connects a Python process to a running Virtuoso session. You load its SKILL server in the CIW once (the package documents the command), and then SKILL functions are available with Python-style names:

from skillbridge import Workspace

ws = Workspace.open()
cv = ws.ge.get_edit_cell_view()   # geGetEditCellView()
print(cv.lib_name, cv.cell_name, cv.view_name)
print(len(cv.shapes), "shapes")

It is convenient for queries, reports and test harnesses. For PCells and anything that must run inside Virtuoso without a Python process, write SKILL; see the Cadence SKILL scripting guide.

PDK and technology checks

PDK work is mostly cross-checking files that should agree: the stream layer map against rule deck layer statements, every device in the CDF against the model files, the extraction layer map against the techfile. Each check is a short parser plus a set comparison, and together they can cut PDK release work from weeks to days. An example layer-map check is in the PDK setup guide.

CAD infrastructure

  • License reports: parse lmutil lmstat -a output into per-feature usage over time.
  • Job submission: thin wrappers around LSF (bsub), Slurm (sbatch) or Grid Engine (Altair or open-source forks) qsub, so flows do not hard-code one scheduler.
  • Deployment: Ansible (written in Python, playbooks in YAML) for installing tool releases across compute nodes.
  • OpenROAD exposes Python bindings to its database for custom checks and flow steps.

Habits for production scripts

Keep scripts in git and review them like design changes. Test parsers with pytest against real report samples, so a tool upgrade that changes a format fails a test instead of a run. Treat a missing or empty report as a failure, never as a pass. Put project settings in a config file instead of in the code, and log the tool version and input paths at the top of every run. The longer versions of these patterns are in tool-agnostic Python wrappers and defensive Python pipelines.

Frequently asked questions

Why is Python used for EDA automation?

Most EDA tools are driven by Tcl (Synopsys, Cadence digital, Siemens) or SKILL (Cadence Virtuoso), but the work around them is files, processes and data: launching runs, parsing reports, checking PDKs, building dashboards. Python is good at all of that, has libraries for layout data and numerics, and most engineers can read it.

Can Python replace Cadence SKILL or Synopsys Tcl?

Not inside the tools: Virtuoso runs SKILL and Custom Compiler, ICC2 and PrimeTime run Tcl. Python works around them, generating SKILL or Tcl, post-processing results and orchestrating runs. Bridges such as the open-source skillbridge package let a Python process call SKILL functions in a running Virtuoso session.

What Python libraries are commonly used in EDA?

pathlib and subprocess for running tools; NumPy, SciPy and pandas for simulation and report data; matplotlib for plots; the KLayout Python module (klayout.db) and gdstk for reading and writing GDSII and OASIS; gdsfactory for parameterized layout; skillbridge for Virtuoso; pytest for testing parsers; pyvisa for lab instruments.

How does Python help with PCell development?

Outside Virtuoso, libraries such as gdsfactory and gdstk generate parameterized layout in Python and write GDSII or OASIS that any editor can stream in. Inside an OpenAccess flow, PyCells are Python-based PCells supported by Synopsys Custom Compiler. Virtuoso-native PCells are still written in SKILL.

More engineering notes

Working through a problem like this?

Tell us about your flow: the tools, the PDK, what is failing and when it needs to be clean.