nlmixr2 / rxode2

rxode2
https://nlmixr2.github.io/rxode2/
GNU General Public License v3.0
28 stars 7 forks source link

Crash when sequentially updating a model #744

Closed billdenney closed 1 month ago

billdenney commented 1 month ago

This causes R in Windows to crash with rxode2 version 2.1.2. And, it also crashes on R in Linux 4.4.1 with rxode2 version 2.1.3.9000. It crashes both after "t" (the 20th iteration).

library(rxode2)

mod1 <- function() {
  ini({
    # central 
    KA=2.94E-01
    CL=1.86E+01
    V2=4.02E+01
    # peripheral
    Q=1.05E+01
    V3=2.97E+02
    # effects
    Kin=1
    Kout=1
    EC50=200 
  })
  model({
    C2 <- centr/V2
    C3 <- peri/V3
    d/dt(depot) <- -KA*depot
    d/dt(centr) <- KA*depot - CL*C2 - Q*C2 + Q*C3
    d/dt(peri)  <- Q*C2 - Q*C3
    eff(0) <- 1
    d/dt(eff)   <- Kin - Kout*(1-C2/(EC50+C2))*eff
  })
}

newMod <- mod1

start_time <- Sys.time()
for (current_letter in letters) {
  message(current_letter, Sys.time() - start_time)
  start_time <- Sys.time()
  newMod <-
    do.call(model, list(newMod, str2lang(paste(current_letter, "<- 1")), append = TRUE))
}
billdenney commented 1 month ago

Here is the backtrace and a bit more info:

[New Thread 0x7ffff3626640 (LWP 2528816)]
rxode2 2.1.3.9000 using 16 threads (see ?getRxThreads)
  no cache: create with `rxCreateCache()`
a0.00288510322570801
[Detaching after vfork from child process 2528817]
[Detaching after vfork from child process 2528819]
[Detaching after vfork from child process 2528824]
b1.10105562210083
c0.127583265304565
d0.132045030593872
e0.129754304885864
f0.134222984313965
g0.13626766204834
h0.142498254776001
i0.142843723297119
j0.145278453826904
k0.146876811981201
l0.210743188858032
m0.14863133430481
n0.138411283493042
o0.137673377990723
p0.140302419662476
q0.139822244644165
r0.142178535461426
s0.14289665222168
t0.144241333007812
free(): invalid pointer

Thread 1 "R" received signal SIGABRT, Aborted.
__pthread_kill_implementation (no_tid=0, signo=6, threadid=140737304253440) at ./nptl/pthread_kill.c:44
44      ./nptl/pthread_kill.c: No such file or directory.
(gdb) bt
#0  __pthread_kill_implementation (no_tid=0, signo=6, threadid=140737304253440) at ./nptl/pthread_kill.c:44
#1  __pthread_kill_internal (signo=6, threadid=140737304253440) at ./nptl/pthread_kill.c:78
#2  __GI___pthread_kill (threadid=140737304253440, signo=signo@entry=6) at ./nptl/pthread_kill.c:89
#3  0x00007ffff796b476 in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26
#4  0x00007ffff79517f3 in __GI_abort () at ./stdlib/abort.c:79
#5  0x00007ffff79b2676 in __libc_message (action=action@entry=do_abort, fmt=fmt@entry=0x7ffff7b04b77 "%s\n")
    at ../sysdeps/posix/libc_fatal.c:155
#6  0x00007ffff79c9cfc in malloc_printerr (str=str@entry=0x7ffff7b02744 "free(): invalid pointer") at ./malloc/malloc.c:5664
#7  0x00007ffff79cba44 in _int_free (av=<optimized out>, p=<optimized out>, have_lock=0) at ./malloc/malloc.c:4439
#8  0x00007ffff79ce453 in __GI___libc_free (mem=<optimized out>) at ./malloc/malloc.c:3391
#9  0x00007ffff291b936 in parseFree (last=last@entry=0) at tran.c:266
#10 0x00007ffff291bb0c in reset () at tran.c:305
#11 0x00007ffff2927437 in setupTrans (parse_file=0x555559126188, fullPrintIn=0x55555b466978, goodFuns=0x55555ad9ae50,
    inME=0x55555844d0c0, isEscIn=0x55555d11b720, parseStr=<optimized out>, model_md5=0x55555d10f288, prefix=0x555559105550)
    at tran.c:539
