11.1.10.7.3. Shared

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.

Warning

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.

Warning

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.

class PySpice.Spice.NgSpice.Shared.Plot(simulation, plot_name)[source]

Bases: dict

This class implements a plot in a simulation output.

Public Attributes:

plot_name

class PySpice.Spice.NgSpice.Shared.Vector(ngspice_shared, name, type_, data)[source]

Bases: object

This class implements a vector in a simulation output.

Public Attributes:

data

name

to_waveform(abscissa=None, to_real=False, to_float=False)[source]

Return a PySpice.Probe.WaveForm instance.