This module provides a Python interface to the Ngspice shared library described in the ngspice as shared library or dynamic link library section of the Ngspice user manual.
In comparison to the subprocess interface, it provides an interaction with the simulator through commands and callbacks and it enables the usage of external voltage and current source in the circuit.
Since we don’t simulate a circuit in a fresh environment on demand, this approach is less safe than the subprocess approach. In case of bugs within Ngspice, we can expect some side effects like memory leaks or worse unexpected things.
This interface use the CFFI module to interface with the shared library. It is thus suited to run within the Pypy interpreter which implements JIT optimisation for Python.
It can also be used to experiment parallel simulation as explained in the Ngspice user manual. But it seems the Ngspice source code was designed with global variables which imply to use one copy of the shared library by worker as explained in the manual.
This interface can strongly slow down the simulation if the input or output callbacks is used. If the simulation time goes wrong for you then you need to implement the callbacks at a lower level than Python. You can have look to Pypy, Cython or a C extension module.
This class implements a plot in a simulation output.