a SPICE-like electronic circuit simulator

Project description

a SPICE-like electronic circuit simulator written in Python

The code should be easy to read and modify, the main language is Python – 2 or 3 – and it is platform-independent.

News!

• Ahkab v0.18 was released on July 18 2015, including new features, bugfixes and improved documentation. It is recommended to upgrade. Check out the release notes for more!

• The whole codebase has been going through a (yet incomplete) refactoring and documenting effort. The new documentation is available on RTD.

My resources are limited these days, so the much-needed work is proceeding slowly, albeit hopefully steadily. If you are interested and you would like to contribute to refactoring or documenting a particular feature, it would be very welcome.

Supported simulations:

• Numeric:

• Operating point, with guess computation to speed up the solution. See example: Downscaling current mirror

• DC sweep

• Transient analysis, available differentiation formulas: implicit Euler, trapezoidal, gear orders from 2 to 5. See for example the simulation of a Colpitts Oscillator.

• AC analysis

• PZ analysis

• Periodic steady state analysis of non-autonomous circuits, time domain shooting and brute-force algorithms.

• Symbolic:

The results are saved to disk, plotted or printed to stdout and can be read/processed by the most common tools (eg. Octave, gnuplot, Matlab, gwave and others)

Install

The program requires:

• the Python interpreter version 2 or 3 (at least v.2.6 for Python2, v.3.3 for Python3),

• numpy>=1.7.0, scipy>=0.14.0, sympy>=0.7.6 and tabulate>=0.7.3.

Matplotlib is strongly recommended and no plotting will work without.

Usage

1. ahkab can be run as a Python library

from ahkab import new_ac, run
from ahkab.circuit import Circuit
from ahkab.plotting import plot_results # calls matplotlib for you
import numpy as np

# Define the circuit
cir = Circuit('Butterworth 1kHz band-pass filter')

# Define the analysis
ac1 = new_ac(2.*np.pi*.97e3, 2.*np.pi*1.03e3, 1e2, x0=None)

# run it
res = run(cir, ac1)

# plot the results
plot_results('5th order 1kHz Butterworth filter', [('|Vn8|',"")], res['ac'],
outfilename='bpf_transfer_fn.png')

2. ahkab can be run from the command line with a netlist file

The syntax is:

\$ python ahkab -o graph.dat <netlist file>

See ahkab --help for command line switches, also online on the documentation pages.

Documentation

There, you can find a documentation and examples regarding how to simulate from a Python script.

Refer to the netlist syntax page if you prefer to write netlist files that describe the circuit.

Experience with running SPICE or related commercial simulators can be very useful: this is not for the faint of heart.

Development model

Patches and pull requests are welcome!

How this project was born

This project was born when I was an enthusistic undergrad, apparently with plenty of free time, attending “Simulazione Circuitale” (Circuit Simulation) taught by Prof. A. Brambilla back in Italy at the Polytechnic University of Milan.

I am grateful to prof. Brambilla for teaching one of the most interesting courses of my university years. -GV

Bugs and patches

Does it work? Bugs? Do you have patches? Did you run some noteworthy simulation? Let me know! Feedback is very welcome, my email address is available after a captcha.

Support the development with a donation

If you wish to support the development of ahkab, *please donate to cancer research:*

or

Credits

Authors: Giuseppe Venturini, with contributions from Ian Daniher and Rob Crowther.

Code: the module py3compat.py is (c) 2013 - the Jinja team.

Dependencies: many thanks to the authors of numpy, scipy, sympy, matplotlib and tabulate!

Project details

Uploaded source