Menu ▾ ▴

#131 inpcom.c: evaluate .param with agauss/gauss/aunif/unif/limit once, as documented

Unstable (example)
closed-fixed
5
2026-10-16
2026-10-15
No

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:

  • Global process variation becomes per-device in the SKY130 (parameters/critical.spice), GF180MCU (.lib statistical) and IHP SG13G2 (*_stat.lib, before the two-stage mc_xxx workaround) libraries.
  • Parameters derived from one random .param get independent draws (aga2 != 2*aga; SKY130 montecarlo.spice correlations are lost).
  • Inside a subckt, two references in the same instance get different mismatch values (GF180 mis_vth).

Change (only src/frontend/inpcom.c, inp_fix_agauss_in_param() plus three static helpers)

  • A top-level random .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.
  • A random .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

  • manual 18.2 (fixed apostrophes): master v14!=v15, v16!=2v14; patched v14=v15, v16=2v14; v11-13, v17/18 still differ.
  • top .param g used in 2 subckt instances + 2 top resistors: master 4 different values; patched all equal.
  • D. Warning stat_test (.param gauss, model in subckt): master Id1!=Id2; patched Id1=Id2. The .func gaussf variant still differs (unchanged).
  • SKY130 critical+montecarlo+nfet_01v8: patched global probes equal and consistent, devices still differ (mismatch).
  • GF180-style toy: patched fingers equal within an instance, instances differ, globals equal.
  • Top .param depending on instance w, l: still works (kept as .func).
  • Current IHP lv-MOS libs (BSIM4 stand-in for PSP): identical to master.

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

  • Per-use redraws of evaluable top-level random .params are gone by design; set stat_param_as_func brings them back.
  • Syntax errors in unused random .params are now reported.
  • The manual could add a sentence that a .param referring to instance parameters is evaluated per use.
1 Attachments

Related

Patches: #131

Discussion

  • Dietmar Warning

    Dietmar Warning - 2026-10-16

    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.

     
    • Lucas Wendland

      Lucas Wendland - 2026-10-16

      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:

      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.


      [patches:#131] inpcom.c: evaluate .param with agauss/gauss/aunif/unif/limit once, as documented

      Status: open
      Group: Unstable (example)
      Labels: inpcom statistics monte carlo
      Created: Thu Oct 15, 2026 01:12 PM UTC by Lucas Wendland
      Last Updated: Thu Oct 15, 2026 01:12 PM UTC
      Owner: nobody
      Attachments:

      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:
      - Global process variation becomes per-device in the SKY130 (parameters/critical.spice), GF180MCU (.lib statistical) and IHP SG13G2 (*_stat.lib, before the two-stage mc_xxx workaround) libraries.
      - Parameters derived from one random .param get independent draws (aga2 != 2*aga; SKY130 montecarlo.spice correlations are lost).
      - Inside a subckt, two references in the same instance get different mismatch values (GF180 mis_vth).

      Change (only src/frontend/inpcom.c, inp_fix_agauss_in_param() plus three static helpers)

      • A top-level random .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.
      • A random .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
      - manual 18.2 (fixed apostrophes): master v14!=v15, v16!=2v14; patched v14=v15, v16=2v14; v11-13, v17/18 still differ.
      - top .param g used in 2 subckt instances + 2 top resistors: master 4 different values; patched all equal.
      - D. Warning stat_test (.param gauss, model in subckt): master Id1!=Id2; patched Id1=Id2. The .func gaussf variant still differs (unchanged).
      - SKY130 critical+montecarlo+nfet_01v8: patched global probes equal and consistent, devices still differ (mismatch).
      - GF180-style toy: patched fingers equal within an instance, instances differ, globals equal.
      - Top .param depending on instance w, l: still works (kept as .func).
      - Current IHP lv-MOS libs (BSIM4 stand-in for PSP): identical to master.

      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
      - Per-use redraws of evaluable top-level random .params are gone by design; set stat_param_as_func brings them back.
      - Syntax errors in unused random .params are now reported.
      - The manual could add a sentence that a .param referring to instance parameters is evaluated per use.


      Sent from sourceforge.net because you indicated interest in https://sourceforge.net/p/ngspice/patches/131/

      To unsubscribe from further messages, please visit https://sourceforge.net/auth/subscriptions/

       

      Related

      Patches: #131

  • Dietmar Warning

    Dietmar Warning - 2026-10-16
    • status: open --> closed-fixed
    • assigned_to: Dietmar Warning
     
    • Lucas Wendland

      Lucas Wendland - 2026-10-16

      Hi 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:

      • status: open --> closed-fixed
      • assigned_to: Dietmar Warning
      • Comment:

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


      [patches:#131] inpcom.c: evaluate .param with agauss/gauss/aunif/unif/limit once, as documented

      Status: closed-fixed
      Group: Unstable (example)
      Labels: inpcom statistics monte carlo
      Created: Thu Oct 15, 2026 01:12 PM UTC by Lucas Wendland
      Last Updated: Fri Oct 16, 2026 05:38 AM UTC
      Owner: Dietmar Warning
      Attachments:

      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:
      - Global process variation becomes per-device in the SKY130 (parameters/critical.spice), GF180MCU (.lib statistical) and IHP SG13G2 (*_stat.lib, before the two-stage mc_xxx workaround) libraries.
      - Parameters derived from one random .param get independent draws (aga2 != 2*aga; SKY130 montecarlo.spice correlations are lost).
      - Inside a subckt, two references in the same instance get different mismatch values (GF180 mis_vth).

      Change (only src/frontend/inpcom.c, inp_fix_agauss_in_param() plus three static helpers)

      • A top-level random .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.
      • A random .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
      - manual 18.2 (fixed apostrophes): master v14!=v15, v16!=2v14; patched v14=v15, v16=2v14; v11-13, v17/18 still differ.
      - top .param g used in 2 subckt instances + 2 top resistors: master 4 different values; patched all equal.
      - D. Warning stat_test (.param gauss, model in subckt): master Id1!=Id2; patched Id1=Id2. The .func gaussf variant still differs (unchanged).
      - SKY130 critical+montecarlo+nfet_01v8: patched global probes equal and consistent, devices still differ (mismatch).
      - GF180-style toy: patched fingers equal within an instance, instances differ, globals equal.
      - Top .param depending on instance w, l: still works (kept as .func).
      - Current IHP lv-MOS libs (BSIM4 stand-in for PSP): identical to master.

      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
      - Per-use redraws of evaluable top-level random .params are gone by design; set stat_param_as_func brings them back.
      - Syntax errors in unused random .params are now reported.
      - The manual could add a sentence that a .param referring to instance parameters is evaluated per use.


      Sent from sourceforge.net because you indicated interest in https://sourceforge.net/p/ngspice/patches/131/

      To unsubscribe from further messages, please visit https://sourceforge.net/auth/subscriptions/

       

      Related

      Patches: #131

  • Dietmar Warning

    Dietmar Warning - 2026-10-16

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

     

Log in to post a comment.