ignamv / ngspyce Goto Github PK
View Code? Open in Web Editor NEWPython bindings for ngspice simulation engine
Home Page: https://ignamv.github.io/ngspyce
License: GNU General Public License v2.0
Python bindings for ngspice simulation engine
Home Page: https://ignamv.github.io/ngspyce
License: GNU General Public License v2.0
I haven't used ngspyce in a while, but the latest two releases of ngspice have separate ngspice-28_64.zip
and ngspice-28_dll_64.zip
files, which contain executables and dll, respectively.
So the documentation I added in https://github.com/ignamv/ngspyce#getting-libngspice needs to be updated. I'm not sure where the recommended DLL installation path is now, and not sure how ngspyce should find the DLL, either.
PDF says "After compilation the executable, code models and initialization files are available in directory
C: as C:\Spice, C:\Spice64 etc." but not the DLL
I know very little about Windows development, but maybe the DLL should be registered so that ngspyce can find it regardless of physical location? Is that how that works? Or maybe it should be included with ngspyce?
Hi, thanks for sharing ngspyce.
I plan to use it for circuit simulation with netlist generated by kicad. Can you set up a document dir ?
and, how could I help in improving this project ?
Hello,
i am looking forward the implementation in derive's "power dissipation R and storage L/C" for long time. There are some trick such as referring "ngspice-28-manual.pdf" chapter 31. Unfortunately, it is not work after many trials. Hereby, could please kindly comment this as possible.
thanks
jasper
On debian ngspyce is unable to find the ngspice library.
I had to make some slight modifications to the ngspice source to get it to compile (warnings treated as errors)
But after the usual ./configure --with-shared && make && sudo makeinstall dance the ngspice library lives in
/usr/local/lib/ngspice.so.0
However since find_library('ngspice') returns ngspice.so.0
CDLL(find_library('ngspice')) fails with:
OSError: libngspice.so.0: cannot open shared object file: No such file or directory
CDLL('/usr/local/lib/'+find_library('ngspice')) on the other hand finds the lib but fails for another reason:
OSError: /usr/local/lib/libngspice.so.0: undefined symbol: wantevtdata
Hi,
I compile a windows x64 based ngspice.dll
for ngspyce and modify line 12 of ngspyce.py
as:
spice = CDLL('ngspice.dll')
I placed all ngspice
binaries and ngspice.dll
in D:/Tools/spice/bin
, and set up the PATH
environment of windows as D:\Tools\spice\bin
. ngspyce
can be loaded and it can find the dll!
In order to find spinit
file for ngspice, I set SPICE_SCRIPTS
of windows to D:\Tools\spice\share\ngspice\scripts
, and modify spinit
as
* For SPICE2 POLYs, edit the below line to point to the location
* of your codemodel.
codemodel D:/Tools/Spice/lib/ngspice/spice2poly.cm
* The other codemodels
codemodel d:/Tools/Spice/lib/ngspice/analog.cm
codemodel d:/Tools/Spice/lib/ngspice/digital.cm
codemodel d:/Tools/Spice/lib/ngspice/xtradev.cm
codemodel d:/Tools/Spice/lib/ngspice/xtraevt.cm
all the examples, lowpass_filter.py
and npn.py
work fine ! But it keeps complaining
ERROR:ngspice:Error: Library D:/Tools/Spice/lib/ngspice/spice2poly.cm couldn't be loaded!
ERROR:ngspice:Error: Library d:/Tools/Spice/lib/ngspice/analog.cm couldn't be loaded!
ERROR:ngspice:Error: Library d:/Tools/Spice/lib/ngspice/digital.cm couldn't be loaded!
ERROR:ngspice:Error: Library d:/Tools/Spice/lib/ngspice/xtradev.cm couldn't be loaded!
ERROR:ngspice:Error: Library d:/Tools/Spice/lib/ngspice/xtraevt.cm couldn't be loaded!
the quad.py
failed because spice2poly.cm
can not be loaded.
Can we solve it and enable ngspyce
for windows ?
BTW: when simulating quad.py
, ngspice seems to be much slower than LTSpice
.
Hey,
can't start the ngspyce,
the error message is here:
File "/home/borisov/Desktop/sht/ngspyce-master/examples/npn/npn.py", line 5, in <module>
import ngspyce
File "/home/borisov/anaconda2/envs/py3/lib/python3.6/site-packages/ngspyce-0.1-py3.6.egg/ngspyce/__init__.py", line 2, in <module>
from .ngspyce import *
File "/home/borisov/anaconda2/envs/py3/lib/python3.6/site-packages/ngspyce-0.1-py3.6.egg/ngspyce/ngspyce.py", line 63, in <module>
spice = CDLL('libngspice.so')
File "/home/borisov/anaconda2/envs/py3/lib/python3.6/ctypes/__init__.py", line 348, in __init__
self._handle = _dlopen(self._name, mode)
OSError: libngspice.so: cannot open shared object file: No such file or directory
I'm using python2.7 and python3.6 on Ubuntu 16.10
Best,
Vadim
If I do hundreds of simulations (experimenting with circuit optimization) the memory usage just increases forever.
after 0:
['Total elapsed time: 3.081 seconds.',
'Total DRAM available = 8072.601563 MB.',
'DRAM currently available = 5075.894531 MB.',
'Total ngspice program size = 2.312500 MB.']
after 1000:
['Total elapsed time: 75.566 seconds.',
'Total DRAM available = 8072.601563 MB.',
'DRAM currently available = 3778.500000 MB.',
'Total ngspice program size = 1320.335938 MB.']
after thousands:
['Total elapsed time: 2419.410 seconds.',
'Total DRAM available = 8072.601563 MB.',
'DRAM currently available = 425.308594 MB.',
'Total ngspice program size = 2960.398438 MB.']
I'm calling ngspyce.destroy()
after each simulation, but it's still increasing continually.
I can't find any way to clear the memory except to completely restart python
Manual says
The simulation result remains in memory until the libspice library is unloaded (typically:
when the tcl script ends) or when a spice::clean command is performed.
But I don't know what spice::clean
means.
I can't call ngspyce.initalize()
to clear it, it gives an exception:
OSError: exception: access violation writing 0x0000000180610CE0
I tried remcirc
, reset
, save none
but none of them clear memory. quit
results in a stack overflow.
CKTdestroy
supposedly does it, but I don't know how to call that.
>>> import sys
>>> sys.modules[__name__].__dict__.clear()
does not clear memory but breaks lots of other things
from importlib import reload
reload(ngspyce)
doesn't clear memory
Went through the trouble of learning how to make a DLL unload() function and that doesn't clear memory either:
def unload():
kernel32 = ctypes.WinDLL('kernel32')
kernel32.FreeLibrary.argtypes = [ctypes.wintypes.HMODULE]
handle = spice._handle # obtain the DLL handle
kernel32.FreeLibrary(handle)
I am trying to change a parameter inside my netlist by doing this:
ngspyce.source('../../simulation/tb_nfet1v8_params.spice')
w=3e-6
l=0.150e-6
ngspyce.alterparams(channel_width=w, channel_length=l)
Here is my netlist (I am working with the sky130 open PDK):
** sch_path: /foss/designs/efabless-opencore/xschem/param/tb_nfet1v8_params.sch
**.subckt tb_nfet1v8_params
Vgs vg GND 1
Vds vd GND 1
XM1 vd vg GND GND sky130_fd_pr__nfet_01v8 L=channel_length W=channel_width nf=1 ad='int((nf+1)/2) * W/nf * 0.29'
+ as='int((nf+2)/2) * W/nf * 0.29' pd='2*int((nf+1)/2) * (W/nf + 0.29)' ps='2*int((nf+2)/2) * (W/nf + 0.29)'
+ nrd='0.29 / W' nrs='0.29 / W' sa=0 sb=0 sd=0 mult=1 m=1
**** begin user architecture code
.param mc_mm_switch=0
.param mc_pr_switch=0
.include /foss/pdk/sky130A/libs.tech/ngspice/corners/tt.spice
.include /foss/pdk/sky130A/libs.tech/ngspice/r+c/res_typical__cap_typical.spice
.include /foss/pdk/sky130A/libs.tech/ngspice/r+c/res_typical__cap_typical__lin.spice
.include /foss/pdk/sky130A/libs.tech/ngspice/corners/tt/specialized_cells.spice
.param channel_width=3
.param channel_length=0.15
**** end user architecture code
**.ends
.GLOBAL GND
.end
But the interpreter is giving me this (not always):
bash-4.4# python nfet_gm.py
ERROR:ngspyce.sharedspice:Error: No internal deck available
ERROR:ngspyce.sharedspice:Command 'alterparam' ignored
After running this command the program eventually segfaults during the simulations.
Is this an issue with the library? If not, maybe you could include some examples of correct usage?
the error message says
ERROR:ngspice:Error: Could not find include file lm324.model
ERROR:ngspice:Error: there aren't any circuits loaded.
ERROR:ngspice:Error: vector time not found!
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
/home/postgres/py/ngspyce/examples/quadrature_oscillator/quad.py in <module>()
11
12 # Read results
---> 13 time, vsin, vcos = map(ngspyce.vector, ['time','Vsin','Vcos'])
14 # And plot them
15 plt.plot(time*1e3, vcos, label='Vcos')
/home/postgres/py/ngspyce/ngspyce/ngspyce.py in vector(name)
208 vec = spice.ngGet_Vec_Info(name.encode('ascii'))
209 if not vec:
--> 210 raise RuntimeError('Vector {} not found'.format(name))
211 vec = vec[0]
212 if vec.v_length == 0:
RuntimeError: Vector time not found
I am using python-2.7
python-3.5
with ngspice 26-3
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.