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.

Build Status Coverage Status PyPi version GPLv2 license DOI

News!

  • Ahkab v0.18 was released on July 12 2015, including new features, many bugfixes and improved documentation. It is recommended to upgrade. Check out the release notes for more!
  • The whole codebase has been going through a refactoring and documenting effort. It's not complete, yet, but it's improving. Take a look at the new documentation!

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.
    • Periodic steady state analysis of non-autonomous circuits, time domain shooting and brute-force algorithms.
    • Pole-zero analysis.
  • Symbolic:

An experimental pypy branch is available on Github for those who are mostly interested in the symbolic capabilities of the simulator and raw speed - be sure to install numpy for pypy first!.

Download and install

That's so easy! Check out the code from Github, or install from a tarball, or even better get the latest ahkab off PYPI with a single command:

# pip install ahkab

Notice pip will try to satisfy the dependencies for you. You may want to install them yourself with your OS package manager before running the above command. All dependencies are listed in the doc.

Run standalone

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

See ahkab --help for command line switches.

Documentation

The simulator can either be run from the command line with a netlist file or included in a python script.

Please refer to the documentation, in particular the netlist syntax page for how to write the netlist files that describe the circuit. Experience with running SPICE or other commercial simulators can be useful.

The latter option is shown briefly in the Python API doc page.

Have fun! Don't forget to report back cool simulations or any bug may you run into!

How this project was born

This project was born when I was an enthusiastic 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

Note that this project is still far from its 1.0 release. I may add new functionality at the expense of breaking stuff. Most likely I will introduce a new feature even if that means breaking backwards compatibility a couple of cases. I apologize about that. If you know how to fix the problem and you have a bit of time to spare, you can send me a pull request or a patch. :)

Does it work? Bugs? Do you have patches? Did you run some noteworthy simulation? Let me know!

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, Rob Crowther and others.

Code: Ahkab redistributes the module py3compat.py, which is (c) 2013 - the Jinja team.