Simulators

class PyLTSpice.sim.simulator.Simulator[source]

Bases: ABC

Pure static class template for Spice simulators. This class only defines the interface of the subclasses. The variables below shall be overridden by the subclasses. Instantiating this class will raise a SpiceSimulatorError exception.

A typical subclass for a Windows installation is:

class MySpiceWindowsInstallation(Simulator):
    spice_exe = ['<path to your own ltspice installation>']
    process_name = "<name of the process on Windows Task Manager>"

or on a Linux distribution:

class MySpiceLinuxInstallation(Simulator):
    spice_exe = ['<wine_command', '<path to your own ltspice installation>']
    process_name = "<name of the process>"

The subclasses should then implement at least the run() function as a classmethod.

@classmethod
def run(cls, netlist_file, cmd_line_switches, timeout):
    '''This method implements the call for the simulation of the netlist file. '''
    cmd_run = cls.spice_exe + ['-Run'] + ['-b'] + [netlist_file] + cmd_line_switches
    return run_function(cmd_run, timeout=timeout)

The run_function() can be imported from the simulator.py with from PyLTSpice.sim.simulator import run_function instruction.

classmethod create_from(path_to_exe, process_name=None)[source]

Creates a simulator class from a path to the simulator executable :param path_to_exe: :type path_to_exe: pathlib.Path or str :param process_name: assigning a process_name to be used for killing phantom processes :return: a class instance representing the Spice simulator :rtype: LTspice

process_name = ''
raw_extension = '.raw'
abstract classmethod run(netlist_file, cmd_line_switches, timeout)[source]

This method implements the call for the simulation of the netlist file. This should be overriden by its subclass.

spice_exe = []
abstract classmethod valid_switch(switch, switch_param) list[source]

This method validates that a switch exist and is valid. This should be overriden by its subclass.

LTSpice

class PyLTSpice.sim.ltspice_simulator.LTspice[source]

Bases: Simulator

Stores the simulator location and command line options and is responsible for generating netlists and running simulations.

classmethod create_netlist(circuit_file: Union[str, Path]) Path[source]
default_folder = '/home/docs/.wine/drive_c/Program Files/LTC/LTspiceXVII'
ltspice_args = {'FixUpSchematicFonts': ['-FixUpSchematicFonts'], 'FixUpSymbolFonts': ['-FixUpSymbolFonts'], 'I': ['-I<path>'], 'PCBnetlist': ['-PCBnetlist'], 'SOI': ['-SOI'], 'alt': ['-alt'], 'ascii': ['-ascii'], 'big': ['-big'], 'encrypt': ['-encrypt'], 'fastaccess': ['-FastAccess'], 'ini': ['- ini', '<path>'], 'max': ['-max'], 'netlist': ['-netlist'], 'norm': ['-norm'], 'sync': ['-sync'], 'uninstall': ['-uninstall']}
process_name = 'XVIIx64.exe'
classmethod run(netlist_file, cmd_line_switches, timeout)[source]

This method implements the call for the simulation of the netlist file. This should be overriden by its subclass.

spice_exe = ['wine', '/home/docs/.wine/drive_c/Program Files/LTC/LTspiceXVII/XVIIx64.exe']
spice_executable = None
spice_folder = None
classmethod valid_switch(switch, path='') list[source]

Validates a command line switch. The following options are available for LTSpice:

  • ‘alt’ : Set solver to Alternate.

  • ‘ascii’ : Use ASCII.raw files. Seriously degrades program performance.

  • ‘encrypt’Encrypt a model library.For 3rd parties wishing to allow people to use libraries without

    revealing implementation details. Not used by AnalogDevices models.

  • ‘fastaccess’: Batch conversion of a binary.rawfile to Fast Access format.

  • ‘FixUpSchematicFonts’Convert the font size field of very old user - authored schematic text to the

    modern default.

  • ‘FixUpSymbolFonts’Convert the font size field of very old user - authored symbols to the modern

    default. See Changelog.txt for application hints.

  • ‘ini <path>’ : Specify an .ini file to use other than %APPDATA%LTspice.ini

  • ‘I<path>’Specify a path to insert in the symbol and file search paths. Must be the last specified

    option.

  • ‘netlist’ : Batch conversion of a schematic to a netlist.

  • ‘normal’ : Set solver to Normal.

  • ‘PCBnetlist’: Batch conversion of a schematic to a PCB format netlist.

  • ‘SOI’ : Allow MOSFET’s to have up to 7 nodes even in subcircuit expansion.

  • ‘sync’ : Update component libraries

  • ‘uninstall’ : Executes one step of the uninstallation process. Please don’t.

