Showing posts with label harald pretl. Show all posts
Showing posts with label harald pretl. Show all posts

Thursday, November 19, 2026

ALIGN's Layout for a NAND Std-Cell is 35x as Large as What the Library Has

ALIGN is an open-source generator that turns a SPICE netlist into a layout. We have been porting it to SkyWater’s sky130 PDK, driven from Xschem. Our port turns a four-transistor NAND2 into a sky130 layout that passes every DRC and LVS check in about seven seconds. The layout is 130 µm², 35 times the 3.75 µm² of the PDK’s own nand2_1. One of its four transistor cells, at 8.76 µm², is larger than the whole standard cell.

This post takes that layout apart and traces each lost micron to the code that costs it, and to the reason that code exists.

Wednesday, November 11, 2026

Does ngspice STB Work? Is ASE-L Geared to Use it?

HRH Claude Opus:

I didn't need any documentation, and native stb in ver_53 works. The ngspice session left a user guide (README.stb), a spec of what it built, three example decks and its review notes in the tree, and I had our own acceptance kit.

- Acceptance kit: accepted, with 323 checks passing, 0 failing and 0 skipped. Older binaries skipped the 32 native checks; on ver_53 all of them now run and pass.
- Your sky130 OTA demo: native gives the same loop gain as ASE-L's current method, to rounding (8e-14). The margins match the walkthrough: UGB 13.20 MHz, phase margin 56.3°, gain margin 44.6 dB at 267 MHz.
  - No probe element needed: naming a pin works, which is the extracted-view case you wanted. rm1:1 breaks the loop at the metal resistor's pin, and x1:inn at the OTA's own input; both give the same margins.
- Speed:
  - On the demo there is no difference, because loading the sky130 models (about 2.5 s) dominates.
  - On a large netlist, with a 20,000-node RC network added to the bench, the stb part takes about 0.2 s natively against about 1.5 s for ASE-L's two-sweep method.
- Monte Carlo: the shipped Monte Carlo example runs 100 samples cleanly, each within 0.002° of the analytic answer.
- Switching from v_52: ver_53 is ver_52 plus the stb work. ASE-L's demo suite prints identical numbers on both, so switching changes no existing ASE-L result.

What native stb doesn't do yet:

- No transistor as the probe: you name one of its pins instead.
- No differential or common-mode loops, the same as ASE-L's stb today.
- Frequency sweeps only: Monte Carlo runs through a loop in the deck.
- Not checked against another simulator: the margins have been checked against textbook closed forms and now ASE-L's own engine, but not against Spectre.

Two other findings:
- ASE-L doesn't use native stb yet. It still runs its own two-sweep method on every binary. Switching is the unbuilt plan in our private notes (CLIENT_NOTES.md §3). It would also let you pick any pin as the loop break, extracted views included.
- ver_53 isn't in your simulator list, which has only v_50 and v_52. Adding it is up to you, in Setup > Simulators.
- Unrelated to ver_53: the demo walkthrough's Monte Carlo table was measured on ver_51. On your v_52, and on ver_53, 3 of its 28 numbers differ in the last digit. The regression suite runs ver_51, so it stays green.



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

Monte-Carlo with ngspice and Xschem

How our Monte Carlo drives ngspice Which ngspice we use, what it adds to stock ngspice, and how one process runs many samples
Date
2026-11-01
Simulator
ngspice-46+, built from our development fork (branch ver_51)
Context
The Monte Carlo engine behind ASE-Integrator, our open-source take on an ADE-Assembler-style test bench manager on top of xschem
Short answer
Several long-lived ngspice processes in parallel, each looping over a list of seeds it is handed. ngspice never knows it is doing an N-sample Monte Carlo.

Which ngspice

We run an ngspice-46+ build from our own fork, branch ver_51. It reports itself as ngspice-46+. The distribution's ngspice 45.2 can simulate the same decks, but our Monte Carlo refuses to use it. That refusal is on purpose; the next section explains why.