#12 _rxode2_trans (parse_file=0x555559126188, prefix=0x555559105550, model_md5=0x55555d10f288, parseStr=<optimized out>,
    isEscIn=0x55555d11b720, inME=0x55555844d0c0, goodFuns=0x55555ad9ae50, fullPrintIn=0x55555b466978) at tran.c:613
#13 0x00007ffff7c4f238 in ?? () from /usr/lib/R/lib/libR.so
#14 0x00007ffff7c92688 in ?? () from /usr/lib/R/lib/libR.so
#15 0x00007ffff7ca619d in ?? () from /usr/lib/R/lib/libR.so
#16 0x00007ffff7ca650b in Rf_eval () from /usr/lib/R/lib/libR.so
#17 0x00007ffff7ca86df in ?? () from /usr/lib/R/lib/libR.so
#18 0x00007ffff7ca94c7 in ?? () from /usr/lib/R/lib/libR.so
#19 0x00007ffff7ca663c in Rf_eval () from /usr/lib/R/lib/libR.so
#20 0x00007ffff7cacbb2 in ?? () from /usr/lib/R/lib/libR.so
#21 0x00007ffff7c8b200 in ?? () from /usr/lib/R/lib/libR.so
#22 0x00007ffff7ca619d in ?? () from /usr/lib/R/lib/libR.so
#23 0x00007ffff7ca650b in Rf_eval () from /usr/lib/R/lib/libR.so
#24 0x00007ffff7ca6eed in ?? () from /usr/lib/R/lib/libR.so
#25 0x00007ffff7ca6710 in Rf_eval () from /usr/lib/R/lib/libR.so
#26 0x00007ffff7cad380 in ?? () from /usr/lib/R/lib/libR.so
#27 0x00007ffff7cecfe7 in ?? () from /usr/lib/R/lib/libR.so
#28 0x00007ffff7c8b01f in ?? () from /usr/lib/R/lib/libR.so
#29 0x00007ffff7ca619d in ?? () from /usr/lib/R/lib/libR.so
#30 0x00007ffff7ca650b in Rf_eval () from /usr/lib/R/lib/libR.so
#31 0x00007ffff7ca86df in ?? () from /usr/lib/R/lib/libR.so
#32 0x00007ffff7ca94c7 in ?? () from /usr/lib/R/lib/libR.so
#33 0x00007ffff7ca9eed in ?? () from /usr/lib/R/lib/libR.so
#34 0x00007ffff7cef5a4 in ?? () from /usr/lib/R/lib/libR.so
#35 0x00007ffff7cefc71 in ?? () from /usr/lib/R/lib/libR.so
#36 0x00007ffff7cefff2 in ?? () from /usr/lib/R/lib/libR.so
#37 0x00007ffff7c8b01f in ?? () from /usr/lib/R/lib/libR.so
#38 0x00007ffff7ca619d in ?? () from /usr/lib/R/lib/libR.so
#39 0x00007ffff7ca650b in Rf_eval () from /usr/lib/R/lib/libR.so
#40 0x00007ffff7ca86df in ?? () from /usr/lib/R/lib/libR.so
#41 0x00007ffff7ca94c7 in ?? () from /usr/lib/R/lib/libR.so
#42 0x00007ffff7ca663c in Rf_eval () from /usr/lib/R/lib/libR.so
#43 0x00007ffff7c364a8 in R_UnwindProtect () from /usr/lib/R/lib/libR.so
#44 0x00007ffff269970f in Rcpp::unwindProtect (callback=0x7ffff26985d0 <Rcpp::internal::Rcpp_protected_eval(void*)>,
--Type <RET> for more, q to quit, c to continue without paging--c
    data=0x7ffffffeb220) at /usr/local/lib/R/site-library/Rcpp/include/Rcpp/unwindProtect.h:74
