Menu ▾ ▴

#884 AC results that disagree with the DC solution: 13 fixes and a memristor follow-up, as one patch series (pre-master-48)

v1.0 (example)
open
5
2026-10-26
2026-10-26
No

As discussed in #883, here are the other issues the AC/DC check found, as one patch series against pre-master-48 (f127e96).

The check is simple: at low frequency, a circuit's AC transfer should equal the derivative of its DC solution, so I compare the two (central differences at two step sizes) and trace any disagreement to the model code. The patches, in the order they apply:

  1. mult: the AC gain is not finite when one input is zero
  2. climit: wrong smoothing derivatives when the limits move
  3. ilimit: the variable output resistance is differentiated incorrectly
  4. ilimit: source current limiting uses the sink smoothing width
  5. multi_input_pwl: the selected input's derivatives are missing
  6. memristor: your f6d11dbbd fixed the rinit selection, but its DC partial is still missing; this patch adds only that
  7. sidiode: the tanh limit derivatives miss the current amplitude
  8. xfer: no DC derivative, which breaks feedback circuits
  9. astate: the pass-through gain is missing
  10. delay: returns zero AC gain
  11. inductoric: stamps an impedance where an admittance is expected
  12. MOS1: the body-effect derivative doesn't match its forward-bias continuation
  13. MOS6: has no AC matrix loader at all (a new mos6acld.c, added to Automake, CMake and the three Visual Studio projects)
  14. native S/W and CSW switches lose the converged DC state when AC is set up

Each commit message gives the symptom, the cause and the fix. Each patch also adds its own test to make check, with its .out file: tests/xspice/analog for the code models (its spinit now loads analog.cm as well) and tests/regression/model for the built-in devices.

The #883 fix comes first, so it's attached again. Patch 13 touches the Visual Studio project files, which keep CRLF line endings, so please apply with --keep-cr:

git am --keep-cr 0001-Fix-switch-AC-current-Jacobians-v2.patch
git am --keep-cr ngspice-ac-dc-series.mbox

How I checked it: on fresh clones of pre-master-48, applying the series one patch at a time, each new test fails before its patch and passes after it. With everything applied, make check passes all 72 tests (the existing 58, which include switch-ac, plus the 14 new ones). I also built the result with Visual Studio 2022 (vngspice.sln, console_release, x64; I don't have libsndfile here, so I built with the sound libraries switched off) and ran the new tests with that binary. They all pass.

The same 14 test circuits are in the attached archive, so you can try any of them on your current build before applying anything, for example ngspice -n -b reproducers/jacobian-mult-zero.cir. Each prints whether it passed and exits 0 or 1.

If any change doesn't fit how a model is meant to work, I'm happy to rework it.

The checker is here: https://github.com/Copprlab/spice-jacobian-check

Attachments:

  1. 0001-Fix-switch-AC-current-Jacobians-v2.patch: the #883 fix, the same one posted there. Apply it first.
  2. ngspice-ac-dc-series.mbox: the 14 patches, one commit each, in the order listed above. Apply it with git am --keep-cr.
  3. ngspice-ac-dc-reproducers.tar.gz: the 14 test circuits on their own, with a short README, so you can run them on a build without the patches.
  4. attachments.sha256: SHA-256 checksums of the three files above. Check them with sha256sum -c attachments.sha256.
4 Attachments

Discussion


Log in to post a comment.