Sub-circuit in library issue

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

try to print(circuit) to see what is send to ngspice

Here is the print(circuit) output :

.title RC Circuit
.include /Users/{my home directory}/simulations/pyspice_models/RC.MOD
V1 VIN 0 AC
X1 VIN 0 VOUT RC

The directory of the .include line is an absolute path computed by pyspice from the local directory specified in SpiceLibrary. Is it then possible that the fact that there are spaces inside the {my home directory} directory name, makes ngspice not able to find the RC.MOD file ?
It seams strange to me that nothing is complaining about not finding the RC.MOD file…

Are you using v1.4.3 ?

Ngspice Manual:

2.6
.INCLUDE
General form:
.INCLUDE filename
Examples:
.INCLUDE /users/spice/common/bsim3-param.mod
Frequently, portions of circuit descriptions will be reused in several input files, particularly with
common models and subcircuits. In any ngspice input file, the .INCLUDE line may be used to
copy some other file as if that second file appeared in place of the .INCLUDE line in the original
file.
There is no restriction on the file name imposed by ngspice beyond those imposed by the local
operating system.

Yes, I think I am. I installed PySpice on my mac using pip3. The libngspice was installed with brew.

$ python3
Python 3.7.4 (default, Oct 12 2019, 19:06:48) 
[Clang 11.0.0 (clang-1100.0.33.8)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import PySpice
>>> print(PySpice.__version__)
1.4.3
>>>