#45 0x00007ffff28d2cdb in Rcpp::Rcpp_fast_eval (env=0x5555555a80c8, expr=0x55555d3d44b8) at /usr/local/lib/R/site-library/Rcpp/include/Rcpp/api/meat/Rcpp_eval.h:63
#46 Rcpp::Function_Impl<Rcpp::PreserveStorage>::invoke (env=0x5555555a80c8, args_=0x55555d3d44f0, this=0x7ffffffeb380) at /usr/local/lib/R/site-library/Rcpp/include/Rcpp/Function.h:118
#47 Rcpp::Function_Impl<Rcpp::PreserveStorage>::operator()<Rcpp::RObject_Impl<Rcpp::PreserveStorage> > (this=0x7ffffffeb380, t1=...) at /usr/local/lib/R/site-library/Rcpp/include/Rcpp/generated/Function__operator.h:35
#48 0x00007ffff28a6c55 in rxModelVars_character (obj=...) at rxData.cpp:871
#49 0x00007ffff28a5951 in rxModelVars_ (obj=...) at rxData.cpp:956
#50 0x00007ffff26855e2 in _rxode2_rxModelVars__try (objSEXP=0x555559126188) at /usr/local/lib/R/site-library/Rcpp/include/Rcpp/InputParameter.h:74
#51 0x00007ffff268576b in _rxode2_rxModelVars_ (objSEXP=0x555559126188) at RcppExports.cpp:682
#52 0x00007ffff7c4f30e in ?? () from /usr/lib/R/lib/libR.so
#53 0x00007ffff7c92688 in ?? () from /usr/lib/R/lib/libR.so
#54 0x00007ffff7ca619d in ?? () from /usr/lib/R/lib/libR.so
#55 0x00007ffff7ca650b in Rf_eval () from /usr/lib/R/lib/libR.so
#56 0x00007ffff7ca6eed in ?? () from /usr/lib/R/lib/libR.so
#57 0x00007ffff7ca6710 in Rf_eval () from /usr/lib/R/lib/libR.so
#58 0x00007ffff7cab8d7 in ?? () from /usr/lib/R/lib/libR.so
#59 0x00007ffff7ca6a2a in Rf_eval () from /usr/lib/R/lib/libR.so
#60 0x00007ffff7ca6eed in ?? () from /usr/lib/R/lib/libR.so
#61 0x00007ffff7ca7160 in ?? () from /usr/lib/R/lib/libR.so
#62 0x00007ffff7c92cfb in ?? () from /usr/lib/R/lib/libR.so
#63 0x00007ffff7ca619d in ?? () from /usr/lib/R/lib/libR.so
#64 0x00007ffff7ca650b in Rf_eval () from /usr/lib/R/lib/libR.so
#65 0x00007ffff7ca6eed in ?? () from /usr/lib/R/lib/libR.so
#66 0x00007ffff7ca6710 in Rf_eval () from /usr/lib/R/lib/libR.so
#67 0x00007ffff7c797be in R_withCallingErrorHandler () from /usr/lib/R/lib/libR.so
#68 0x00007ffff45a97a6 in ?? () from /usr/lib/R/library/methods/libs/methods.so
#69 0x00007ffff7cf1db9 in ?? () from /usr/lib/R/lib/libR.so
#70 0x00007ffff7ca6ab0 in Rf_eval () from /usr/lib/R/lib/libR.so
#71 0x00007ffff7ca86df in ?? () from /usr/lib/R/lib/libR.so
#72 0x00007ffff7ca94c7 in ?? () from /usr/lib/R/lib/libR.so
#73 0x00007ffff7c93dc3 in ?? () from /usr/lib/R/lib/libR.so
#74 0x00007ffff7ca619d in ?? () from /usr/lib/R/lib/libR.so
#75 0x00007ffff7ca650b in Rf_eval () from /usr/lib/R/lib/libR.so
#76 0x00007ffff7ca86df in ?? () from /usr/lib/R/lib/libR.so
#77 0x00007ffff7ca94c7 in ?? () from /usr/lib/R/lib/libR.so
#78 0x00007ffff7cabcdc in R_forceAndCall () from /usr/lib/R/lib/libR.so
#79 0x00007ffff7bd0b27 in ?? () from /usr/lib/R/lib/libR.so
#80 0x00007ffff7cecfe7 in ?? () from /usr/lib/R/lib/libR.so
#81 0x00007ffff7c8b01f in ?? () from /usr/lib/R/lib/libR.so
#82 0x00007ffff7ca619d in ?? () from /usr/lib/R/lib/libR.so
#83 0x00007ffff7ca650b in Rf_eval () from /usr/lib/R/lib/libR.so
#84 0x00007ffff7ca86df in ?? () from /usr/lib/R/lib/libR.so
#85 0x00007ffff7ca94c7 in ?? () from /usr/lib/R/lib/libR.so
#86 0x00007ffff7cabcdc in R_forceAndCall () from /usr/lib/R/lib/libR.so
#87 0x00007ffff7bd0b27 in ?? () from /usr/lib/R/lib/libR.so
#88 0x00007ffff7cecfe7 in ?? () from /usr/lib/R/lib/libR.so
#89 0x00007ffff7c8b01f in ?? () from /usr/lib/R/lib/libR.so
#90 0x00007ffff7ca619d in ?? () from /usr/lib/R/lib/libR.so
#91 0x00007ffff7ca650b in Rf_eval () from /usr/lib/R/lib/libR.so
#92 0x00007ffff7ca86df in ?? () from /usr/lib/R/lib/libR.so
#93 0x00007ffff7ca94c7 in ?? () from /usr/lib/R/lib/libR.so
#94 0x00007ffff7ca663c in Rf_eval () from /usr/lib/R/lib/libR.so
#95 0x00007ffff7caa238 in ?? () from /usr/lib/R/lib/libR.so
#96 0x00007ffff7ca6936 in Rf_eval () from /usr/lib/R/lib/libR.so
#97 0x00007ffff7ca86df in ?? () from /usr/lib/R/lib/libR.so
#98 0x00007ffff7ca94c7 in ?? () from /usr/lib/R/lib/libR.so
#99 0x00007ffff7c93dc3 in ?? () from /usr/lib/R/lib/libR.so
#100 0x00007ffff7ca619d in ?? () from /usr/lib/R/lib/libR.so
#101 0x00007ffff7ca650b in Rf_eval () from /usr/lib/R/lib/libR.so
#102 0x00007ffff7ca86df in ?? () from /usr/lib/R/lib/libR.so
#103 0x00007ffff7ca94c7 in ?? () from /usr/lib/R/lib/libR.so
#104 0x00007ffff7ca9eed in ?? () from /usr/lib/R/lib/libR.so
#105 0x00007ffff7cef5a4 in ?? () from /usr/lib/R/lib/libR.so
#106 0x00007ffff7cefc71 in ?? () from /usr/lib/R/lib/libR.so
#107 0x00007ffff7cefff2 in ?? () from /usr/lib/R/lib/libR.so
#108 0x00007ffff7c8b01f in ?? () from /usr/lib/R/lib/libR.so
#109 0x00007ffff7ca619d in ?? () from /usr/lib/R/lib/libR.so
#110 0x00007ffff7ca650b in Rf_eval () from /usr/lib/R/lib/libR.so
#111 0x00007ffff7ca86df in ?? () from /usr/lib/R/lib/libR.so
#112 0x00007ffff7ca94c7 in ?? () from /usr/lib/R/lib/libR.so
#113 0x00007ffff7ca663c in Rf_eval () from /usr/lib/R/lib/libR.so
#114 0x00007ffff7c17edf in ?? () from /usr/lib/R/lib/libR.so
#115 0x00007ffff7c8b200 in ?? () from /usr/lib/R/lib/libR.so
#116 0x00007ffff7ca619d in ?? () from /usr/lib/R/lib/libR.so
#117 0x00007ffff7cae469 in ?? () from /usr/lib/R/lib/libR.so
#118 0x00007ffff7cae969 in ?? () from /usr/lib/R/lib/libR.so
#119 0x00007ffff7ca6936 in Rf_eval () from /usr/lib/R/lib/libR.so
#120 0x00007ffff7cdccea in Rf_ReplIteration () from /usr/lib/R/lib/libR.so
#121 0x00007ffff7cdd080 in ?? () from /usr/lib/R/lib/libR.so
#122 0x00007ffff7cdd140 in run_Rmainloop () from /usr/lib/R/lib/libR.so
#123 0x000055555555509f in main ()
#124 0x00007ffff7952d90 in __libc_start_call_main (main=main@entry=0x555555555080 <main>, argc=argc@entry=3, argv=argv@entry=0x7fffffffe3d8) at ../sysdeps/nptl/libc_start_call_main.h:58
#125 0x00007ffff7952e40 in __libc_start_main_impl (main=0x555555555080 <main>, argc=3, argv=0x7fffffffe3d8, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7fffffffe3c8) at ../csu/libc-start.c:392
#126 0x00005555555550d5 in _start ()
billdenney commented 1 month ago

