Two related pieces that complete the statistical flow:
- Native process/mismatch correlations —
mccorr+mvnorm(), so random.params can be correlated (a shared process factor, a mismatch covariance, an arbitrary correlation matrix) instead of only independent. - A packaged yield command —
montecarlo, which runs the Monte Carlo, applies pass/fail specs, and reports the yield with a confidence interval.
Plain ngspice Monte Carlo draws every agauss/gauss independently, so matched
devices can't be modelled — yet whether two devices' variation is correlated is
often what decides the yield. mccorr registers a k × k correlation matrix
(Cholesky-factored once), and mvnorm(i) returns the i-th component of one
correlated standard-normal draw per Monte Carlo sample:
mccorr 2 1 0.9 0.9 1 ; 90% correlation between two factors
.param r1 = 1000 + 50*mvnorm(1) ; r1, r2 now vary together
.param r2 = 1000 + 50*mvnorm(2)
mvnorm(i) inherits the active sampler: it composes with Latin-Hypercube
(Enhancement-149) and scaled-sigma importance sampling (Enhancement-150)
automatically, and with no matrix registered it simply draws independently. The
common process + local mismatch model is the special case
p = sigma_proc*mvnorm(shared) + sigma_mm*agauss(...).
montecarlo <N> [-lhs] [-seed <s>] [-analysis <cmd>]
(-spec <metric> [-max <hi>] [-min <lo>])...
Runs N samples; a sample passes only if every spec's metric is within its
-max/-min limits. Reports the yield (fraction passing) with a Wilson 95%
confidence interval and a per-spec violation count, and leaves
montecarlo_yield, montecarlo_npass, montecarlo_n for scripting. -lhs
draws Latin-Hypercube samples for a much lower-variance yield estimate.
- Process corners are the ordinary
.lib/.includecorner selection — load a corner model set, then runmontecarloat that corner. Correlations and corners compose: run the yield MC at each corner.
yield_demo.cir— a matched resistor divider with a ±4% ratio spec; the same devices give ~100% yield when process-correlated (ρ=0.9) but only ~74% when independent (ρ=0) — the correlation model is what decides it. Run withngspice -b yield_demo.cir.verify_yield.py— validation against analytic ground truth (Sparse-only — a heavy, thousands-of-re-sources deck):- an
mccorrρ=+0.7 / −0.6 matrix reproduces the target correlation, means, and sigmas; mvnormwithout a matrix draws independently;- a non-positive-definite matrix is rejected;
- single two-sided spec yield matches
P(|Z| < k); - two independent specs' yields multiply;
-lhsis unbiased and much lower-variance;- positive parameter correlation raises the joint yield.
- an
python3 verify_yield.py
mvnorm(i)returns a unit-variance standard normal; scale it in the.param(nom + sigma*mvnorm(i)). Themccorrmatrix is a correlation matrix (unit diagonal).- Correlations and yield are front-end features (they change only which parameter values are drawn), so they are solver-independent; the verify is a heavy deck and runs under Sparse only.
- Every SPICE deck's first line is the title (ignored by the parser); the
decks here start with a
*title line accordingly.