ropensci / nlrx

nlrx NetLogo R
https://docs.ropensci.org/nlrx
GNU General Public License v3.0
77 stars 12 forks source link

R handing after Java finished computing #95

Open WillRust303 opened 5 months ago

WillRust303 commented 5 months ago

Hi there,

I am trying to calculate the CPU time for a broad range of netlogo sims, however at the moment I am only running one simulation and timing that. I have noticed that simulations (even for one, small simulation) takes ~7x longer on nrlx than it does in NetLogo (NetLogo ~1 min, nlrx ~7 mins). Looking at the Processes in Windows Task Manager, it seems that when I run the sim from nlrx, java starts computing and then after about a minute, java finishes and closes. R then hangs for the remaining time before completeing its process.

I see other issues posted here on similar issues but the response is typically due to running too many sims / parameters. Whereas I am running only one simulation. I have pasted my code below:

R Code

Sys.setenv(JAVA_HOME='C:/Program Files/Java/jre-1.8')

netlogopath <- file.path("C:/Program Files/NetLogo 6.0.3") modelpath <- "AJ2015_upscale_test.nlogo") outpath <- file.path("C:/out")

~~~~OPEN MODEL AND TEST~~~~

nl <- nl(nlversion = "6.0.3", nlpath = netlogopath, modelpath = modelpath, jvmmem = 2048*8)

nl@experiment <- experiment(expname = "worms", outpath = outpath, repetition = 1,
tickmetrics = "true", idsetup = "setup",
idgo = "go",
runtime = 7300, evalticks = seq(1,7300), constants = list("Application_Rate" = 0, "Application_Year" = 0, "Application_Day" = 0, "Initial_Number_Adults" = 300, "Initial_Number_Juveniles" = 300, "Initial_Number_Cocoons" = 300), metrics.turtles = list("turtles" = c("who", "xcor", "ycor", "mass", "age", "breed")))

eval_variables_constants(nl)

nl@simdesign <- simdesign_simple(nl = nl, nseeds = 1) start <- Sys.time() results <- run_nl_all(nl = nl) end <- Sys.time()

difftime(end, start, units = "mins")

Any help you could give would be great! Thanks again.

nldoc commented 1 month ago

Hi @WillRust303, Thank you for the issue report. It is not completely unexpected that R takes some time after a simulation has finished. This is because the NetLogo output needs to be post-processed to generate a tidy R tibble format from the csv output. For example, lists take quite some parsing time. In your example above, you are including turtle metrics, whose parsing time heavily depends on the number of individuals. You might want to check show many individuals you have in your model. Please try to run the model without turtle metrics and check if it still takes that much post-processing time.

Unfortunately, I barely have time to develop the package aside from critical failures and general maintenance. However, I assume, the post-processing could be optimized quite a bit (in terms of flexibility (speaking of nested lists for example) and performance). I cannot promise anything, but I hope to find a slot for looking into it in the next weeks.