FYI, I was trying this to setup the list-version testing. The timing before the crash was very similar between the environment and list versions.

mattfidler commented 1 month ago

Valgrind:

Ini
==313542== Invalid read of size 4
==313542==    at 0xA07A471E: handleRemainingAssignmentsCalcPropIni (parseCmtProperties.h:197)
==313542==    by 0xA07A5241: handleRemainingAssignmentsCalcProps (parseCmtProperties.h:256)
==313542==    by 0xA07A0837: handleRemainingAssignments (parseStatements.h:57)
==313542==    by 0xA07A8460: parseNodeAfterRecursion (tran.c:184)
==313542==    by 0xA07A8BA9: wprint_parsetree (tran.c:214)
==313542==    by 0xA07A8A34: wprint_parsetree (tran.c:212)
==313542==    by 0xA07A8A34: wprint_parsetree (tran.c:212)
==313542==    by 0xA07A8A34: wprint_parsetree (tran.c:212)
==313542==    by 0xA07A8A34: wprint_parsetree (tran.c:212)
==313542==    by 0xA07AA13A: trans_internal (tran.c:525)
==313542==    by 0xA07AA6A6: _rxode2_trans (tran.c:617)
==313542==    by 0x4958237: ??? (in /usr/lib/R/lib/libR.so)
==313542==  Address 0xa325c278 is 8 bytes before a block of size 200,000 alloc'd
==313542==    at 0x484DA83: calloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==313542==    by 0x49EA195: R_chk_calloc (in /usr/lib/R/lib/libR.so)
==313542==    by 0xA07A93B4: reset (tran.c:336)
==313542==    by 0xA07AA1D3: setupTrans (tran.c:541)
==313542==    by 0xA07AA671: _rxode2_trans (tran.c:615)
==313542==    by 0x4958237: ??? (in /usr/lib/R/lib/libR.so)
==313542==    by 0x499B687: ??? (in /usr/lib/R/lib/libR.so)
==313542==    by 0x49AF19C: ??? (in /usr/lib/R/lib/libR.so)
==313542==    by 0x49AF50A: Rf_eval (in /usr/lib/R/lib/libR.so)
==313542==    by 0x49B16DE: ??? (in /usr/lib/R/lib/libR.so)
==313542==    by 0x49B24C6: ??? (in /usr/lib/R/lib/libR.so)
==313542==    by 0x49AF63B: Rf_eval (in /usr/lib/R/lib/libR.so)
==313542== 
==313542== Invalid write of size 4
==313542==    at 0xA07A4749: handleRemainingAssignmentsCalcPropIni (parseCmtProperties.h:200)
==313542==    by 0xA07A5241: handleRemainingAssignmentsCalcProps (parseCmtProperties.h:256)
==313542==    by 0xA07A0837: handleRemainingAssignments (parseStatements.h:57)
==313542==    by 0xA07A8460: parseNodeAfterRecursion (tran.c:184)
==313542==    by 0xA07A8BA9: wprint_parsetree (tran.c:214)
==313542==    by 0xA07A8A34: wprint_parsetree (tran.c:212)
==313542==    by 0xA07A8A34: wprint_parsetree (tran.c:212)
==313542==    by 0xA07A8A34: wprint_parsetree (tran.c:212)
==313542==    by 0xA07A8A34: wprint_parsetree (tran.c:212)
==313542==    by 0xA07AA13A: trans_internal (tran.c:525)
==313542==    by 0xA07AA6A6: _rxode2_trans (tran.c:617)
==313542==    by 0x4958237: ??? (in /usr/lib/R/lib/libR.so)
==313542==  Address 0xa325c278 is 8 bytes before a block of size 200,000 alloc'd
==313542==    at 0x484DA83: calloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==313542==    by 0x49EA195: R_chk_calloc (in /usr/lib/R/lib/libR.so)
==313542==    by 0xA07A93B4: reset (tran.c:336)
==313542==    by 0xA07AA1D3: setupTrans (tran.c:541)
==313542==    by 0xA07AA671: _rxode2_trans (tran.c:615)
==313542==    by 0x4958237: ??? (in /usr/lib/R/lib/libR.so)
==313542==    by 0x499B687: ??? (in /usr/lib/R/lib/libR.so)
==313542==    by 0x49AF19C: ??? (in /usr/lib/R/lib/libR.so)
==313542==    by 0x49AF50A: Rf_eval (in /usr/lib/R/lib/libR.so)
==313542==    by 0x49B16DE: ??? (in /usr/lib/R/lib/libR.so)
==313542==    by 0x49B24C6: ??? (in /usr/lib/R/lib/libR.so)
==313542==    by 0x49AF63B: Rf_eval (in /usr/lib/R/lib/libR.so)
==313542== 
==313542== Invalid write of size 4
==313542==    at 0xA07A4882: handleRemainingAssignmentsCalcPropIni (parseCmtProperties.h:210)
==313542==    by 0xA07A5241: handleRemainingAssignmentsCalcProps (parseCmtProperties.h:256)
==313542==    by 0xA07A0837: handleRemainingAssignments (parseStatements.h:57)
==313542==    by 0xA07A8460: parseNodeAfterRecursion (tran.c:184)
==313542==    by 0xA07A8BA9: wprint_parsetree (tran.c:214)
==313542==    by 0xA07A8A34: wprint_parsetree (tran.c:212)
==313542==    by 0xA07A8A34: wprint_parsetree (tran.c:212)
==313542==    by 0xA07A8A34: wprint_parsetree (tran.c:212)
==313542==    by 0xA07A8A34: wprint_parsetree (tran.c:212)
==313542==    by 0xA07AA13A: trans_internal (tran.c:525)
==313542==    by 0xA07AA6A6: _rxode2_trans (tran.c:617)
==313542==    by 0x4958237: ??? (in /usr/lib/R/lib/libR.so)
==313542==  Address 0xa3691078 is 8 bytes before a block of size 200,000 alloc'd
==313542==    at 0x484DA83: calloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==313542==    by 0x49EA195: R_chk_calloc (in /usr/lib/R/lib/libR.so)
==313542==    by 0xA07A9408: reset (tran.c:339)
==313542==    by 0xA07AA1D3: setupTrans (tran.c:541)
==313542==    by 0xA07AA671: _rxode2_trans (tran.c:615)
==313542==    by 0x4958237: ??? (in /usr/lib/R/lib/libR.so)
==313542==    by 0x499B687: ??? (in /usr/lib/R/lib/libR.so)
==313542==    by 0x49AF19C: ??? (in /usr/lib/R/lib/libR.so)
==313542==    by 0x49AF50A: Rf_eval (in /usr/lib/R/lib/libR.so)
==313542==    by 0x49B16DE: ??? (in /usr/lib/R/lib/libR.so)
==313542==    by 0x49B24C6: ??? (in /usr/lib/R/lib/libR.so)
==313542==    by 0x49AF63B: Rf_eval (in /usr/lib/R/lib/libR.so)
==313542== 
==313542== Invalid write of size 8
==313542==    at 0xA07A494F: handleRemainingAssignmentsCalcPropIni (parseCmtProperties.h:218)
==313542==    by 0xA07A5241: handleRemainingAssignmentsCalcProps (parseCmtProperties.h:256)
==313542==    by 0xA07A0837: handleRemainingAssignments (parseStatements.h:57)
==313542==    by 0xA07A8460: parseNodeAfterRecursion (tran.c:184)
==313542==    by 0xA07A8BA9: wprint_parsetree (tran.c:214)
==313542==    by 0xA07A8A34: wprint_parsetree (tran.c:212)
==313542==    by 0xA07A8A34: wprint_parsetree (tran.c:212)
==313542==    by 0xA07A8A34: wprint_parsetree (tran.c:212)
==313542==    by 0xA07A8A34: wprint_parsetree (tran.c:212)
==313542==    by 0xA07AA13A: trans_internal (tran.c:525)
==313542==    by 0xA07AA6A6: _rxode2_trans (tran.c:617)
==313542==    by 0x4958237: ??? (in /usr/lib/R/lib/libR.so)
==313542==  Address 0xa5509c10 is 16 bytes before a block of size 400,000 alloc'd
==313542==    at 0x484DA83: calloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==313542==    by 0x49EA195: R_chk_calloc (in /usr/lib/R/lib/libR.so)
==313542==    by 0xA07A93EB: reset (tran.c:338)
==313542==    by 0xA07AA1D3: setupTrans (tran.c:541)
==313542==    by 0xA07AA671: _rxode2_trans (tran.c:615)
==313542==    by 0x4958237: ??? (in /usr/lib/R/lib/libR.so)
==313542==    by 0x499B687: ??? (in /usr/lib/R/lib/libR.so)
==313542==    by 0x49AF19C: ??? (in /usr/lib/R/lib/libR.so)
==313542==    by 0x49AF50A: Rf_eval (in /usr/lib/R/lib/libR.so)
==313542==    by 0x49B16DE: ??? (in /usr/lib/R/lib/libR.so)
==313542==    by 0x49B24C6: ??? (in /usr/lib/R/lib/libR.so)
==313542==    by 0x49AF63B: Rf_eval (in /usr/lib/R/lib/libR.so)
==313542== 
mattfidler commented 1 month ago

