11.1.9.6. Netlist

This modules implements circuit and subcircuit.

The definition of a netlist follows the same conventions as SPICE. For example this SPICE netlist is translated to Python like this:

.title Voltage Divider
Vinput in 0 10V
R1 in out 9k
R2 out 0 1k
.end
 circuit = Circuit('Voltage Divider')
circuit.V('input', 'in', circuit.gnd, 10)
 circuit.R(1, 'in', 'out', kilo(9))
 circuit.R(2, 'out', circuit.gnd, kilo(1))

or as a class definition:

class VoltageDivider(Circuit):

    def __init__(self, **kwargs):

        super().__init__(title='Voltage Divider', **kwargs)

        self.V('input', 'in', self.gnd, '10V')
        self.R(1, 'in', 'out', kilo(9))
        self.R(2, 'out', self.gnd, kilo(1))

The circuit attribute gnd represents the ground of the circuit or subcircuit, usually set to 0.

We can get an element or a model using its name using these two possibilities:

circuit['R1'] # dictionary style
circuit.R1    # attribute style

The dictionary style always works, but the attribute only works if it complies with the Python syntax, i.e. the element or model name is a valide attribute name (identifier), i.e. starting by a letter and not a keyword like ‘in’, cf. Python Language Reference.

We can update an element parameter like this:

circuit.R1.resistance = kilo(1)

To simulate the circuit, we must create a simulator instance using the Circuit.simulator():

simulator = circuit.simulator()
class PySpice.Spice.Netlist.AnyPinElement(netlist, name, *args, **kwargs)[source]

Bases: PySpice.Spice.Netlist.Element

copy_to(netlist)[source]
class PySpice.Spice.Netlist.Circuit(title, ground=0, global_nodes=())[source]

Bases: PySpice.Spice.Netlist.Netlist

This class implements a cicuit netlist.

To get the corresponding Spice netlist use:

circuit = Circuit()
...
str(circuit)
clone(title=None)[source]
include(path)[source]

Include a file.

parameter(name, expression)[source]

Set a parameter.

simulator(*args, **kwargs)[source]
str(simulator=None)[source]

Return the formatted desk.

str_end()[source]
class PySpice.Spice.Netlist.DeviceModel(name, modele_type, **parameters)[source]

Bases: object

This class implements a device model.

Ngspice model types:

Code Model Type
R Semiconductor resistor model
C Semiconductor capacitor model
L Inductor model
SW Voltage controlled switch
CSW Current controlled switch
URC Uniform distributed RC model
LTRA Lossy transmission line model
D Diode model
NPN NPN BJT model
PNP PNP BJT model
NJF N-channel JFET model
PJF P-channel JFET model
NMOS N-channel MOSFET model
PMOS P-channel MOSFET model
NMF N-channel MESFET model
PMF P-channel MESFET model
clone()[source]
model_type
name
parameters
class PySpice.Spice.Netlist.Element(netlist, name, *args, **kwargs)[source]

Bases: object

This class implements a base class for an element.

It use a metaclass machinery for the declaration of the parameters.

copy_to(element)[source]
detach()[source]
format_node_names()[source]

Return the formatted list of nodes.

format_spice_parameters()[source]

Return the formatted list of parameters.

name
netlist
node_names
nodes
parameter_iterator()[source]

This iterator returns the parameter in the right order.

pins
class PySpice.Spice.Netlist.ElementParameterMetaClass(class_name, base_classes, namespace)[source]

Bases: type

Metaclass to customise the element classes when they are created and to register SPICE prefix.

Element classes are of type ElementParameterMetaClass instead of type

class Resistor(metaclass=ElementParameterMetaClass):

<=>

Resistor = ElementParameterMetaClass('Foo', ...)
number_of_pins
number_of_positional_parameters
optional_parameters
parameters_from_args
positional_parameters
spice_to_parameters
class PySpice.Spice.Netlist.FixedPinElement(netlist, name, *args, **kwargs)[source]

Bases: PySpice.Spice.Netlist.Element

copy_to(netlist)[source]
class PySpice.Spice.Netlist.NPinElement(netlist, name, nodes, *args, **kwargs)[source]

Bases: PySpice.Spice.Netlist.Element

copy_to(netlist)[source]
class PySpice.Spice.Netlist.Netlist[source]

Bases: object

This class implements a base class for a netlist.

Note

This class is completed with element shortcuts when the module is loaded.

A(*args, **kwargs)
AcLine(*args, **kwargs)
AmplitudeModulatedCurrentSource(*args, **kwargs)
AmplitudeModulatedVoltageSource(*args, **kwargs)
B(*args, **kwargs)
BJT(*args, **kwargs)
BehavioralCapacitor(*args, **kwargs)
BehavioralInductor(*args, **kwargs)
BehavioralResistor(*args, **kwargs)
BehavioralSource(*args, **kwargs)
BipolarJunctionTransistor(*args, **kwargs)
C(*args, **kwargs)
CCCS(*args, **kwargs)
CCS(*args, **kwargs)
CCVS(*args, **kwargs)
Capacitor(*args, **kwargs)
CoupledInductor(*args, **kwargs)
CoupledMulticonductorLine(*args, **kwargs)
CurrentControlledCurrentSource(*args, **kwargs)
CurrentControlledSwitch(*args, **kwargs)
CurrentControlledVoltageSource(*args, **kwargs)
CurrentSource(*args, **kwargs)
D(*args, **kwargs)
Diode(*args, **kwargs)
ExponentialCurrentSource(*args, **kwargs)
ExponentialVoltageSource(*args, **kwargs)
F(*args, **kwargs)
GSSElement(*args, **kwargs)
H(*args, **kwargs)
I(*args, **kwargs)
Inductor(*args, **kwargs)
J(*args, **kwargs)
JFET(*args, **kwargs)
JunctionFieldEffectTransistor(*args, **kwargs)
K(*args, **kwargs)
L(*args, **kwargs)
LosslessTransmissionLine(*args, **kwargs)
LossyTransmission(*args, **kwargs)
M(*args, **kwargs)
MESFET(*args, **kwargs)
MOSFET(*args, **kwargs)
Mesfet(*args, **kwargs)
Mosfet(*args, **kwargs)
N(*args, **kwargs)
NonLinearCurrentSource(*args, **kwargs)
NonLinearVoltageSource(*args, **kwargs)
O(*args, **kwargs)
P(*args, **kwargs)
PieceWiseLinearCurrentSource(*args, **kwargs)
PieceWiseLinearVoltageSource(*args, **kwargs)
PulseCurrentSource(*args, **kwargs)
PulseVoltageSource(*args, **kwargs)
Q(*args, **kwargs)
R(*args, **kwargs)
RandomCurrentSource(*args, **kwargs)
RandomVoltageSource(*args, **kwargs)
Resistor(*args, **kwargs)
S(*args, **kwargs)
SemiconductorCapacitor(*args, **kwargs)
SemiconductorResistor(*args, **kwargs)
SingleFrequencyFMCurrentSource(*args, **kwargs)
SingleFrequencyFMVoltageSource(*args, **kwargs)
SingleLossyTransmissionLine(*args, **kwargs)
SinusoidalCurrentSource(*args, **kwargs)
SinusoidalVoltageSource(*args, **kwargs)
SubCircuitElement(*args, **kwargs)
TransmissionLine(*args, **kwargs)
U(*args, **kwargs)
UniformDistributedRCLine(*args, **kwargs)
V(*args, **kwargs)
VCCS(*args, **kwargs)
VCS(*args, **kwargs)
VCVS(*args, **kwargs)
VoltageControlledCurrentSource(*args, **kwargs)
VoltageControlledSwitch(*args, **kwargs)
VoltageControlledVoltageSource(*args, **kwargs)
VoltageSource(*args, **kwargs)
W(*args, **kwargs)
X(*args, **kwargs)
XSpiceElement(*args, **kwargs)
Y(*args, **kwargs)
Z(*args, **kwargs)
copy_to(netlist)[source]
element_names
elements
get_node(node, create=False)[source]
gnd
has_ground_node()[source]
model(name, modele_type, **parameters)[source]

Add a model.

model_names
models
node_names
nodes
subcircuit(subcircuit)[source]

Add a sub-circuit.

subcircuit_names
subcircuits
class PySpice.Spice.Netlist.Node(netlist, name)[source]

Bases: object

This class implements a node in the circuit. It stores a reference to the pins connected to the node.

connect(pin)[source]
disconnect(pin)[source]
is_ground_node
name
netlist
pins
class PySpice.Spice.Netlist.OptionalPin(name)[source]

Bases: object

name
class PySpice.Spice.Netlist.Pin(element, pin_definition, node)[source]

Bases: PySpice.Spice.Netlist.PinDefinition

This class implements a pin of an element. It stores a reference to the element, the name of the pin and the node.

add_current_probe(circuit)[source]

Add a current probe between the node and the pin.

The ammeter is named ElementName_PinName.

disconnect()[source]
element
node
class PySpice.Spice.Netlist.PinDefinition(position, name=None, alias=None, optional=False)[source]

Bases: object

This class defines a pin of an element.

alias
clone()[source]
name
optional
position
class PySpice.Spice.Netlist.SubCircuit(name, *nodes, **kwargs)[source]

Bases: PySpice.Spice.Netlist.Netlist

This class implements a sub-cicuit netlist.

check_nodes()[source]

Check for dangling nodes in the subcircuit.

clone(name=None)[source]
external_nodes
name
parameters

Parameters

class PySpice.Spice.Netlist.SubCircuitFactory(**kwargs)[source]

Bases: PySpice.Spice.Netlist.SubCircuit