Parameters:
  • switch (str) – switch to be added. If the switch is not on the list above, it should be correctly formatted with the preceding ‘-’ switch

  • path (str, optional) – path to the file related to the switch being given.

Returns:

Nothing

Return type:

None

Others

class PyLTSpice.sim.ngspice_simulator.NGspiceSimulator[source]

Bases: Simulator

Stores the simulator location and command line options and runs simulations.

default_run_switches = ['-b', '-o', '-r', '-a']
ngspice_args = {'--autorun': ['--autorun'], '--batch': ['--batch'], '--circuitfile': ['--circuitfile', '<FILE>'], '--completion': ['--completion'], '--define': ['--define', 'var_value'], '--help': ['--help'], '--interactive': ['--interactive'], '--no-spiceinit': ['--no-spiceinit'], '--output': ['--output', '<FILE>'], '--pipe': ['--pipe'], '--rawfile': ['--rawfile', '<FILE>'], '--server': ['--server'], '--soa-log': ['--soa-log', '<FILE>'], '--term': ['--term', '<TERM>'], '--version': ['--version'], '-D': ['-D', 'var_value'], '-a': ['-a'], '-b': ['-b'], '-c': ['-c', '<FILE>'], '-h': ['-h'], '-i': ['-i'], '-n': ['-n'], '-o': ['-o', '<FILE>'], '-p': ['-p'], '-q': ['-q'], '-r': ['-r'], '-s': ['-s'], '-t': ['-t', '<TERM>'], '-v': ['-v']}
process_name = 'ngspice.exe'
classmethod run(netlist_file, cmd_line_switches, timeout)[source]

This method implements the call for the simulation of the netlist file. This should be overriden by its subclass.

spice_exe = ['C:/Apps/NGSpice64/bin/ngspice.exe']
classmethod valid_switch(switch, parameter='') list[source]

Validates a command line switch. The following options are available for NGSpice:

Parameters:
  • switch (str) – switch to be added. If the switch is not on the list above, it should be correctly formatted with the preceding ‘-’ switch

  • parameter (str, optional) – parameter for the switch

Returns:

the correct formatting for the switch

Return type:

list

class PyLTSpice.sim.xyce_simulator.XyceSimulator[source]

Bases: Simulator

Stores the simulator location and command line options and runs simulations.

process_name = 'XVIIx64.exe'
classmethod run(netlist_file, cmd_line_switches, timeout)[source]

This method implements the call for the simulation of the netlist file. This should be overriden by its subclass.

spice_exe = ['C:/Program Files/Xyce 7.6 NORAD/bin/xyce.exe']
classmethod valid_switch(switch, parameter='') list[source]

Validates a command line switch. The following options are available for Xyce:

Parameters:
  • switch (str) – switch to be added. If the switch is not on the list above, it should be correctly formatted with the preceding ‘-’ switch

  • parameter (str, optional) – parameter for the switch

Returns:

the correct formatting for the switch

Return type:

list

xyce_args = {'-a': ['-a', '<path>'], '-b': ['-b'], '-capabilities': ['-capabilities'], '-count': ['-count'], '-delim': ['-delim', '<delim_option>'], '-doc': ['-doc', '<param_options>'], '-doc_cat': ['-doc_cat', '<param_options>'], '-h': ['-h'], '-hspice-ext': ['-hspice-ext', '<hsext_options>'], '-jacobian_test': ['-jacobian_test'], '-l': ['-l', '<path>'], '-license': ['-license'], '-linsolv': ['-linsolv', '<solver>'], '-max': ['-max', '<int_option>'], '-maxord': ['-maxord', '<int_option>'], '-namesfile': ['-namesfile', '<path>'], '-noise_names_file': ['-noise_names_file', '<path>'], '-norun': ['-norun'], '-nox': ['-nox', 'onoff_option'], '-o': ['-o', '<basename>'], '-param': ['-param', '<param_options>'], '-per-processor': ['-per-processor'], '-prf': ['-prf', '<path>'], '-quiet': ['-quiet'], '-r': ['-r', '<path>'], '-randseed': ['-randseed', '<int_option>'], '-redefined_params': ['-redefined_params', '<redef_param_option>'], '-remeasure': ['-remeasure', '<path>'], '-rsf': ['-rsf', '<path>'], '-subckt_multiplier': ['-subckt_multiplier', '<truefalse_option>'], '-syntax': ['-syntax'], '-v': ['-v']}