Showing posts with label KLayout. Show all posts
Showing posts with label KLayout. Show all posts

Wednesday, November 11, 2026

Why is Xschem Refusing to Annotate OP Info?

I pressed 6 on a sky130 schematic and xschem answered, in the console:

These symbol types have no operating-point values to show: capacitor, high_precision_poly_resistor, nmos, pmos and more.

Read quickly, that says the sky130 FETs cannot show operating-point annotation. My message to Claude was more or less "No kidding?". The IHP cells in the same project annotate fine. Same tool, same build, same simulator. Why would one process be a second-class citizen?

It was not. The feature is table-driven, and the table for sky130 had never been loaded into that xschem session. This post is about how we found that out, what we changed, and the handful of lessons that are worth more than the fix.

How the annotation knows a FET

To put gm or vth next to a transistor, the tool has to know two things that are different for every process: how the simulator spells that device in the results (for a sky130 wrapper it is @m.x1.xm1.msky130_fd_pr__nfet_g5v0d10v5, for IHP's PSP model it is @n.x1.xm1.nsg13_hv_nmos), and which quantities to ask for. Each PDK workarea ships a small descriptor that answers both, keyed by the symbol type (nmos, pmos), and registers it when the workarea's rc file is sourced. The same descriptor is what puts the device requests into the simulation deck, so without it a run saves nothing per device either.

Two details made the symptom confusing. First, the key is the symbol type, and both PDKs use nmos. So the registry holds one descriptor per type, and registering a second PDK replaces the first. The tool's own spec calls this out as "one interpreter per PDK", and it degrades to blank rather than to wrong numbers, which is the right failure. Second, a descriptor only claims cells whose name matches its PDK's library glob. Our project's startup script sourced the IHP workarea rc and nothing from sky130. The IHP descriptor looked at a sky130_fd_pr cell, declined it, and the annotator reported the type as one with nothing to show. Which, in that session, was true.

The tool had said so already. The run log in the console carried this line, printed at netlist time, before anyone pressed a key:

ASE: no device below this cell produced an OP save card — no registered op_annot PDK descriptor matched, or nothing below it is annotatable. The deck asks for no device parameters.

Nobody read it. Two sentences in a console pane, between a hundred others.

The fix I did not want

Claude's first proposal was an environment variable, with the PDK inferred from the schematic path when the variable was absent: a cell under lib/hdo_sky130/ would get a sky130 session, anything else IHP. Reasonable on paper. I turned it down. A setting that decides what a whole session can do should not be inferred from where a file happens to live, and a wrong guess here fails silently: the editor works, the simulation works, and the FETs quietly stop annotating. We already had the right model in the xschem repo: a small Tk launcher where you pick a PDK and press Launch. So:

Make it a minimal GUI like the pdk_launcher.sh thing in the Xschem repo. I'll pick the PDK when I run the launcher.
The project launcher. The Command field is a rendering of the list the dialog executes, so what you read is what runs, and it pastes into a terminal unchanged.

The dialog is about a hundred lines of Tcl. It exports the choice as two environment variables, the project's rc file resolves the matching workarea and switches the fresh-state simulation defaults with it, and the startup script sources that workarea's rc instead of a hard-coded one. One session, one PDK, chosen on purpose and visible in the command line.

Proving it, and the proxies that lied

The first three attempts to verify the fix all drew the six-row block with every value blank. Each attempt was a shortcut: run the bench headless, then load the cell and call the annotation. The deck and results were right. The shortcut was wrong twice over. The annotator finds its results file through the simulation session that owns the sheet, and a run started outside such a session left it looking for a file the simulator never writes. And the annotation has to be issued in the design window the simulation environment opens, not after a bare load into the main one. Only the user's own path proved anything: open the state in the simulation environment, Netlist and Run, open the design window, descend into the cell, press 6.

Before: a shortcut run. The block is drawn, every value is blank.
After: the real flow in a sky130 session. M1 at 5.2 µA has gm 100.6 µS and gds 245.6 nS; the tail switch drops 21.5 mV.
The whole cell. The console sentence now names only the capacitor, the resistor and the probe, which is what it should say.

One more thing the verification turned up, and it would have fooled a deck-grepping check forever: on this ngspice build the device numbers never appear as .save cards in the deck at all. The simulation environment measures that the simulator can dump every device's operating point in one go, asks for that instead, and the values land in a small .opinfo file beside the raw. The deck looked empty of device requests and was fine.

What three reviewers found

Before calling it done we ran three independent reviews: one on the launcher code, one on the tool-side assumptions against the xschem source, one on the write-up against the evidence. None of the three found the fix wrong. All three found something the author's tests could not:

  • The launcher did not change into the project directory before starting xschem, so the project's own operating-point parameter lists, which the tool reads from ./.xschem, were silently skipped unless you happened to start from the project root.
  • Return with the keyboard focus on Quit launched xschem instead of quitting. Inherited from the launcher we copied.
  • The project's parameter-list settings carried rows spelled for IHP's model, unscoped, so a sky130 session would have asked BSIM4 for quantities it does not publish. One section header fixed it.

The lessons

  1. A "cannot" from a tool is usually a "was not told". Before concluding that a feature does not support something, find who was supposed to register, configure or load it, and check whether that happened in this session.
  2. Read the console at run time. The cause was printed before the question was asked. A notice you do not read is a notice the tool did not print.
  3. Session-wide settings get an explicit choice, not an inference. One click in a dialog, with the resulting command visible, beats a clever rule whose failure mode is silence.
  4. Verify through the user's path, not a proxy. Three shortcuts produced blank values and looked exactly like a broken feature. The feature was fine; the probes were not the user.
  5. A table-driven feature has a scope. Here the scope is one xschem process, one registry, one PDK. Know the scope before you ask why something is missing from it.
  6. Independent review earns its cost on infrastructure. A launcher that every session goes through is worth three readers. A two-component schematic edit is not.

Total time, from the question to the memory note: about ninety minutes, then the review. The fix itself was a day's worth of understanding compressed into a dialog with two radio buttons.

Sunday, November 1, 2026

Which FOSSi PDK Can Truly Hack It? (Hint : Not GF or SKY :)

Monte Carlo in ngspice on three open PDKs: sky130, GF180MCU and IHP SG13G2 What is real, what is broken, and how to get usable statistics out of each
Date
2026-10-30
Simulators
ngspice 45.2 (distribution build), and an ngspice-46+ development build carrying a resistor temperature-coefficient fix
Method
200-seed loops of small test decks per PDK, with every draw read back and compared against the PDK's own constants and, where they exist, its published measurements
Verdict
IHP SG13G2 is the most complete; sky130 is real for mismatch but not for process; GF180MCU is real for transistors but has no resistor mismatch

A common belief in the open-source analog community is that "sky130 Monte Carlo doesn't work in ngspice". We needed a definite answer, because we are building Monte Carlo support into an open-source schematic and simulation environment, and its first real use is trim-and-sim on a bandgap: one test finds a trim code for each Monte Carlo sample, and a second test runs that sample with its trim code under stress. A bandgap's spread is dominated by resistor-ratio and bipolar mismatch, as well as transistor offsets, so a PDK that leaves any of those out gives a falsely tight answer.

So we measured all three open PDKs the same way, rather than relying on folklore.

How we measured

Each PDK got the same kinds of test circuit: diode-connected transistor pairs at several sizes, resistor pairs, MIM capacitor pairs and bipolar devices. Each deck ran 200 samples inside a single ngspice process, using a loop that we had already validated for repeatability:

.control
foreach k 1 2 3 ... 200
  setseed $k
  reset
  op
  echo "ROW $k $&v(a) $&v(b) ..." >> rows.txt
  destroy all
end
.endc

Two details matter here:

  • destroy all in every sample is essential. Without it, reset slows down with every stored plot, and a 5000-sample run takes more than three times as long.
  • Each test directory had its own explicit .spiceinit. Otherwise one in $HOME can leak into the run and silently change the draws: ngbehavior=hsa changes the random sequence on sky130.

From each run we computed the per-device and pair-difference standard deviation, checked the Pelgrom scaling (σ·√(W·L) should be roughly constant across sizes), checked that two "identical" devices draw independently, and checked that sample k gives the same answer in a loop and in a fresh process. For every PDK the stock 45.2 binary and the development build gave bit-identical draws.

The summary

sky130GF180MCUIHP SG13G2
MOS mismatchreal, plausiblereal, matches PDK docsreal, plausible
Process (die-to-die)broken as shipped; workaround gives VT onlyreal, combines with mismatchreal, but section order matters
Resistor mismatchrealnone (zero in the model)real; centred upstream since 2026-03-02 (58d1f3d, on main too); the copy measured before 2026-10-30's update predates it and was about one local σ high
Resistor temperature coefficientcorrect only with a patched ngspicecorrectcorrect
Bipolar mismatchpnp realpnp real, npn nonereal, scaled by size since PR #1234 (not scaled in the copy measured before 2026-10-30's update)
Capacitor mismatchrealnonereal
Speed, 200 samplesslowest (2.5 s just to parse the library)about 1 s for 20 FETsabout 2 s for 12 PSP FETs

sky130

Mismatch: real

With the tt library and MC_MM_SWITCH=1, local mismatch is per device, Pelgrom-scaled and repeatable. tt with the switch on is bit-identical to the tt_mm section.

Pair (W/L, µm)σ(ΔVth)σ·√(WL)
nfet_01v8 1/0.1530.4 mV11.8 mV·µm
nfet_01v8 2/0.56.3 mV6.3 mV·µm
nfet_01v8 10/11.5 mV4.8 mV·µm
pfet_01v8 2/0.57.9 mV7.9 mV·µm
pfet_01v8 10/12.7 mV8.5 mV·µm

The PDK's own constants give a pair AVT of 4.75 mV·µm (n) and 8.28 mV·µm (p), which is plausible for a 130 nm process. Only VT varies: the mobility and oxide mismatch lines in the model are commented out. Minimum-size nfets come out about 2.4× wider than the constant suggests, because in nfet_01v8 the mismatch term sits inside a geometry multiplier. That looks unintended, and it makes small nfets pessimistic. We found no published SkyWater mismatch measurement to compare with.

Resistors (res_xhigh_po, res_high_po), MIM capacitors and the pnp_05v5 all vary, by amounts consistent with the PDK constants. For example, a res_xhigh_po 1×20 µm pair shows 1.4% σ in its ratio, and a 10×10 µm MIM pair shows 0.07%.

Process variation: broken as shipped

The .lib mc section cannot be used under ngspice. We found four separate defects:

  • 69 GAUSS(0, rel, 1) sites apply relative variation to a nominal of 0, so they never vary.
  • sw_nw_rs_mult uses 1+EXP(AGAUSS), which adds where it should multiply.
  • Every reference to a global agauss parameter draws it again, so devices on the same die are not correlated.
  • VT and oxide process variation are hard-coded to 0.

What remains spread is uncorrelated between identical devices, so it behaves like extra mismatch, not like die-to-die variation.

Workaround: draw the die-level VT yourself. The sw_vth0_*_mc parameters are plain constants, so alterparam can set them per sample. The standard deviations below come from the PDK's own (commented-out) Spectre vary block:

setseed $k
let zn = sgauss(0)
let zp = sgauss(0)
let vn = 0.006*zn
let vp = 0.009*zp
alterparam sw_vth0_sky130_fd_pr__nfet_01v8_mc = $&vn
alterparam sw_vth0_sky130_fd_pr__pfet_01v8_mc = $&vp
reset

This gives genuine die-to-die VT variation, fully correlated across all devices of a type, with n and p independent. It combines correctly with mismatch. It is VT only: there is no oxide, critical-dimension, mobility, resistor or capacitor process variation, and it needs one line per device family. For resistors and capacitors only the discrete corners work.

Resistor temperature coefficient

ngspice converts res_xhigh_po's voltage-dependent body into a B-source, and in doing so drops the model and with it the temperature coefficient. In stock ngspice the body is flat with temperature; it should be +17% at −40 °C and −22% at 125 °C. That alone flips the sign of a bandgap's output slope over temperature. Our patched ngspice build gets it right. Do not also apply the "three-line PDK edit" fix to a patched build, or the coefficient is applied twice.

GF180MCU

Mismatch and process: both real, but off by default

design.ngspice ships with sw_stat_global=0 and sw_stat_mismatch=0; mismatch was switched off by default after an upstream issue in 2022. To get real statistics, use the statistical sections instead of the typical ones, and turn the switches on afterwards:

.include design.ngspice
.lib sm141064.ngspice statistical
.lib sm141064.ngspice res_statistical
.lib sm141064.ngspice bjt_statistical
.lib sm141064.ngspice cap_mim
.lib sm141064_mim.ngspice mimcap_statistical
.param sw_stat_global=1
.param sw_stat_mismatch=1

Replace typical and res_typical with these; do not add them alongside. Including res_typical and res_statistical together fails with subcircuit redefinition and formula errors.

Pair (W/L, µm)σ(ΔVth) measuredPDK formula
nfet_03v3 1/0.2817.4 mV18.9 mV
pfet_03v3 1/0.2818.1 mV17.6 mV
nfet_03v3 10/12.5 mV2.4 mV
nfet_03v3 20/50.73 mV0.72 mV

These match both the model's formula and the measured mismatch plot in the GF180MCU documentation (about 9 mV·µm for n and 8.6 mV·µm for p). Global variation is a genuine die-wide draw: with mismatch off, a pair's difference is exactly zero. With both switches on, single-device σ is the root-sum-square of the two. The ff and ss corners sit about 5σ from typical, wider than a "3σ corner" would be.

What is missing or wrong

  • No resistor, MIM or npn mismatch. They vary only globally. The resistor mismatch term exists in the model only as a comment, although the PDK documentation shows measured resistor mismatch of up to about 0.85%. For a bandgap this is serious: the resistor-ratio spread is simply absent.
  • The resistor body has no thermal noise. The same B-source conversion that costs sky130 its temperature coefficient costs GF180 its noise: a 10.5 kΩ ppolyf_u_1k produced 1.7 nV/√Hz instead of 13.2. Only the two head resistors are noisy. The temperature coefficient survives, because it is written into the expression itself.
  • m= overstates mismatch by √m. The per-instance draw ignores m: an m=4 pair gave 19.5 mV instead of about 8.7. Use par= for matched arrays, which the formula does scale by. (xschem's GF180 symbols emit m=.)

The pnp mismatch (0.035 mV ΔVeb for 10×10 µm) matches the documentation. GF180 is also by far the fastest PDK to parse.

IHP SG13G2

Update, 2026-10-30. We re-measured against IHP-Open-PDK dev at dcb03b1 (2026-10-30), which includes the resistor-statistics restructure of 2026-10-17 (1d12af5). Our previous copy dated from February 2026, so the update brings in several upstream fixes made since then. Most of them are already on the main branch (last updated 2026-09-01): the resistor centring (58d1f3d, 2026-03-02), the pmos muew fix (bc94a21, 2026-05-18) and the mm_ok changes. Only the HBT size scaling and the 2026-10-17 restructure (with res_stat_mismatch) are on dev alone. We used the same decks and 200 seeds, on both ngspice builds. What the update fixes:
  • Resistor mismatch is centred. In res_typ_mismatch with mm_ok=1, the mean of a 1×10 µm resistor equals its typical value within sampling error: rsil −0.01%, rppd −0.01%, rhigh +0.02%, against +0.15%, +0.26% and +1.39% before. With mm_ok=0, a resistor now sits exactly at nominal. The pair scatter is about what it was (0.75%, 0.93%, 2.17%).
  • The pmos muew process parameter varies (σ 0.024 on 1.052). It was frozen before.
  • HBT mismatch scales with size (dev only). ΔVbe σ is 1.52 mV for one emitter and 0.66 mV for four, against about 4 mV for both before.
  • A combined resistor section exists (dev only): res_stat_mismatch gives resistor process and mismatch together. MOS still has no combined section, and the stat-then-mismatch order trap below is still there.
What to watch for in the new release:
  • Mismatch is mostly off by default. The MOS, HBT, resistor, varactor and MIM capacitor (cap_cmim, cap_rfcmim) subcircuits now default to mm_ok=0 (for the MIM caps this is new: the old copy defaulted them to 1 in the mismatch section, and a hand-written 10×10 µm cap_cmim went from a 0.09% capacitance sigma to 0), so a hand-written instance of those gets zero mismatch. The MOS capacitors (sg13_moscap_n/_p) are the exception: they default to mm_ok=1 and still vary in moscap_tt_mismatch without it. IHP's own symbols put mm_ok=1 on each instance, so a schematic drawn from them is fine. A hand-written netlist needs mm_ok=1 on every device line that should vary.
  • The plain sections are no longer mismatch-free. The HBT model now carries its mismatch itself, so hbt_typ and hbt_typ_stat also draw HBT mismatch for an mm_ok=1 device, and every schematic HBT is one. An ordinary typical simulation of an HBT schematic is therefore random: with no seed set, three runs of the same hbt_typ deck gave Vbe 0.72713, 0.72710 and 0.72660 V, while an instance without mm_ok stayed at 0.72656 V. A nominal or process-only run must set mm_ok=0 on the HBTs to stay one.
  • res_typ_stat is renamed res_stat. Three of IHP's own example benches still use the old name and stop with "section definition res_typ_stat not found". num_sigmas no longer scales the resistors' process spread.
  • Typical resistance moved: at 1×10 µm, rsil +0.9%, rppd +0.6% and rhigh −4.1%. The global spreads are now rsil 4.4%, rppd 3.5% and rhigh 5.4%, where they were 4.2%, 3.1% and 8.3%.
The rest of this section describes the copy measured before 2026-10-30's update, unless it says otherwise.

Running PSP

The SG13G2 MOS model is PSP 103, which ngspice runs through OSDI. The PDK ships only the Verilog-A sources, so the modules have to be compiled. The workarea carries them prebuilt: psp103.osdi (PSP 103.8.2), psp103_nqs.osdi, r3_cmc.osdi, mosvar.osdi, cap_cmomi.osdi and cap_cmomf.osdi, the set upstream's own build script makes, compiled with OpenVAF-Reloaded v24.0.2mob for generic x86-64. They load with pre_osdi on both ngspice 45.2 and the development build. You need OpenVAF only to rebuild them. Moving from PSP 103.6 to 103.8.2 left the MOS numbers here unchanged: the Id check point and the 5.52 mV mismatch pair agree to the printed digit.

Mismatch: real, for every device type

The corner libraries have a _mismatch twin of each section (mos_tt_mismatch, res_typ_mismatch, and so on). Local variation is written on the instance line inside each subcircuit, so every instance draws independently, controlled by the mm_ok instance parameter.

Pair (W/L, µm)nmos σ(ΔVgs)pmos σ(ΔVgs)
0.5/0.1321.5 mV (5.5 mV·µm)12.8 mV (3.3 mV·µm)
1/15.7 mV (5.7 mV·µm)3.6 mV (3.6 mV·µm)
4/41.4 mV (5.7 mV·µm)0.8 mV (3.3 mV·µm)

Pelgrom scaling holds very well, m=2 is applied correctly, and the values were reworked upstream in late 2025 to match measurement. IHP's process specification does not publish an AVT figure, so the cross-check is the upstream rework rather than a datasheet.

Resistor, 1×10 µmpair ΔR/R σ (local)R σ (global)
rsil0.66%4.2%
rppd0.82%3.1%
rhigh2.23%8.3%

MIM capacitors show 1%/√(area in µm²) local mismatch and 3.3% global. The npn13G2 HBT varies both locally and globally. Resistor temperature behaviour is correct (rsil +3100 ppm/K, rhigh −2300 ppm/K), because the resistor model is an OSDI device and is not converted to a B-source.

Process variation, and the order trap

mos_tt_stat gives genuine die-to-die variation (nmos 1×1 Vgs σ 34 mV). But the PDK has no section combining process and mismatch, and combining the two existing ones depends on their order:

Trap: .lib … mos_tt_stat followed by .lib … mos_tt_mismatch gives no variation of any kind. The only sign is a redefinition of .subckt … ignored warning. The first, non-mismatch subcircuit wins, and the second section's fixed parameters overwrite the global draws. The opposite order works.

A cleaner fix is a small wrapper section of your own that leaves the PDK files untouched: the _norm parameter values from mos_tt_stat, followed by the stat and mismatch model files.

.LIB mos_tt_stat_mm
  .param sg13g2_lv_nmos_vfbo_norm = 1.0
  .param sg13g2_lv_nmos_ctl_norm  = 1.2080
  * ... the rest of the *_norm parameters, copied from mos_tt_stat ...
  .include <pdk>/models/sg13g2_moslv_stat.lib
  .include <pdk>/models/sg13g2_moslv_mismatch.lib
  .include <pdk>/models/sg13g2_moslv_mod_mismatch.lib
.ENDL mos_tt_stat_mm

With it, a sample gets the same global draw as the stat-only section plus independent per-device mismatch (34 mV global, 5.3 mV pair difference at 1×1 µm).

Defects in the copy measured before 2026-10-30's update

  • One pmos process parameter never varies. In sg13g2_moslv_stat.lib the pmos muew line reads gauss(…_muew_norm, 0.0235  num_sigmas), with a missing comma. It is fixed upstream, and the update varies it (MEASURED 2026-10-30).
  • Resistor mismatch is biased. See the next section. It is fixed in the update.
  • HBT mismatch does not scale with size. ΔVbe σ is about 4 mV for both one and four emitters, so large devices are too pessimistic. It is fixed upstream (PR #1234, October 2026): 1.52 mV for one emitter and 0.66 mV for four in the update.
  • Global spreads are only indicative. The nmos spread is about twice what the process specification's min/max implies, the pmos spread about 0.7×, and the corners sit at 1–1.6σ (n) and 4–5σ (p) from typical.

Resistor mismatch: right spread, wrong centre (before 2026-10-30's update)

Resistor mismatch should be "nominal plus z × σ", where z is a random number with mean 0 and standard deviation 1, and σ is the local mismatch for that resistor's size. In the copy we measured, the draws are written gauss(1, 1, …): z has mean 1 instead of 0. Every resistor therefore gets "nominal plus (1 + random) × σ". The scatter is the right size, but it is centred about one local σ too high. That is σ of the small random scatter between neighbouring resistors, not the much larger die-to-die variation.

Resistor, 1×10 µmlocal σ (one resistor)mean shift
rsil0.47%+0.15%
rppd0.58%+0.26%
rhigh1.63%+1.39% (14,943 Ω → about 15,150 Ω)

The shift is not exactly one σ for every type, because each resistor model applies the draw through its own parameters (sheet resistance, width and length). Turning mismatch off with mm_ok=0 removes the scatter but not the offset: every resistor then sits at its shifted value instead of nominal.

Why it mostly does not matter for matching: two resistors of the same size and type get the same upward shift, so their ratio is unaffected. Only the random part differs between them, and that part is correct; the rhigh pair's 2.23% ratio scatter above is right.

Where it does matter:

  • Absolute resistance comes out slightly high, so for example a bandgap's bias current is slightly off. Trim usually absorbs this.
  • Ratios between resistors of different sizes or types are biased slightly, because the shift differs between them. For a 1×10 µm rhigh against a 1×10 µm rsil that is about 1.2%.

Fix: load a copy of the resistor mismatch file with mean 0 instead of 1 from a wrapper section, as for the MOS wrapper above, leaving the PDK files untouched. Alternatively, update the PDK: upstream corrected the mean on 2026-03-02 (58d1f3d, on both main and dev), and we measured it centred on 2026-10-30 (see the update above). The wrapper is only needed for a copy older than that.

When updating the PDK: since May 2026 upstream sets the MOS subcircuit default to mm_ok=0. A newer copy therefore gives zero transistor mismatch in mos_tt_mismatch unless each instance sets mm_ok=1. Measured on the 2026-10-30 copy: a plain 1/1 µm nmos pair gives a ΔVgs σ of 0, and with mm_ok=1 it gives 5.52 mV, the same as before. The update applies the same default to resistors, HBTs, varactors and the MIM capacitors (which defaulted to 1 before), but not to the MOS capacitors. Check for this before trusting a run after a PDK update.

Which PDK for bandgap trim-and-sim?

  • IHP SG13G2 varies everything that matters for a bandgap: transistors, resistors, bipolars and capacitors, locally and globally, with correct temperature behaviour in stock ngspice. Its defects are known and can be worked around, and upstream has fixed the resistor centre and the pmos muew (both on main) and the HBT area scaling (dev only). In return, mismatch now has to be switched on per instance (mm_ok=1). This is the one we are building on.
  • sky130 is fine for mismatch, including resistors and the pnp, but its process variation is VT-only by workaround, and temperature sweeps need a patched ngspice.
  • GF180MCU is excellent for transistors but has no resistor mismatch, so it would understate a bandgap's spread.

Whichever you use, read back a few draws before trusting a run. In every one of these PDKs a plausible-looking simulation can quietly have zero variation in one device class, and the only way to know is to look.

Tuesday, October 27, 2026

Klayout Developer FAQ

Notes from building KLayout 0.30.12 from source on Ubuntu 26.04 (WSL2) with Qt 6, on the way to an open-source schematic-driven layout flow with Xschem. Every answer below was checked against the source tree or a real build in October 2026. Where I compare with Cadence Virtuoso, the point is how the tool feels to use, not what it can or can't do.

Building and the repo

1What do I need to install to build KLayout?

On a recent Ubuntu with Qt 6, you need a compiler, Qt 6 development packages, and Ruby and Python headers. Ruby matters because KLayout's DRC and LVS engines are written in Ruby, so they're only built when Ruby is present.

sudo apt install build-essential git ccache python3-dev ruby-dev zlib1g-dev \
  qt6-base-dev qt6-tools-dev qt6-5compat-dev qt6-svg-dev qt6-multimedia-dev \
  libgit2-dev libcurl4-openssl-dev

qt6-5compat-dev is the one that's easy to miss. The Qt 6 build needs it whenever the Qt bindings for scripts are enabled, which is the default. libgit2-dev and libcurl4-openssl-dev are optional. Ubuntu's Qt 6 has no plain qmake, so name it explicitly:

./build.sh -qmake qmake6 -rpath $HOME/dev/klayout/bin-release -j8
Tip: watch your RAM. The generated Qt bindings are memory-hungry to compile, so on a 16 GB machine I used -j8 rather than all 20 cores. Prefix the command with QMAKE_CCACHE=1 for faster rebuilds.

2How big is the code base?

About 3.2 million lines of C++. Roughly 2.2 million of those are auto-generated Qt bindings (src/gsiqt), which is why that part of the build seems to take forever. The hand-written code is about 1 million lines:

ModuleWhat it isLines
dbLayout database, geometry engine, netlist extraction and LVS core~255k
laybasicView and rendering core~196k
pluginsFile formats (GDS2, OASIS, LEF/DEF, DXF, …) and tools~144k
unit testsC++ tests~128k
drc/lvsThe DRC/LVS language itself (Ruby)~18k

Most of the code base is organised around one idea, which KLayout calls GSI. Each C++ class is declared once in a gsiDecl*.cc file, and that one declaration becomes the Ruby API, the Python API and the API documentation. To find out what a script can do, grep for gsi::method ("name".

3Should I run Doxygen on it?

Probably not, at least not at first. The repo has no Doxyfile. For anything scripted (PCells, macros, tool integration) the API you program against is the GSI script API, and KLayout already documents it in its built-in help (Help → Class Index). The same docs are on klayout.de. If you go deep into the C++ later, run Doxygen only on src/{tl,gsi,db,laybasic,layui,lay,edt} and exclude src/gsiqt, which would otherwise be two thirds of the input.

4"error while loading shared libraries: libklayout_tl.so.0". What now?

Two things cause this:

  1. You ran the wrong binary. build-release/klayout is an intermediate copy. The installed app is bin-release/klayout.
  2. The binaries carry no RPATH. Unless you pass -rpath, build.sh leaves RPATH empty, so you have to run LD_LIBRARY_PATH=$PWD ./klayout from bin-release.
Gotcha: if you add -rpath to an existing build, make doesn't relink files that are already up to date just because the linker flags changed. You end up with an executable that has the path and libraries that don't. Delete the linked outputs in the build directory (*.so*, *.ut and the executables), then run make -j8 && make install. The object files are reused, so it's only a relink.

The unit tests live in the build directory, not the bin directory (the README is out of date on this):

cd build-release
TESTTMP=testtmp TESTSRC=.. LD_LIBRARY_PATH=. ./ut_runner dbBoxTests

5Why is my checkout 2 GB after building?

PartSizeNotes
build-release/1.2 GBAbout 750 MB of object files. The generated Qt bindings alone are 470 MB.
.git356 MBFull history
bin-release/209 MBThe actual install
src / testdata157 / 79 MB

You can delete the build directory once things are installed, but you lose incremental rebuilds. Building with -without-qtbinding saves about half a gigabyte and a lot of compile time. The cost is that scripts lose access to Qt classes such as QTcpServer, which I need for tool-to-tool communication.

Setup and customisation

6How do I get a black background like Virtuoso, and only set it once?

In the GUI, go to File → Setup → Display → Background. KLayout saves all settings to ~/.klayout/klayoutrc when it exits, so this is a one-time step.

If you'd rather keep settings in a version-controlled init file, as you would with .cdsinit or xschemrc, use a startup macro. Any .pym file in ~/.klayout/pymacros/ runs automatically at startup:

# ~/.klayout/pymacros/my_init.pym
import pya
mw = pya.MainWindow.instance()
mw.set_config("background-color", "#000000")

7Can I keep custom keyboard shortcuts in an init file?

Yes. In the GUI, use File → Setup → Application → Customize Menu, which saves to klayoutrc. For an init file, the script API has MainWindow.set_key_bindings, get_key_bindings and get_default_key_bindings. Bindings are keyed by menu path, and any menu entry can be bound, including your own macros:

mw.set_key_bindings({
    "zoom_menu.zoom_fit": "F",      # default is F2
    "edit_menu.undo":     "U",      # default is Ctrl+Z
})

Print get_default_key_bindings() once to see every menu path. With that, a Virtuoso-style keymap can live in a single file under version control.

8Magic has R and C parasitic extraction. Does KLayout?

  • Built in: since 0.30.2 KLayout has a pex module for resistance extraction only. It provides pex.RExtractor with square-counting and triangulation methods, plus RNetExtractor and RNetwork.
  • Add-on: KLayout-PEX (kpex) from IIC-JKU does R and C extraction on top of KLayout, with FasterCap, FastCap2 or Magic as optional backends. I haven't yet compared it with Magic on sky130.

Analog flow and sky130

9Is there an existing Xschem ↔ KLayout cross-probe?

I couldn't find one. The closest things are klink/klive, a KLayout plugin that opens a TCP server so other tools can push layouts into a running KLayout, and example projects such as mole99/klayout-sky130-inverter that use the two tools side by side through a Makefile-driven LVS flow.

Both tools have the pieces needed to build one:

  • Xschem has a Tcl TCP server and select/highlight commands that take hierarchical paths.
  • KLayout has a scriptable netlist browser, an LVS cross-reference that maps schematic objects to layout objects, selection events, and Qt networking for scripts.
Two gotchas: KLayout's embedded Python never releases the interpreter lock, so use Qt signals or timers, not Python threads or asyncio. And Xschem's TCP server evaluates any Tcl it receives, so bind it to localhost only.

10What does it take to do sky130 layout in KLayout if I already use sky130 in Xschem?

An Xschem-only setup usually has symbols and SPICE models but nothing for layout. With ciel, open_pdks ships one tarball per library, and you need two: common (6.6 MB: KLayout tech and layer files, DRC and LVS decks, the PCell library) and sky130_fd_pr (14.2 MB: device GDS, SPICE, LEF). That's about 105 MB on disk. Magic and netgen aren't required, because KLayout runs DRC and LVS itself.

The stock Xschem sky130 symbols already write LVS netlist lines such as sky130_fd_pr__nfet_01v8 L= W= nf= m=, which is the naming the KLayout LVS deck expects.

The catch: the PCells need patching. An nfet at any W/L/nf comes from a gdsfactory-based PCell library called skywater130. With current gdsfactory 9 / kfactory 3 every PCell quietly produces an empty cell, which is why so many people report it "doesn't work". The JKU IIC-OSIC-TOOLS install script carries the fixes. Install the PDK at their pinned open_pdks commit (1689ac3f) and keep gdsfactory 9.51.0 / kfactory 3.0.4 in a venv.

What I verified on my own 0.30.12 build:

  • PCells: nfet, pfet, poly resistor, MIM cap, vias and guard rings all generate.
  • DRC: sky130A_mr.drc with -rd feol=true -rd beol=true -rd offgrid=true runs 256 rule categories with 0 violations. The default .lydrc has front-end checks off, so a clean result from it means little.
  • LVS: an Xschem-style netlist matches with -rd convert_subckts=true -rd scale=true.
Things that bit me: KLayout's Python ignores PYTHONPATH; point it at the venv with KLAYOUT_PYTHONPATH. The PCell's w is per finger while Xschem's W is total, so w = W/nf. Pass gate_con_pos and bulk explicitly. Multi-finger PCells don't strap their fingers, so an nf=4 device extracts as four devices until you route it.

UI/UX compared with Cadence Virtuoso

Short version: KLayout's viewing and script API are strong. What it lacks are the things that make Virtuoso feel like an environment rather than a viewer.

VirtuosoKLayout 0.30Verdict
CIW with command log (CDS.log)Script console and a log viewer; GUI actions aren't logged as commandsMissing
Library Manager (lib/cell/view)Libraries panel: list and drag; one file = one libraryMinimal
Many windows, any monitorOne main window with tabs; side panels can floatMissing
SKILLPython and Ruby, full API, macro IDEStrong
f = zoom fit, bindkeys in .cdsinitF2; rebind anything from an init macroFine

11Does KLayout have a Command Interpreter Window that logs commands?

No. There are two partial equivalents:

  • Macro Development → Console: an interactive Python or Ruby prompt, the equivalent of typing SKILL into the CIW.
  • File → Log Viewer: info, warning and error messages. Starting with -d <level> makes it chattier.

What's missing is the part of the CIW that makes SKILL learnable: GUI actions are never echoed as replayable commands. There's no CDS.log-style journal and no macro recorder. A CIW-style dock that logs each menu action as its script call could be built as a plugin on the existing API, but it doesn't exist today.

12Is there a Library Manager?

A minimal one. The Libraries panel lists registered libraries with their cells and PCells, and you drag from it into a layout. The Cells panel shows the hierarchy within the open file. There's no library → cell → view browser, no cds.lib, no categories, and no copy, rename, delete or check-in.

The underlying difference is the data model. In Virtuoso a library is a directory of cells, each with views. In KLayout a library is a file, or a set of PCells registered by a script. A lib/cell/view layer has to be added on top, which is what my project plans to do.

13Can I look at two layouts in separate windows on two monitors?

Not from one process. KLayout allows a single main window (it's enforced in layMainWindow.cc). Extra layouts open as tabs that can't be torn off. The side panels (layers, cells, libraries, navigator) are dock widgets and can be floated onto another monitor.

The practical answer is two KLayout processes, one per monitor.

Gotcha: each process writes ~/.klayout/klayoutrc when it exits, so the last one closed wins. Start the second one with -t so it doesn't save its settings:
klayout top.gds &
klayout -t other.gds &

Within one window you can also overlay two layouts in the same tab ("add to current panel" when opening), compare them with the XOR and Diff tools, or turn on Display → Synchronized Views so switching tabs keeps the same zoom area.

14What is the command language? How good is scripting support?

Python and Ruby, both built in, and the scripting is excellent. There's no single native language like SKILL. Instead both languages get the same complete API, generated from the C++ declarations: the layout database, views, menus, the netlist and LVS engine, and even Qt widgets for building your own dialogs. It's documented in Help → Class Index.

  • Macro Development IDE: an editor, debugger and console.
  • Init files: .pym and .rbm files in ~/.klayout/pymacros and ~/.klayout/macros run at startup, the equivalent of .cdsinit.
  • Batch mode: klayout -b -r script.py.
  • DRC and LVS are rule languages (Ruby DSLs) on the same engine.
  • Standalone module: pip install klayout gives you the database without the GUI.

The gap compared with SKILL isn't power, it's discoverability. Without a command log you learn the API from the docs rather than by watching what the GUI does.

15What is the keyboard shortcut for zoom fit? (Virtuoso: f)

F2. Shift+F2 fits the selection, and Ctrl++ / Ctrl+- zoom in and out. To get Virtuoso's f, put this in your init macro:

pya.MainWindow.instance().set_key_bindings({"zoom_menu.zoom_fit": "F"})

Thursday, August 14, 2025

If You Want to Add Value to Open EDA - chatGPT's Advice

Analog · Automation · Open Flow

EDA Automation for Analog — a 90-Day MVP You Can Start Today

Build the missing glue: auto testbenches, corner/MC orchestration, lint, and clean HTML reports — open-source first, portable to Virtuoso/Spectre later.

xschem ngspice/Xyce Magic KLayout netgen Python · Jinja2 · YAML · pandas

Strategy in One Paragraph

Use free/open tools to prove value on Sky130/GF180: generate testbenches from a small YAML “design contract,” run corners & Monte Carlo with reproducible seeds, lint schematic/layout for analog foot-guns, and publish a one-page HTML dashboard leadership can skim. Keep clean adapters so you can swap ngspice→Spectre and xschem→Virtuoso later with minimal rework.

Tool Stack (Free)

Schematic
xschem
Simulation
ngspice or Xyce
Layout
Magic + KLayout
LVS/DRC
netgen (LVS), Magic/KLayout (DRC)
PDKs
SkyWater 130, GF180 (open)
Glue
Python 3.11+, Jinja2, YAML, pandas, HTML

Milestones & Deliverables

Weeks 1–2 v0.1

  • Repo layout: tools/, examples/, reports/, docs/
  • gen_tb.py — Jinja SPICE TB generator
  • run_corners.py — PVT runner (real if ngspice found; mock otherwise)
  • report_html.py — JSON → HTML report
  • schematic_lint.py — basic xschem lint (stub)

Success: An inverter example renders a shareable HTML report.

Weeks 3–4 v0.2

  • YAML-driven corners (VDD, temp, tt/ss/ff when available)
  • Parameter sweeps: cload, W/L, bias current
  • Measurements: tpHL/tpLH, tr/tf, static current
  • Artifacts: summary.json, results.csv, sortable HTML

Success: 6+ corners with one command, neat table output.

Weeks 5–6 MC

  • Monte Carlo with deterministic seeds
  • Stats & yield: mean/σ/min/max, pass/fail vs. spec
  • HTML distributions + yield bar

Success: 200-run MC of comparator delay across 3 corners.

Weeks 7–8 Lint

  • Schematic lint: unlabeled nets, P/G rails, floating nodes, naming consistency
  • Layout lint (KLayout): symmetry pairs, matched areas, orientation checks
  • Checklist emitted into HTML

Success: Actionable lint before LVS/DRC, fewer late surprises.

Weeks 9–10 LVS/DRC

  • Wrap netgen (LVS): device/net mismatches, pin naming
  • Wrap Magic/KLayout (DRC): total errors, top rules, coordinates
  • One-page sign-off snapshot

Success: PVT + MC + LVS/DRC summary on one screen.

Weeks 11–12 v0.4

  • Cell pack: Inverter, Comparator, Two-stage Op-Amp (or simple LDO stage)
  • Each with ready configs, corners, MC, lint, LVS/DRC
  • One-Click: run_all.py examples/opamp/config.yaml

Success: A non-expert can clone & run and get a professional report.

Example: Minimal Workflow

# 1) Generate a testbench from YAML
python tools/gen_tb.py examples/inverter/config.yaml

# 2) Run corners (uses ngspice if present; otherwise mock)
python tools/run_corners.py examples/inverter/config.yaml --out reports/inverter

# 3) Build a shareable HTML report
python tools/report_html.py reports/inverter/summary.json --out reports/inverter/report.html

What to Automate (High Value)

  • Auto Testbench Generation: from a small YAML “design contract” (pins, supplies, stimulus recipe) → SPICE with measures.
  • Corner/MC Orchestration: reproducible seeds, resumable runs, cache, CSV+JSON artifacts, CI-friendly.
  • Lint: schematic (nets, names, floating nodes) and layout (symmetry/matching heuristics) for early catches.
  • HTML Reports: specs vs targets, pass/fail heatmap, MC yield, LVS/DRC counts, links to artifacts.

Porting to Cadence/Synopsys Later

Design with adapters so swapping tools is trivial:

  • Simulator: NgspiceAdapter ⇄ SpectreAdapter (CLI args, netlist dialect, measures/Ocean)
  • Schematic: xschem parse ⇄ Virtuoso via SKILL/Ocean or exported netlists
  • Layout Checks: KLayout scripts stay useful even in Virtuoso flows; later swap to Calibre/PVS wrappers

The value isn’t replacing Virtuoso — it’s automating everything around it.

Validation & First “Customers”

  • Who first: small analog consultancies & university labs (hate manual PVT/MC + reporting).
  • Pilot: offer your stack free to 1–2 teams for feedback and anonymized screenshots.
  • Measure: time saved/iteration, bugs caught by lint pre-LVS/DRC, earlier MC yield visibility.

Risks & Mitigations

  • Open PDK limits: use Sky130/GF180 to prove flow; keep adapters ready for proprietary PDKs.
  • Layout heuristics: start with simple symmetry checks; evolve toward device-graph matching.
  • Vendor lock-in: strict adapter boundaries to avoid rewrites when adding Spectre/Calibre.

Quick Start Checklist

  • Python 3.11+, optional ngspice on PATH
  • YAML config describing pins, supplies, stimulus, corners, MC
  • Run: generate TB → run corners/MC → build HTML
  • Iterate: add lint and LVS/DRC wrappers, then ship one-click reports

Want an expanded YAML schema, a first KLayout symmetry macro, or a SKILL/Ocean mapping sheet to Virtuoso? Say the word and I’ll include them in a follow-up post.

Getting a Useful VcXsrv Crash Dump

Winner of the first Nobel Prize in Physics ❯ tell me how to do the VcXsrv shortcut that I currently have in my Startup folder so that we get...