-
Notifications
You must be signed in to change notification settings - Fork 174
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
Fix NgSpice shared FFI duplication #94
base: master
Are you sure you want to change the base?
Conversation
Also, for anyone having this issue - a temporary workaround, without having to modify PySpice sources, is to reset the FFI before constructing the object: class Shared(NgSpiceShared):
def __init__(self, inputs, dt):
PySpice.Spice.NgSpice.Shared.ffi = FFI()
super().__init__() |
Thanks for reporting this issue. Could you explain a bit more what you are doing ? Do you mean simulate in parallel a circuit ? As far I know it requires several ngspice libraries clones (cf. user manual). |
Not necessairly in parallel, but in the same Python script. Right now, even the code I linked to, when pasted twice, will fail with the error I described. |
I believe the wrapper must be a singleton due to ngspice design. Could you provide a basic example ? To be sure on the use case. |
A dumb example: https://gist.github.com/akrasuski1/d4a0e5c524202b0c3aa2511159101d91 There, I create two experiments, one with voltage divider driven by a sine source, the other with cosine (yeah, I know they are the same, but imagine cosine was square or something). I would expect to be able to analyze the same circuit using both voltage sources (one at a time), but instead, the code crashes. |
Thanks it is now clear. |
Use case is
But It is a limitation of NgSpice since we cannot instantiate more than one simulator. A solution is to implement a switch in the callback :
|
I am getting the exact same error originally described (CDefError: duplicate declaration of struct ngcomplex), except I am am getting it when I run the external source example https://pyspice.fabrice-salvaire.fr/examples/ngspice-shared/external-source.html as written, without trying to create multiple instances. |
How do you run this example ? |
I was running it out of a ipython notebook, but I think I found the issue. It was with the kernel, not the example. Now, however, I'm getting the following errors:
|
only first is an error, you have to check your ngspice installation, on Linux /usr/share/ngspice/scripts/spinit |
I'm on windows 10, the init file looks good; it's in Program FIles\Spice64\share\ngspice\scripts. Where does the module expect to find it? |
It is not related to PySpice, but Ngspice. I don't know why your setup is wrong. |
I have the same problem on my win10 64bit setup. The Setting |
What was the issue? how did you resolve it? |
I have the same problem, can't find the init file, on Windows 10 x64. Is there any solution yet? |
@peter-ch, read the ngspice manual:
So, on OSX: export SPICE_SCRIPTS=/usr/local/Cellar/ngspice/31/share/ngspice/scripts/ |
Changing that environment variable had no effect on the error. I changed it from both Python (os.environ) and Windows GUI, same thing. 2020-04-06 21:52:52,869 - PySpice.Spice.NgSpice.Shared.NgSpiceShared - Shared.INFO - New instance for id 0 |
So is the problem fixed or no? Any updates? Thanks. |
When creating more than one
NgSpiceShared
instances, like in https://pyspice.fabrice-salvaire.fr/examples/ngspice-shared/external-source.html, for example to do two simulations in a row, there was an exception thrown from PySpice:Tracing the source of the error showed that global
ffi
variable in PySpice was filled twice with API structures, which caused it to fail with duplicate declaration error. The simple fix in pull request is to just remember that API data was already read and not do it again.