Projets:Perso:2014:PySpice

From Electrolab
Jump to: navigation, search
PySpice
Auteur Fabrice
Tags du projet spice, berkeley, ngspice, soft, python
Utilisateur final Simuler avec Berkeley Spice en Open Source et sans se prendre la tête avec TclSpice
Type de projet

Projet personnel de Fabrice

Projet PySpice

Intégrer le simulateur de circuit Berkeley SPICE (ngspice) dans l’environnement Python.




English Resume

PySpice is a Python library which interplay with Berkeley SPICE, the industrial circuit simulator reference.

The PySpice home page is located https://pyspice.fabrice-salvaire.fr

PySpice is born as a personal project to relearn electronics where circuit simulation is a part of this goal. Since I use the Python language every day, I quickly feel the need to plug SPICE and Python.

The aim of PySpice is to address several needs:

  • SPICE language is fine to describe circuits, but it lacks a real language for circuit steering. By contrast Python is a powerful high level, oriented object and dynamic language which is perfectly suited for steering and reusing circuit. But it comes at the price its more general syntax is less fluent than SPICE for circuit description.
  • Ngspice provides some extension to Berkeley SPICE for data analysis, but its interactive environment or TCL module are now outdated. By contrast Python has scientific framework like Numpy and Matplotlib that compete with Matlab.
  • Ngspice source code is derived from Berkeley SPICE and thus has a very old basis. Moreover the sources are poorly documented. So it is really difficult to understand how it works and modify it. PySpice could serve to easily experiment extension.

As opposite to other SPICE derivatives, PySpice focus on programming and not on graphical user interface. Thus it does not feature a schematic capture editor and we cannot pickup a node or an element and plot the associated waveform. Moreover we can notice the Modelica language treats diagrams as annotations. A choice which I consider judicious. Thus we can imagine to follow the same principle and extend PySpice later.

The main features of PySpice are:

  • actually PySpice only supports the Ngspice flavour
  • an oriented-object API to describe circuit in a way similar to SPICE
  • a library and model manager that index recursively a directory
  • an incomplete SPICE parser (mainly used for the library and model indexer)
  • a SPICE server to run the simulator and to get back the result as Numpy array
  • some data analysis add-on

Since PySpice is born with a learning goal, many examples are provided with the sources. These examples could serve as a learning material. A tool to generate an HTML and PDF documentation is included in the tools directory. This tool could be extended to generate IPython Notebook as well.

Présentation de PySpice

PySpice est une bibliothèque écrit en Python qui permet d'intégrer le simulateur de circuit Berkeley SPICE dans l'environnement Python.

L'adresse de la page du projet est https://pyspice.fabrice-salvaire.fr

PySpice est né du projet personnel de me replonger dans l'électronique, qui m'a amené à utiliser Ngspice pour la simulation de circuit. Du faîte que j'utilise le langage Python au quotidien, j'ai rapidement ressenti le besoin d'interconnecter les deux.

Le but de PySpice est d'adresser les besoins suivants:

  • le langage SPICE est bien adapté pour la description des circuits, mais les choses se corsent lorsqu'il s'agit de paramétrer un circuit. Il manque un vrai langage de programmation. Le langage Python qui est un langage de haut niveau, orienté objet et dynamique et de plus une référence dans le monde scientifique, est particulièrement bien adapté pour cela.
  • Ngspice dispose d'outils pour l'analyse de données, mais ceux-ci sont bien obsolète par rapport à l'environnement Python et ses bibliothèques scientifiques tel que Numpy et Matplotlib qui font jeu égale avec Matlab.
  • Le code source de Ngspice est bien ancien et quasiment pas documenté. PySpice pourrait servir de base à des développements futurs.

Contrairement à d'autres clones de SPICE, PySpice est orienté programmation et ne dispose donc pas d'interface graphique. Ceci est à rapprocher de la manière dont le langage Modelica traite les schémas sous la forme d'annotations.

Les fonctionnalités principales de PySpice sont:

  • actuellement seul Ngspice est supporté comme backend
  • une API orienté objet pour décrire les circuits
  • un indexeur de bibliothèques et modèles
  • un analyseur syntaxique (partiel) du langage SPICE
  • une interface entre le simulateur Ngspice et Python qui convertit la simulation en tableaux Numpy
  • des outils d'analyse de données

Comme PySpice est né dans une optique d'apprentissage, une série d'exemples est fournit avec les sources. Ces exemples peuvent servir de support pour un apprentissage de l'électronique.