Discussion: https://sourceforge.net/p/ngspice/discussion/133842/thread/c13bbd10c6/ ("Unexpected behavior of .param including statistical functions"). Dietmar Warning confirmed the patch applies to pre-master-48 and that the two-stage workaround is no longer needed.
Problem
Since ngspice-29, inp_fix_agauss_in_param() turns every .param containing a statistical function into a .func, so every reference draws a new random value. This contradicts the manual (18.2: aga, aga2, lim), and is still the case in master 75f22a99 (2026-10-14).
Effects:
parameters/critical.spice), GF180MCU (.lib statistical) and IHP SG13G2 (*_stat.lib, before the two-stage mc_xxx workaround) libraries..param get independent draws (aga2 != 2*aga; SKY130 montecarlo.spice correlations are lost).mis_vth).Change (only src/frontend/inpcom.c, inp_fix_agauss_in_param() plus three static helpers)
.param stays a .param (one draw per load / reset / mc_source) when all identifiers in its expression are top-level parameters or functions, numbers, or function calls. Otherwise it is converted to a .func as before (e.g. agauss(0, avt/sqrt(w*l), 1), which needs per-use evaluation in the instance scope). Dependents are handled by fixed-point iteration..param inside a .subckt stays a .param: numparam evaluates it once per instance.set stat_param_as_func restores the previous behaviour.Why IHP failed when the conversion was simply disabled: a missing comma in the Jan 2025 sg13g2_moslv_stat.lib (gauss(sg13g2_lv_pmos_muew_norm, 0.0235 mc_ok)). The lazy .func hid it; eager evaluation reports it. With the comma restored, the old IHP libs work as intended. IHP fixed it in May 2026.
Tests
make check (patched): 57 PASS, 0 FAIL. No existing test uses statistical functions; the netlists above could be added as regression tests (with .option seed).
Compatibility notes
.params are gone by design; set stat_param_as_func brings them back..params are now reported..param referring to instance parameters is evaluated per use.
I made few more tests with my statistical evaluation in actual IHP OpenPDK and got problems which I can't relate explicite to the code change by your patch. It may be a numerical problem with the statistical package (gnuplot) or other.
But anyway we need additional checks. Can I send you the osdi files that you can evaluate the patch with original IHP's PDK? Tell me your OS.
Hi Dietmar,
Thanks for running the extra tests with the IHP OpenPDK. I'm on Ubuntu
24.04, so Linux OSDI builds would be perfect. I'll run the patch
against the original IHP PDK as soon as I have them and report back
here.
Best,
Lucas
On Fri, 16 Oct 2026 05:38:11 -0000, Dietmar Warning
dwarning@users.sourceforge.net wrote:
Related
Patches:
#131Hi Dietmar,
That's great to hear, thank you for testing it so thoroughly against
the IHP libraries and for merging it. Happy to help with regression
tests for the statistical functions if that would be useful.
Best,
Lucas
On Fri, 16 Oct 2026 14:21:54 -0000, Dietmar Warning
dwarning@users.sourceforge.net wrote:
Related
Patches:
#131The problem I mentioned was with a inappropriate binning of the statistical package and as suspected not related to this patch. The new approach also work with the copy workaround in IHPs library and show same results. These redundant variables will removed after long waiting time because not any user have updated ngspice.
So the patch is applied to pre-master-48.
Thank you.