Hi there !
I would like to use a spice circuit model (a sub-circuit in a .MOD file) in a circuit created from a spice netlist (a .net file) inside PySpice. Following is a simplistic example that shows the problem with a simple RC sub-circuit. I can’t figure out why the sub-circuit is not found although it is explicitly included with the circuit.include call as in the documentation examples…
The RC.py file :
import PySpice.Logging.Logging as Logging
logger = Logging.setup_logging()
from PySpice.Spice.Library import SpiceLibrary
from PySpice.Spice.Netlist import Circuit
from PySpice.Spice.Parser import SpiceParser
from PySpice.Unit import *
spice_library = SpiceLibrary('../models/')
parser = SpiceParser(path='RC.net')
circuit = parser.build_circuit()
circuit.include(spice_library['RC'])
simulator = circuit.simulator(temperature=25, nominal_temperature=25)
analysis = simulator.ac('dec', 10, 100, 100e3)
The RC.net circuit file :
.title RC Circuit
V1 VIN 0 AC
X1 VIN 0 VOUT RC
.end
The RC.MOD model file in the ../models directory :
* PINOUT 1 2 3
* PINOUT IN+ IN- OUT
.subckt RC 1 2 3
R1 1 3 1k
C1 3 2 1nF
.ends
Runing the python script gives :
$ python RC.py
2020-07-06 15:12:47,850 - PySpice.Spice.NgSpice.Shared.NgSpiceShared - Shared.ERROR - Error: unknown subckt: x1 vin 0 vout rc
2020-07-06 15:12:47,851 - PySpice.Spice.NgSpice.Shared.NgSpiceShared - Shared.ERROR - Error: there aren't any circuits loaded.
Traceback (most recent call last):
File "RC.py", line 14, in <module>
analysis = simulator.ac('dec', 10, 100, 100e3)
File "/usr/local/lib/python3.7/site-packages/PySpice/Spice/Simulation.py", line 1161, in ac
return self._run('ac', *args, **kwargs)
File "/usr/local/lib/python3.7/site-packages/PySpice/Spice/NgSpice/Simulation.py", line 118, in _run
self._ngspice_shared.run()
File "/usr/local/lib/python3.7/site-packages/PySpice/Spice/NgSpice/Shared.py", line 1168, in run
self.exec_command(command)
File "/usr/local/lib/python3.7/site-packages/PySpice/Spice/NgSpice/Shared.py", line 842, in exec_command
raise NgSpiceCommandError("Command '{}' failed".format(command))
PySpice.Spice.NgSpice.Shared.NgSpiceCommandError: Command 'run' failed