Closed dzianismr closed 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?
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..?
The current RxODE
build is successful with MacOS
; You can update both and try, though it may be a different issue.
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 ...
I forgot to remove rxPermessive
from nlmixr
; It is now done here 4f44858
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!
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.
on my side: after removal of rxPermessive from nlmixr I could install it, however the crush persists.
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()
@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
I was hoping for a shorter running example. I will see if I can reproduce this with the github runner.
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)
Leave out the npde=TRUE
in the above reprex, obviously not needed.
@mattfidler you are right, the crush occurs in the simulation. The last message is: "Compiling NPDE model ... done"
Thank you. The following file will allow this to be run without nlmixr
:
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)
Github runner status for mac:
https://github.com/nlmixrdevelopment/RxODE/runs/1653178059?check_suite_focus=true
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?
What version of Mac are you running?
I think I can try it out on Catalina using QEMU:
To debug I think I need to turn off sip
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.
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.
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)
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)
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.
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.
After the most recent RxODE
this no longer crashes in my mac virtual environment. Let me know if it crashes for you or not.
thank you @mattfidler, I can confirm that on my side it runs as well! What was the fix?
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.
Thanks!
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?