johnmchambers / XRJulia

XR-style Interface to Julia (from "Extending R")
33 stars 2 forks source link

Running long code on Julia returns error in R #15

Closed oliviaAB closed 6 years ago

oliviaAB commented 6 years ago

Hi,

I am trying to run long simulations in Julia (using the module BioSimulator.jl), calling the appropriate functions from R, via the function juliaCall. In some cases the simulation is really long (i.e. more than 10 minutes). When trying to run it, after approx. 10 minutes the R interface throws the following error:

Error: lexical error: invalid char in json text.
                                       NA
                     (right here) ------^

But the Julia server continues to run the computation.

This is due to the fact that the JuliaInterface method ServerTask is constructed such that it tries for ten minutes (10 trials with a sleep time of 1 sec between them) to listen to the connection. After these 10 trials if the method wasn't able to read anything from the connection it simply return the value value = NA, which when read by the function XR::valueFromServer(value, key, get, .self) from the JuliaInterface method ServerEval throws the error. I was wondering if there is any way to wait for the Julia server to finish the computation before trying to read something from the server. I am sorry if my question has a really obvious answer, I am not yet familiar with the XR and XRJulia package.

Thanks for your help!

johnmchambers commented 6 years ago

The error message is because Julia is writing to the connection directly rather than through the JSON print used for other non-error returns.

The solution seems to be on the Julia side: either get Julia to wait on your computation before giving up; or have your computation return a special not-done-yet value after it waits some length of time. Then the R side would be a repeat loop that kept recalling the Julia function until it returned the actual answer.

oliviaAB commented 6 years ago

I see, thank you for your help! I will do that.