nlmixrdevelopment / nlmixr

nlmixr: an R package for population PKPD modeling
https://nlmixrdevelopment.github.io/nlmixr/
GNU General Public License v2.0
115 stars 45 forks source link

nlmixr: 2.0.1., npde=TRUE - crushes R session #460

Closed dzianismr closed 3 years ago

dzianismr commented 3 years ago

I was interested to test new nlmixr release, so I run examples described here https://nlmixrdevelopment.github.io/nlmixr/articles It was all going fine, until I got to the last one: https://nlmixrdevelopment.github.io/nlmixr/articles/xgxr-nlmixr-ggpmx.html in this example line nlmixr(cmt2m, dat, "saem", control=list(print=50), table=tableControl(npde=TRUE, cwres=TRUE)) crushes R session ( R session aborted; r encountered a fatal error. The session was terminated.). The crush is caused by npde=TRUE option. The last output in console is: Compiling NPDE model...qs v0.23.4 done

I can run nlmixr(cmt2m, dat, "saem") w/o npde=TRUE option, however than R session crushes same way during controller creation: ctr <- pmx_nlmixr(cmt2fit.prop, conts = c("WEIGHTB"), cats="TRTACT")

Basic system info: platform x86_64-apple-darwin15.6.0
arch x86_64
os darwin15.6.0
system x86_64, darwin15.6.0
status
major 3
minor 6.0
year 2019
month 04
day 26
svn rev 76424
language R
version.string R version 3.6.0 (2019-04-26) nickname Planting of a Tree

Any idea what is going wrong?

mattfidler commented 3 years ago

I'm unsure @dzianismr, but I will see if I can reproduce it on my end; I could run the vignette on windows and linux; I haven't run this on a mac.

@RichardHooijmaijers can you also see if you can verify this issue?

mattfidler commented 3 years ago

The Current RxODE build doesn't work with MacOS, I will see if I can fix that; perhaps that will fix your issue as well..?

mattfidler commented 3 years ago

The current RxODE build is successful with MacOS; You can update both and try, though it may be a different issue.

dzianismr commented 3 years ago

thanks @mattfidler, I reinstalled RxODE. On attempt to reinstall nlmixr I am getting the following error: ** byte-compile and prepare package for lazy loading Error: object ‘rxPermissive’ is not exported by 'namespace:RxODE' Any ideas? Will try to run it on Windows ...

mattfidler commented 3 years ago

I forgot to remove rxPermessive from nlmixr; It is now done here 4f44858

RichardHooijmaijers commented 3 years ago

I just installed the latest versions of RxODE and nlmixr and I can confirm that the same issue is present on my machine. When requesting NPDE, R crashes entirely. This was tested with the latest versions of the packages. The main difference is that I have tested it with R 4.0.3 on macOS Catalina (10.15.17). I think it uses a different version of xcode (and maybe gfortran/symengine?). Just let me know if there is anything more I can test!

mattfidler commented 3 years ago

Lets see if I can see anything on the linux side. Perhaps we can do a screen share and I help you debug where the crash is coming from.

dzianismr commented 3 years ago

on my side: after removal of rxPermessive from nlmixr I could install it, however the crush persists.

mattfidler commented 3 years ago

Ok. I need a small example that the crash persists, what about:

one.compartment <- function() {
    ini({
      tka <- 0.45 # Log Ka
      tcl <- 1 # Log Cl
      tv <- 3.45 # Log V
      eta.ka ~ 0.6
      eta.cl ~ 0.3
      eta.v ~ 0.1
      add.sd <- 0.7
    })
    model({
      ka <- exp(tka + eta.ka)
      cl <- exp(tcl + eta.cl)
      v <- exp(tv + eta.v)
      d/dt(depot) <- -ka * depot
      d/dt(center) <- ka * depot - cl/v * center
      cp <- center/v
      cp ~ add(add.sd)
    })
  }

 suppressWarnings(nlmixr(one.compartment, theo_sd,
                                       est = "focei",
                                       control = list(print = 0)
                                       table=tableControl(npde=TRUE)
                                       ))

Or

