Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash with rxSolve() attempt of simulation #449

Closed
billdenney opened this issue Jul 26, 2021 · 6 comments
Closed

Crash with rxSolve() attempt of simulation #449

billdenney opened this issue Jul 26, 2021 · 6 comments

Comments

@billdenney
Copy link
Contributor

Related to #442 (in that I'm still trying to make that simulation), the below code crashes R at the rxSolve() call:

library(nlmixr)

linear_twocmt_iiv_growth <- function() {
  ini({
    tcl <- fixed(log(0.01)) ; label("Clearance (L/kg/hr)")
    tq <- fixed(log(0.05)) ; label("Intercompartmental clearance (L/kg/hr)")
    tv <- fixed(log(1.5)) ; label("Volume central (L/kg)")
    tv1 <- fixed(log(2)) ; label("Volume peripheral (L/kg)")
    
    tktr <- log(c(0.00001, 0.03, 3)) ; label("Transit compartment rate (1/hr)")
    slope <- c(-2, -0.02, 2) ; label("Slope on growth rate ((ng/mL)/hr)")
    ltumorgrowth <- log(c(0.0001, 0.01, 1)) ; label("Baseline tumor exponential growth rate (1/hr)")

    iiv_tumorgrowth ~ 0.1 ; label("Inter-individual variability in baseline tumor exponential growth rate")

    prop_sd <- 0.2 ; label("Proportional error for tumor volume (fraction)")
    add_sd <- 100 ; label("Additive error for tumor volume (mm^3)")
  })
  drake::no_deps(model({
    cl <- exp(tcl)
    q <- exp(tq)
    v <- exp(tv)
    v1 <- exp(tv1)
    kcp <- q/v
    kpc <- q/v1
    ktr <- exp(tktr)
    TUMOR(0) <- TUMORBL
    
    d/dt(CENTRAL) = -cl/v * CENTRAL - kcp*CENTRAL + kpc*PERIPH1
    d/dt(PERIPH1) = kcp*CENTRAL - kpc*PERIPH1
    # unit conversion
    cp <- CENTRAL/v*1000
    d/dt(TRANSIT) = ktr*(cp - TRANSIT)
    tumorgrowth <- exp(ltumorgrowth + iiv_tumorgrowth)
    ktumor <- tumorgrowth + slope*TRANSIT
    d/dt(TUMOR) = ktumor*TUMOR
    TUMOR ~ add(add_sd) + prop(prop_sd)
  }))
}

sim_dose <-
  data.frame(
    ID=1:50,
    time=0,
    amt=rep(seq(0, 20, by=5), each=10),
    evid=1,
    cmt="CENTRAL",
    mdv=1,
    TUMORBL=100
  )

sim_obs <-
  expand.grid(
    ID=1:50,
    time=(0:60)*24,
    amt=0,
    evid=0,
    cmt="TUMOR",
    mdv=0,
    TUMORBL=100
  )

sim_data <- rbind(sim_dose, sim_obs)
sim_data <- sim_data[order(sim_data$ID, sim_data$time), ]

model <- nlmixr(linear_twocmt_iiv_growth)
simulation <- rxSolve(model, events=sim_data)

My sessionInfo is:

> sessionInfo()
R version 4.1.0 (2021-05-18)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19043)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252    LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] nlmixr_2.0.4

loaded via a namespace (and not attached):
 [1] styler_1.5.1        tidyselect_1.1.1    xfun_0.24           purrr_0.3.4         lattice_0.20-44     RxODE_1.0.9         colorspace_2.0-2    vctrs_0.3.8         generics_0.1.0     
[10] htmltools_0.5.1.1   yaml_2.2.1          utf8_1.2.1          rlang_0.4.11        pillar_1.6.1        glue_1.4.2          withr_2.4.2         DBI_1.1.1           lbfgsb3c_2020-3.2  
[19] lifecycle_1.0.0     n1qn1_6.0.1-10      munsell_0.5.0       gtable_0.3.0        stringfish_0.15.1   evaluate_0.14       memoise_2.0.0       RApiSerialize_0.1.0 knitr_1.33         
[28] callr_3.7.0         fastmap_1.1.0       ps_1.6.0            parallel_4.1.0      sys_3.4             fansi_0.5.0         highr_0.9           Rcpp_1.0.7          clipr_0.7.1        
[37] backports_1.2.1     scales_1.1.1        checkmate_2.0.0     cachem_1.0.5        RcppParallel_5.1.4  fs_1.5.0            brew_1.0-6          ggplot2_3.3.5       digest_0.6.27      
[46] lotri_0.3.1         processx_3.5.2      dplyr_1.0.7         qs_0.24.1           grid_4.1.0          cli_3.0.1           tools_4.1.0         magrittr_2.0.1      tibble_3.1.2       
[55] PreciseSums_0.4     crayon_1.4.1        pkgconfig_2.0.3     ellipsis_0.3.2      data.table_1.14.0   reprex_2.0.0        assertthat_0.2.1    rmarkdown_2.9       rstudioapi_0.13    
[64] R6_2.5.0            nlme_3.1-152        units_0.7-2         compiler_4.1.0     
@mattfidler
Copy link
Collaborator

I will look into this. I will likely transfer this to RxODE when I figure out what the issue is.

@mattfidler
Copy link
Collaborator

C based back-trace:

Thread 1 "R" received signal SIGSEGV, Segmentation fault.
0x00007ffff3022317 in Rcpp::Rcpp_precious_preserve (object=0x5555580bc7f0) at barrier.cpp:107
107	barrier.cpp: No such file or directory.
(gdb) bt
#0  0x00007ffff3022317 in Rcpp::Rcpp_precious_preserve (object=0x5555580bc7f0) at barrier.cpp:107
nlmixrdevelopment/nlmixr#1  0x00007ffff27f19e8 in Rcpp::Rcpp_precious_preserve (object=0x5555580bc7f0)
    at /home/matt/R/x86_64-pc-linux-gnu-library/4.1/Rcpp/include/Rcpp/routines.h:155
nlmixrdevelopment/nlmixr#2  0x00007ffff27f1782 in Rcpp::Rcpp_PreciousPreserve (object=0x5555580bc7f0)
    at /home/matt/R/x86_64-pc-linux-gnu-library/4.1/Rcpp/include/RcppCommon.h:116
nlmixrdevelopment/nlmixr#3  0x00007ffff281c6e3 in Rcpp::PreserveStorage<Rcpp::Vector<16, Rcpp::PreserveStorage> >::set__ (this=0x7fffff670110, x=0x5555580bc7f0)
    at /home/matt/R/x86_64-pc-linux-gnu-library/4.1/Rcpp/include/Rcpp/storage/PreserveStorage.h:43
nlmixrdevelopment/nlmixr#4  0x00007ffff281d200 in Rcpp::Vector<16, Rcpp::PreserveStorage>::Vector (this=0x7fffff670110, x=0x5555580bc7f0)
    at /home/matt/R/x86_64-pc-linux-gnu-library/4.1/Rcpp/include/Rcpp/vector/Vector.h:74
nlmixrdevelopment/nlmixr#5  0x00007ffff282a593 in Rcpp::traits::Exporter<Rcpp::Vector<16, Rcpp::PreserveStorage> >::Exporter (this=0x7fffff670110, x=0x5555580bc7f0)
    at /home/matt/R/x86_64-pc-linux-gnu-library/4.1/Rcpp/include/Rcpp/internal/Exporter.h:31
nlmixrdevelopment/nlmixr#6  0x00007ffff281dade in Rcpp::internal::as<Rcpp::Vector<16, Rcpp::PreserveStorage> > (x=0x5555580bc7f0)
    at /home/matt/R/x86_64-pc-linux-gnu-library/4.1/Rcpp/include/Rcpp/as.h:87
nlmixrdevelopment/nlmixr#7  0x00007ffff2816fe3 in Rcpp::as<Rcpp::Vector<16, Rcpp::PreserveStorage> > (x=0x5555580bc7f0)
    at /home/matt/R/x86_64-pc-linux-gnu-library/4.1/Rcpp/include/Rcpp/as.h:152
nlmixrdevelopment/nlmixr#8  0x00007ffff28d643d in Rcpp::AttributeProxyPolicy<Rcpp::RObject_Impl<Rcpp::PreserveStorage> >::const_AttributeProxy::operator Rcpp::Vector<16, Rcpp::PreserveStorage><Rcpp::Vector<16, Rcpp::PreserveStorage> >() const (this=0x7fffff6702a0)
    at /home/matt/R/x86_64-pc-linux-gnu-library/4.1/Rcpp/include/Rcpp/api/meat/proxy.h:51
nlmixrdevelopment/nlmixr#9  0x00007ffff288bbef in rxIs_list (obj=..., cls="rxModelVars") at rxData.cpp:176
nlmixrdevelopment/nlmixr#10 0x00007ffff288e064 in rxIs (obj=..., cls="rxModelVars") at rxData.cpp:397
nlmixrdevelopment/nlmixr#11 0x00007ffff2894706 in rxModelVars_ (obj=...) at rxData.cpp:817
nlmixrdevelopment/nlmixr#12 0x00007ffff28cc966 in rxRxODEenv (obj=...) at rxData.cpp:5504
nlmixrdevelopment/nlmixr#13 0x00007ffff28cc999 in rxRxODEenv (obj=...) at rxData.cpp:5504

@mattfidler
Copy link
Collaborator

An even smaller reprex is:

rxSolve(list(a=3), events=et(0))

@mattfidler mattfidler transferred this issue from nlmixrdevelopment/nlmixr Jul 29, 2021
@billdenney
Copy link
Contributor Author

That is a lot smaller... (Thanks for looking into this one.)

@mattfidler
Copy link
Collaborator

This no longer crashes R, but says the model is unsupported (at least for now)

@billdenney
Copy link
Contributor Author

An "Unsupported" error makes sense to me.

mattfidler added a commit that referenced this issue Jul 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants