Using Python with ngspice

From Microlab Classes
Revision as of 14:45, 6 August 2020 by Louis Alarcon (talk | contribs)
Jump to navigation Jump to search

We can automate this process by using ngspice in batch mode, i.e. running the simulator from the command line, and reading the output file using Python, and do the processing automatically. To run ngspice at the command line, you can use ngspice <circuit file>.

One very good environment for Python3 is Spyder. You can download this for multiple platforms, and the easiest way to install Spyder is as part of the Anaconda distribution, also available for various operating systems.

Running ngspice from Python

Below is a simple Python script for running ngspice, reading its output. It uses the ngspice_link module, that contains convenient classes and functions for running ngspice from within Python.