PySpice-org / PySpice

Simulate electronic circuit using Python and the Ngspice / Xyce simulators
https://pyspice.fabrice-salvaire.fr
GNU General Public License v3.0
650 stars 170 forks source link

Ngspice 28 is unsupported #119

Closed minecraft2048 closed 6 years ago

minecraft2048 commented 6 years ago

Environment (OS, Python version, PySpice version, simulator)

OS: Arch Linux Pyspice version:

$  pip show pyspice
Name: PySpice
Version: 1.2.0
Summary: Simulate electronic circuit using Python and the Ngspice / Xyce simulators
Home-page: https://github.com/FabriceSalvaire/PySpice
Author: Fabrice Salvaire
Author-email: fabrice.salvaire@orange.fr
License: GPLv3
Location: /usr/lib/python3.6/site-packages
Requires: ply, cffi, matplotlib, numpy, scipy, PyYAML
Required-by: 

Python version:

 $  python -V
Python 3.6.5

Ngspice version:

ngspice -v
ngspice compiled from ngspice revision 28
Written originally by Berkeley University
Currently maintained by the NGSpice Project

Copyright (C) 1985-1996,  The Regents of the University of California
Copyright (C) 1999-2011,  The NGSpice Project

Expected Behaviour

The example runs

Actual Behaviour

It crashes with this debug log:

2018-06-08 10:15:30,580 - PySpice.Spice.NgSpice.Shared.NgSpiceShared.new_instance - INFO - New instance for id 0
2018-06-08 10:15:30,642 - PySpice.Spice.NgSpice.Shared.NgSpiceShared._load_library - DEBUG - Load libngspice.so
2018-06-08 10:15:30,957 - PySpice.Spice.NgSpice.Shared.NgSpiceShared.exec_command - DEBUG - Execute command: version -f
2018-06-08 10:15:30,958 - PySpice.Spice.NgSpice.Shared.NgSpiceShared._get_version - DEBUG - Ngspice version 28 with extensions: CIDER, XSPICE
2018-06-08 10:15:30,958 - PySpice.Spice.NgSpice.Shared.NgSpiceShared._init_ngspice - ERROR - Unsupported Ngspice version 28

Steps to reproduce the behaviour

I'm following this example: https://pyspice.fabrice-salvaire.fr/examples/resistor/voltage-divider.html on IPython

The question is which version of Ngspice that is supported?

FabriceSalvaire commented 6 years ago

fixed in 62d08ea

awade commented 5 years ago

Doesn't look like this fix (62d08ea) has made it to the latest release on pip. I just did a fresh install of pyspice using pip and its not in PySpice/Spice/NgSpice/SimulationType.py, I had to add it manually.

It looks like release 1.2 (June 7, 2018) just predates this bug fix. Is it possible to up the release version number so we don't have to manually add changes in #62d08ea every we do a pip install?

SeongRyong0726 commented 4 years ago

Hi, I'm not sure whether my problem is same to that or not. In my case, .simulator doesn't work... please help me..

2020-01-10 23:30:39,656 - PySpice.Spice.NgSpice.Shared.NgSpiceShared - Shared.INFO - New instance for id 0


CDefError Traceback (most recent call last)

