Skip to content

PySpice raises Python exceptions when it reads some warnings from ngspice #134

Open
@aiifabbf

Description

@aiifabbf

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

Ubuntu 16.04, Python 3.6.5, PySpice 1.2.0, ngspice 26 as subprocess

Expected Behaviour

PySpice should not raise Python exceptions when encountered with warnings in ngspice, because the simulation can still go on in ngspice interactive mode.

Actual Behaviour

When ngspice works under interactive mode and encounters a warning, it prints the warning but does not stop the simulation.

******
** ngspice-26 : Circuit level simulation program
** The U. C. Berkeley CAD Group
** Copyright 1985-1994, Regents of the University of California.
** Please get your ngspice manual from http://ngspice.sourceforge.net/docs.html
** Please file your bug-reports at http://ngspice.sourceforge.net/bugrep.html
** Creation Date: Sun Feb  7 10:53:02 UTC 2016
******

Circuit: *sheet name:/opa_sr

Warning: Model issue on line 6160 : .model nch.2 nmos ( lmin=    1.19999999999999995e-06   l ...
  unrecognized parameter (n) - ignored
unrecognized parameter (tlev) - ignored
unrecognized parameter (tlevc) - ignored
unrecognized parameter (sfvtflag) - ignored
Warning: Model issue on line 7568 : .model pch.3 pmos ( lmin=    4.99999999999999977e-07   l ...
  unrecognized parameter (n) - ignored
unrecognized parameter (tlev) - ignored
unrecognized parameter (tlevc) - ignored
unrecognized parameter (sfvtflag) - ignored
Warning: Model issue on line 7895 : .model pch.7 pmos ( lmin=    4.99999999999999977e-07   l ...
  unrecognized parameter (n) - ignored
unrecognized parameter (tlev) - ignored
unrecognized parameter (tlevc) - ignored
unrecognized parameter (sfvtflag) - ignored
ngspice 2 -> ac dec 100 1 10G
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000



No. of Data Rows : 1001
ngspice 2 -> plot
which variable: Vout
ngspice 2 -> 

But when PySpice reads the same warning from ngspice, it raises a Python exception and the simulation pauses.

---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-358-f69c3c6637ef> in <module>()
----> 1 analysis = simulator.ac(start_frequency=1@u_Hz, stop_frequency=10e+9@u_Hz, number_of_points=100, variation="dec")

~/Desktop/lab-ngspice/lib/python3.6/site-packages/PySpice/Spice/Simulation.py in ac(self, *args, **kwargs)
    745     def ac(self, *args, **kwargs):
    746 
--> 747         return self._run('ac', *args, **kwargs)
    748 
    749     ##############################################

~/Desktop/lab-ngspice/lib/python3.6/site-packages/PySpice/Spice/NgSpice/Simulation.py in _run(self, analysis_method, *args, **kwargs)
     74         super()._run(analysis_method, *args, **kwargs)
     75 
---> 76         raw_file = self._spice_server(spice_input=str(self))
     77         self.reset_analysis()
     78         raw_file.simulation = self

~/Desktop/lab-ngspice/lib/python3.6/site-packages/PySpice/Spice/NgSpice/Server.py in __call__(self, spice_input)
    160                             stderr)
    161 
--> 162         return RawFile(stdout, number_of_points)

~/Desktop/lab-ngspice/lib/python3.6/site-packages/PySpice/Spice/NgSpice/RawFile.py in __init__(self, stdout, number_of_points)
    168         self.number_of_points = number_of_points
    169 
--> 170         raw_data = self._read_header(stdout)
    171         self._read_variable_data(raw_data)
    172         # self._to_analysis()

~/Desktop/lab-ngspice/lib/python3.6/site-packages/PySpice/Spice/NgSpice/RawFile.py in _read_header(self, stdout)
    191 
    192         self.circuit_name = self._read_header_field_line(header_line_iterator, 'Circuit')
--> 193         self.temperature, self.nominal_temperature = self._read_temperature_line(header_line_iterator)
    194         self.warnings = [self._read_header_field_line(header_line_iterator, 'Warning')
    195                          for i in range(stdout.count(b'Warning'))]

~/Desktop/lab-ngspice/lib/python3.6/site-packages/PySpice/Spice/RawFile.py in _read_temperature_line(self, header_line_iterator)
    251         # Doing analysis at TEMP = 25.000000 and TNOM = 25.000000
    252 
--> 253         line = self._read_header_line(header_line_iterator, 'Doing analysis at TEMP')
    254         pattern1 = 'TEMP = '
    255         pattern2 = ' and TNOM = '

~/Desktop/lab-ngspice/lib/python3.6/site-packages/PySpice/Spice/RawFile.py in _read_header_line(self, header_line_iterator, head_line)
    221             return line
    222         else:
--> 223             raise NameError("Unexpected line: %s" % (line))
    224 
    225     ##############################################

NameError: Unexpected line: Warning: Model issue on line 6315 : .model nch.4 nmos ( lmin=1.8e-007 lmax=    4.99999999999 ...

Steps to reproduce the behaviour

Include an ngspice model lib that contains parameters undefined in ngspice(but properly defined in some commercial spice-compatible simulators like hspice) and this issue would happen, e.g. tsmc rf18 lib.

circuit.raw_spice += ".lib rf018.l tt"
simulator = circuit.simulator(simulator="ngspice-subprocess")
analysis = simulator.ac(start_frequency=1@u_Hz, stop_frequency=10e+9@u_Hz, number_of_points=100, variation="dec")

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions