I’m trying to get Monte Carlo analysis of filters to work. A basic .AC analysis works fine, but I can’t get a script to work to run a sizeable iteration count and collect output.

Here’s the SPICE netlist generated (the blockquote unfortunately seems to not format correct). The .ac directive before .control and the loop is for KiCAD to understand this is an .AC analysis. Otherwise it just issues an error when I try to run it.

.title KiCad schematic

R1 Net-C2-Pad1Net-C1-Pad11000

R2 Net-C2-Pad2Net-C1-Pad190.9

R3 Net-C1-Pad1VIN 100

C1 Net-C1-Pad10 76.9nF

C2 Net-C2-Pad1Net-C2-Pad26.83nF

X1 0 Net-C2-Pad2VDD VSS Net-C2-Pad1IDEAL

R4 Net-C4-Pad1Net-C3-Pad11000

R5 Net-C4-Pad2Net-C3-Pad1500

R6 Net-C3-Pad1Net-C2-Pad11000

C3 Net-C3-Pad10 15.0nF

C4 Net-C4-Pad1Net-C4-Pad25.99nF

X2 0 Net-C4-Pad2VDD VSS Net-C4-Pad1IDEAL

R7 Net-C6-Pad1Net-C5-Pad11000

R8 Net-C6-Pad2Net-C5-Pad1500

R9 Net-C5-Pad1Net-C4-Pad11000

C5 Net-C5-Pad10 17.9nF

C6 Net-C6-Pad1Net-C6-Pad24.42nF

X3 0 Net-C6-Pad2VDD VSS Net-C6-Pad1IDEAL

R10 VOUT Net-C7-Pad11000

R11 Net-C8-Pad2Net-C7-Pad1500

R12 Net-C7-Pad1Net-C6-Pad11000

C7 Net-C7-Pad10 27.5nF

C8 VOUT Net-C8-Pad22.29nF

X4 0 Net-C8-Pad2VDD VSS VOUT IDEAL

V1 VDD 0 dc 15

V2 0 VSS dc 15

V3 Net-R100-Pad20 dc 0 ac 1 0 sin(0 1 12.5k 0 0)

R100 VIN Net-R100-Pad20

R101 VOUT 0 100k

… removed ATr1 through ATr102 since the annoying forumware thinks I’m trying to reference other users rather than simply insert a text block and refuses to accept it …

.save V(0)

.save V(GND)

.save V(Net-C1-Pad1)

.save V(Net-C2-Pad1)

.save V(Net-C2-Pad2)

.save V(Net-C3-Pad1)

.save V(Net-C4-Pad1)

.save V(Net-C4-Pad2)

.save V(Net-C5-Pad1)

.save V(Net-C6-Pad1)

.save V(Net-C6-Pad2)

.save V(Net-C7-Pad1)

.save V(Net-C8-Pad2)

.save V(Net-R100-Pad2)

.save V(VDD)

.save V(VIN)

.save V(VOUT)

.save V(VSS)

.subckt IDEAL 1 2 3 4 5

E1 5 0 1 2 1000000.0

.ends

.ac dec 10 10 1000000.0

.control

let mc_runs = 100

let run = 1

- set curplot = new

set scratch = $curplot

define tolerance(val, pct) (val + val * (pct/100) * sunif(0))

dowhile run <= mc_runs

alter C1 = tolerance(76.9n, 5)

alter C2 = tolerance(6.83n, 5)

alter C3 = tolerance(15.0n, 5)

alter C4 = tolerance(5.99n, 5)

alter C5 = tolerance(17.9n, 5)

alter C6 = tolerance(4.42n, 5)

alter C7 = tolerance(27.5n, 5)

alter C8 = tolerance(2.29n, 5)

alter R1 = tolerance(1000, 2)

alter R10 = tolerance(1000, 2)

alter R100 = tolerance(0, 2)

alter R101 = tolerance(100k, 2)

alter R11 = tolerance(500, 2)

alter R12 = tolerance(1000, 2)

alter R2 = tolerance(90.9, 2)

alter R3 = tolerance(100, 2)

alter R4 = tolerance(1000, 2)

alter R5 = tolerance(500, 2)

alter R6 = tolerance(1000, 2)

alter R7 = tolerance(1000, 2)

alter R8 = tolerance(500, 2)

alter R9 = tolerance(1000, 2)

ac dec 10 10 1000000.0

set run = “$&run”

set dt = $curplot

setplot $scratch

let vout{$run}={$dt}.v(out)

setplot $dt

let run = run + 1

end

plot db({$scratch}.all)

.endc

.end

The code is almost verbatim from an example bundled with ngspice-28, in examples/Monte_Carlo/MonteCarlo.sp

It does run for a while, about 5 seconds on my MacBook Pro, so it’s clearly doing something apart from spitting out errors.

The console output is:

Circuit: KiCad schematic

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

Reference value : 1.00000e+01No. of Data Rows : 51

Error: no such function as ac304.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac305.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac306.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac307.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac308.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac309.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac310.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac311.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac312.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac313.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac314.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac315.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac316.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac317.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac318.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac319.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac320.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac321.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac322.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac323.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

Reference value : 1.00000e+01No. of Data Rows : 51

Error: no such function as ac324.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac325.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac326.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac327.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac328.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac329.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac330.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac331.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac332.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac333.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac334.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac335.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac336.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac337.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac338.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac339.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac340.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac341.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac342.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

Reference value : 1.00000e+01No. of Data Rows : 51

Error: no such function as ac343.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac344.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac345.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac346.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac347.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac348.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac349.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac350.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac351.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac352.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac353.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac354.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac355.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac356.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac357.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac358.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac359.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac360.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

Reference value : 1.00000e+01No. of Data Rows : 51

Error: no such function as ac361.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac362.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac363.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac364.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac365.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac366.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac367.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac368.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac369.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac370.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac371.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac372.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac373.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac374.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac375.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac376.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac377.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac378.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

Reference value : 1.00000e+01No. of Data Rows : 51

Error: no such function as ac379.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac380.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac381.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac382.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac383.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac384.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac385.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac386.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac387.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac388.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac389.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac390.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac391.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac392.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac393.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac394.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac395.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

Reference value : 1.00000e+01No. of Data Rows : 51

Error: no such function as ac396.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac397.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac398.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac399.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac400.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac401.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac402.v.

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

Error: no such function as ac403.v.

Error: no such vector @c1[i]

Background thread stopped with timeout = 0

Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

No. of Data Rows : 51

I can’t really tell what the problem here is… if it’s simply a matter of integrating with KiCAD, if KiCAD doesn’t know how to obtain the plot data. Or if the example is broken. (I built ngspice as a shared object so don’t have the command line to experiment with and I’m afraid building and installing a command line version will nuke the shared object installed.)

Why is it looking for “@c1[i]”?!