nlmixrdevelopment / nlmixr

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

`nlmixr::nlmxir` throwing cpp error with parameter `est="saem"` #575

Closed bedwards-mango closed 2 years ago

bedwards-mango commented 2 years ago

Minimal reprex:

d <- Oral_1CPT
d <- d[,names(d) != "SS"];
d <- nmDataConvert(d);
f <- function(){
  ini({
    lCl <- 1.6      #log Cl (L/hr)
    lVc <- log(90)   #log Vc (L)
    lKA <- 0.1      #log Ka (1/hr)
    prop.err <- c(0, 0.2, 1)
    eta.Cl ~ 0.1 ## BSV Cl
    eta.Vc ~ 0.1 ## BSV Vc
    eta.KA ~ 0.1 ## BSV Ka
  })
  model({
    ## First parameters are defined in terms of the initial estimates
    ## parameter names.
    Cl <- exp(lCl + eta.Cl)
    Vc = exp(lVc + eta.Vc)
    KA <- exp(lKA + eta.KA)
    ## After the differential equations are defined
    kel <- Cl / Vc;
    d/dt(depot)    = -KA*depot;
    d/dt(centr)  =  KA*depot-kel*centr;
    ## And the concentration is then calculated
    cp = centr / Vc;
    ## Last, nlmixr is told that the plasma concentration follows
    ## a proportional error (estimated by the parameter prop.err)
    cp ~ prop(prop.err)
  })
}
fit.s <- nlmixr(f,d,est="saem",control=saemControl(n.burn=50,n.em=100,print=50))

Error thrown:

Compiling RxODE equations...done.
Building SAEM model...error
Error building SAEM model
── stdout output ─────────────────────────────────────────────────────────────────────────────────────────────────────
g++ -m64 -std=gnu++11 -I"/opt/user/R/3.6.3/include" -DNDEBUG   -I/usr/local/include -I/opt/user/R/3.6.3/lib/R/library/nlmixr//include -I/opt/user/R/3.6.3/lib/R/library/StanHeaders//include -I/opt/user/R/3.6.3/lib/R/library/Rcpp//include -I/opt/user/R/3.6.3/lib/R/library/RcppArmadillo//include -I/opt/user/R/3.6.3/lib/R/library/RcppEigen//include -I/opt/user/R/3.6.3/lib/R/library/BH//include -I/opt/user/R/3.6.3/lib/R/library/RxODE//include -fpic  -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches   -m64 -mtune=generic  -c saemf12d4154eceef65f53afdc16fe348edc.cpp -o saemf12d4154eceef65f53afdc16fe348edc.o

── stderr output ─────────────────────────────────────────────────────────────────────────────────────────────────────
In file included from /opt/user/R/3.6.3/lib/R/library/RcppArmadillo//include/RcppArmadilloConfig.h:109:0,
                 from /opt/user/R/3.6.3/lib/R/library/RcppArmadillo//include/RcppArmadilloForward.h:28,
                 from /opt/user/R/3.6.3/lib/R/library/RcppArmadillo//include/RcppArmadillo.h:31,
                 from saemf12d4154eceef65f53afdc16fe348edc.cpp:3:
/opt/user/R/3.6.3/lib/R/library/RcppArmadillo//include/RcppArmadilloConfigGenerated.h:32:0: warning: "ARMA_DONT_USE_OPENMP" redefined [enabled by default]
 #define ARMA_DONT_USE_OPENMP 1
 ^
saemf12d4154eceef65f53afdc16fe348edc.cpp:2:0: note: this is the location of the previous definition
 #define ARMA_DONT_USE_OPENMP // Known to cause speed problems
 ^
In file included from saemf12d4154eceef65f53afdc16fe348edc.cpp:5:0:
/opt/user/R/3.6.3/lib/R/library/nlmixr//include/saem_class_rcpp.hpp: In member function ‘void SAEM::saem_fit()’:
/opt/user/R/3.6.3/lib/R/library/nlmixr//include/saem_class_rcpp.hpp:493:26: error: call of overloaded ‘isnan(double&)’ is ambiguous
       if (isnan(sigma2[b])) sigma2[b] = 1.0e99;
                          ^
