Skip to content

Using circuit.simulator(simulator='ngspice-subprocess',...) breaks PySpice execution #352

@cyber-g

Description

@cyber-g

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

Ubuntu 20.04.6 LTS
Python 3.8.10
PySpice version: '1.5'
Simulator: NGSpice

Expected Behaviour

No error message ; elements values should be printed

Actual Behaviour

PySpice stops with the following output:

me@compute:PySpice/examples/resistor$ python3 voltage-divider.py 
2023-09-08 19:08:14,060 - PySpice.Spice.Netlist.Node.__init__ - WARNING - Node name 'in' is a Python keyword
2023-09-08 19:08:14,071 - PySpice.Spice.NgSpice.Server.SpiceServer.__call__ - INFO - Start the spice subprocess
Traceback (most recent call last):
  File "voltage-divider.py", line 27, in <module>
    analysis = simulator.operating_point()
  File "git-dir/PySpice/PySpice/Spice/Simulation.py", line 1194, in operating_point
    return self._run('operating_point', *args, **kwargs)
  File "git-dir/PySpice/PySpice/Spice/NgSpice/Simulation.py", line 76, in _run
    raw_file = self._spice_server(spice_input=str(self))
  File "git-dir/PySpice/PySpice/Spice/NgSpice/Server.py", line 162, in __call__
    return RawFile(stdout, number_of_points)
  File "git-dir/PySpice/PySpice/Spice/NgSpice/RawFile.py", line 170, in __init__
    raw_data = self._read_header(stdout)
  File "git-dir/PySpice/PySpice/Spice/NgSpice/RawFile.py", line 192, in _read_header
    self.circuit_name = self._read_header_field_line(header_line_iterator, 'Circuit')
  File "git-dir/PySpice/PySpice/Spice/RawFile.py", line 243, in _read_header_field_line
    raise NameError("Expected label %s instead of %s" % (expected_label, label))
NameError: Expected label Circuit instead of No compatibility mode selected
me@compute:PySpice/examples/resistor$ 

The failure happens for any kind of circuit but is demonstrated below with one of the builtin example.

Steps to reproduce the behaviour

Open example examples/resistor/voltage-divider.py and replace line L25:

simulator = circuit.simulator(temperature=25, nominal_temperature=25)

with

simulator = circuit.simulator(simulator='ngspice-subprocess',temperature=25, nominal_temperature=25)

Then run :

python3 voltage-divider.py

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions