RBigData / pbdCS

A set of utilities for interactively using pbdR.
Other
8 stars 3 forks source link

parallel plotting #9

Open go-ski opened 6 years ago

go-ski commented 6 years ago

When managing own plotting devices on each rank to make plots in parallel, such as this code given at the pbdR: prompt:

pdf(file = paste0("plot", comm.rank(), ".pdf"))
    plot(1:100, rnorm(100))
dev.off()

I get the following error:

Check 'local' .GlobalEnv$.rpng.img for the incorrect (raster) image.
Error: invalid 'path' argument

Is plotting being hijacked into another file by default? What am I missing?

This is pbdCS version 0.2-0 on R 3.4.2.

wrathematics commented 6 years ago

The plots seem to get created. I'm not sure what's causing the error to print.

go-ski commented 6 years ago

Sorry, I forgot to mention, the plots are produced. Just noticed the error is coming from remoter. Seems to be related to current rpng.off() issue for remoter.

snoweye commented 6 years ago

@go-ski I have some fixes of remoter for this. Please test this version before I send a PR. Thanks.

Yes, dev.off() is hijacked as needed, but the pdf() does not need interaction and pipe the plot to file. So, there is no need to return the image and re-plot it at client. This is the same for all other image file types.

No changes to the pbdCS.

go-ski commented 6 years ago

Thanks @snoweye. The new version fixes things for the plot example I gave.

My original issue that I reduced to the example was actually with ggplot2. Can you run the ggplot example below (at the pbdR: prompt) to see if it produces both plots correctly? I get rank 0 correct but rank 1 seems to only make the pdf() result without the ggplot().

library(pbdMPI)
library(pbdCS)
library(ggplot2)
dat = data.frame(x = rnorm(100), y = rnorm(100))

pdf(file = paste0("plot", comm.rank(), ".pdf"))
  ggplot(dat, aes(x, y)) + geom_point()
dev.off()
snoweye commented 6 years ago

@go-ski pbdR> print(g) where g is a ggplot object will work for both ranks. Regular plot() or print() will not have this problem. The default R> g will display to console, but R> print(g) will go to where you want it to. This is the same under remoter> and pbdR>. However, currently pbdCS may only get returns from rank 0 that was the results you got (only rank 0 was saved). (Right? @wrathematics)

@wrathematics How do I trace/print returns from ranks other than 0? (I can not remember we seem talk about this before ...) In @go-ski case, the rank 1 seems print the ggplot object to somewhere, I need to know where and how I can pipe them to file ggplot2 uses funny ways differently.

go-ski commented 6 years ago

Appears that replacing dev.off() with grid::grid.draw(myplot) as in the following (replacing my earlier snippet):

pdf(file = paste0("plot", comm.rank(), ".pdf"))
  myplot = ggplot(dat, aes(x, y)) + geom_point()
grid::grid.draw(myplot)

is currently a workaround for ggplot2 that does not get hijacked and produces all plots.

snoweye commented 6 years ago

Please see the fixes at pbdCS and remoter for these problems.

rpng needs more works in pbdCS which is not trivial as the case in remoter. I leave several TODO in pbdCS and may come back when I find time.