/opt/user/R/3.6.3/lib/R/library/nlmixr//include/saem_class_rcpp.hpp:493:26: note: candidates are:
In file included from /usr/include/features.h:375:0,
                 from /usr/include/c++/4.8.2/x86_64-redhat-linux/bits/os_defines.h:39,
                 from /usr/include/c++/4.8.2/x86_64-redhat-linux/bits/c++config.h:2097,
                 from /usr/include/c++/4.8.2/cmath:41,
                 from /opt/user/R/3.6.3/lib/R/library/Rcpp//include/Rcpp/platform/compiler.h:100,
                 from /opt/user/R/3.6.3/lib/R/library/Rcpp//include/Rcpp/r/headers.h:67,
                 from /opt/user/R/3.6.3/lib/R/library/Rcpp//include/RcppCommon.h:29,
                 from /opt/user/R/3.6.3/lib/R/library/RcppArmadillo//include/RcppArmadilloForward.h:26,
                 from /opt/user/R/3.6.3/lib/R/library/RcppArmadillo//include/RcppArmadillo.h:31,
                 from saemf12d4154eceef65f53afdc16fe348edc.cpp:3:
/usr/include/bits/mathcalls.h:235:1: note: int isnan(double)
 __MATHDECL_1 (int,isnan,, (_Mdouble_ __value)) __attribute__ ((__const__));
 ^
In file included from /opt/user/R/3.6.3/lib/R/library/Rcpp//include/Rcpp/platform/compiler.h:100:0,
                 from /opt/user/R/3.6.3/lib/R/library/Rcpp//include/Rcpp/r/headers.h:67,
                 from /opt/user/R/3.6.3/lib/R/library/Rcpp//include/RcppCommon.h:29,
                 from /opt/user/R/3.6.3/lib/R/library/RcppArmadillo//include/RcppArmadilloForward.h:26,
                 from /opt/user/R/3.6.3/lib/R/library/RcppArmadillo//include/RcppArmadillo.h:31,
                 from saemf12d4154eceef65f53afdc16fe348edc.cpp:3:
/usr/include/c++/4.8.2/cmath:626:3: note: constexpr bool std::isnan(long double)
   isnan(long double __x)
   ^
/usr/include/c++/4.8.2/cmath:622:3: note: constexpr bool std::isnan(double)
   isnan(double __x)
   ^
/usr/include/c++/4.8.2/cmath:618:3: note: constexpr bool std::isnan(float)
   isnan(float __x)
   ^
saemf12d4154eceef65f53afdc16fe348edc.cpp: In function ‘arma::vec user_function(const mat&, const mat&, const List&)’:
saemf12d4154eceef65f53afdc16fe348edc.cpp:57:7: warning: unused variable ‘_cores’ [-Wunused-variable]
   int _cores = 1;//_op->cores;
       ^
make: *** [saemf12d4154eceef65f53afdc16fe348edc.o] Error 1

Error: Error building SAEM model

R Version: 3.6.3 nlmixr version: 1.1.1-5

This error does not occur with R 4.0.4 and nlmixr 2.0.4, however upgrading is not an option.

Is this a bug, or setup issue?

bedwards-mango commented 2 years ago

Note: The error occurs for any model only when est="saem"

mattfidler commented 2 years ago

Hi @bedwards-mango,

It could be considered either a bug or a setup issue, I know that doesn't help.

In the saem the key error message is:

 error: call of overloaded ‘isnan(double&)’ is ambiguous

If you edit the source headers to call std::isnan() everywhere in the .hpp files inside ~/opt/user/R/3.6.3/lib/R/library/nlmixr//include/saem_class_rcpp.hpp instead of isnan() it should work just fine.

However, this is also related to setup. Some versions of the c++ compilers do not need this convention to run (you are just lucky enough to have one that does :roll_eyes: :smile: ).

This was taken care of in other versions of nlmixr, though. In fact compiling saem models is no longer done for the most recent nlmixr, so if you can load nlmixr you don't need to worry about this.

mattfidler commented 2 years ago

Hopefully this was helpful.