What the fork adds to stock ngspice

  1. A draw log (set rnddraws=<file>). This is the essential one. It records every random number drawn while the netlist is read: which parameter, which device, and what value. That lets us see each sample's per-device mismatch rather than only its outputs. Stock 45.2 has nothing like it. Our Monte Carlo refuses 45.2 with a clear message (mc_ngspice_min: "Monte Carlo needs an ngspice that writes the draw log") rather than run blind.
  2. Seeding fixes:
    • The startup random stream is seeded from rndseed, not from the process id.
    • The draw log is closed properly when the circuit is reset.
    • A warning is printed once when .option seed= silently overrides setseed.
  3. Resistor fixes: the resistor model survives ngspice's internal conversion of a resistor to a B-source. Without this, sky130's high-value resistor loses its temperature coefficient.
  4. Many smaller fixes: case handling of node names, .save name lookup, the exit status of a batch run, an .op card with no netlist, and others. Several have been offered upstream.

One process per sample? No.

We do not launch a new ngspice per sample. One ngspice process, which we call a lane, handles a whole range of samples. Inside its .control block it loops over the seeds it has been given. For each sample:

set rnddraws=<sample dir>/draws   * where this sample's draw log goes
setseed <seed>                     * this sample's own, literal seed
reset                              * re-read the netlist: mismatch is drawn fresh
set temp=<T>
op                                 * write this sample's raw file and measures
echo ASEMC_DONE s=<seed> ...       * tell the supervisor this sample is finished
unset rnddraws
destroy all                        * drop this sample's results from memory

The order matters, and each step is there because a measurement showed it was needed:

  • setseed has to come before reset, because the mismatch values are drawn while the netlist is read.
  • destroy all keeps memory flat over hundreds of samples.
  • The ASEMC_DONE line is how the outside world learns that a sample has finished.

Several lanes in parallel

A small Python worker sits between the GUI and ngspice:

  • It splits the N samples into contiguous ranges across L lanes. L is the smallest of the setup's job limit, the number of CPUs and N.
  • Lane 1 also runs the nominal sample (sample 0), with mismatch switched off.
  • For example, 200 samples on a 20-core machine can be 20 ngspice processes of about 10 samples each, all running at once.

The worker supervises the lanes:

  • It reads each lane's log as it is written, and it records a sample (raw file, measures and draw log) the moment that sample's ASEMC_DONE line appears.
  • A sample that errors is marked as a simulation failure, and the lane carries on.
  • A lane that stops making progress is killed. Its stalled sample is marked as timed out, and a fresh lane restarts from the next sample.
  • The Stop button kills every lane. Unfinished samples are left pending, not half-written.

Does ngspice know it is doing Monte Carlo?

No. ngspice has no "run N Monte Carlo samples" command, and we don't need one. Each lane receives a deck whose seeds are written out as a literal list. There is no arithmetic and no counter inside ngspice. It runs the loop it has been handed, without knowing that it is a Monte Carlo or how big the whole run is.

Everything Monte Carlo-specific lives in the worker:

  • N, and the seed for each sample.
  • The split into lanes, and which sample is which.
  • The nominal run.
  • Retries, stop and progress.
  • The results database the GUI reads (yield, histograms, re-evaluation).

Why it is built this way

  • Speed: the netlist is redrawn inside one long-lived process, so there is no start-up cost per sample.
  • Reproducibility: every seed is explicit, and every draw is logged. Any single sample can be re-run on its own and give exactly the same numbers.
  • Robustness: one bad sample costs one sample, not the run. A stalled lane costs one sample, then the work continues on a fresh process.
  • Simplicity: ngspice does what it is good at, simulating one circuit. The bookkeeping lives in ordinary code that can be tested.

Wednesday, October 1, 2025

ALIGN - Automated Layout - What it May Have Cost

University of Minnesota audited federal-expenditure report that lists:

- Contract: N660011824048 P00005

- Federal expenditures: $1,307,362

- Subrecipient expenditures: $743,968

NSF award CCF-2212345 : $900k/14 going by https://www.nsf.gov/awardsearch/show-award/?AWD_ID=2212345

2212346 : $300k/6 per https://www.nsf.gov/awardsearch/show-award?AWD_ID=2212346

So, let's make the most of it :)



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