danStich / shadia

shadia: dam passage performance standard models for R
https://shadia-ui.github.io/index.html
GNU General Public License v3.0
6 stars 1 forks source link

Bug: invalid length argument with no traceback #10

Closed danStich closed 6 years ago

danStich commented 6 years ago

Looks like a bug was introduced in one of the variable storage routines during transition to a package. I think this may be related to garbage collection in R/innerLoopSampling.R. Need to look into it, because it causes cores to crash and execution is halted.

danStich commented 6 years ago

not related to population crashing (and resultant empty vectors)

danStich commented 6 years ago

does not appear to be related to garbage collection in R/innerLoopSampling.R

danStich commented 6 years ago

EDIT: This was not the problem, but the change has been implemented.

Possible that this is the von Bertalanffy growth function crashing. Going to bootstrap the growth model and just add the parameters as a built-in data set like we did with arrival regression.

danStich commented 6 years ago

Also, this is happening very infrequently. Usually 1000 runs across 48 cores finishes fine, but haven't finished a run of 2,500 iterations b/c it keeps crashing.

danStich commented 6 years ago

Next steps

  1. Wrapping all 1st level internal funs in tryCatch
  2. Will look closer at garbage collection in the main file (penobscotRiverModel.R) that was commented out in favor of doing garbage collection in innerLoopSampling.R

EDIT:

  1. Wrapping penobscotRiverModel and merrimackRiverModel in try function using a while loop works, but is not a desirable long-term solution.

  2. Garbage collection ruled out as the problem.

danStich commented 6 years ago

This is happening much more frequently now in the merrimackRiverModel() function. Might be related to old fish and NaN being produced in the pRepeat_* columns of the results df. These occur commonly in the output from this function). Do not notice these very often during serial implementation of penobscotRiverModel(). Could be related to how the population is created, or the fact that those fish are removed from the population quickly/frequently because of mortality rates in simulation model. Guessing this is caused by division by zero when calculating pRepeat_ vectors, or that the lack of old fish results in vectors that are incorrect in length compared to a vector of names (which is based on maxAge).

danStich commented 6 years ago

Have narrowed down this error after extensive prodding.

The error is being produced in line 163 of inner-loop-sampling.R. It is occurring because there is an invalid value being passed to the length argument of the vector function. The purpose of that code is to create a vector that will hold entryDate, which is the first step for initializing individuals within the population. I'm guessing this occurs as a result of the conditional before that (used to build empty matrices in the event of zero spawners).

danStich commented 6 years ago

The problem was occurring when spawning population was reduced to 1 individual. Patched code to deal with this case in all models.