# [SciPy-user] odeint memoryError

Steve Schmerler elcorto@gmx....
Tue Jul 31 04:09:55 CDT 2007

```Robert VERGNES wrote:
> Dear Rob,
>
> It is related with step size and accuracy. Is there some way I could
> know if ODEINT will crash or not ? - hence I would adapt the length of
> my t_vector...
>
>
> an example of crashing odeint is below:
>
> from scipy import *
> from numpy import *
> from scipy.integrate import *
>
> # Equation Parameters
> t_step= 1E-12
> t_start=1.0172
> t_end = 1.01726095276
> t_interim = t_range = arange(t_start, t_end,t_step)
> print 'Length of t_range: ' + str(len(t_range))
> print 'Length should be around: '+ str(((t_end-t_start)/t_step))
> w0 =sqrt (10)
> fo = 0.075
> y0_interim = [-2.20182185029, 0.0120342071085] #[Theta_dot, Theta]
>
> def func_f3(y,t):
>     """  Jacobian function """
>     return [ - fo*y[0]- w0**2*sin(y[1]), y[0]]
>
> if __name__ == '__main__':
>     # ODE calculation
>     y, infodict = odeint(func_f3,y0_interim,t_interim, full_output =1)
>     print y
>     print infodict
>

With t_step= 1E-12, you t_range array has a size of about 6e7 floats, which is
about 460 MB of memory for t_range alone. With 2 additional arrays for y[0] and
y[1], you will run out of memory or at least force extensive swap usage. On my
machine with 512 MB RAM I also get a MemoryError. Are you sure you need such a
high resolution? Usually I'm happy with, say 50000 points. Like this:

# Equation Parameters
##t_step= 1E-12
npts=50000
t_start=1.0172
t_end = 1.01726095276
##t_interim = t_range = arange(t_start, t_end,t_step)
t_interim = t_range = linspace(t_start, t_end, npts)
print 't_step: %e' %(t_range[-1]-t_range[-2])
print 'Length of t_range: ' + str(len(t_range))
print 'Length should be around: '+ str(((t_end-t_start)/t_step))
.....

HTH

--
cheers,
steve

I love deadlines. I like the whooshing sound they make as they fly by. --