kingaa / pomp

R package for statistical inference using partially observed Markov processes
https://kingaa.github.io/pomp
GNU General Public License v3.0
110 stars 26 forks source link

Error: error in building shared-object library from C snippets: in ‘Cbuilder’: compilation error #115

Closed navarromia2 closed 4 years ago

navarromia2 commented 4 years ago

Hello Aaron,

After going through your FAQ and trying the two installation methods, as well as installing XCode, I keep getting the compilation error. I followed your script linked below using the negative binomial distribution. Let me know what you may think the error is. I also looked at forum posts and reviewed your advice there (ex. installing gfortran) and still no luck.

Best, Mia

(I also attached the data csv in case you need it.) Cleaned dati-regioni_Lombardia 0224-0424.csv.zip

Error & Code (starts after line of ##)

Error: error in building shared-object library from C snippets: in ‘Cbuilder’: compilation error: cannot compile shared-object library ‘/var/folders/yk/_h3q1nws2f13n6p3_0w2h5xh0000gp/T//Rtmp4MPStb/74117/pomp_c2e76eb1a52f716b7bbe3d4a676b8d8a.so’: status = 1
compiler messages:
clang -mmacosx-version-min=10.13 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I -I/Users/mianavarro 1/Documents/GADL_Model  -I/usr/local/include   -fPIC  -Wall -g -O2  -c /var/folders/yk/_h3q1nws2f13n6p3_0w2h5xh0000gp/T//Rtmp4MPStb/74117/pomp_c2e76eb1a52f716b7bbe3d4a676b8d8a.c -o /var/folders/yk/_h3q1nws2f13n6p3_0w2h5xh0000gp/T//Rtmp4MPStb/74117/pomp_c2e76eb1a52f716b7bbe3d4a676b8d8a.o
clang: error: no such file or directory: '1/Documents/GADL_Model'
make: *** [/var/folders/yk/_h3q1nws2f13n6p3_0w2h5xh0000gp/T//Rtmp4MPStb/74117/pomp_c2e76eb1a52f716b7bbe3d4a676b8d8a.o] Error 1
In addition: Warning messages:
1: In read.dcf(file.path(p, "DESCRIPTION"), c("Package", "Version")) :
  cannot open compressed file '/Library/Frameworks/R.framework/Versions/4.0/Resources/library/pomp/DESCRIPTION', probable reason 'No such file or directory'
2: In system2(command = R.home("bin/R"), args = c("CMD", "SHLIB", "-c",  :
  running command 'PKG_CPPFLAGS="-I -I/Users/mianavarro 1/Documents/GADL_Model" '/Library/Frameworks/R.framework/Resources/bin/R' CMD SHLIB -c -o /var/folders/yk/_h3q1nws2f13n6p3_0w2h5xh0000gp/T//Rtmp4MPStb/74117/pomp_c2e76eb1a52f716b7bbe3d4a676b8d8a.so /var/folders/yk/_h3q1nws2f13n6p3_0w2h5xh0000gp/T//Rtmp4MPStb/74117/pomp_c2e76eb1a52f716b7bbe3d4a676b8d8a.c 2>&1' had status 1```
###################################################
#             SET UP THE SCRIPT
###################################################
# 1. Load packages. (Be sure to install packages before uploading.)
library(readr)
library(ggplot2)
library(pomp) #To install pomp, run > install.packages("pomp",repos="https://kingaa.github.io/")
library(coda)
library(mvtnorm)

###################################################
#           IMPORT & PREVIEW DATASET
###################################################
# 1. Imported data from Cleaned dati-regioni_Lombardia 0224-0424.csv
Lombardy_data <- read_csv("Cleaned dati-regioni_Lombardia 0224-0424.csv")
View(Lombardy_data)

# 2. Visualize data
ggplot(Lombardy_data,mapping=aes(x=DAYS,y=NUM_PEOPLE,color=GROUP))+
  geom_line()

###################################################
#   SET UP THE ODES AND PARAMS TO BE OPTIMIZED
###################################################
pomp(
  data=subset(Lombardy_data,GROUP=="TOTAL_CASES",select=-GROUP),
  times="DAYS",t0=1,
  skeleton=vectorfield(
    Csnippet("
    double lam.kk; double lam.ka; double lam.kv; double lam.ak; double lam.aa; double lam.av;
    double lam.vk; double lam.va; double lam.vv; double Rho.k;  double Rho.a;  double Rho.v;

    lam.kk <- c.kk * beta.k * (eps.kP * Pk + eps.kA * Ak + eps.kL * Lk + 
                               eps.kM * Mk + eps.kF * Fk + eps.kH * Hk);
    lam.ka <- c.ka * beta.a * (eps.aP * Pa + eps.aA * Aa + eps.aL * La + 
                               eps.aM * Ma + eps.aF * Fa + eps.aH * Ha);
    lam.kv <- c.kv * beta.v * (eps.vP * Pv + eps.vA * Av + eps.vL * Lv + 
                               eps.vM * Mv + eps.vF * Fv + eps.vH * Hv);    
    lam.ak <- c.ak * beta.k * (eps.kP * Pk + eps.kA * Ak + eps.kL * Lk + 
                               eps.kM * Mk + eps.kF * Fk + eps.kH * Hk);
    lam.aa <- c.aa * beta.a * (eps.aP * Pa + eps.aA * Aa + eps.aL * La + 
                               eps.aM * Ma + eps.aF * Fa + eps.aH * Ha);
    lam.av <- c.av * beta.v * (eps.vP * Pv + eps.vA * Av + eps.vL * Lv + 
                               eps.vM * Mv + eps.vF * Fv + eps.vH * Hv);
    lam.vk <- c.vk * beta.k * (eps.kP * Pk + eps.kA * Ak + eps.kL * Lk + 
                               eps.kM * Mk + eps.kF * Fk + eps.kH * Hk);
    lam.va <- c.va * beta.a * (eps.aP * Pa + eps.aA * Aa + eps.aL * La + 
                               eps.aM * Ma + eps.aF * Fa + eps.aH * Ha);
    lam.vv <- c.vv * beta.v * (eps.vP * Pv + eps.vA * Av + eps.vL * Lv + 
                               eps.vM * Mv + eps.vF * Fv + eps.vH * Hv);

    Rho.k <- rho.kA * Ak + rho.kL * Lk + rho.kM * Mk + 
             rho.kF * Fk + rho.kH * Hk + rho.kU * Uk;
    Rho.a <- rho.aA * Aa + rho.aL * La + rho.aM * Ma + 
             rho.aF * Fa + rho.aH * Ha + rho.aU * Ua;
    Rho.v <- rho.vA * Av + rho.vL * Lv + rho.vM * Mv + 
             rho.vF * Fv + rho.vH * Hv + rho.vU * Uv;

    dSk.dt <- -(lam.kk + lam.ka + lam.kv) * Sk + phi.kC * Ck;
    dEk.dt <-  (lam.kk + lam.ka + lam.kv) * Sk - gam.kE * Ek;
    dPk.dt <-   gam.kE * Ek - gam.kP * Pk;
    dAk.dt <-  (1-zk)* gam.kP * Pk - (rho.kA + kap.kA) * Ak;
    dLk.dt <-     zk * gam.kP * Pk - (gam.kL + rho.kL) * Lk + kap.kA * Ak;
    dMk.dt <-          gam.kL * Lk - (gam.kM + rho.kM) * Mk;
    dFk.dt <-          gam.kM * Mk - (gam.kF + rho.kF + mor.kF) * Fk;
    dHk.dt <-          gam.kF * Fk - (gam.kH + rho.kH + mor.kH) * Hk;
    dUk.dt <-          gam.kH * Hk - (         rho.kU + mor.kU) * Uk;
    dRk.dt <-  Rho.k - rho.kR * Rk;  
    dCk.dt <-          rho.kR * Rk - phi.kC * Ck;
    dDk.dt <-  mor.kF * Fk + mor.kH * Hk + mor.kU * Uk;

    dSa.dt <- -(lam.ak + lam.aa + lam.av) * Sa + phi.aC * Ca;
    dEa.dt <-  (lam.ak + lam.aa + lam.av) * Sa - gam.aE * Ea;
    dPa.dt <-   gam.aE * Ea - gam.aP * Pa;
    dAa.dt <-  (1-za)* gam.aP * Pa - (rho.aA + kap.aA) * Aa;
    dLa.dt <-     za * gam.aP * Pa - (gam.aL + rho.aL) * La + kap.aA * Aa;
    dMa.dt <-          gam.aL * La - (gam.aM + rho.aM) * Ma;
    dFa.dt <-          gam.aM * Ma - (gam.aF + rho.aF + mor.aF) * Fa;
    dHa.dt <-          gam.aF * Fa - (gam.aH + rho.aH + mor.aH) * Ha;
    dUa.dt <-          gam.aH * Ha - (         rho.aU + mor.aU) * Ua;
    dRa.dt <-  Rho.a - rho.aR * Ra;  
    dCa.dt <-          rho.aR * Ra - phi.aC * Ca;
    dDa.dt <-  mor.aF * Fa + mor.aH * Ha + mor.aU * Ua;

    dSv.dt <- -(lam.vk + lam.va + lam.vv) * Sv + phi.vC * Cv;
    dEv.dt <-  (lam.vk + lam.va + lam.vv) * Sv - gam.vE * Ev;
    dPv.dt <-   gam.vE * Ev - gam.vP * Pv;
    dAv.dt <-  (1-zv)* gam.vP * Pv - (rho.vA + kap.vA) * Av;
    dLv.dt <-     zv * gam.vP * Pv - (gam.vL + rho.vL) * Lv + kap.vA * Av;
    dMv.dt <-          gam.vL * Lv - (gam.vM + rho.vM) * Mv;
    dFv.dt <-          gam.vM * Mv - (gam.vF + rho.vF + mor.vF) * Fv;
    dHv.dt <-          gam.vF * Fv - (gam.vH + rho.vH + mor.vH) * Hv;
    dUv.dt <-          gam.vH * Hv - (         rho.vU + mor.vU) * Uv;
    dRv.dt <-  Rho.v - rho.vR * Rv;  
    dCv.dt <-          rho.vR * Rv - phi.vC * Cv;
    dDv.dt <-  mor.vF * Fv + mor.vH * Hv + mor.vU * Uv;"
             )),
  rinit=Csnippet("
      Sk <- Sk_0; Ek <- Ek_0; Pk <- Pk_0;
      Ak <- Ak_0; Lk <- Lk_0; Mk <- Mk_0;
      Fk <- Fk_0; Hk <- Hk_0; Uk <- Uk_0; 
      Rk <- Rk_0; Ck <- Ck_0; Dk <- Dk_0;

      Sa <- Sa_0; Ea <- Ea_0; Pa <- Pa_0;
      Aa <- Aa_0; La <- La_0; Ma <- Ma_0;
      Fa <- Fa_0; Ha <- Ha_0; Ua <- Ua_0;
      Ra <- Ra_0; Ca <- Ca_0; Da <- Da_0;

      Sv <- Sv_0; Ev <- Ev_0; Pv <- Pv_0;
      Av <- Av_0; Lv <- Lv_0; Mv <- Mv_0;
      Fv <- Fv_0; Hv <- Hv_0; Uv <- Uv_0;
      Rv <- Rv_0; Cv <- Cv_0; Dv <- Dv_0;"),
  paramnames=c("beta.k", "beta.a", "beta.v",
               "c.kk"  , "c.ka"  , "c.kv"  ,
               "c.ak"  , "c.aa"  , "c.av"  ,
               "c.vk"  , "c.va"  , "c.vv"  ,
               "eps.kP", "eps.aP", "eps.vP",
               "eps.kA", "eps.aA", "eps.vA",
               "eps.kL", "eps.aL", "eps.vL",
               "eps.kM", "eps.aM", "eps.vM",
               "eps.kF", "eps.aF", "eps.vF",
               "eps.kH", "eps.aH", "eps.vH",
               "zk"    , "za"  , "zv",
               "gam.kE", "gam.aE", "gam.vE",
               "gam.kP", "gam.aP", "gam.vP",
               "gam.kL", "gam.aL", "gam.vL",
               "gam.kM", "gam.aM", "gam.vM",
               "gam.kF", "gam.aF", "gam.vF",
               "gam.kH", "gam.aH", "gam.vH",
               "rho.kA", "rho.aA", "rho.vA",
               "rho.kL", "rho.aL", "rho.vL",
               "rho.kM", "rho.aM", "rho.vM",
               "rho.kF", "rho.aF", "rho.vF",
               "rho.kU", "rho.aU", "rho.vU",
               "rho.kH", "rho.aH", "rho.vH",
               "rho.kR", "rho.aR", "rho.vR",
               "mor.kF", "mor.aF", "mor.vF",
               "mor.kU", "mor.aU", "mor.vU",
               "mor.kH", "mor.aH", "mor.vH",
               "kap.kA", "kap.aA", "kap.vA",
               "phi.kC", "phi.aC", "phi.vC",
               "Sk_0", "Ek_0", "Pk_0", "Ak_0",
               "Lk_0", "Mk_0", "Fk_0", "Hk_0",
               "Uk_0", "Rk_0", "Ck_0", "Dk_0",
               "Sa_0", "Ea_0", "Pa_0", "Aa_0",
               "La_0", "Ma_0", "Fa_0", "Ha_0",
               "Ua_0", "Ra_0", "Ca_0", "Da_0",
               "Sv_0", "Ev_0", "Pv_0", "Av_0",
               "Lv_0", "Mv_0", "Fv_0", "Hv_0",
               "Uv_0", "Rv_0", "Cv_0", "Dv_0"),
  statenames=c("Sk","Ek","Pk","Ak","Lk","Mk","Fk","Hk","Uk","Rk","Ck","Dk",
               "Sa","Ea","Pa","Aa","La","Ma","Fa","Ha","Ua","Ra","Ca","Da",
               "Sv","Ev","Pv","Av","Lv","Mv","Fv","Hv","Uv","Rv","Cv","Dv")) -> Lombardy_dataA2

(@kingaa removed the link to Issue 9, which was marked "invalid" and is not pertinent here).

kingaa commented 4 years ago

@navarromia2: the compiler seems to be complaining

clang: error: no such file or directory: '1/Documents/GADL_Model'

Is there a file or directory at that location on your machine?

kingaa commented 4 years ago

Look at the line invoking the compiler:

clang -mmacosx-version-min=10.13 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I -I/Users/mianavarro 1/Documents/GADL_Model  -I/usr/local/include   -fPIC  -Wall -g -O2  -c /var/folders/yk/_h3q1nws2f13n6p3_0w2h5xh0000gp/T//Rtmp4MPStb/74117/pomp_c2e76eb1a52f716b7bbe3d4a676b8d8a.c -o /var/folders/yk/_h3q1nws2f13n6p3_0w2h5xh0000gp/T//Rtmp4MPStb/74117/pomp_c2e76eb1a52f716b7bbe3d4a676b8d8a.o

It seems you have perhaps a directory named /Users/mianavarro 1? Command-line tools handle file and directory names with spaces in them properly only if you take care to quote them appropriately. That's always something of a difficulty, as different kinds of quotes are needed in different contexts. The easiest solution is probably just to remove spaces from your file and directory names. You'll notice that most programmers use underscores "_" where a space " " would make sense from the point of view of natural language. The reason is that for the shell (the program that interprets the command-line instructions), the space is syntactic. Of course, in natural language it is too.

If you want my unsolicited advice, I would recommend that you make a habit of excluding all spaces from all your file and directory names. There is a little command called detox that will do this for you (but be cautious when using it in bulk).

Also (more unsolicited advice, apologies for that), remember: the error messages are your friend!

navarromia2 commented 4 years ago

@navarromia2: the compiler seems to be complaining

clang: error: no such file or directory: '1/Documents/GADL_Model'

Is there a file or directory at that location on your machine?

Yes, there is a folder in the Documents directory called GADL_Model, which holds the R script and the csv.

navarromia2 commented 4 years ago

After fixing the space and turning the periods into underscores in variable names, I now have this error:


Error: error in building shared-object library from C snippets: in ‘Cbuilder’: compilation error: cannot compile shared-object library ‘/var/folders/yk/_h3q1nws2f13n6p3_0w2h5xh0000gp/T//RtmpYUhGyY/2538/pomp_adc970b3eddd7d97d12f8c38c4d74243.so’: status = 1
compiler messages:
clang -mmacosx-version-min=10.13 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I/Library/Frameworks/R.framework/Versions/4.0/Resources/library/pomp/include -I/Users/mianavarro_1/Documents/GADL_Model  -I/usr/local/include   -fPIC  -Wall -g -O2  -c /var/folders/yk/_h3q1nws2f13n6p3_0w2h5xh0000gp/T//RtmpYUhGyY/2538/pomp_adc970b3eddd7d97d12f8c38c4d74243.c -o /var/folders/yk/_h3q1nws2f13n6p3_0w2h5xh0000gp/T//RtmpYUhGyY/2538/pomp_adc970b3eddd7d97d12f8c38c4d74243.o
/var/folders/yk/_h3q1nws2f13n6p3_0w2h5xh0000gp/T//RtmpYUhGyY/2538/pomp_adc970b3eddd7d97d12f8c38c4d74243.c:590:5: error: use of undeclared identifier 'dSk_dt'
    dSk_dt = -(lam_kk + lam_ka + lam_kv) * Sk + phi_kC * Ck;
    ^
/var/folder
In addition: Warning message:
In system2(command = R.home("bin/R"), args = c("CMD", "SHLIB", "-c",  :
  running command 'PKG_CPPFLAGS="-I/Library/Frameworks/R.framework/Versions/4.0/Resources/library/pomp/include -I/Users/mianavarro_1/Documents/GADL_Model" '/Library/Frameworks/R.framework/Resources/bin/R' CMD SHLIB -c -o /var/folders/yk/_h3q1nws2f13n6p3_0w2h5xh0000gp/T//RtmpYUhGyY/2538/pomp_adc970b3eddd7d97d12f8c38c4d74243.so /var/folders/yk/_h3q1nws2f13n6p3_0w2h5xh0000gp/T//RtmpYUhGyY/2538/pomp_adc970b3eddd7d97d12f8c38c4d74243.c 2>&1' had status 1```
kingaa commented 4 years ago

I see you understood to fix the path to the GADL_Model folder.

On to your latest message. The error message says

error: use of undeclared identifier 'dSk_dt'

Have you declared dSK_dt? It seems you have not, at least in the last code that you have shown.

The compiler messages are generally somewhat informative, but one must read them for them to be useful. If these messages are not sufficiently meaningful, one can often google the error message to find out what it means.

Looking ahead, I point out that the assignment operator in C is not '<-' as in R, but is rather '='.

In general, C snippets must contain valid C code. Please consult a reference on writing C, or find someone willing to teach you these basics. This is not the intended purpose of the issues page.

vgdeven commented 5 months ago

Hi @kingaa ,

I have a compilation error which I think is caused due to syntax misspecification. However, unlike the error: use of undeclared identifier 'dSk_dt' in your comment above, I get no hints from my error messages about the offending syntax.

I know that it might be a syntactic error since I have reproduced it by purposely misspecifying a Csnippet within a working code elsewhere. Is there an option in the pomp call that I might have switched on/off by mistake? Frankly, I have never incurred this issue before.

Any insight would be greatly appreciated.

Following is the error message --


Error: error in building shared-object library from C snippets: in ‘Cbuilder’: compilation error: cannot compile shared-object library ‘/Users/devengokhale/Documents/GitHub/social-determinants-causal-inference/workshop/toy_cm/SEIR/seir_metapop_toy.so’: status = 1
compiler messages:
using C compiler: ‘Apple clang version 15.0.0 (clang-1500.1.0.2.5)’
using SDK: ‘MacOSX14.2.sdk’
clang -arch arm64 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I'/Users/devengokhale/Library/R/arm64/4.3/library/pomp/include' -I'/Users/devengokhale/Documents/GitHub/social-determinants-causal-inference/workshop/toy_cm/SEIR'  -I/opt/R/arm64/include    -fPIC  -falign-functions=64 -Wall -g -O2  -c /Users/devengokhale/Documents/GitHub/social-determinants-causal-inference/workshop/toy_cm/SEIR/seir_metapop_toy.c -o /Users/devengokhale/Documents/GitHub/social-determinants-causal-inference/workshop/toy_cm/SEIR/seir_metapop_toy.o
/Users/devengokhale/Documents/GitHub/social-determinants-
In addition: Warning message:
In system2(command = R.home("bin/R"), args = c("CMD", "SHLIB", "-c",  :
  running command 'PKG_CPPFLAGS="-I'/Users/devengokhale/Library/R/arm64/4.3/library/pomp/include' -I'/Users/devengokhale/Documents/GitHub/social-determinants-causal-inference/workshop/toy_cm/SEIR'" '/Library/Frameworks/R.framework/Resources/bin/R' CMD SHLIB -c -o /Users/devengokhale/Documents/GitHub/social-determinants-causal-inference/workshop/toy_cm/SEIR/seir_metapop_toy.so /Users/devengokhale/Documents/GitHub/social-determinants-causal-inference/workshop/toy_cm/SEIR/seir_metapop_toy.c 2>&1' had status 1
kingaa commented 5 months ago

@vgdeven: sorry that the error message is not more helpful. pomp can only pass along the messages it gets from the compiler. It should be possible to get your compiler (clang) to give more informative messages, through some combination of options and environment variables. You can adjust various environment variables to control the options that are passed to the compiler on a call to R CMD SHLIB.

You may find it useful to save the whole C file that pomp is creating (adjust the cfile and/or cdir options as needed) and then try to compile it manually just to interact more directly with the compiler.

vgdeven commented 5 months ago

@kingaa: On tinkering with this issue for a bit, a rather bizarre behavior clang emerged. If executed while setting the home (root) directory of my hard drive as my working directory, all of my error messages are again switched to being very informative.

I think there is a certain clang option that restricts the diagnostic output to the root directory. I am reading up on clang right now. I will post a solution here if I find one.

But thanks very much for helping out.