Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ngspyce using ngspice.dll under windows ? #5

Closed
liubenyuan opened this issue Mar 1, 2016 · 3 comments
Closed

ngspyce using ngspice.dll under windows ? #5

liubenyuan opened this issue Mar 1, 2016 · 3 comments

Comments

@liubenyuan
Copy link
Collaborator

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.

@endolith
Copy link
Collaborator

I got 4 examples to work: lowpass_filter.py and npn.py quad.py quadosc,py.

Downloaded ngspice.dll and related files from http://ngspice.sourceforge.net/shared.html

Modified ngspyce.py because of the path issue:

import os
os.chdir('C:/Users/ ... ng_start64_binaries/bin/')
spice = CDLL('ngspice.dll')

also had to install under a Python 3 environment in Anaconda because it uses things like list.clear() that are not in Python 2?

@endolith
Copy link
Collaborator

Found this http://stackoverflow.com/a/13277363/125507

and changed my code to this:

if os.name == 'nt':  # Windows
    curr_dir_before = os.getcwd()
    os.chdir('C:/Users/.../ng_start64_binaries/bin/')
    spice = CDLL('ngspice')
    os.chdir(curr_dir_before)
else:
    # Probably Linux?
    spice = CDLL('libngspice.so')

ngspice-26plus-master-32.7z also has ngspice.dll but the folder structure is different?

@endolith
Copy link
Collaborator

endolith commented Feb 3, 2017

BTW: when simulating quad.py, ngspice seems to be much slower than LTSpice.

Maybe related to this line of spinit?:

** set the number of threads in openmp
** default (if compiled with --enable-openmp) is: 2
set num_threads=4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants