metrumresearchgroup / mrgsolve

Simulate from ODE-based population PK/PD and QSP models in R
https://mrgsolve.org
GNU General Public License v2.0
130 stars 36 forks source link

Too big dataset to be simulated? #403

Closed ChenyanLoveModel closed 6 years ago

ChenyanLoveModel commented 6 years ago

Hi, there always comes an error message as below when I set a big end point (eg. 96hours) or low delta (eg. 0.0001) or have thoudsands of ID in doing the simulation. Is it because MRGsolve can't handle such big computational request? How to solve it?

DLSODA-  At current T (=R1), MXSTEP (=I1) steps   
      taken on this call before reaching TOUT     
In above message, I = 
[1] 2000
In above message, R = 
[1] 0.0004049985
DLSODA-  ISTATE (=I1) illegal.
In above message, I = 
[1] -1
DLSODA-  Run aborted.. apparent infinite loop.    
Error in (function (x, data, idata = null_idata, carry.out = character(0),  : 
  error from XERRWD
kylebaron commented 6 years ago

Hi @ChenyanLoveModel -

Generally, mrgsolve can handle 1000s of IDs, small delta (although some values might be so low that you run out of memory .... a limitation of your hardware) or large end time (some models we simulate out for 20 years or more).

If you focus on this part of the error message

DLSODA-  At current T (=R1), MXSTEP (=I1) steps   
      taken on this call before reaching TOUT     
In above message, I = 
[1] 2000

This is coming from the ODEPACK solver. It means that the system tried to advance to the next time, but couldn't make it within 2000 steps (the default maximum number of steps).

You can set it to a larger number and see what happens

mod %>% mrgsim(..., maxsteps = 10000)

But it is sort of strange that this would be happening with very small delta (you don't have to advance very far ... it shouldn't take a lot of steps) and I'm not sure what the connection is to 1000s of IDS.

I'm not sure how complicated the model is ... but might be worth a check of the code. IF the model is wacky, that also might cause it to need more steps to get to the next time. But try increasing maxsteps first.

Kyle

ChenyanLoveModel commented 6 years ago

Hi Kyle,

Thanks for your suggestion! I believe it would help, but I can't tell now because that message disappeared all of a sudden (not having the chance to test maxsteps) after I clean the chache...I will update you next time I face the same situation...Anyway, your answer provides me with a powerful weapon at hand!

On the other hand, I want to pose another error message I have experienced (looks similar at first sight). In this case, maxsteps = 10000 doesn't help. Could you help me to judge what it is? I wonder if it is the same kind of problem. And how to solve it? (More details below after the error message)

DLSODA-  At T (=R1) and step size H (=R2), the    
      corrector convergence failed repeatedly     
      or with ABS(H) = HMIN   
In above message, R1 =
[1] 3.855001e-236 2.432713e+225
DLSODA-  ISTATE (=I1) illegal.
In above message, I = 
[1] -5
DLSODA-  Run aborted.. apparent infinite loop.    
Error in (function (x, data, idata = null_idata, carry.out = character(0),  : 
  error from XERRWD

The situation is that I have a model successfully fitted in NONMEM, but shows weird behavior in MRGsolve.

Maybe the possible reason is that my model ("wacky") depends a lot on the stepsize (the smaller the better)? But your suggestion doesn't help magically here! Do you have any idea? Thank you.

kylebaron commented 6 years ago

Ok. You're getting a different message now. Naturally, changing maxsteps will not work here. This is what I was warning you about in the previous message.

DLSODA-  At T (=R1) and step size H (=R2), the    
      corrector convergence failed repeatedly     
      or with ABS(H) = HMIN   
In above message, R1 =
[1] 3.855001e-236 2.432713e+225

The noise happens in the PREDS because the values are getting smaller than the tolerance you have. It looks like you are running some sort of predator-prey type model, maybe viral dynamics or something similar (you haven't shared the model, so I can't tell). But I frequently see this with viral dynamics models, when the value in a compartment gets very small. The value in the compartment can turn negative in that case.

To address that problem you can try

mod %>% mrgsim(atol = 1E-20) ## or smaller

You might also try checking for some negative value that you might be (unknowingly) generating.

I'm not offering you "magic solutions". Just trying to advise the best I can based on the information you are sharing. It would be more helpful for us if you can post a reproducible example that we could work with. Until then I can only respond to the information you share. But either way, we expose the solver settings so that they can be used. Sometimes you need to understand the problem a bit and make the appropriate adjustments.

ChenyanLoveModel commented 6 years ago

Hi Kyle,

Thank you again for your suggestion.

Yes, my project is a Predator-Prey model, on bacterial count. But since the model hasn't been published yet, I'am bit reluctant to share the code on open-source.

Your suggestionmrgsim(atol = 1E-20) works this time. By using small delta value at the same time, we can get quite reasonable plots for a very long time period without any error message mrgsim(delta=0.001, atol = 1E-20, end=96) image

Apologize that the first posed question was kind of "at will". On the bright side, you let us know and be aware of the use of maxsteps = 10000.

Thank you!