Giter Site home page Giter Site logo

Maximum iteration depth exceeded about ahkab HOT 10 CLOSED

ahkab avatar ahkab commented on July 25, 2024
Maximum iteration depth exceeded

from ahkab.

Comments (10)

itdaniher avatar itdaniher commented on July 25, 2024

I just checked with most recent ahkab and

numpy-1.7.1
scipy-0.13.0.dev-c31f167
sympy-0.7.3
matplotlib-1.3.0

and didn't get that error. I'll update my F19 system after exams and try and reproduce, but this may be an upstream problem. What version of matplotlib are you using?

It looks like numpy changed around a handful of things from 1.7 to 1.8, as per release notes, could be related.

from ahkab.

liubenyuan avatar liubenyuan commented on July 25, 2024

with
matplotlib-1.3.1-1

I think it relate to the problem of plot r['tran']['T'], the error occurs there.

from ahkab.

ggventurini avatar ggventurini commented on July 25, 2024

Thanks for the bug report!

Also good to know matplotlib 1.3.0 is unaffected.

I can reproduce this with this setup:

>>> import numpy, scipy, matplotlib
>>> for i in numpy, scipy, matplotlib:
...     print i.__version__
... 
1.7.1
0.12.0
1.3.1

I'll be looking into this and I'll try to come up with a patch shortly.

I'll be looking at the changes in numpy too while I'm at it.. :)

Cheers!

from ahkab.

ggventurini avatar ggventurini commented on July 25, 2024

It is indeed a bug upstream in matplotlib.

I can reproduce the same RuntimeError: maximum recursion depth exceeded with just:

import pylab as plt
import numpy as np
a = np.mat([1, 2, 3])
plt.plot(a)

This merge is said to fix the issue: matplotlib/matplotlib#2290

It was merged yesterday to the git matplotlib repo, it will take a bit for package mantainers to add the patch to their code bases I'd expect.

A quick work-around is to pass all your data through np.array() before plotting it. It requires modifying your files, sorry about that.

If need be, a temporary work-around targeted to matplotlib 1.3.1 can be introduced in the data interface. If you guys think it is a good idea, please let me know.

Best,

Giuseppe

from ahkab.

ggventurini avatar ggventurini commented on July 25, 2024

Kinda off topic but numpy 1.8 seems relatively safe to me. I see no worrisome changes. It was a nice read too!

from ahkab.

liubenyuan avatar liubenyuan commented on July 25, 2024

I tried np.array, how ever the data become multi-dimensional and the legend is a mess.

BTW: I am new to python maybe I need to learn more about the coding style to catch up.

from ahkab.

ggventurini avatar ggventurini commented on July 25, 2024

Here is what I was referring to:

import numpy as np

import ahkab
from ahkab import ahkab, circuit, printing, devices

mycircuit = circuit.circuit(title="Butterworth Example circuit", filename=None)

gnd = mycircuit.get_ground_node()

mycircuit.add_resistor(name="R1", ext_n1="n1", ext_n2="n2", R=600)
mycircuit.add_inductor(name="L1", ext_n1="n2", ext_n2="n3", L=15.24e-3)
mycircuit.add_capacitor(name="C1", ext_n1="n3", ext_n2=gnd, C=119.37e-9)
mycircuit.add_inductor(name="L2", ext_n1="n3", ext_n2="n4", L=61.86e-3)
mycircuit.add_capacitor(name="C2", ext_n1="n4", ext_n2=gnd, C=155.12e-9)
mycircuit.add_resistor(name="R2", ext_n1="n4", ext_n2=gnd, R=1.2e3)

voltage_step = devices.pulse(v1=0, v2=1, td=500e-9, tr=1e-12, pw=1, tf=1e-12, per=2)
mycircuit.add_vsource(name="V1", ext_n1="n1", ext_n2=gnd, vdc=5, vac=1, function=voltage_step)

printing.print_circuit(mycircuit)

op_analysis = ahkab.new_op()
ac_analysis = ahkab.new_ac(start=1e3, stop=1e5, points=100)
tran_analysis = ahkab.new_tran(tstart=0, tstop=1.2e-3, tstep=1e-6, x0=None)

r = ahkab.run(mycircuit, an_list=[op_analysis, ac_analysis, tran_analysis])

import pylab

fig = pylab.figure()
pylab.title(mycircuit.title + " - TRAN Simulation")
T = np.array(r['tran']['T'])
VN1 = np.array(r['tran']['VN1'])
VN4 = np.array(r['tran']['VN4'])
w = np.array(r['ac']['w'])
absVN4 = np.array(r['ac']['|Vn4|'])
argVN4 = np.array(r['ac']['arg(Vn4)'])
pylab.plot(T, VN1, label="Input voltage")
pylab.hold(True)
pylab.plot(T, VN4, label="output voltage")
pylab.legend()
pylab.hold(False)
pylab.grid(True)
pylab.ylim([0,1.2])
pylab.ylabel('Step response')
pylab.xlabel('Time [s]')
fig.savefig('tran_plot.png')

fig = pylab.figure()
pylab.subplot(211)
pylab.semilogx(w, absVN4, 'o-')
pylab.ylabel('abs(V(n4)) [V]')
pylab.title(mycircuit.title + " - AC Simulation")
pylab.subplot(212)
pylab.grid(True)
pylab.semilogx(w, argVN4, 'o-')
pylab.xlabel('Angular frequency [rad/s]')
pylab.ylabel('arg(V(n4)) [rad]')
fig.savefig('ac_plot.png')
pylab.show()

Hopefully that bug will be fixed downstream quickly enough. The above is a temporary solution (slightly more verbose...)

Best, GV

ac_plot

from ahkab.

liubenyuan avatar liubenyuan commented on July 25, 2024

It works! I for got to delete the transpose operator .T

from ahkab.

ggventurini avatar ggventurini commented on July 25, 2024

This should be fixed in 4c2dbe6, independently from whether your matplotlib version is affected by this regression or not.

from ahkab.

ggventurini avatar ggventurini commented on July 25, 2024

Also it should be transparent to you, whether you are passing your results through array() or not makes no difference. And no need for the ugly transpose operator .T anymore.

from ahkab.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.