Skip to main content

Python for Spice

Project description

Python for Spice

Lightweight Python interface to Ngspice

Movtivation

Ngspice is an open source circuit simulator with a command line interface (CLI). It's natural to use Python to interact with the CLI, making it easier to use Ngspice for advanced design analysis.

There exists a simulator called PySpice which embeds Ngspice through its API. Python for Spice, on the other hand, is a lightweight module that facilitates Ngspice interaction. Simple classes and functions transparently create Ngspice netlists and commands. You can launch multiple analyses and convert the results to Pandas and Numpy, enabling downstream computation or plotting with Matplotlib.

A modest knowledge of Ngspice and Python is assumed.

Usage

Python for Spice requires an Ngspice design, either in the form of a netlist or a KiCad (version 7.0 or higher) schematic.

Ngspice can be used in many different ways. However, Python for Spice will interface to Ngspice only through the CLI in non-interactive mode. It creates a control section that will execute simulations in batch mode. Results from the simulation will be converted to Pandas DataFrames.

Typical Program Flow

A main Python program controls the flow. An example can be found here.

  1. import py4spice

  2. Specify paths to KiCad and Ngspice executables, and project directory

  3. Define signals of interest (node voltage, currents, etc.) with Vectors objects

  4. Use a KicadCmd object to extract and condition a netlist from a schematic

  5. Define one or more analyses (op, dc, tr, ac) with Analyses objects

  6. A Control object defines the control section. The analyses and other control functions are part of it.

  7. A Simulation Object is created and executed.

  8. The tabular results from the simulation are converted to Pandas DataFrames

  9. A Plot object can be used to encapsulate Matplotlib to view the results.

Installation

  1. install package:

python -m pip install --upgrade py4spice

  1. Download this example (a bipolar amplifier) to try out the py4spice package.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py4spice-0.0.1.tar.gz (12.9 kB view hashes)

Uploaded Source

Built Distribution

py4spice-0.0.1-py3-none-any.whl (11.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page