11.1.10.11. Simulation

This modules implements classes to perform simulations.

class PySpice.Spice.Simulation.ACAnalysisParameters(variation, number_of_points, start_frequency, stop_frequency)[source]

Bases: PySpice.Spice.Simulation.AnalysisParameters

This class defines analysis parameters for AC analysis.

ANALYSIS_NAME = 'ac'
property number_of_points
property start_frequency
property stop_frequency
to_list()[source]
property variation
class PySpice.Spice.Simulation.AcSensitivityAnalysisParameters(output_variable, variation, number_of_points, start_frequency, stop_frequency)[source]

Bases: PySpice.Spice.Simulation.AnalysisParameters

This class defines analysis parameters for AC sensitivity analysis.

ANALYSIS_NAME = 'sens'
property number_of_points
property output_variable
property start_frequency
property stop_frequency
to_list()[source]
property variation
class PySpice.Spice.Simulation.AnalysisParameters[source]

Bases: object

Base class for analysis parameters

ANALYSIS_NAME = None
property analysis_name
to_list()[source]
class PySpice.Spice.Simulation.CircuitSimulation(circuit, **kwargs)[source]

Bases: object

Define and generate the spice instruction to perform a circuit simulation.

Warning

In some cases NgSpice can perform several analyses one after the other. This case is partially supported.

ac(variation, number_of_points, start_frequency, stop_frequency)[source]

Perform a small-signal AC analysis of the circuit where all non-linear devices are linearized around their actual DC operating point.

Examples of usage:

analysis = simulator.ac(start_frequency=10@u_kHz, stop_frequency=1@u_GHz, number_of_points=10,  variation='dec')

Note that in order for this analysis to be meaningful, at least one independent source must have been specified with an AC value. Typically it does not make much sense to specify more than one AC source. If you do, the result will be a superposition of all sources, thus difficult to interpret.

Spice examples:

.ac dec nd fstart fstop
.ac oct no fstart fstop
.ac lin np fstart fstop

The parameter variation must be either dec, oct or lin.

ac_sensitivity(output_variable, variation, number_of_points, start_frequency, stop_frequency)[source]

Compute the sensitivity of the AC values of a node voltage or voltage-source branch current to all non-zero device parameters.

Examples of usage:

analysis = simulator.ac_sensitivity(...)

Spice syntax:

.sens outvar ac dec nd fstart fstop
.sens outvar ac oct no fstart fstop
.sens outvar ac lin np fstart fstop

Spice examples:

.sens V(OUT) AC DEC 10 100 100 k
analysis_iter()[source]
property circuit
dc(**kwargs)[source]

Compute the DC transfer fonction of the circuit with capacitors open and inductors shorted.

Examples of usage:

analysis = simulator.dc(Vinput=slice(-2, 5, .01))
analysis = simulator.dc(Ibase=slice(0, 100e-6, 10e-6))
analysis = simulator.dc(Vcollector=slice(0, 5, .1), Ibase=slice(micro(10), micro(100), micro(10))) # broken ???

Spice syntax:

.dc src_name vstart vstop vincr [ src2 start2 stop2 incr2 ]

src_name is the name of an independent voltage or a current source, a resistor or the circuit temperature.

vstart, vstop, and vincr are the starting, final, and incrementing values respectively.

A second source (src2) may optionally be specified with associated sweep parameters. In this case, the first source is swept over its range for each value of the second source.

Spice examples:

.dc VIN 0 .2 5 5.0 0.25
.dc VDS 0 10 .5 VGS 0 5 1
.dc VCE 0 10 .2 5 IB 0 10U 1U
.dc RLoad 1k 2k 100
.dc TEMP -15 75 5
dc_sensitivity(output_variable)[source]

Compute the sensitivity of the DC operating point of a node voltage or voltage-source branch current to all non-zero device parameters.

Examples of usage:

analysis = simulator.dc_sensitivity('v(out)')

Spice syntax:

.sens outvar

Examples:

.sens V(1, OUT)
.sens I(VTEST)
distortion(variation, points, start_frequency, stop_frequency, f2overf1=None)[source]

Perform a distortion analysis of the circuit.

variation, points, start_frequency, stop_frequency - typical ac range parameters. if f2overf1 is specified, perform a spectral analysis, else perform a harmonic analysis.

