Kreijstal / PySpice

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

Trying to run examples with devel2 branch #3

Open Trophime opened 1 week ago

Trophime commented 1 week ago

Hi, I would like to use ngspice 44 with pyspice. I'm trying to run examples and I run into this kind of problems:

python spice-parser/bootstrap-example.py
2025-02-05 10:34:49,149 - PySpice.Doc.ExampleTools.find_libraries - INFO - SPICE library path is /workspaces/PySpice/examples/spice-library
2025-02-05 10:34:49,149 - PySpice.Spice.Library.Library.Library.__init__ - INFO - Initialize library...
2025-02-05 10:34:49,149 - PySpice.Spice.Library.Library.Library.scan - INFO - Scan /workspaces/PySpice/examples/spice-library...
2025-02-05 10:34:49,149 - PySpice.Spice.Library.SpiceInclude.SpiceInclude.load_yaml - INFO - Load /workspaces/PySpice/examples/spice-library/discrete-semiconductors/transistors/ptm_65nm_pmos_bulk.yaml
2025-02-05 10:34:49,150 - PySpice.Spice.Library.SpiceInclude.SpiceInclude.load_yaml - INFO - Load /workspaces/PySpice/examples/spice-library/discrete-semiconductors/transistors/ptm_65nm_nmos_bulk.yaml
2025-02-05 10:34:49,151 - PySpice.Spice.Library.SpiceInclude.SpiceInclude.load_yaml - INFO - Load /workspaces/PySpice/examples/spice-library/discrete-semiconductors/transistors/2N2222A.yaml
2025-02-05 10:34:49,152 - PySpice.Spice.Library.SpiceInclude.SpiceInclude.parse - INFO - Parse /workspaces/PySpice/examples/spice-library/discrete-semiconductors/transistors/MOSFET/irf150.lib
line=[22:22] ELEMENT / CONTROL COMMAND
    M1 9 7 8 8 MM L=100u W=100u ;  ast=M1 9 7 8 8 MM L=100u W=100u first_set_position=5
ElementData.elements=dict_keys([])
self._letter=M
Traceback (most recent call last):
  File "/workspaces/PySpice/examples/spice-parser/bootstrap-example.py", line 27, in <module>
    spice_library = SpiceLibrary(libraries_path)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspaces/PySpice/pyspicedev-env/lib/python3.11/site-packages/PySpice-1.6-py3.11.egg/PySpice/Spice/Library/Library.py", line 87, in __init__
    self.scan()
  File "/workspaces/PySpice/pyspicedev-env/lib/python3.11/site-packages/PySpice-1.6-py3.11.egg/PySpice/Spice/Library/Library.py", line 172, in scan
    self._handle_library(path)
  File "/workspaces/PySpice/pyspicedev-env/lib/python3.11/site-packages/PySpice-1.6-py3.11.egg/PySpice/Spice/Library/Library.py", line 177, in _handle_library
    spice_include = SpiceInclude(path)
                    ^^^^^^^^^^^^^^^^^^
  File "/workspaces/PySpice/pyspicedev-env/lib/python3.11/site-packages/PySpice-1.6-py3.11.egg/PySpice/Spice/Library/SpiceInclude.py", line 278, in __init__
    self.parse()
  File "/workspaces/PySpice/pyspicedev-env/lib/python3.11/site-packages/PySpice-1.6-py3.11.egg/PySpice/Spice/Library/SpiceInclude.py", line 365, in parse
    spice_file = SpiceFile(self._path)
                 ^^^^^^^^^^^^^^^^^^^^^
  File "/workspaces/PySpice/pyspicedev-env/lib/python3.11/site-packages/PySpice-1.6-py3.11.egg/PySpice/Spice/Parser/HighLevelParser.py", line 1278, in __init__
    self.parse_file(path)
  File "/workspaces/PySpice/pyspicedev-env/lib/python3.11/site-packages/PySpice-1.6-py3.11.egg/PySpice/Spice/Parser/HighLevelParser.py", line 1167, in parse_file
    self._parse()
  File "/workspaces/PySpice/pyspicedev-env/lib/python3.11/site-packages/PySpice-1.6-py3.11.egg/PySpice/Spice/Parser/HighLevelParser.py", line 1152, in _parse
    self.analyse()
  File "/workspaces/PySpice/pyspicedev-env/lib/python3.11/site-packages/PySpice-1.6-py3.11.egg/PySpice/Spice/Parser/HighLevelParser.py", line 1102, in analyse
    obj = cls(line, ast)
          ^^^^^^^^^^^^^^
  File "/workspaces/PySpice/pyspicedev-env/lib/python3.11/site-packages/PySpice-1.6-py3.11.egg/PySpice/Spice/Parser/HighLevelParser.py", line 319, in __init__
    data = ElementData.elements[self._letter]
           ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
KeyError: 'M'

I haven't any idea how to fix this. Could you help me out? Best

Kreijstal commented 1 week ago

you mean the devel branch, that one was left untouched by @FabriceSalvaire, I tried to use it but I did have issues, right now I'm using patch-2 branch my goal is to eventually find time to merge the openspice changes, there are some things that do break on the openspice branch. It's not a nice situation that pyspice finds itself in, however I found that it is greatly hackable.

In you error, it seems ElementData doesn't contain nmos pmos transistors, they'd have to be added. I dont know how much the devel branch changes things from the 1.5 version, however.