one.compartment <- function() {
    ini({
      tka <- 0.45 # Log Ka
      tcl <- 1 # Log Cl
      tv <- 3.45 # Log V
      eta.ka ~ 0.6
      eta.cl ~ 0.3
      eta.v ~ 0.1
      add.sd <- 0.7
    })
    model({
      ka <- exp(tka + eta.ka)
      cl <- exp(tcl + eta.cl)
      v <- exp(tv + eta.v)
      d/dt(depot) <- -ka * depot
      d/dt(center) <- ka * depot - cl/v * center
      cp <- center/v
      cp ~ add(add.sd)
    })
  }

 suppressWarnings(nlmixr(one.compartment, theo_sd,
                                       est = "focei",
                                       control = list(print = 0))) %>% addNpde()
dzianismr commented 3 years ago

@mattfidler I tested your example and it does not lead to a crush on my system. Your example has both different dataset and model. After some testing it seems that nlmixr does not crush with theo_sd dataset. Could you try the following:

## adapted from https://nlmixrdevelopment.github.io/nlmixr/articles/xgxr-nlmixr-ggpmx.html
# data
dat <- case1_pkpd %>%
    rename(DV=LIDV) %>%
    filter(CMT %in% 1:2) %>%
    # Filter (for now) since CENS supprot in nlmixr is in development
    filter(TRTACT != "Placebo") 

# model
## Use 2 compartment model
cmt2 <- function(){
    ini({
        lka <- log(0.1) # log Ka
        lv <- log(10) # Log Vc
        lcl <- log(4) # Log Cl
        lq <- log(10) # log Q
        lvp <- log(20) # Log Vp

        eta.ka ~ 0.01
        eta.v ~ 0.1
        eta.cl ~ 0.1
        logn.sd = 10
    })
    model({
        ka <- exp(lka + eta.ka)
        cl <- exp(lcl + eta.cl)
        v <- exp(lv + eta.v)
        q <- exp(lq)
        vp <- exp(lvp)
        linCmt() ~ lnorm(logn.sd)
    })
}
cmt2m <- nlmixr(cmt2)

# run
cmt2fit.logn1 <- nlmixr(cmt2m, dat, "saem",
                       control=list(print=50 ), 
                       table=tableControl(npde=TRUE,cwres=TRUE))
## 1 cmt model crushes as well
mattfidler commented 3 years ago

I was hoping for a shorter running example. I will see if I can reproduce this with the github runner.

mattfidler commented 3 years ago

Perhaps you can run it in this order to see where it is crashing in the MacOS system:

## adapted from https://nlmixrdevelopment.github.io/nlmixr/articles/xgxr-nlmixr-ggpmx.html
# data
library(nlmixr)
dat <- xgxr::case1_pkpd %>%
    dplyr::rename(DV=LIDV) %>%
    dplyr::filter(CMT %in% 1:2) %>%
    dplyr::filter(TRTACT != "Placebo")

# model
## Use 2 compartment model
cmt2 <- function(){
    ini({
        lka <- log(0.1) # log Ka
        lv <- log(10) # Log Vc
        lcl <- log(4) # Log Cl
        lq <- log(10) # log Q
        lvp <- log(20) # Log Vp

        eta.ka ~ 0.01
        eta.v ~ 0.1
        eta.cl ~ 0.1
        logn.sd = 10
    })
    model({
        ka <- exp(lka + eta.ka)
        cl <- exp(lcl + eta.cl)
        v <- exp(lv + eta.v)
        q <- exp(lq)
        vp <- exp(lvp)
        linCmt() ~ lnorm(logn.sd)
    })
}

# run
cmt2fit.logn1 <- nlmixr(cmt2, dat, "saem",
                       control=list(print=50 ),
                       table=tableControl(npde=TRUE))