in 4 TB.SetupCir() 5 #Run the AC Bode Simulation ----> 6 TB.Simulate() 7 #View Bode Simulation 8 TB.PlotResults() in Simulate(self, fMin, fMax) 55 """ 56 ---> 57 simulator = self.simulator(temperature=25, nominal_temperature=25) 58 self.results = simulator.ac(start_frequency=fMin@u_Hz, stop_frequency=fMax@u_Hz, number_of_points=10, variation='dec') 59 ~\Anaconda3\envs\py36\lib\site-packages\PySpice\Spice\Netlist.py in simulator(self, *args, **kwargs) 1294 def simulator(self, *args, **kwargs): 1295 -> 1296 return CircuitSimulator.factory(self, *args, **kwargs) ~\Anaconda3\envs\py36\lib\site-packages\PySpice\Spice\Simulation.py in factory(cls, circuit, *args, **kwargs) 706 707 if sub_cls is not None: --> 708 return sub_cls(circuit, *args, **kwargs) 709 else: 710 raise ValueError('Unknown simulator type') ~\Anaconda3\envs\py36\lib\site-packages\PySpice\Spice\NgSpice\Simulation.py in __init__(self, circuit, **kwargs) 97 ngspice_shared = kwargs.get('ngspice_shared', None) 98 if ngspice_shared is None: ---> 99 self._ngspice_shared = NgSpiceShared.new_instance() 100 else: 101 self._ngspice_shared = ngspice_shared ~\Anaconda3\envs\py36\lib\site-packages\PySpice\Spice\NgSpice\Shared.py in new_instance(cls, ngspice_id, send_data) 329 else: 330 cls._logger.info("New instance for id {}".format(ngspice_id)) --> 331 instance = cls(ngspice_id=ngspice_id, send_data=send_data) 332 cls._instances[ngspice_id] = instance 333 return instance ~\Anaconda3\envs\py36\lib\site-packages\PySpice\Spice\NgSpice\Shared.py in __init__(self, ngspice_id, send_data) 347 self._stderr = [] 348 --> 349 self._load_library() 350 self._init_ngspice(send_data) 351 ~\Anaconda3\envs\py36\lib\site-packages\PySpice\Spice\NgSpice\Shared.py in _load_library(self) 365 api_path = os.path.join(os.path.dirname(__file__), 'api.h') 366 with open(api_path) as f: --> 367 ffi.cdef(f.read()) 368 369 if not self._ngspice_id: ~\Anaconda3\envs\py36\lib\site-packages\cffi\api.py in cdef(self, csource, override, packed, pack) 110 packed=True). 111 """ --> 112 self._cdef(csource, override=override, packed=packed, pack=pack) 113 114 def embedding_api(self, csource, packed=False, pack=None): ~\Anaconda3\envs\py36\lib\site-packages\cffi\api.py in _cdef(self, csource, override, **options) 124 with self._lock: 125 self._cdef_version = object() --> 126 self._parser.parse(csource, override=override, **options) 127 self._cdefsources.append(csource) 128 if override: ~\Anaconda3\envs\py36\lib\site-packages\cffi\cparser.py in parse(self, csource, override, packed, pack, dllexport) 356 'packed': pack, 357 'dllexport': dllexport} --> 358 self._internal_parse(csource) 359 finally: 360 self._options = prev_options ~\Anaconda3\envs\py36\lib\site-packages\cffi\cparser.py in _internal_parse(self, csource) 396 else: 397 realtype, quals = self._get_type_and_quals( --> 398 decl.type, name=decl.name, partial_length_ok=True) 399 self._declare('typedef ' + decl.name, realtype, quals=quals) 400 elif decl.__class__.__name__ == 'Pragma': ~\Anaconda3\envs\py36\lib\site-packages\cffi\cparser.py in _get_type_and_quals(self, typenode, name, partial_length_ok) 629 if isinstance(type, pycparser.c_ast.Struct): 630 # 'struct foobar' --> 631 tp = self._get_struct_union_enum_type('struct', type, name) 632 return tp, quals 633 # ~\Anaconda3\envs\py36\lib\site-packages\cffi\cparser.py in _get_struct_union_enum_type(self, kind, type, name, nested) 776 # 777 if tp.fldnames is not None: --> 778 raise CDefError("duplicate declaration of struct %s" % name) 779 fldnames = [] 780 fldtypes = [] CDefError: :7: duplicate declaration of struct ngcomplex
tadeussilver commented 4 years ago

I have one of the errors

---------------------------------------------------------------------------

AttributeError                            Traceback (most recent call last)

<ipython-input-6-475d4280ae1b> in <module>()
----> 1 simulator = circuit.simulator(temperature=25, nominal_temperature=25)
      2 analysis = simulator.ac(start_frequency=1@u_Hz, stop_frequency=1@u_MHz, number_of_points=10,  variation='dec')

2 frames

/usr/local/lib/python3.6/dist-packages/PySpice/Spice/NgSpice/Simulation.py in __init__(self, circuit, **kwargs)
     97         ngspice_shared = kwargs.get('ngspice_shared', None)
     98         if ngspice_shared is None:
---> 99             self._ngspice_shared = NgSpiceShared.new_instance()
    100         else:
    101             self._ngspice_shared = ngspice_shared

AttributeError: type object 'NgSpiceShared' has no attribute 'new_instance'
FabriceSalvaire commented 4 years ago

which release are you using ?