See section 15.3.3 of ngspice manual.

  • harmonic analysis, The distof1 parameter of the AC input to the circuit must be specified. Second harmonic magnitude and phase are calculated at each circuit node.

  • Spectral analysis,

    The distof2 parameter of the AC input to the circuit must be specified as well as distof1. See the ngspice manual.

Spice syntax:

General form:

.disto dec nd fstart fstop <f2overf1 >
.disto oct no fstart fstop <f2overf1 >
.disto lin np fstart fstop <f2overf1 >

Examples:

.disto dec 10 1kHz 100 MEG
.disto dec 10 1kHz 100 MEG 0.9
initial_condition(**kwargs)[source]

Set initial condition for voltage nodes.

Usage:

simulator.initial_condition(node_name=value, ...)

General form:

.ic v(node_name)=value ...

The .ic line is for setting transient initial conditions. It has two different interpretations, depending on whether the uic parameter is specified on the .tran control line, or not. One should not confuse this line with the .nodeset line. The .nodeset line is only to help DC convergence, and does not affect the final bias solution (except for multi-stable circuits). The two indicated interpretations of this line are as follows:

  1. When the uic parameter is specified on the .tran line, the node voltages specified on the .ic control line are used to compute the capacitor, diode, BJT, JFET, and MOSFET initial conditions. This is equivalent to specifying the ic=… parameter on each device line, but is much more convenient. The ic=… parameter can still be specified and takes precedence over the .ic values. Since no dc bias (initial transient) solution is computed before the transient analysis, one should take care to specify all dc source voltages on the .ic control line if they are to be used to compute device initial conditions.

  2. When the uic parameter is not specified on the .tran control line, the DC bias (initial transient) solution is computed before the transient analysis. In this case, the node voltages specified on the .ic control lines are forced to the desired initial values during the bias solution. During transient analysis, the constraint on these node voltages is removed. This is the preferred method since it allows Ngspice to compute a consistent dc solution.

measure(analysis_type, name, *args)[source]

Add a measure in the circuit.

Examples of usage:

simulator.measure('TRAN', 'tdiff', 'TRIG AT=10m', 'TARG v(n1) VAL=75.0 CROSS=1')
simulator.measure('tran', 'tdiff', 'TRIG AT=0m', f"TARG par('v(n1)-v(derate)') VAL=0 CROSS=1")

Note: can be used with the .options AUTOSTOP to stop the simulation at Trigger.

Spice syntax:

.meas tran tdiff TRIG AT=0m TARG v(n1) VAL=75.0 CROSS=1
node_set(**kwargs)[source]

Specify initial node voltage guesses.

Usage:

simulator.node_set(node_name=value, ...)

General form:

.nodeset v(node_name)=value ...
.nodeset all=val

The .nodeset line helps the program find the DC or initial transient solution by making a preliminary pass with the specified nodes held to the given voltages. The restrictions are then released and the iteration continues to the true solution. The .nodeset line may be necessary for convergence on bistable or astable circuits. .nodeset all=val sets all starting node voltages (except for the ground node) to the same value. In general, the .nodeset line should not be necessary.

noise(output_node, ref_node, src, variation, points, start_frequency, stop_frequency, points_per_summary=None)[source]

Perform a Pole-Zero analysis of the circuit.

output_node, ref_node - output node pair. src - signal source, typically an ac voltage input. variation - must be ‘dec’ or ‘lin’ or ‘oct’ for decade, linear, or octave. points, start_frequency, stop_frequency - number of points, start and stop frequencies. points_per_summary - if specified, the noise contributions of each noise generator is produced every points_per_summary frequency points.

See section 15.3.4 of ngspice manual.

Spice syntax:

General form:

.noise v(output <,ref >) src ( dec | lin | oct ) pts fstart fstop <pts_per_summary >

Examples:

.noise v(5) VIN dec 10 1kHz 100 MEG
.noise v(5 ,3) V1 oct 8 1.0 1.0 e6 1
property nominal_temperature
operating_point()[source]

Compute the operating point of the circuit with capacitors open and inductors shorted.

options(*args, **kwargs)[source]
polezero(node1, node2, node3, node4, tf_type, pz_type)[source]