Yep. This comes from:

rxode2({ t <- 1})

Which isn't allowed (and wasn't caught as an exception). Time cannot be assigned to 1.

mattfidler commented 1 month ago

With fix:

library(rxode2)
#> rxode2 2.1.3.9000 using 8 threads (see ?getRxThreads)
#>   no cache: create with `rxCreateCache()`

mod1 <- function() {
  ini({
    # central
    KA=2.94E-01
    CL=1.86E+01
    V2=4.02E+01
    # peripheral
    Q=1.05E+01
    V3=2.97E+02
    # effects
    Kin=1
    Kout=1
    EC50=200
  })
  model({
    C2 <- centr/V2
    C3 <- peri/V3
    d/dt(depot) <- -KA*depot
    d/dt(centr) <- KA*depot - CL*C2 - Q*C2 + Q*C3
    d/dt(peri)  <- Q*C2 - Q*C3
    eff(0) <- 1
    d/dt(eff)   <- Kin - Kout*(1-C2/(EC50+C2))*eff
  })
}

newMod <- mod1

start_time <- Sys.time()
for (current_letter in letters) {
  message(current_letter, Sys.time() - start_time)
  start_time <- Sys.time()
  newMod <-
    do.call(model, list(newMod, str2lang(paste(current_letter, "<- 1")), append = TRUE))
}
#> a0.0119056701660156
#> b0.720271587371826
#> c0.129557371139526
#> d0.131191253662109
#> e0.118805170059204
#> f0.12668776512146
#> g0.126613140106201
#> h0.125054121017456
#> i0.123105764389038
#> j0.127390384674072
#> k0.128254652023315
#> l0.130600690841675
#> m0.130775451660156
#> n0.131662368774414
#> o0.134022951126099
#> p0.134353876113892
#> q0.136140108108521
#> r0.138394594192505
#> s0.13759183883667
#> t0.139049530029297
#> rxode2 model syntax error:
#> ================================================================================
#> :ERR: 't' is a rxode2 reserved variable and cannot be assigned:
#>
#> :001: 2 <- centr/V2
#> :002: C3 <- peri/V3
#> :003: d/dt(depot) <- -KA * depot
#> :004: d/dt(centr) <- KA * depot - CL * C2 - Q * C2 + Q * C3
#> :005: d/dt(peri) <- Q * C2 - Q * C3
#> :006: eff(0) <- 1
#> :007: d/dt(eff) <- Kin - Kout * (1 - C2/(EC50 + C2)) * eff
#> :008: a <- 1
#> :009: b <- 1
#> :010: c <- 1
#> :011: d <- 1
#> :012: e <- 1
#> :013: f <- 1
#> :014: g <- 1
#> :015: h <- 1
#> :016: i <- 1
#> :017: j <- 1
#> :018: k <- 1
#> :019: l <- 1
#> :020: m <- 1
#> :021: n <- 1
#> :022: o <- 1
#> :023: p <- 1
#> :024: q <- 1
#> :025: r <- 1
#> :026: s <- 1
#> :027: t <- 1
#> ================================================================================
#> Error: syntax errors (see above)

Created on 2024-07-31 with reprex v2.1.1

billdenney commented 1 month ago

Thanks!