role-model / roleR

R package implementing the RoLE model
https://role-model.github.io/roleR
GNU General Public License v3.0
1 stars 2 forks source link

Index out of bounds #85

Closed diazrenata closed 1 year ago

diazrenata commented 1 year ago

On my machine, this throws an Index out of Bounds error. I think it's seed (and maybe computer? IDK if it's in the loop 👀) dependent. Just documenting it here 😄

library(roleR)
library(ggplot2)
library(dplyr)
set.seed(1988) #jbp
### Setting up a roleExperiment

#### Replicates of the same parameter settings

params1 <- untbParams(individuals_local = 100, individuals_meta = 1000, 
                      species_meta = 50, 
                      speciation = 0.2, 
                      dispersal_prob = 0.1, init_type = 'oceanic_island',
                      niter = 10000, niterTimestep = 100) 

paramsList1 <- list(a= params1, b= params1, c=params1, d= params1, e=params1)

trial1 <- roleExperiment(paramsList1)

results1 <- runRole(trial1)
Error: Index out of bounds: [index=2101; extent=2101].
diazrenata commented 1 year ago

@jidec @ajrominger I am actually getting this error pretty frequently and I think it would be good to look into where it's coming from. Would one of you like to do that, or would you like me to do some digging?

ajrominger commented 1 year ago

yes, definitely would be good to figure this out! a few questions to help diagnose:

does the error happen with those same parameter values, but when you only make a list of length 1, e.g. like this:

params1 <- untbParams(individuals_local = 100, individuals_meta = 1000, 
                      species_meta = 50, 
                      speciation = 0.2, 
                      dispersal_prob = 0.1, init_type = 'oceanic_island',
                      niter = 10000, niterTimestep = 100) 

plist <- list(a= params1)
e <- roleExperiment(plist)
r <- runRole(e)

Does the error happen when you pass those same params to roleModel instead of roleExperiment?

If the errors don't happen in those cases that would be wonderful, cause it means the bug is somewhere outside the core loop, and rather somewhere in the setup/execution of the multi-model experiement.

But if the error happens everywhere, it's probably in the main loop.

That will be a bug fix for @jidec for sure! (though I can help starting on April 10)

diazrenata commented 1 year ago

Excellent questions! In response:

In short, it occurs in all of the cases (a roleExperiment with a params list of only one model, and running on a roleModel instead of a roleExperiment).

It also seems to be idiosyncratic even regarding seed. I can run the exact code in the first post in a clean R environment and sometimes get it and sometimes not.

isaacovercast commented 1 year ago

Reminds me of an old quote from the quote wall: "Stochasticity! That's the Devil's middle name."

jidec commented 1 year ago

If I had to guess it's an in-loop augmentation bug - I will try to replicate and turn on loop print statements to try to figure out where this is happening - more soon!

jidec commented 1 year ago

It was an in-loop augmentation bug where some of the phylo objects weren't getting buffered, so when the speciation rate is high (0.2 in Renata's params) you can get index out of range. I pushed a fix for the one that Renata was encountering, but I found another one that happens much more infrequently (once every 300-400 models?) and have yet to fix, so I will leave this issue open.

jidec commented 1 year ago

fixed the known rare augmentation bug #d668db8