#> ℹ parameter labels from comments will be replaced by 'label()'
#> qs v0.23.4.
#> RxODE 1.0.1 using 4 threads (see ?getRxThreads)
#> 1:   -2.3079   1.4377   2.2865   2.2290   3.0557   0.0095   0.0968   0.0950   1.8376
#> 50:   -1.5766   2.0157   1.0323   2.3637   4.5875   0.3689   0.7037   2.0742   0.1187
#> 100:   -1.3195   2.0315   1.3059   2.6515   4.7028   0.3274   0.7293   2.1481   0.1162
#> 150:   -1.2241   2.0266   1.3743   2.7437   4.7300   0.3147   0.7274   2.3197   0.1160
#> 200:   -1.1377   2.0270   1.5638   2.8380   4.7476   0.2278   0.7249   1.7837   0.1174
#> 250:   -1.1071   2.0255   1.5662   2.8601   4.7552   0.2441   0.7296   1.9375   0.1163
#> 300:   -1.1010   2.0279   1.5790   2.8592   4.7478   0.2511   0.7256   1.9556   0.1177
#> 350:   -1.1008   2.0313   1.5841   2.8555   4.7403   0.2648   0.7148   1.9592   0.1238
#> 400:   -1.1025   2.0328   1.5829   2.8545   4.7383   0.2761   0.7026   1.9613   0.1321
#> 450:   -1.1020   2.0337   1.5842   2.8543   4.7381   0.2861   0.6941   1.9696   0.1386
#> 500:   -1.1015   2.0341   1.5862   2.8543   4.7381   0.2935   0.6881   1.9722   0.1432
#> Calculating covariance matrix
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00
#> Calculating residuals/tables
#> done.
#> Compiling NPDE model...done
#> Warning in (function (uif, data, est = NULL, control = list(), ..., sum.prod = FALSE, : 
#> with negative times, compartments initialize at first negative observed time
#> with positive times, compartments initialize at time zero
#> use 'rxSetIni0(FALSE)' to initialize at first observed time
#> this warning is displayed once per session

## Now try to debug where the crash occurs;

# Possibly in the simulation

sim <- .npdeSim(cmt2fit.logn1)
#> Compiling NPDE model...done

# or use sim <- .npdeSim(cmt2fit.logn1, nsim = 1000)

npde <- .npdeCalc(cmt2fit.logn1, sim=sim)

print(head(npde))
#>          EPRED        ERES       NPDE
#> 1 2.303985e-16          NA         NA
#> 2 2.318070e-16          NA         NA
#> 3 1.134244e-02 0.027028417  2.4883456
#> 4 2.148270e-02 0.001817948 -2.0672683
#> 5 3.202672e-02 0.005965148 -0.2778415
#> 6 2.594364e-02 0.019981324  1.7604708

Created on 2021-01-04 by the reprex package (v0.3.0)

