# Monte Carlo Analysis

In this topic:

## Multi-step

Monte Carlo runs are invoked in the same way as multi-step analyses (see General Sweep Specification). The basic syntax is:

`.analysis_name analysis_parameters SWEEP MONTE num_runs NUMCORES=num_cores`

Where:

 .analysis_name Dot statement for analysis. Either .TRAN, .AC, .DC, .NOISE, .TF analysis_parameters Specific parameters for that analysis num_runs Number of runs num_cores Specify the number of processor cores to use.

### Examples

Run 10 Monte Carlo runs for 1mS transient analysis

`.TRAN 1m SWEEP MONTE 10`

Run 1000 Monte Carlo steps for 1mS transient analysis using 4 processor cores. This will split the 1000 steps into 4 cores with each running 250 steps

`.TRAN 1m SWEEP MONTE 1000 NUMCORES=4`

100 Runs of a DC Sweep

`.DC V1 0 5 0.01 SWEEP MONTE 100`

AC sweep of voltage source V5 from -300mV to 300mV. Repeat 50 times

`.AC DEVICE=V5 LIN 100 -300m 300m F=100000 SWEEP MONTE 50`

## Single Step Sweep

Monte Carlo sweep is one of the eight modes available to the swept analysis modes, .AC, .DC .NOISE and .TF. The other modes are explained in General Sweep Specification. The general syntax is:

`.analysis_name MONTE num_points analysis_parameters`

Where:

 .analysis_name Dot statement for analysis. Either .AC, .DC, .NOISE, .TF analysis_parameters Specific parameters for that analysis num_points Number of points in sweep

### Examples

1000 point Monte Carlo sweep.

`.DC MONTE 1000`

AC Monte Carlo sweep 100 steps. Frequency = 10K. This is useful if - say - you are interested in the gain of an amplifier at one frequency and it needs to lie within a defined tolerance. The analysis defined by the following line will take very little time even for a large circuit.

`.AC MONTE 100 F=10K`

## Monte Carlo Log File

Monte Carlo analysis generates an XML data file called an MSW file. (Monte Carlo, Sensitivity, Worst-case). The file contains the values of the parameters actually used in each run along with a seed value used to seed the random number generator.

The front-end can generate a user-readable HTML file from the MSW file.

The generation of the MSW file can be disabled with the NOMCLOG parameter on the analysis line. Note that with single-step sweeps, the generation of this file can significantly affect the overall simulation time.

The 'Seed' values displayed for each run at the top are the values used to seed the random number generator. These can be used to set the SEED option in order to repeat a particular random set. See below for more details.

## Seeding the Random Number Generator

The random variations are created using a pseudo random number sequence. The sequence can be seeded such that it always produces the same sequence of numbers for a given seed. In Monte Carlo analysis, the random number generator is seeded with a new value at the start of each run and this seed value is displayed in the log file (see above). It is also possible to fix the first seed that is used using the SEED option. This makes it possible to repeat a run. To do this, note the seed value of the run of interest then add the line:

`.OPTIONS SEED=seed_value`

For example if you wanted to repeat run 2 in the above example you would add this line:

`.OPTIONS SEED=1521158126`

The first run of each Monte Carlo analysis will use the same random values as run 2 above. Note this assumes that only changes in values are made to the circuit. Any topology change will upset the sequence.