Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Decouple computing data for a plot and creating the plot object?

The plot() function does Two Things:

  1. takes your function and samples its values (somewhat intelligently) to create a list of 2D coordinate pairs
  2. uses that list of coordinates to create a plot object

Is there a way to decouple these steps, i.e. separately invoke the logic of step 1 to obtain a list of 2D points and then the logic of step 2 to obtain the plot object?

The motivation for this is computing different curves of a composite plot on different cores using @parallel. Very unfortunately the return value of plot(), whatever it is, doesn't pickle/unpickle properly, and thus cannot be returned between threads. So if you generate separate plot objects in your @parallel function, all you will get at the call point will be an iterator yielding error messages. This could be avoided if I could _just_ compute the 2D data lists in threads, and "render" them to plots in the main thread.

Is that doable?

Please be aware that I am interested in using plot()'s actual logic for sampling the plotted function, rather than writing my own logic that would probably be inferior.

Decouple computing data for a plot and creating the plot object?

The plot() function does Two Things:

  1. takes your function and samples its values (somewhat intelligently) to create a list of 2D coordinate pairs
  2. uses that list of coordinates to create a plot object

Is there a way to decouple these steps, i.e. separately invoke the logic of step 1 to obtain a list of 2D points and then the logic of step 2 to obtain the plot object?

The motivation for this is computing different curves of a composite plot on different cores using @parallel. Very unfortunately the return value of plot(), whatever it is, doesn't pickle/unpickle properly, and thus cannot be returned between threads. So if you generate separate plot objects in your @parallel function, all you will get at the call point will be an iterator yielding error messages. This could be avoided if I could _just_ compute the 2D data lists in threads, and "render" them to plots a plot in the main thread.

Is that doable?

Please be aware that I am interested in using plot()'s actual logic for sampling the plotted function, rather than writing my own logic that would probably be inferior.

Decouple computing data for a plot and creating the plot object?

The plot() function does Two Things:

  1. takes your function and samples its values (somewhat intelligently) to create a list of 2D coordinate pairs
  2. uses that list of coordinates to create a plot object

Is there a way to decouple these steps, i.e. separately invoke the logic of step 1 to obtain a list of 2D points and then the logic of step 2 to obtain the plot object?

The motivation for this is computing different curves of a composite plot on different cores using @parallel. Very unfortunately the return value of plot(), whatever it is, doesn't pickle/unpickle properly, and thus cannot be returned between threads. So if you generate separate plot objects in your @parallel function, all you will get at the call point will be an iterator yielding error messages. This could be avoided if I could _just_ compute the 2D data lists in threads, and "render" them to a plot in the main thread.

Is that doable?

Please be aware that I am interested in using plot()'s actual logic for sampling the plotted function, rather than writing my own logic that would probably be inferior.

EDIT: toy example

@parallel
def singlePlot(v):
    x = var('x')
    return plot((x-v)^2, xmin=-3, xmax=3)

plots = [];
for onePlot in singlePlot([0,1,2,3]):
    plots.append(onePlot)

plots[0]

Outputs:

(((0,), {}), "INVALID DATA invalid load key, 'x'.")

I made this example because I was explicitly asked about "what I am trying to achieve", but please note that I have ZERO hope that this serialization bug will ever be fixed, so I need a workaround, not a fix. What I am trying to achieve is to somehow, anyhow be able to, rather than be unable to, compute separate lines of a plot in parallel threads and successfully collect them in the calling thread. Simply creating plot objects and passing them between processes doesn't work and likely never will, so I need an alternative.

Decouple computing data for a plot and creating the plot object?

The plot() function does Two Things:

  1. takes your function and samples its values (somewhat intelligently) to create a list of 2D coordinate pairs
  2. uses that list of coordinates to create a plot object

Is there a way to decouple these steps, i.e. separately invoke the logic of step 1 to obtain a list of 2D points and then the logic of step 2 to obtain the plot object?

The motivation for this is computing different curves of a composite plot on different cores using @parallel. Very unfortunately the return value of plot(), whatever it is, doesn't pickle/unpickle properly, and thus cannot be returned between threads. So if you generate separate plot objects in your @parallel function, all you will get at the call point will be an iterator yielding error messages. This could be avoided if I could _just_ compute the 2D data lists in threads, and "render" them to a plot in the main thread.

Is that doable?

Please be aware that I am interested in using plot()'s actual logic for sampling the plotted function, rather than writing my own logic that would probably be inferior.

EDIT: toy example

@parallel
def singlePlot(v):
    x = var('x')
    return plot((x-v)^2, xmin=-3, xmax=3)

plots = [];
for onePlot in singlePlot([0,1,2,3]):
    plots.append(onePlot)

plots[0]

Outputs:

(((0,), {}), "INVALID DATA invalid load key, 'x'.")

The same singlePlot() function works as expected if I remove the @parallel decorator and call it with a single integer rather than a list.

I made this example because I was explicitly asked about "what I am trying to achieve", but please note that I have ZERO hope that this serialization bug will ever be fixed, so I need a workaround, not a fix. What I am trying to achieve is to somehow, anyhow be able to, rather than be unable to, compute separate lines of a plot in parallel threads and successfully collect them in the calling thread. Simply creating plot objects and passing them between processes doesn't work and likely never will, so I need an alternative.

Decouple computing data for a plot and creating the plot object?

The plot() function does Two Things:

  1. takes your function and samples its values (somewhat intelligently) to create a list of 2D coordinate pairs
  2. uses that list of coordinates to create a plot object

Is there a way to decouple these steps, i.e. separately invoke the logic of step 1 to obtain a list of 2D points and then the logic of step 2 to obtain the plot object?

The motivation for this is computing different curves of a composite plot on different cores using @parallel. Very unfortunately the return value of plot(), whatever it is, doesn't pickle/unpickle properly, and thus cannot be returned between threads. So if you generate separate plot objects in your @parallel function, all you will get at the call point will be an iterator yielding error messages. This could be avoided if I could _just_ compute the 2D data lists in threads, and "render" them to a plot in the main thread.

Is that doable?

Please be aware that I am interested in using plot()'s actual logic for sampling the plotted function, rather than writing my own logic that would probably be inferior.

EDIT: toy example

@parallel
def singlePlot(v):
    x = var('x')
    return plot((x-v)^2, xmin=-3, xmax=3)

plots = [];
for onePlot in singlePlot([0,1,2,3]):
    plots.append(onePlot)

plots[0]

Outputs:

(((0,), {}), "INVALID DATA invalid load key, 'x'.")

The same singlePlot() function works as expected if I remove the @parallel decorator and call it with a single integer rather than a list.

I made this example because I was explicitly asked about "what I am trying to achieve", but please note that I have ZERO hope that this serialization bug will ever be fixed, so I need a workaround, not a fix. What I am trying to achieve is to somehow, anyhow be able to, rather than be unable to, compute separate lines of a plot in parallel threads and successfully collect them in the calling thread. Simply creating plot objects and passing them between processes doesn't work and likely never will, so I need an alternative.