Session info ``` r devtools::session_info() #> ─ Session info ─────────────────────────────────────────────────────────────── #> setting value #> version R version 4.0.3 (2020-10-10) #> os Pop!_OS 20.10 #> system x86_64, linux-gnu #> ui X11 #> language en_US:en #> collate en_US.UTF-8 #> ctype en_US.UTF-8 #> tz America/Chicago #> date 2021-01-04 #> #> ─ Packages ─────────────────────────────────────────────────────────────────── #> package * version date lib source #> assertthat 0.2.1 2019-03-21 [1] CRAN (R 4.0.3) #> backports 1.2.1 2020-12-09 [1] CRAN (R 4.0.3) #> binom 1.1-1 2014-01-02 [1] CRAN (R 4.0.3) #> brew 1.0-6 2011-04-13 [1] CRAN (R 4.0.3) #> callr 3.5.1 2020-10-13 [1] CRAN (R 4.0.3) #> checkmate 2.0.0 2020-02-06 [1] CRAN (R 4.0.3) #> cli 2.2.0 2020-11-20 [1] CRAN (R 4.0.3) #> colorspace 2.0-0 2020-11-11 [1] CRAN (R 4.0.3) #> crayon 1.3.4 2017-09-16 [1] CRAN (R 4.0.3) #> data.table 1.13.4 2020-12-08 [1] CRAN (R 4.0.3) #> desc 1.2.0 2018-05-01 [1] CRAN (R 4.0.3) #> devtools 2.3.2 2020-09-18 [1] CRAN (R 4.0.3) #> digest 0.6.27 2020-10-24 [1] CRAN (R 4.0.3) #> dparser 0.1.8 2017-11-13 [1] CRAN (R 4.0.3) #> dplyr 1.0.2 2020-08-18 [1] CRAN (R 4.0.3) #> ellipsis 0.3.1 2020-05-15 [1] CRAN (R 4.0.3) #> evaluate 0.14 2019-05-28 [1] CRAN (R 4.0.3) #> fansi 0.4.1 2020-01-08 [1] CRAN (R 4.0.3) #> fs 1.5.0 2020-07-31 [1] CRAN (R 4.0.3) #> generics 0.1.0 2020-10-31 [1] CRAN (R 4.0.3) #> ggplot2 3.3.3 2020-12-30 [1] CRAN (R 4.0.3) #> glue 1.4.2 2020-08-27 [1] CRAN (R 4.0.3) #> gtable 0.3.0 2019-03-25 [1] CRAN (R 4.0.3) #> highr 0.8 2019-03-20 [1] CRAN (R 4.0.3) #> htmltools 0.5.0 2020-06-16 [1] CRAN (R 4.0.3) #> knitr 1.30 2020-09-22 [1] CRAN (R 4.0.3) #> labeling 0.4.2 2020-10-20 [1] CRAN (R 4.0.3) #> lattice 0.20-41 2020-04-02 [4] CRAN (R 4.0.0) #> lazyeval 0.2.2 2019-03-15 [1] CRAN (R 4.0.3) #> lbfgsb3c 2020-3.2 2020-03-03 [1] CRAN (R 4.0.3) #> lifecycle 0.2.0 2020-03-06 [1] CRAN (R 4.0.3) #> lotri 0.3.1 2021-01-04 [1] local #> magrittr 2.0.1 2020-11-17 [1] CRAN (R 4.0.3) #> Matrix 1.2-18 2019-11-27 [4] CRAN (R 4.0.0) #> memoise 1.1.0 2017-04-21 [1] CRAN (R 4.0.3) #> munsell 0.5.0 2018-06-12 [1] CRAN (R 4.0.3) #> n1qn1 6.0.1-10 2020-11-17 [1] CRAN (R 4.0.3) #> nlme 3.1-149 2020-08-23 [4] CRAN (R 4.0.2) #> nlmixr * 2.0.1 2021-01-05 [1] local #> pander 0.6.3 2018-11-06 [1] CRAN (R 4.0.3) #> pillar 1.4.7 2020-11-20 [1] CRAN (R 4.0.3) #> pkgbuild 1.2.0 2020-12-15 [1] CRAN (R 4.0.3) #> pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.0.3) #> pkgload 1.1.0 2020-05-29 [1] CRAN (R 4.0.3) #> png 0.1-7 2013-12-03 [1] CRAN (R 4.0.3) #> PreciseSums 0.4 2020-07-10 [1] CRAN (R 4.0.3) #> prettyunits 1.1.1 2020-01-24 [1] CRAN (R 4.0.3) #> processx 3.4.5 2020-11-30 [1] CRAN (R 4.0.3) #> ps 1.5.0 2020-12-05 [1] CRAN (R 4.0.3) #> purrr 0.3.4 2020-04-17 [1] CRAN (R 4.0.3) #> qs * 0.23.4 2020-11-25 [1] CRAN (R 4.0.3) #> R6 2.5.0 2020-10-28 [1] CRAN (R 4.0.3) #> RApiSerialize 0.1.0 2014-04-19 [1] CRAN (R 4.0.3) #> Rcpp 1.0.5 2020-07-06 [1] CRAN (R 4.0.3) #> RcppParallel 5.0.2 2020-06-24 [1] CRAN (R 4.0.3) #> remotes 2.2.0 2020-07-21 [1] CRAN (R 4.0.3) #> rex 1.2.0 2020-04-21 [1] CRAN (R 4.0.3) #> rlang 0.4.10 2020-12-30 [1] CRAN (R 4.0.3) #> rmarkdown 2.6 2020-12-14 [1] CRAN (R 4.0.3) #> rprojroot 2.0.2 2020-11-15 [1] CRAN (R 4.0.3) #> RxODE * 1.0.1 2021-01-04 [1] local #> scales 1.1.1 2020-05-11 [1] CRAN (R 4.0.3) #> sessioninfo 1.1.1 2018-11-05 [1] CRAN (R 4.0.3) #> stringfish 0.14.2 2020-09-05 [1] CRAN (R 4.0.3) #> stringi 1.5.3 2020-09-09 [1] CRAN (R 4.0.3) #> stringr 1.4.0 2019-02-10 [1] CRAN (R 4.0.3) #> testthat 3.0.1 2020-12-17 [1] CRAN (R 4.0.3) #> tibble 3.0.4 2020-10-12 [1] CRAN (R 4.0.3) #> tidyselect 1.1.0 2020-05-11 [1] CRAN (R 4.0.3) #> units 0.6-7 2020-06-13 [1] CRAN (R 4.0.3) #> usethis 2.0.0 2020-12-10 [1] CRAN (R 4.0.3) #> vctrs 0.3.6 2020-12-17 [1] CRAN (R 4.0.3) #> withr 2.3.0 2020-09-22 [1] CRAN (R 4.0.3) #> xfun 0.19 2020-10-30 [1] CRAN (R 4.0.3) #> xgxr 1.0.9 2020-04-14 [1] CRAN (R 4.0.3) #> yaml 2.2.1 2020-02-01 [1] CRAN (R 4.0.3) #> #> [1] /home/matt/R/x86_64-pc-linux-gnu-library/4.0 #> [2] /usr/local/lib/R/site-library #> [3] /usr/lib/R/site-library #> [4] /usr/lib/R/library ```
mattfidler commented 3 years ago

