A problem with coupled transmission line


I am trying to simulate quadrature hybrid with coupled transmission line (CPL). I have the following netlist:

Vin1 in 0 dc 0 sin(0 1 1000Meg)
R3 iso 0 50
R2 out2 0 50
R1 out1 0 50
P1 in iso 0 out1 out2 0 QH
.model QH CPL length=75.75m C=66p 33p 66p L=165n 82.5n 165n G=0 0 0 R=0 0 0
.tran .001ns 5n

When I try to parse this file (SpiceParser(cir_file)), I will get the following error:

P1 in iso 0 out1 out2 0 QH
P1 in iso 0 out1 out2 0 QH
P1 in iso 0 out1 out2 0 QH
P1 in iso 0 out1 out2 0 QH
P1 in iso 0 out1 out2 0 QH
Traceback (most recent call last):
File “/Users/huttunen/work/Electronics/NodalAnalysis/Run.py”, line 273, in
File “/Users/huttunen/work/Electronics/NodalAnalysis/Run.py”, line 67, in main
parser = SpiceParser(path=args.cir_file)
File “/Users/huttunen/python/miniconda3/envs/spice/lib/python3.7/site-packages/PySpice/Spice/Parser.py”, line 805, in init
self._statements = self._parse(lines)
File “/Users/huttunen/python/miniconda3/envs/spice/lib/python3.7/site-packages/PySpice/Spice/Parser.py”, line 881, in _parse
model = Model(line)
File “/Users/huttunen/python/miniconda3/envs/spice/lib/python3.7/site-packages/PySpice/Spice/Parser.py”, line 281, in init
self._name, self._model_type = parts
ValueError: too many values to unpack (expected 2)

There seems to be also some other problems with CPL. The following netlist does not give any error but, output of CPL component (vout) is zero. Works with ngspice.

.title KiCad schematic
Vin1 vin_pre 0 sin(0 1 1000Meg)
O1 vin2 0 vout2 0 ltra
Rin2 vin2 vin_pre 50
R2 vout2 0 50
P1 vin 0 vout 0 QH
Rin1 vin vin_pre 50
R1 vout 0 50
.model ltra LTRA C=66p L=165n len=75.75m R=0 G=0
.model QH CPL C=66p L=165n length=75.75m R=0 G=0
.tran .005ns 10ns

Using the version from “pip install PySpice”. (Btw the link to Installation documentation in https://pypi.org/project/PySpice/ leads to 404 error).

To be fixed in next release …

Spice parser is far from complete actually …

Could yo create an issue for each on https://github.com/FabriceSalvaire/PySpice/issues

How are you passing the netlist to the simulator ?

I created an issue.

I use the line:
parser = SpiceParser(path=cir_file) which gives the errors.

You could use circuit.raw = "...spice commands..." instead
Because you are trying to parse Spice commands with an incomplete parser, and then to regenerat the netlist

Sorry for delay. I was having some holidays.

Can you give or point me to an example that how to use this raw feature?

Or newermind, I found this in the forum:

So I guess a plan could be to read the netlist as a text and then pass it to circuit.raw_source. Trying that next.

For a reference to others, this seems to work (simulation fails without output if string includes a line starting with “.tran”):

from PySpice.Spice.Netlist import Circuit
circuit = Circuit(‘Test’)
str = open(cir_file, ‘r’).readlines()
str = [s for s in str if not (s.startswith(’.tran’) or s.startswith(’.end’) or s.startswith(’.op’)) ]
str = ’ '.join(str)
circuit.raw_spice = str