Monte Carlo Simulation
Guided Tutorial

All files and samples are included in the downloads page.
This is a sample current mirror.  We will be comparing the current running through the negative terminals of the dummy voltmeters V0 and V2.


current mirror


To start, make sure all "info" lines of the netlists are commented out as spectre cannot format "info". 
We also make sure we have the netlist and deviations file prepared.

Step 1: we run the first program:  ./MCInputRandomizer.pl
But this error will show up because we did not provide enough input arguments:

Monte Carlo Simulation Input Randomizer takes a Spectre netlist and generates variations of the netlist

usage: MCInputRandomizer.pl <input_netlist.scs> <num_outputs> <deviation_file>


To properly run: ./MCInputRandomizer.pl input.scs 5 parameters.txt

This is the output.  Please note we only ran a DC Analysis:

Starting parsing deviations file parameters.txt...
Voltage Nodes:
Voltage Nodes:          V0:n V2:n
Resistor Deviation:     -0.10           Shift:  0.10
Capacitor Deviation:    0.01            Shift:  -0.10
Inductor Deviation:     0.05            Shift:  0.01
MOSFET n_bpw_18_mm
MOSFET n_zero_18_mm
MOSFET nch
        Ab:             .03
        avt:            0.1
        db_b:           0.01
        delvt:          0.1
MOSFET p_18_mm
Done parsing deviations file parameters.txt...

save  V0:n V2:n

If you check inside the results folder there should be 5 files: ls results/

input1.scs  input2.scs  input3.scs  input4.scs  input5.scs

Step 2: we run the second program:  ./MCRunSpectre.pl
Spectre should output the following five times.

Simulating `results/input5.scs' on corinth.cisl.columbia.edu at 12:48:05 AM,
        Sun Dec 12, 2004.

Warning from spectre during circuit read-in.
    IM2: `region' is not a valid parameter for an instance of `Nnch'.
        Ignored.
    IM1: `region' is not a valid parameter for an instance of `Nnch'.
        Ignored.
    IM0: `region' is not a valid parameter for an instance of `Nnch'.
        Ignored.


Circuit inventory:
              nodes 10
          equations 29
             iprobe 2
            bsim3v3 3
               cccs 3
            isource 1
            vsource 9


******************************************
DC Analysis `dc': I0 = (100e-06 -> 10e-03)
******************************************
    dc: I0 = 120.2e-06      (4 %), step = 10.58e-06       (2 %)
    dc: I0 = 144.5e-06      (8 %), step = 12.72e-06       (2 %)
    dc: I0 = 190.5e-06     (14 %), step = 16.77e-06       (2 %)
    dc: I0 = 229.1e-06     (18 %), step = 20.16e-06       (2 %)
    dc: I0 = 302e-06       (24 %), step = 26.57e-06       (2 %)
    dc: I0 = 363.1e-06     (28 %), step = 31.95e-06       (2 %)
    dc: I0 = 478.6e-06     (34 %), step = 42.11e-06       (2 %)
    dc: I0 = 575.4e-06     (38 %), step = 50.63e-06       (2 %)
    dc: I0 = 758.6e-06     (44 %), step = 66.75e-06       (2 %)
    dc: I0 = 912e-06       (48 %), step = 80.25e-06       (2 %)
    dc: I0 = 1.202e-03     (54 %), step = 105.8e-06       (2 %)
    dc: I0 = 1.445e-03     (58 %), step = 127.2e-06       (2 %)
    dc: I0 = 1.905e-03     (64 %), step = 167.7e-06       (2 %)
    dc: I0 = 2.291e-03     (68 %), step = 201.6e-06       (2 %)
    dc: I0 = 3.02e-03      (74 %), step = 265.7e-06       (2 %)
    dc: I0 = 3.631e-03     (78 %), step = 319.5e-06       (2 %)
    dc: I0 = 4.786e-03     (84 %), step = 421.1e-06       (2 %)
    dc: I0 = 5.754e-03     (88 %), step = 506.3e-06       (2 %)
    dc: I0 = 7.586e-03     (94 %), step = 667.5e-06       (2 %)

Warning from spectre at I0 = 9.12011e-03 during DC analysis `dc'.
    IM2.Nnch: Vgs has exceeded the oxide breakdown voltage of `vbox' = 4.08 V.
    IM1.Nnch: Vgs has exceeded the oxide breakdown voltage of `vbox' = 4.08 V.
    IM0.Nnch: Vgs has exceeded the oxide breakdown voltage of `vbox' = 4.08 V.

    dc: I0 = 9.12e-03      (98 %), step = 802.5e-06       (2 %)

Warning from spectre at I0 = 10e-03 during DC analysis `dc'.
    IM2.Nnch: Vgs has exceeded the oxide breakdown voltage of `vbox' = 4.08 V.
    IM1.Nnch: Vgs has exceeded the oxide breakdown voltage of `vbox' = 4.08 V.
        Further occurrences of this warning will be suppressed.

Total time required for dc analysis `dc' was 80 ms.


Warning from spectre.
    1 warning suppressed.


Aggregate audit (12:48:06 AM, Sun Dec 12, 2004):
Time used: CPU = 680 ms, elapsed = 1 s, util. = 68%.
Virtual memory used = 3.16 Mbytes.
spectre completes with 0 errors, 10 warnings, and 0 notices.


Step 3:  We now organize the output: ./MCOutputOrganizer.pl

0:I0
1:V0:n
2:V2:n

Also to check, we now have .scs files, .out files and individual RESULTnet files: ls /results

input1.out  input2.out  input3.out  input4.out  input5.out  RESULTSV0n
input1.scs  input2.scs  input3.scs  input4.scs  input5.scs  RESULTSV2n

A sample RESULTSV0n file looks like this:

# Time Trial #1 Trial #2 Trial #3 Trial #4 Trial #5 Mean Standard Deviation









0 0.0001 -0.00013202 -0.00013202 -0.00013202 -0.00013202 -0.00013202 -0.00013202 1.51E-15
1 0.000109648 -0.000143289 -0.000143289 -0.000143289 -0.000143289 -0.000143289 -0.000143289 1.57E-15
2 0.000120226 -0.000155562 -0.000155562 -0.000155562 -0.000155562 -0.000155562 -0.000155562 1.64E-15
3 0.000131826 -0.000168892 -0.000168892 -0.000168892 -0.000168892 -0.000168892 -0.000168892 1.71E-15
4 0.000144544 -0.000183373 -0.000183373 -0.000183373 -0.000183373 -0.000183373 -0.000183373 1.77E-15
5 0.000158489 -0.000199107 -0.000199107 -0.000199107 -0.000199107 -0.000199107 -0.000199107 1.84E-15
6 0.00017378 -0.000216207 -0.000216207 -0.000216207 -0.000216207 -0.000216207 -0.000216207 1.90E-15
7 0.000190546 -0.000234795 -0.000234795 -0.000234795 -0.000234795 -0.000234795 -0.000234795 1.97E-15
8 0.00020893 -0.000255004 -0.000255004 -0.000255004 -0.000255004 -0.000255004 -0.000255004 2.03E-15
9 0.000229087 -0.000276983 -0.000276983 -0.000276983 -0.000276983 -0.000276983 -0.000276983 2.09E-15
10 0.000251189 -0.00030089 -0.00030089 -0.00030089 -0.00030089 -0.00030089 -0.00030089 2.15E-15
11 0.000275423 -0.000326902 -0.000326902 -0.000326902 -0.000326902 -0.000326902 -0.000326902 2.20E-15
12 0.000301995 -0.000355211 -0.000355211 -0.000355211 -0.000355211 -0.000355211 -0.000355211 2.25E-15
13 0.000331131 -0.000386026 -0.000386026 -0.000386026 -0.000386026 -0.000386026 -0.000386026 2.30E-15
14 0.000363078 -0.000419579 -0.000419579 -0.000419579 -0.000419579 -0.000419579 -0.000419579 2.35E-15
15 0.000398107 -0.000456121 -0.000456121 -0.000456121 -0.000456121 -0.000456121 -0.000456121 2.39E-15
16 0.000436516 -0.000495928 -0.000495928 -0.000495928 -0.000495928 -0.000495928 -0.000495928 2.43E-15
17 0.00047863 -0.000539302 -0.000539302 -0.000539302 -0.000539302 -0.000539302 -0.000539302 2.46E-15
18 0.000524807 -0.000586576 -0.000586576 -0.000586576 -0.000586576 -0.000586576 -0.000586576 2.50E-15
19 0.00057544 -0.000638111 -0.000638111 -0.000638111 -0.000638111 -0.000638111 -0.000638111 2.53E-15
20 0.000630957 -0.000694306 -0.000694306 -0.000694306 -0.000694306 -0.000694306 -0.000694306 2.55E-15
21 0.000691831 -0.000755597 -0.000755597 -0.000755597 -0.000755597 -0.000755597 -0.000755597 2.58E-15
22 0.000758578 -0.000822463 -0.000822463 -0.000822463 -0.000822463 -0.000822463 -0.000822463 2.60E-15
23 0.000831764 -0.000895427 -0.000895427 -0.000895427 -0.000895427 -0.000895427 -0.000895427 2.62E-15
24 0.000912011 -0.000975066 -0.000975066 -0.000975066 -0.000975066 -0.000975066 -0.000975066 2.64E-15
25 0.001 -0.001062012 -0.001062012 -0.001062012 -0.001062012 -0.001062012 -0.001062012 2.66E-15
26 0.001096478 -0.001156957 -0.001156957 -0.001156957 -0.001156957 -0.001156957 -0.001156957 2.67E-15
27 0.001202264 -0.001260662 -0.001260662 -0.001260662 -0.001260662 -0.001260662 -0.001260662 2.69E-15
28 0.001318257 -0.00137396 -0.00137396 -0.00137396 -0.00137396 -0.00137396 -0.00137396 2.70E-15
29 0.00144544 -0.001497765 -0.001497765 -0.001497765 -0.001497765 -0.001497765 -0.001497765 2.71E-15
30 0.001584893 -0.001633078 -0.001633078 -0.001633078 -0.001633078 -0.001633078 -0.001633078 2.72E-15
31 0.001737801 -0.001780995 -0.001780995 -0.001780995 -0.001780995 -0.001780995 -0.001780995 2.73E-15
32 0.001905461 -0.001942712 -0.001942712 -0.001942712 -0.001942712 -0.001942712 -0.001942712 2.74E-15
33 0.002089296 -0.002119534 -0.002119534 -0.002119534 -0.002119534 -0.002119534 -0.002119534 2.75E-15
34 0.002290868 -0.00231288 -0.00231288 -0.00231288 -0.00231288 -0.00231288 -0.00231288 2.75E-15
35 0.002511886 -0.002524286 -0.002524286 -0.002524286 -0.002524286 -0.002524286 -0.002524286 2.76E-15
36 0.002754229 -0.002755402 -0.002755402 -0.002755402 -0.002755402 -0.002755402 -0.002755402 2.77E-15
37 0.003019952 -0.003007986 -0.003007986 -0.003007986 -0.003007986 -0.003007986 -0.003007986 2.78E-15
38 0.003311311 -0.003283872 -0.003283872 -0.003283872 -0.003283872 -0.003283872 -0.003283872 2.78E-15
39 0.003630781 -0.003584925 -0.003584925 -0.003584925 -0.003584925 -0.003584925 -0.003584925 2.79E-15
40 0.003981072 -0.003912934 -0.003912934 -0.003912934 -0.003912934 -0.003912934 -0.003912934 2.79E-15
41 0.004365158 -0.004269441 -0.004269441 -0.004269441 -0.004269441 -0.004269441 -0.004269441 2.79E-15
42 0.004786301 -0.004655443 -0.004655443 -0.004655443 -0.004655443 -0.004655443 -0.004655443 2.79E-15
43 0.005248075 -0.005070926 -0.005070926 -0.005070926 -0.005070926 -0.005070926 -0.005070926 2.77E-15
44 0.005754399 -0.005514214 -0.005514214 -0.005514214 -0.005514214 -0.005514214 -0.005514214 2.75E-15
45 0.006309573 -0.005981197 -0.005981197 -0.005981197 -0.005981197 -0.005981197 -0.005981197 2.70E-15
46 0.00691831 -0.006464658 -0.006464658 -0.006464658 -0.006464658 -0.006464658 -0.006464658 2.64E-15
47 0.007585776 -0.006954142 -0.006954142 -0.006954142 -0.006954142 -0.006954142 -0.006954142 2.56E-15
48 0.008317638 -0.007436692 -0.007436692 -0.007436692 -0.007436692 -0.007436692 -0.007436692 2.48E-15
49 0.009120108 -0.007898362 -0.007898362 -0.007898362 -0.007898362 -0.007898362 -0.007898362 2.42E-15
50 0.01 -0.00832586 -0.00832586 -0.00832586 -0.00832586 -0.00832586 -0.00832586 2.39E-15



Step 4:  We now organize the output: ./MCMakeGraph.pl

This will give the error:   Usage: MCMakeGraph.pl -f out.gnu -o out.ps -t 'graph title' -x 'x label' -y 'y label [file1] [file2] ... [filen]'
Because we didn't specify what files to print. 
The user can also specify options including:

-t  =  Title
-x = X Axis Label
-y = YAxis Label
-f = Gnuplot File
-o = Gnuplot Output File



We choose to print all Result nets:  ./MCMakeGraph.pl -t Title results/RESULTSV*   <--We set the title to be "Title"


If nothing is specified, the following default names will appear:

 ./MCMakeGraph.pl  results/RESULTSV*

Graph  Title:  Title
X Axis Label:  X Label
Y Axis Label:  Y Label
GnuPlot File:  out.gnu
Graph   File:  out.ps
Can't exec "gnuplot": No such file or directory at ./MCMakeGraph.pl line 82.
     <--Unfortunately, our default shell does not have GNUPLOT

After running gnuplot, a postcript should be created.  To view, try running  ggv out.ps

output graph


In total, there should be 12 files created in the results/ directory: ls /results

input1.out  input2.out  input3.out  input4.out  input5.out  out.gnu  RESULTSV0n
input1.scs  input2.scs  input3.scs  input4.scs  input5.scs  out.ps   RESULTSV2n



If you have any questions, please email me at hch2007@columbia.edu