Leave out the npde=TRUE in the above reprex, obviously not needed.

dzianismr commented 3 years ago

@mattfidler you are right, the crush occurs in the simulation. The last message is: "Compiling NPDE model ... done"

mattfidler commented 3 years ago

Thank you. The following file will allow this to be run without nlmixr:

si.zip

If so I can add it to the RxODE testing matrix to see if it will fail on MacOS there:

library(RxODE)
#> RxODE 1.0.1 using 4 threads (see ?getRxThreads)
tempdir <- tempdir()
download.file("https://github.com/nlmixrdevelopment/nlmixr/files/5772994/si.zip",
              file.path(tempdir, "si.zip"))

unzip(file.path(tempdir, "si.zip"), files="si.qs", exdir=tempdir)

si <- qs::qread(file.path(tempdir, "si.qs"))

si$object <- RxODE(si$object)
#> qs v0.23.4.

set.seed(1009)
solve <- do.call(RxODE::rxSolve, si)
#> Warning: 
#> with negative times, compartments initialize at first negative observed time
#> with positive times, compartments initialize at time zero
#> use 'rxSetIni0(FALSE)' to initialize at first observed time
#> this warning is displayed once per session

print(head(solve))
#>   sim.id id      time        sim CENS rxLambda rxYj rxLow rxHi
#> 1      1 31 -23.95311 -36.178002    0        0    3     0    1
#> 2      1 31  -0.03594 -35.985310    0        0    3     0    1
#> 3      1 31   0.13381  -4.654889    1        0    3     0    1
#> 4      1 31   0.48619  -3.910119    1        0    3     0    1
#> 5      1 31   1.00637  -3.392926    1        0    3     0    1
#> 6      1 31   2.02464  -3.625505    1        0    3     0    1

Created on 2021-01-05 by the reprex package (v0.3.0)

