Package: ahkab
a SPICE-like electronic circuit simulator written in PythonThe 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 outthe release
notesfor
more!The whole codebase has been going through a (yet incomplete)
refactoring and documenting effort. Thenew 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
mirrorDC sweepTransient analysis, available differentiation formulas:
implicit Euler, trapezoidal, gear orders from 2 to 5. See for
example thesimulation of a Colpitts
Oscillator.AC analysisPZanalysisPeriodic steady state analysisof non-autonomous circuits,timedomainshooting and brute-force algorithms.Symbolic:Small signal analysis, AC or DC, with extraction of transfer
functions, DC gain, poles and zeros. Varioussymbolic analysis
examples on this
page.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,gwaveand others)InstallThe 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.If you need more information about the dependencies, check theInstall
notes.Usage1.ahkabcan be run as a Python libraryfromahkabimportnew_ac,runfromahkab.circuitimportCircuitfromahkab.plottingimportplot_results# calls matplotlib for youimportnumpyasnp# Define the circuitcir=Circuit('Butterworth 1kHz band-pass filter')cir.add_vsource('V1','n1',cir.gnd,dc_value=0.,ac_value=1.)cir.add_resistor('R1','n1','n2',50.)cir.add_inductor('L1','n2','n3',0.245894)cir.add_capacitor('C1','n3','n4',1.03013e-07)cir.add_inductor('L2','n4',cir.gnd,9.83652e-05)cir.add_capacitor('C2','n4',cir.gnd,0.000257513)cir.add_inductor('L3','n4','n5',0.795775)cir.add_capacitor('C3','n5','n6',3.1831e-08)cir.add_inductor('L4','n6',cir.gnd,9.83652e-05)cir.add_capacitor('C4','n6',cir.gnd,0.000257513)cir.add_capacitor('C5','n7','n8',1.03013e-07)cir.add_inductor('L5','n6','n7',0.245894)cir.add_resistor('R2','n8',cir.gnd,50.)# Define the analysisac1=new_ac(2.*np.pi*.97e3,2.*np.pi*1.03e3,1e2,x0=None)# run itres=run(cir,ac1)# plot the resultsplot_results('5th order 1kHz Butterworth filter',[('|Vn8|',"")],res['ac'],outfilename='bpf_transfer_fn.png')2.ahkabcan be run from the command line with a netlist fileThe syntax is:`$ python ahkab -o graph.dat <netlist file>`Seeahkab--helpfor command line switches,also online on the
documentation
pages.DocumentationThedocumentation is available on
RTD.There, you can find adocumentationandexamplesregarding how to simulate from a Python script.Refer to thenetlist syntax
pageif 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 modelThe development happens on thegithub
repository,Mostly on the master branch, with feature branch being created only
for special purposes or non-trivial features.Snapshots are released on a (hopefully) regular basis and are
available on theReleases pages, complete with
changelogand onPYPIPatches and pull requests are welcome!How this project was bornThis project was born when I was an enthusistic undergrad, apparently
with plenty of free time, attending “Simulazione Circuitale” (Circuit
Simulation) taught byProf. A.
Brambillaback 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. -GVBugs and patchesDoes it work? Bugs? Do you have patches? Did you run some noteworthy
simulation? Let me know! Feedback is very welcome, myemail
addressis available after a captcha.Support the development with a donationIf you wish to support the development ofahkab,*please donate to
cancer research:*Association for International Cancer Research
(eng),orFond. IRCCS Istituto Nazionale dei Tumori
(it).CreditsAuthors:Giuseppe Venturini,
with contributions fromIan DaniherandRob Crowther.Code:the modulepy3compat.pyis (c) 2013 - the Jinja team.Dependencies:many thanks to the authors ofnumpy,scipy,sympy,matplotlibandtabulate!