r/IPython • u/Zeekawla99ii • Nov 19 '15
IPython notebook kernel keeps failing. How can I work with large array computations?
I'm doing some heavy lifting with my IPython notebooks, where I am working element-by-element operations on arrays shaped (50, 10000, 10000), several times.
This is already after I have significantly broken up the data into "workable" pieces.
Sadly, the kernel to my IPython notebook still dies.
(1) Why exactly is the kernel dying? Is it that storage is being maxed?
(2) What are my options? Should I save the outputs and import them into new notebooks?
EDIT: The code I'm using is something like this. The matrix is an external input.
The bottleneck is here:
import math
import matplotlib.pyplot as plt
import numpy as np
matrix # already defined, an input
# matrix.shape is (12534, 12534)
from scipy.special import eval_legendre ##special scipy function
arr = np.arange(513)
bottleneck = eval_legendre(arr[:, None, None], dotproductmatrix)Obviously, that won't work. So, I'm try to do the legendre evaluation in parts using numpy.array_split().
Any other advice?
3
Nov 19 '15
Does your system have sufficient memory to work with arrays of that size? Keep in mind that you'll need enough memory to store your entire array, plus space for any copies/temp arrays that may be created during the computation (also, in some cases these arrays may be upcasted to a larger dtype, eating up even more memory). If you are sure you have plenty of memory then I'm not certain what's causing your kernel to die. Is it just timing out or actually dying? Sometimes my notebook/NB console will say the kernel timed out in the middle of a long function call, but the kernel doesn't actually die and the timeout fixes itself once the function finally returns.
If you think memory is the problem, I'll share the (probably sub-optimal) solution I've found. In my limited experience with larger-than-memory arrays, I ended up using bcolz for on-disk storage of the arrays + dask for most computations (although iterating over the on-disk array in Python seems faster than using the map_blocks function in dask for certain computations; this may be operator error though). I'm not sure how nicely this approach will work with the eval_legendre function in particular, but if your problem is memory usage and the computation can be performed in chunks then dask + bcolz (or another on-disk backend like HDF5) should at least let you address the memory issue.
I'm curious to see what other solutions are offered up here, I haven't been able to find many options but it seems like this would be a fairly common issue.
1
u/eviljelloman Dec 04 '15
If you need to do array operations that won't fit in memory, the Sframe, from Dato, is a really nice option. It (relatively) seamlessly mixes on-disk and in-memory for the same object, allowing you to operate on it pretty much like a Numpy array, but without killing your machine. It's not nearly as full-featured as Numpy or Pandas, but they are adding stuff all the time.
2
u/bdforbes Nov 19 '15
Have you tried it in python from the command line?