Skip to main content

Updated 5 min readPython

Tool-agnostic Python wrappers for EDA

Build Python wrappers around EDA tools: an abstract interface per task, streamed logs, exit-code plus log plus output checks, and config kept out of code.

By the SkyCadEda engineering teamHow these notes are written

  • Python
  • EDA Automation
  • Tool Wrappers
  • Software Architecture

ShareLinkedInX

On this page

A tool-agnostic wrapper is a Python class that describes what a flow step must do (run timing for a corner, run DRC on a cell) and hides how a particular tool and version does it. The flow calls the interface; a per-tool subclass writes the tool's Tcl or command file, launches it, and decides whether the run passed. When a tool version changes a flag or a project switches vendors, you change one subclass instead of every script that calls it.

Why tool-specific scripts break

Most flows grow as shell and Perl scripts that call tool binaries directly, with flags, paths and log formats spread through the code. They work until a major tool release renames an option, a site moves the install tree, or a block needs a different signoff tool. Then every script that touched the tool has to be found and edited. A wrapper layer puts that knowledge in one place.

An abstract interface per task

Python's abc module turns the interface into a contract: a subclass that forgets a required method cannot be instantiated, so the mistake shows up when the flow starts rather than hours into a run. The examples use built-in generic type hints such as list[str], which need Python 3.9 or later.

from abc import ABC, abstractmethod
from pathlib import Path

class TimingTool(ABC):
    """One timing run: load a design, analyse one corner, write reports."""

    @abstractmethod
    def write_script(self, run_dir: Path, corner: str) -> Path:
        """Write the tool's command script and return its path."""

    @abstractmethod
    def command(self, script: Path) -> list[str]:
        """Return the argv used to launch the tool on that script."""

    @abstractmethod
    def expected_outputs(self, run_dir: Path) -> list[Path]:
        """Reports that must exist and be non-empty after a good run."""

class PrimeTimeTool(TimingTool):
    def write_script(self, run_dir, corner):
        script = run_dir / f"sta_{corner}.tcl"
        script.write_text(f"source setup_{corner}.tcl\n"
                          "redirect rpt/timing.rpt { report_timing -max_paths 50 }\n"
                          "exit\n")
        return script

    def command(self, script):
        return ["pt_shell", "-f", str(script)]

    def expected_outputs(self, run_dir):
        return [run_dir / "rpt" / "timing.rpt"]

Adding Tempus means one more subclass with its own script and command line. It also lets you write a fake subclass that copies canned reports into place, so the flow logic can be tested in CI without a license.

Run the tool and decide pass or fail

Exit codes alone are not enough: many EDA tools exit 0 after errors that invalidate the results. A wrapper should check three things: the exit code, the log for error messages, and the expected outputs. Stream the log straight to a file. EDA logs can reach hundreds of megabytes, so capturing them in memory with capture_output=True is the wrong default.

import re
import subprocess

ERROR_RE = re.compile(r"^(Error|ERROR|FATAL)\b")

class ToolRunError(RuntimeError):
    pass

def run(tool: TimingTool, run_dir: Path, corner: str) -> None:
    (run_dir / "rpt").mkdir(parents=True, exist_ok=True)
    script = tool.write_script(run_dir, corner)
    log = run_dir / f"{corner}.log"
    with log.open("w") as fh:
        proc = subprocess.run(tool.command(script), cwd=run_dir,
                              stdout=fh, stderr=subprocess.STDOUT)
    if proc.returncode != 0:
        raise ToolRunError(f"{corner}: exit code {proc.returncode}, see {log}")
    with log.open() as fh:
        errors = [line for line in fh if ERROR_RE.match(line)]
    if errors:
        raise ToolRunError(f"{corner}: {len(errors)} error lines, first: {errors[0].strip()}")
    missing = [p for p in tool.expected_outputs(run_dir)
               if not p.exists() or p.stat().st_size == 0]
    if missing:
        raise ToolRunError(f"{corner}: missing or empty outputs {missing}")

The error pattern is per tool in practice, and most teams keep an allowlist of known-harmless messages next to it. The point is that the flow above the wrapper only sees a Python exception, so a failed stage cannot pass silently to the next one.

Keep configuration out of the code

Tool versions, install paths, license variables and PDK locations belong in a config file (YAML or TOML) or in environment modules, not in the wrapper. The wrapper reads which version to load and how to launch it, so the same code runs on a workstation, the farm and a CI runner. Trying a new tool release becomes a config change on a branch, compared against the current release on the same blocks.

Environment modules (Lmod or Environment Modules) are the usual way to pin versions per project. For stricter reproducibility some teams package tool environments as Apptainer images, which run without root on shared clusters; check the vendor's supported OS matrix and licensing behaviour first, as noted in the FAQ.

Run in parallel on the farm

Corner and mode runs are independent, so the wrapper layer is the natural place to fan them out. On a single host, concurrent.futures.ThreadPoolExecutor is enough to run several run() calls at once, because each thread just waits on a subprocess. On a farm, submit through the scheduler instead (bsub on LSF, sbatch on Slurm) with explicit memory and core requests. Record the peak memory of each run; past runs of the same block are the best estimate for the next request, and over-requesting wastes as much capacity as under-requesting costs in killed jobs.

Qualify new tool versions before rollout

Keep a small set of reference blocks, from quick tests to one large block, with known-good results. Before a new tool version goes into the production config, run the set through the wrappers and compare key metrics (worst slack, violation counts, DRC counts, runtime, memory) against the baseline with an agreed tolerance. Mark only versions that pass as production; others stay available for experiments. The wrapper layer is what makes this cheap, because the comparison runs the same flow code against both versions.

Shell script versus wrapper

Direct shell or Perl callPython wrapper
Tool flag changesEdit every callerEdit one subclass
Pass/failUsually exit code onlyExit code, log scan, output check
Testing without a licenseHardFake subclass in CI
Switching vendorsRewriteNew subclass, same flow

We build wrapper layers like this as part of CAD infrastructure services.

Frequently asked questions

Does a Python wrapper slow the flow down?

No. Starting a Python process and a subprocess costs milliseconds to seconds; the EDA jobs it wraps run for minutes to days. The cost that matters is memory, which is why the wrapper should stream tool output to a file instead of holding it in memory.

How do we handle legacy Perl or shell scripts that already work?

Wrap them first. A Python class can call the existing script as its implementation, so the flow moves to the new interface immediately. Replace the internals one stage at a time, comparing outputs against the old script on the same inputs before switching.

Do containers work for commercial EDA tools?

Often, with caveats. Apptainer (formerly Singularity) is common on HPC clusters because it runs without root, but check the vendor's supported OS list and how the license is checked out: FlexNet licenses tied to a host ID or served from a license server need the container to see the right network and host identity.

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.