Closed levenc closed 3 years ago
Some additional information after my tests this morning.
Using a single vector of parameters for all individuals, I get no errors.
solved_model <- RxODE::rxSolve(ppk_model,cbind(theta,eta_dt[1,!c("ID")]),dat_dt)
However, when I try to include all the individual parameters, the same error occurs.
solved_model$params <- cbind(theta,eta_dt)
Error in `$<-.rxSolve`(`*tmp*`, params, value = list(THETA_LAGTIME = c(0.07, :
could not allocate enough memory for solving
One clarification (this may be a problem on my side), when I use a single vector of parameters with the model of the original post, the solving fails with this message:
solved_model <- RxODE::rxSolve(ppk_model,cbind(theta,eta_dt[1,!c("ID")]),dat_dt)
[====|====|====|====|====|====|====|====|====|====] 0:00:00
Error : 'alag(.)'/'rate(.)'/'dur(.)' cannot depend on the state values
I had to comment out the lines that relate to LAGTIME in the model to get it to work.
Hi @levenc
I cannot solve a problem of running out of memory very easily. But I can give you a possible work-around. Simply solve the first group of subjects and then solve the second group of subjects. In between save the files and then put them together in the end.
The memory that RxODE currently requires is the:
Some memory could be spared by not duplicating the data, but this would also remove the ability to solve the system in parallel. In R, the data structures like data.frames are actually not thread safe. This would also require a major rewrite of the solving engine to support both duplicate data structures for solving the system in a threaded manner as well as another data structure that takes the data in-place. While I think it is valuable, it is not the top of my todo list currently.
I'm unsure if this is helpful, but it at least explains the current state of RxODE.
Note you could also use:
rxSolve(..., returnType="data.table")
Since you seem to be using data.table
elsewhere. It will also save memory and slightly speed up the solving.
Also note, there is some rudimentary support for inter-occasion varaibility built in to the latest RxODE. It itsn't as well tested, but you can see the example here:
https://nlmixrdevelopment.github.io/RxODE/articles/RxODE-nesting.html?q=occasion#nesting-variability
Thank you @mattfidler for this detailed answer, I understand the situation better.
To get around the problem, I will implement the option you suggest: divide the subject group into smaller sets, solve for each set, and then combine them afterwards.
Also thanks for the note on data.table, that's good to know. This is the first time I use data.table for one of my projects, but certainly not the last; the performance and syntax make me want to forget about data.frames.
Hello, The following error appeared when applying rxSolve() to a dataset of 19,000 rows (10,000 individuals, with 19 rows per patient dataset):
My system: Dell XPS 13 9360, 16 GB RAM, 7th generation Intel Core i7 processor.
Surprisingly, whatever the memory available on the system, the error always occurs for the same number of individuals: no problem for n = 7,600 individuals, error for 7,700 individuals. I tested the same code today on a server with twice as much RAM, and the values that trigger the error were identical (with the same version of R, same version of RxODE, same GNU/linux distribution).
Here is a code snippet that reproduces the error:
On the other hand, updating the parameters of a model for 100,000 patients with the following syntax is not a problem :
Unfortunately, I am not using this approach here because I use the patient data set to input inter-occasion variability as time-varying covariates (I use RxODE as a simulation engine for a dosage individualization R package I'm working on, and for now the randoms effects are handled separately in R).
Also, and unrelated to this error, I had not had the opportunity to thank you for issue 185: thank you for your help.