next up previous contents index
Next: Example Monte Carlo Analysis Up: Margin Analysis Previous: Example Operating Range Analysis   Contents   Index

Monte Carlo Analysis

WRspice has a built-in facility for performing Monte Carlo analysis, where one or more circuit variables are set according to a random distribution, and the circuit analyzed for functionality. The file formats and operation are very similar to operating range analysis.

As in operating range analysis, a complete input file consists of three sections: a header, an executable script analyzing operation, and the circuit deck. Unlike operating range analysis, however, the header block is executed before every simulation run, so that circuit variables may be changed (not just initialized) in the header. As in operating range analysis, an ``old format'' and a ``new format'' are recognized. These formats are identical in Monte Carlo analysis, except that instead of a line containing the string .check, Monte Carlo files contain the keyword .monte. This must be the first line of the file in the old format, but can appear anywhere in a new format file. If both keywords appear in the file (not a good idea), then Monte Carlo analysis is assumed.

As with conventional circuit and command files, Monte Carlo analysis files can be sourced by simply typing in the file name. If the file name happens to conflict with a command, then the file can be input with the source command. If not in batch mode, the analysis is initiated with the check command, otherwise the analysis is performed immediately.

Monte Carlo analysis is enforced by supplying the -m option to the check command, which initiates analysis. The -m option is only necessary if the input file does not contain a .monte line. If the -r option is given, the simulations will be parceled out to remote servers, allowing parallelism in computation.

Output from a Monte Carlo run is saved in a file with base name that of the circuit, with a suffix ``.mxx'', where xx is a sequentially assigned number so as to make the file name unique. The output file name is stored in the mplot_cur shell variable.

The number of runs performed in Monte Carlo analysis is set by the checkSTP1 and checkSTP2 variables, as in operating range analysis. The number of points will be (2*checkSTP1 + 1)*(2*checkSTP2 + 1). If the values are not given, they default to 3 (49 points).

In Monte Carlo analysis, the header block is executed before each simulation. In the header block, shell variables and vectors may be set for each new trial. These variables and vectors can be used in the SPICE text to modify circuit parameters. The names of the variables used, and whether to use vectors or variables, is up to the user (variables are a little more efficient). Monte Carlo analysis does not use predefined names for parameter data. Typically, the gauss function is used to specify a random value for the variables in the header block.

It is possible to use .param defines to introduce random values in Monte Carlo analysis, as well as shell variables and vectors. Parameters defined in .param lines are recomputed at the start of each trial, before the .exec block is evaluated. Random values can be set by calling the random number generation functions (unif, aunif, gauss, agauss, limit).

Parameters are visible in the .exec block if the .exec block is defined in the same file as the circuit (directly or through an .include). Parameters are not visible in the .control block. Parameters are not visible in bound codeblocks.

There is a special echof command that allows text to be printed in the output file. This is the means by which the trial values are recorded, as there is no default recording mechanism. The file by default records only the success or failure of each run. The echof command is used exactly as the echo command. If there is no output file open, the command returns with no action. The echof command can be used in either .control or .exec blocks in the input file.

Monte Carlo results can be viewed during analysis ar afterward with the mplot command. Giving ``mplot -on'' will display results while simulating, as in operating range analysis. The display consists of (2*checkSTP1 + 1) * (2*checkSTP2 + 1) squares, as in operating range analysis, with each square indicating pass or fail. In Monte Carlo analysis, the squares are simply filled in in sequence, and their placement has nothing to do with the actual circuit values.

next up previous contents index
Next: Example Monte Carlo Analysis Up: Margin Analysis Previous: Example Operating Range Analysis   Contents   Index
Stephen R. Whiteley 2017-03-28