Perform a Pole-Zero analysis of the circuit.

node1, node2 - Input node pair. node3, node4 - Output node pair tf_type - should be cur for current or vol for voltage pz_type - should be pol for pole, zer for zero, or pz for combined pole zero analysis.

See section 15.3.6 of ngspice manual.

Spice syntax:

.tran tstep tstop <tstart <tmax>> <uic>
.pz node1 node2 node3 node4 cur pol
.pz node1 node2 node3 node4 cur zer
.pz node1 node2 node3 node4 cur pz
.pz node1 node2 node3 node4 vol pol
.pz node1 node2 NODE3 node4 vol zer
.pz node1 node2 node3 node4 vol pz

Examples:

.pz 1 0 3 0 cur pol
.pz 2 3 5 0 vol zer
.pz 4 1 4 1 cur pz
reset_analysis()[source]
save(*args)[source]

Set the list of saved vectors.

If no .save line is given, then the default set of vectors is saved (node voltages and voltage source branch currents). If .save lines are given, only those vectors specified are saved.

Node voltages may be saved by giving the node_name or v(node_name). Currents through an independent voltage source (including inductor) are given by i(source_name) or source_name#branch. Internal device data are accepted as @dev[param].

If you want to save internal data in addition to the default vector set, add the parameter all to the additional vectors to be saved.

property save_currents

Save all currents.

save_internal_parameters(*args)[source]

This method is similar to`save` but assume all.

str_options(unit=True)[source]
property temperature
transfer_function(outvar, insrc)[source]

The python arguments to this function should be two strings, outvar and insrc.

ngspice documentation as follows:

General form:

.tf outvar insrc

Examples:

.tf v(5, 3) VIN
.tf i(VLOAD) VIN

The .tf line defines the small-signal output and input for the dc small-signal analysis. outvar is the small signal output variable and insrc is the small-signal input source. If this line is included, ngspice computes the dc small-signal value of the transfer function (output/input), input resistance, and output resistance. For the first example, ngspice would compute the ratio of V(5, 3) to VIN, the small-signal input resistance at VIN, and the small signal output resistance measured across nodes 5 and 3

transient(step_time, end_time, start_time=0, max_time=None, use_initial_condition=False)[source]

Perform a transient analysis of the circuit.

Examples of usage:

analysis = simulator.transient(step_time=1@u_us, end_time=500@u_us)
analysis = simulator.transient(step_time=source.period/200, end_time=source.period*2)

Spice syntax:

.tran tstep tstop <tstart <tmax>> <uic>
class PySpice.Spice.Simulation.CircuitSimulator(circuit, **kwargs)[source]

Bases: PySpice.Spice.Simulation.CircuitSimulation

This class implements a circuit simulator. Each analysis mode is performed by a method that return the measured probes.

For ac and transient analyses, the user must specify a list of nodes using the probes key argument.

DEFAULT_SIMULATOR = 'ngspice-shared'
ac(*args, **kwargs)[source]

Perform a small-signal AC analysis of the circuit where all non-linear devices are linearized around their actual DC operating point.

Examples of usage:

analysis = simulator.ac(start_frequency=10@u_kHz, stop_frequency=1@u_GHz, number_of_points=10,  variation='dec')

Note that in order for this analysis to be meaningful, at least one independent source must have been specified with an AC value. Typically it does not make much sense to specify more than one AC source. If you do, the result will be a superposition of all sources, thus difficult to interpret.

Spice examples:

.ac dec nd fstart fstop
.ac oct no fstart fstop
.ac lin np fstart fstop

The parameter variation must be either dec, oct or lin.

dc(*args, **kwargs)[source]

Compute the DC transfer fonction of the circuit with capacitors open and inductors shorted.

Examples of usage:

analysis = simulator.dc(Vinput=slice(-2, 5, .01))
analysis = simulator.dc(Ibase=slice(0, 100e-6, 10e-6))
analysis = simulator.dc(Vcollector=slice(0, 5, .1), Ibase=slice(micro(10), micro(100), micro(10))) # broken ???

Spice syntax:

.dc src_name vstart vstop vincr [ src2 start2 stop2 incr2 ]

src_name is the name of an independent voltage or a current source, a resistor or the circuit temperature.

