OpenSPICE: A Portable Python Circuit Simulator

[Roman Parise] and [Georgios Is. Detorakis] have created OpenSPICE a fork of the PySpice project, adding a new simulation engine written entirely in Python. This enables the same PySpice simulations to be executed on any platform that runs python (which we reckon is quite a few!) whilst leveraging the full power of the python infrastructure. Since it is a fork — for supported platforms — you can also run your simulations upon Ngspice as well as Xyce, giving options for scaling up to larger systems when required, but importantly without having to recreate your circuit from scratch.

The OpenSPICE simulator first converts the parsed netlist into a set of data structures that represent the equations describing the various parts of the system. These are then in turn passed along the scipy library “optimize.root” function which solves the system, generating a list of branch currents and node voltages. The output of the simulation is a numpy array, which can be further processed and visualized with the mathplotlib library. All pretty standard stuff in python circles. Since this is based upon PySpice, it’s also possible to use KiCAD netlists, so you have a nice way to enter those schematics. We’ve not dug into this much yet, but support for the vast libraries of spice models out there in circulation would be high up on our wish list if it already can’t handle this. This scribe will most definitely be checking this out, as LTSpice whilst good, is a bit of a pain to use and does lack the power of a Python backend!

Continue reading “OpenSPICE: A Portable Python Circuit Simulator”

Simple Wave Generation In Python (and SciPy)

[153Armstrong] did a short post on how easy it is to generate waveforms using Python. We agree it is simple, but actually, it isn’t so much Python per se, it is some pretty cool libraries (SciPy, in particular) that do all the hard work. That may be splitting hairs, but it is worth nothing that SciPy (pronounced “Sigh Pie”) also does other handy tricks like Fourier transforms, too. You can see a video of his results, below.

The code is simple and one of the commenters pointed out an even more efficient way to write the data to a WAV file. The basic idea is to create an array of samples in a buffer using some features of SciPy’s NumPy component.

Continue reading “Simple Wave Generation In Python (and SciPy)”