Ask Your Question

Creating plots in parallel

asked 2011-08-12 18:11:09 -0500

benjaminfjones gravatar image

Ok, even though my last question about @parallel was foolish, here is another one. I want to create a simple animation that consists of many plots. It takes a minute or two on my computer to produce. But it would be nice if I could harness the idle CPU's I have and create the frames for the animation in parellel. I thought this would be easy like this:

x = var('x')    

def frame(i):
    return plot(sin(i*x), (x, 0, pi))

P = [ p[1] for p in frame(range(1,FRAMES+1)) ]
#A = animate(blah, blah, ...)

and what I get back (in the Sage notebook) is:

invalid load key, 'x'.
Killing any remaining workers...

Any idea what is going wrong here?

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted

answered 2011-08-15 02:19:20 -0500

niles gravatar image

Ok, I couldn't resist looking into this more. I'm using sage 4.7, and the code I posted above works for me even without ticket 11461 applied. Strangely, I get the error "invalid load key, 'x'" only when I return the graphics object. Moreover, I get that same error (with x) even when I change the variable name to t. So I think this is a bug. I wonder if it has something to do with passing the bare graphics object between separate sage processes. There seems to be no error if I return something containing the graphics object:


def frame(i):
    t = var('t')
    g = plot(sin(i*t), (t,0, pi))
    return (g,)

frame_iter = frame(range(2,FRAMES+1))
P = list(frame_iter)
Q = [p[1][0] for p in P]
Animation with 9 frames

p.s. For longer animations, I really like ffmpeg. An option to use it with the animate command should be coming in sage 4.7.1 (see ticket 11170 if you can't wait).

UPDATE: Searching for "invalid load key" with search_src yields only one use in the entire Sage library, in a doctest for load in structure/sage_object.pyx.

edit flag offensive delete link more


Yeah, I was thinking that `invalid load key` has something to do with the inputs / outputs being pickled and then unpickled so the error is coming from Python..

benjaminfjones gravatar imagebenjaminfjones ( 2011-08-16 07:25:50 -0500 )edit

answered 2011-08-13 04:20:10 -0500

niles gravatar image

No, no idea what's wrong, but the following does work:

x = var('x')

def frame(i):
    g = plot(sin(i*x), (x, 0, pi))

P = [ p[1] for p in frame(range(1,FRAMES+1)) ]

p.s. parallel is awesome, but the documentation is sparse, and confusing, so keep the questions coming :) If you haven't found it yet, Trac ticket 11461 implements parallel for classes; I've been using it for a long animation project, and it works great!

edit flag offensive delete link more


Is there any documentation except '@parallel?' default help?

Eugene gravatar imageEugene ( 2011-08-13 09:23:11 -0500 )edit

Well, there are the other docstrings in the source code, if that counts . . .

niles gravatar imageniles ( 2011-08-13 09:47:58 -0500 )edit

That doesn't work for me, the notebook displays a 10 identical plots (not sure why they're identical) and after it's done, `P = [None, None, None, None, None, None, None, None, None, None]`.

benjaminfjones gravatar imagebenjaminfjones ( 2011-08-14 10:07:57 -0500 )edit

bummer . . . the version of sage I'm using does have ticket 11461 applied to it, so that might be why it's working for me. The result you're getting for P is because `frame` doesn't have a return value anymore. Could you try running it with `'~/tmp_%03d.png'%i)`, and see if the saved files are also all the same? For this, you should be able to just run `frame(range(1,FRAMES+1))` too, without the `P`

niles gravatar imageniles ( 2011-08-14 13:44:42 -0500 )edit

Thanks, I've got the plots written to image files (had to use'~/tmp/tmp_%03d.png'%i)) to get the tilde to resolve to a directory), now I need to assemble them into an animation. To use `animate` I guess I need to read the files back into Graphics objects. Or else use some other software to create the animation. I wish I could get Graphics objects created in parallel. I'll have to look into the @parallel code and try to see what's going on.

benjaminfjones gravatar imagebenjaminfjones ( 2011-08-14 17:40:29 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2011-08-12 18:11:09 -0500

Seen: 229 times

Last updated: Aug 15 '11