vstart, vstop, and vincr are the starting, final, and incrementing values respectively.

A second source (src2) may optionally be specified with associated sweep parameters. In this case, the first source is swept over its range for each value of the second source.

Spice examples:

.dc VIN 0 .2 5 5.0 0.25
.dc VDS 0 10 .5 VGS 0 5 1
.dc VCE 0 10 .2 5 IB 0 10U 1U
.dc RLoad 1k 2k 100
.dc TEMP -15 75 5
dc_sensitivity(*args, **kwargs)[source]

Compute the sensitivity of the DC operating point of a node voltage or voltage-source branch current to all non-zero device parameters.

Examples of usage:

analysis = simulator.dc_sensitivity('v(out)')

Spice syntax:

.sens outvar

Examples:

.sens V(1, OUT)
.sens I(VTEST)
distortion(*args, **kwargs)[source]

Perform a distortion analysis of the circuit.

variation, points, start_frequency, stop_frequency - typical ac range parameters. if f2overf1 is specified, perform a spectral analysis, else perform a harmonic analysis.

See section 15.3.3 of ngspice manual.

  • harmonic analysis, The distof1 parameter of the AC input to the circuit must be specified. Second harmonic magnitude and phase are calculated at each circuit node.

  • Spectral analysis,

    The distof2 parameter of the AC input to the circuit must be specified as well as distof1. See the ngspice manual.

Spice syntax:

General form:

.disto dec nd fstart fstop <f2overf1 >
.disto oct no fstart fstop <f2overf1 >
.disto lin np fstart fstop <f2overf1 >

Examples:

.disto dec 10 1kHz 100 MEG
.disto dec 10 1kHz 100 MEG 0.9
classmethod factory(circuit, *args, **kwargs)[source]

Return a PySpice.Spice.Simulation.SubprocessCircuitSimulator or PySpice.Spice.Simulation.NgSpiceSharedCircuitSimulator instance depending of the value of the simulator parameter: subprocess or shared, respectively. If this parameter is not specified then a subprocess simulator is returned.

noise(*args, **kwargs)[source]

Perform a Pole-Zero analysis of the circuit.

output_node, ref_node - output node pair. src - signal source, typically an ac voltage input. variation - must be ‘dec’ or ‘lin’ or ‘oct’ for decade, linear, or octave. points, start_frequency, stop_frequency - number of points, start and stop frequencies. points_per_summary - if specified, the noise contributions of each noise generator is produced every points_per_summary frequency points.

See section 15.3.4 of ngspice manual.

Spice syntax:

General form:

.noise v(output <,ref >) src ( dec | lin | oct ) pts fstart fstop <pts_per_summary >

Examples:

.noise v(5) VIN dec 10 1kHz 100 MEG
.noise v(5 ,3) V1 oct 8 1.0 1.0 e6 1
operating_point(*args, **kwargs)[source]

Compute the operating point of the circuit with capacitors open and inductors shorted.

polezero(*args, **kwargs)[source]

Perform a Pole-Zero analysis of the circuit.

node1, node2 - Input node pair. node3, node4 - Output node pair tf_type - should be cur for current or vol for voltage pz_type - should be pol for pole, zer for zero, or pz for combined pole zero analysis.

See section 15.3.6 of ngspice manual.

Spice syntax:

.tran tstep tstop <tstart <tmax>> <uic>
.pz node1 node2 node3 node4 cur pol
.pz node1 node2 node3 node4 cur zer
.pz node1 node2 node3 node4 cur pz
.pz node1 node2 node3 node4 vol pol
.pz node1 node2 NODE3 node4 vol zer
.pz node1 node2 node3 node4 vol pz

Examples:

.pz 1 0 3 0 cur pol
.pz 2 3 5 0 vol zer
.pz 4 1 4 1 cur pz
tf(*args, **kwargs)

The python arguments to this function should be two strings, outvar and insrc.

ngspice documentation as follows:

General form:

.tf outvar insrc

Examples:

.tf v(5, 3) VIN
.tf i(VLOAD) VIN

The .tf line defines the small-signal output and input for the dc small-signal analysis. outvar is the small signal output variable and insrc is the small-signal input source. If this line is included, ngspice computes the dc small-signal value of the transfer function (output/input), input resistance, and output resistance. For the first example, ngspice would compute the ratio of V(5, 3) to VIN, the small-signal input resistance at VIN, and the small signal output resistance measured across nodes 5 and 3

transfer_function(*args, **kwargs)[source]

The python arguments to this function should be two strings, outvar and insrc.

ngspice documentation as follows:

General form:

.tf outvar insrc

Examples:

.tf v(5, 3) VIN
.tf i(VLOAD) VIN

The .tf line defines the small-signal output and input for the dc small-signal analysis. outvar is the small signal output variable and insrc is the small-signal input source. If this line is included, ngspice computes the dc small-signal value of the transfer function (output/input), input resistance, and output resistance. For the first example, ngspice would compute the ratio of V(5, 3) to VIN, the small-signal input resistance at VIN, and the small signal output resistance measured across nodes 5 and 3

transient(*args, **kwargs)[source]

Perform a transient analysis of the circuit.

Examples of usage:

analysis = simulator.transient(step_time=1@u_us, end_time=500@u_us)
analysis = simulator.transient(step_time=source.period/200, end_time=source.period*2)

Spice syntax:

.tran tstep tstop <tstart <tmax>> <uic>
class PySpice.Spice.Simulation.DCAnalysisParameters(**kwargs)[source]

Bases: PySpice.Spice.Simulation.AnalysisParameters

This class defines analysis parameters for DC analysis.

ANALYSIS_NAME = 'dc'
property parameters
to_list()[source]
class PySpice.Spice.Simulation.DcSensitivityAnalysisParameters(output_variable)[source]

Bases: PySpice.Spice.Simulation.AnalysisParameters

This class defines analysis parameters for DC sensitivity analysis.

ANALYSIS_NAME = 'sens'
property output_variable
to_list()[source]
class PySpice.Spice.Simulation.DistortionAnalysisParameters(variation, points, start_frequency, stop_frequency, f2overf1)[source]

Bases: PySpice.Spice.Simulation.AnalysisParameters

This class defines analysis parameters for distortion analysis.

ANALYSIS_NAME = 'disto'
property f2overf1
property points
property start_frequency
property stop_frequency
to_list()[source]
property variation
class PySpice.Spice.Simulation.MeasureParameters(analysis_type, name, *args)[source]

Bases: PySpice.Spice.Simulation.AnalysisParameters

This class defines measurements on analysis.

ANALYSIS_NAME = 'meas'
property parameters
to_list()[source]
class PySpice.Spice.Simulation.NoiseAnalysisParameters(output, src, variation, points, start_frequency, stop_frequency, points_per_summary)[source]

Bases: PySpice.Spice.Simulation.AnalysisParameters

This class defines analysis parameters for noise analysis.

ANALYSIS_NAME = 'noise'
property output
property points
property points_per_summary
property src
property start_frequency
property stop_frequency
to_list()[source]
property variation
class PySpice.Spice.Simulation.OperatingPointAnalysisParameters[source]

Bases: PySpice.Spice.Simulation.AnalysisParameters

This class defines analysis parameters for operating point analysis.

ANALYSIS_NAME = 'op'
class PySpice.Spice.Simulation.PoleZeroAnalysisParameters(node1, node2, node3, node4, tf_type, pz_type)[source]

Bases: PySpice.Spice.Simulation.AnalysisParameters

This class defines analysis parameters for pole-zero analysis.

ANALYSIS_NAME = 'pz'
property node1
property node2
node3()[source]
property node4
property pz_type
property tf_type
to_list()[source]
class PySpice.Spice.Simulation.TransferFunctionAnalysisParameters(outvar, insrc)[source]

Bases: PySpice.Spice.Simulation.AnalysisParameters

This class defines analysis parameters for transfer function (.tf) analysis.

ANALYSIS_NAME = 'tf'
property insrc
property outvar
to_list()[source]
class PySpice.Spice.Simulation.TransientAnalysisParameters(step_time, end_time, start_time=0, max_time=None, use_initial_condition=False)[source]

Bases: PySpice.Spice.Simulation.AnalysisParameters

This class defines analysis parameters for transient analysis.

ANALYSIS_NAME = 'tran'
property end_time
property max_time
property start_time
property step_time
to_list()[source]
property use_initial_condition