SimCommander

class PyLTSpice.sim_batch.SimCommander(circuit_file: str, parallel_sims: int = 4, timeout=None, verbose=True, encoding='autodetect', simulator=None)[source]

Bases: SpiceEditor

The SimCommander class implements all the methods required for launching batches of LTSpice simulations. It takes a parameter the path to the LTSpice .asc file to be simulated, or directly the .net file. If an .asc file is given, the class will try to generate the respective .net file by calling LTspice with the –netlist option

Parameters:
  • circuit_file (str) – Path to the circuit to simulate. It can be either a .asc or a .net file

  • parallel_sims (int, optional) – Defines the number of parallel simulations that can be executed at the same time. Ideally this number should be aligned to the number of CPUs (processor cores) available on the machine.

  • timeout (float, optional) – Timeout parameter as specified on the os subprocess.run() function

  • verbose (bool, optional) – If True, it enables a richer printout of the program execution.

  • encoding (str, optional) – Forcing the encoding to be used on the circuit netlile read. Defaults to ‘autodetect’ which will call a function that tries to detect the encoding automatically. This however is not 100% fool proof.

  • simulator (str or Simulator, optional) – Forcing a given simulator executable.

add_LTspiceRunCmdLineSwitches(*args) None[source]

Used to add an extra command line argument such as -I<path> to add symbol search path or -FastAccess to convert the raw file into Fast Access. The arguments is a list of strings as is defined in the LTSpice command line documentation.

Parameters:

args (list[str]) – list of strings A list of command line switches such as “-ascii” for generating a raw file in text format or “-alt” for setting the solver to alternate. See Command Line Switches information on LTSpice help file.

Returns:

Nothing

static kill_all_ltspice()[source]

Function to terminate LTSpice in windows

run(run_filename: Optional[str] = None, wait_resource: bool = True, callback: Optional[Callable[[str, str], Any]] = None, timeout: float = 600) RunTask[source]

Executes a simulation run with the conditions set by the user. Conditions are set by the set_parameter, set_component_value or add_instruction functions.

Parameters:
  • run_filename (str, optional) – The name of the netlist can be optionally overridden if the user wants to have a better control of how the simulations files are generated.

  • wait_resource (bool, optional) – Setting this parameter to False will force the simulation to start immediately, irrespective of the number of simulations already active. By default the SimCommander class uses only four processors. This number can be overridden by setting the parameter ´parallel_sims´ to a different number. If there are more than ´parallel_sims´ simulations being done, the new one will be placed on hold till one of the other simulations are finished.

  • callback – The user can optionally give a callback function for when the simulation finishes so that processing can be done immediately.

  • timeout (float, optional) – Timeout to be used in waiting for resources. Default time is 600 seconds, i.e. 10 minutes.

Type:

callback: function(raw_file, log_file), optional

Returns:

The task object of type RunTask

setLTspiceRunCommand(spice_tool: Union[str, Simulator]) None[source]

Manually setting the LTSpice run command.

Parameters:

spice_tool (str or Simulator) – String containing the path to the spice tool to be used, or alternatively the Simulator object.

Returns:

Nothing

Return type:

None

updated_stats()[source]

This function updates the OK/Fail statistics and releases finished RunTask objects from memory.

Returns:

Nothing

wait_completion(timeout=None, abort_all_on_timeout=False) bool[source]

This function will wait for the execution of all scheduled simulations to complete.

Parameters:
  • timeout (int) – Cancels the wait after the number of seconds specified by the timeout. This timeout is reset everytime that a simulation is completed. The difference between this timeout and the one defined in the SimCommander instance, is that the later is implemented by the subprocess class, and the this timeout just cancels the wait.

  • abort_all_on_timeout (bool) – attempts to stop all LTSpice processes if timeout is expired.

Returns:

True if all simulations were executed successfully

Return type:

bool