mph- / lcapy

Lcapy is a Python package for symbolic linear circuit analysis and signal processing. It uses SymPy for symbolic mathematics.
GNU Lesser General Public License v2.1
234 stars 45 forks source link

Make netlist drawing more robust #109

Closed schlatterbeck closed 1 year ago

schlatterbeck commented 1 year ago

The following little script consume very much memory very fast due to a broken netlist. The netlist is parsed successfully but the attempt to display it seems to run into an infinite recursion. (The netlist resulted from a broken qucsstudio filter designer output combined with a broken parser for the qucsstudio format I'm currently writing: Not something that anyone sane would create by hand but maybe a good example for a regression test)

>>> from lcapy import show_version
>>> show_version()
Python: 3.11.2 (main, Mar 13 2023, 12:18:29) [GCC 12.2.0]
SymPy: 1.11.1
NumPy: 1.24.2
Matplotlib: 3.6.3
SciPy: 1.10.1
Lcapy: 1.17
#!/usr/bin/python3

from lcapy import Circuit

c = Circuit ("""
P1 1 0_0 ; down
L1 1 2 ; right
C1 1_0 3 ; right
C2 3 0_1 ; down
L2 3 0_2 ; down
L3 3 4 ; right
C3 3 5 ; right
P_lowFreq 5 0_3 ; down
P_highFreq 5 0_4 ; down
W 0_0 0_1 ; right
W 0_1 0_2 ; right
W 0_2 0_3 ; right
W 0_3 0_4 ; right
""")

c.draw ()
mph- commented 1 year ago

Ha! What a nasty netlist! it's not topologically possible. This patch should throw an exception now.