Session info ``` r devtools::session_info() #> ─ Session info ─────────────────────────────────────────────────────────────── #> setting value #> version R version 4.0.3 (2020-10-10) #> os Pop!_OS 20.10 #> system x86_64, linux-gnu #> ui X11 #> language en_US:en #> collate en_US.UTF-8 #> ctype en_US.UTF-8 #> tz America/Chicago #> date 2021-01-05 #> #> ─ Packages ─────────────────────────────────────────────────────────────────── #> package * version date lib source #> assertthat 0.2.1 2019-03-21 [1] CRAN (R 4.0.3) #> backports 1.2.1 2020-12-09 [1] CRAN (R 4.0.3) #> callr 3.5.1 2020-10-13 [1] CRAN (R 4.0.3) #> checkmate 2.0.0 2020-02-06 [1] CRAN (R 4.0.3) #> cli 2.2.0 2020-11-20 [1] CRAN (R 4.0.3) #> colorspace 2.0-0 2020-11-11 [1] CRAN (R 4.0.3) #> crayon 1.3.4 2017-09-16 [1] CRAN (R 4.0.3) #> data.table 1.13.4 2020-12-08 [1] CRAN (R 4.0.3) #> desc 1.2.0 2018-05-01 [1] CRAN (R 4.0.3) #> devtools 2.3.2 2020-09-18 [1] CRAN (R 4.0.3) #> digest 0.6.27 2020-10-24 [1] CRAN (R 4.0.3) #> dparser 0.1.8 2017-11-13 [1] CRAN (R 4.0.3) #> dplyr 1.0.2 2020-08-18 [1] CRAN (R 4.0.3) #> ellipsis 0.3.1 2020-05-15 [1] CRAN (R 4.0.3) #> evaluate 0.14 2019-05-28 [1] CRAN (R 4.0.3) #> fansi 0.4.1 2020-01-08 [1] CRAN (R 4.0.3) #> fs 1.5.0 2020-07-31 [1] CRAN (R 4.0.3) #> generics 0.1.0 2020-10-31 [1] CRAN (R 4.0.3) #> ggplot2 3.3.3 2020-12-30 [1] CRAN (R 4.0.3) #> glue 1.4.2 2020-08-27 [1] CRAN (R 4.0.3) #> gtable 0.3.0 2019-03-25 [1] CRAN (R 4.0.3) #> highr 0.8 2019-03-20 [1] CRAN (R 4.0.3) #> htmltools 0.5.0 2020-06-16 [1] CRAN (R 4.0.3) #> knitr 1.30 2020-09-22 [1] CRAN (R 4.0.3) #> lifecycle 0.2.0 2020-03-06 [1] CRAN (R 4.0.3) #> lotri 0.3.1 2021-01-04 [1] local #> magrittr 2.0.1 2020-11-17 [1] CRAN (R 4.0.3) #> memoise 1.1.0 2017-04-21 [1] CRAN (R 4.0.3) #> munsell 0.5.0 2018-06-12 [1] CRAN (R 4.0.3) #> pillar 1.4.7 2020-11-20 [1] CRAN (R 4.0.3) #> pkgbuild 1.2.0 2020-12-15 [1] CRAN (R 4.0.3) #> pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.0.3) #> pkgload 1.1.0 2020-05-29 [1] CRAN (R 4.0.3) #> PreciseSums 0.4 2020-07-10 [1] CRAN (R 4.0.3) #> prettyunits 1.1.1 2020-01-24 [1] CRAN (R 4.0.3) #> processx 3.4.5 2020-11-30 [1] CRAN (R 4.0.3) #> ps 1.5.0 2020-12-05 [1] CRAN (R 4.0.3) #> purrr 0.3.4 2020-04-17 [1] CRAN (R 4.0.3) #> qs * 0.23.4 2020-11-25 [1] CRAN (R 4.0.3) #> R6 2.5.0 2020-10-28 [1] CRAN (R 4.0.3) #> RApiSerialize 0.1.0 2014-04-19 [1] CRAN (R 4.0.3) #> Rcpp 1.0.5 2020-07-06 [1] CRAN (R 4.0.3) #> RcppParallel 5.0.2 2020-06-24 [1] CRAN (R 4.0.3) #> remotes 2.2.0 2020-07-21 [1] CRAN (R 4.0.3) #> rlang 0.4.10 2020-12-30 [1] CRAN (R 4.0.3) #> rmarkdown 2.6 2020-12-14 [1] CRAN (R 4.0.3) #> rprojroot 2.0.2 2020-11-15 [1] CRAN (R 4.0.3) #> RxODE * 1.0.1 2021-01-05 [1] local #> scales 1.1.1 2020-05-11 [1] CRAN (R 4.0.3) #> sessioninfo 1.1.1 2018-11-05 [1] CRAN (R 4.0.3) #> stringfish 0.14.2 2020-09-05 [1] CRAN (R 4.0.3) #> stringi 1.5.3 2020-09-09 [1] CRAN (R 4.0.3) #> stringr 1.4.0 2019-02-10 [1] CRAN (R 4.0.3) #> testthat 3.0.1 2020-12-17 [1] CRAN (R 4.0.3) #> tibble 3.0.4 2020-10-12 [1] CRAN (R 4.0.3) #> tidyselect 1.1.0 2020-05-11 [1] CRAN (R 4.0.3) #> units 0.6-7 2020-06-13 [1] CRAN (R 4.0.3) #> usethis 2.0.0 2020-12-10 [1] CRAN (R 4.0.3) #> vctrs 0.3.6 2020-12-17 [1] CRAN (R 4.0.3) #> withr 2.3.0 2020-09-22 [1] CRAN (R 4.0.3) #> xfun 0.19 2020-10-30 [1] CRAN (R 4.0.3) #> yaml 2.2.1 2020-02-01 [1] CRAN (R 4.0.3) #> #> [1] /home/matt/R/x86_64-pc-linux-gnu-library/4.0 #> [2] /usr/local/lib/R/site-library #> [3] /usr/lib/R/site-library #> [4] /usr/lib/R/library ```
mattfidler commented 3 years ago

Github runner status for mac:

https://github.com/nlmixrdevelopment/RxODE/runs/1653178059?check_suite_focus=true

mattfidler commented 3 years ago

For the mac github runner, the run is successful, meaning that it cannot reproduce the crash.

Could you see if you can run the simulation?

mattfidler commented 3 years ago

What version of Mac are you running?

I think I can try it out on Catalina using QEMU:

https://github.com/foxlet/macOS-Simple-KVM

mattfidler commented 3 years ago

To debug I think I need to turn off sip

https://hackintosher.com/forums/thread/enable-disable-system-integrity-protection-sip-on-a-hackintosh.53/

mattfidler commented 3 years ago
 thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x10baf7038)
    frame #0: 0x00000001099873cd RxODE.so`get_fkeep + 61
RxODE.so`get_fkeep:
->  0x1099873cd <+61>: movsd  (%rax,%rcx,8), %xmm0      ; xmm0 = mem[0],zero 
    0x1099873d2 <+66>: addq   $0x8, %rsp
    0x1099873d6 <+70>: popq   %rbx
    0x1099873d7 <+71>: popq   %rbp
Target 0: (R) stopped.
mattfidler commented 3 years ago

I installed in the mac using these instructions and the fix above and the mac no longer crashes for me (and has OpenMP support). I am rerunning the whole vignette now to see if there is another issue.

dzianismr commented 3 years ago

I have just reinstalled R and compilers, however the crush persist here. System info: platform x86_64-apple-darwin17.0
arch x86_64
os darwin17.0
system x86_64, darwin17.0
status
major 4
minor 0.3
year 2020
month 10
day 10
svn rev 79318
language R
version.string R version 4.0.3 (2020-10-10) nickname Bunny-Wunnies Freak Out

rxode version: Github (nlmixrdevelopment/RxODE@33f8725) nlmixr version: Github (nlmixrdevelopment/nlmixr@ab2aa7c)

dzianismr commented 3 years ago

I run code in R console, instead of R Studio and got the following details on the error message:

sim <- .npdeSim(cmt2fit.logn1) Compiling NPDE model...done

caught segfault address 0x7fa3d1548008, cause 'memory not mapped'

Traceback: 1: rxSolveSEXP(object, .ctl, .nms, .xtra, params, events, inits, setupOnlyS = .setupOnly) 2: withCallingHandlers(expr, warning = function(w) { assign(".ws", unique(c(w$message, .ws)), .thisEnv)}) 3: withCallingHandlers(expr, warning = function(w) if (inherits(w, classes)) tryInvokeRestart("muffleWarning")) 4: suppressWarnings(withCallingHandlers(expr, warning = function(w) { assign(".ws", unique(c(w$message, .ws)), .thisEnv)})) 5: .collectWarnings(rxSolveSEXP(object, .ctl, .nms, .xtra, params, events, inits, setupOnlyS = .setupOnly), lst = TRUE) 6: rxSolve.default(rx = "rxyj~3;\nrxlambda~0;\nrxhi~1;\nrxlow~0;\nrxpred~log(linCmtB(rxPTR,t,0,2,1,0,exp(eta.cl+lcl),exp(eta.v+lv),exp(lq),exp(lvp),0,0,0,1,0,0,exp(eta.ka+lka),0,1,0,0));\nrxr~logn.sd;\nipred~rxTBSi(rxpred, rxlambda, rxyj, rxlow, rxhi);\nsim=rxpred+rxr", params = c(lka = -1.10154188820861, lv = 1.58622598533733, lcl = 2.03412291145376, lq = 2.85430448403909, lvp = 4.73808608096545 ), ... ... returnType = "data.frame.TBS", nsim = 300, modelName = "NPDE", keep = "CENS") 10: do.call("nlmixrSim", .si) 11: .npdeSim(cmt2fit.logn1)

mattfidler commented 3 years ago

Thanks. The full vignette didn't work for me either; I will let you know if I can run it on the mac emulator correctly. I know I can't currently reproduce your system, though.

mattfidler commented 3 years ago

If you are brave, you can disable SIP and work in the console too to get a c-level backtrace:

R -d lldb
run

Here R will run and you can run your problem once it crashes it will drop into the (lldb) prompt to get a backtrace of the problem. For me it is still the get_fkeep c function with the invalid memory access on the mac.

mattfidler commented 3 years ago

After the most recent RxODE this no longer crashes in my mac virtual environment. Let me know if it crashes for you or not.

dzianismr commented 3 years ago

thank you @mattfidler, I can confirm that on my side it runs as well! What was the fix?

mattfidler commented 3 years ago

There was a garbage collection issue (which removed the memory when it tried to access it) and a index that was not being reset at the simulation level, but at the problem level.

mattfidler commented 3 years ago

Thanks!