Hey all,
I am having a weird compilation error. I say weird, because my colleague
was able to compile and run this model on his machine (linux,mint), while I
have been consistently getting the same error on my own 2 computers (linux,
ubuntu). Currently I have the latest nimble-dev version installed re: drfishes
from this user list and using R 3.5.3.
I have written a nimble function to calculate derived quantities, then pass
these quantities back to the model to be used in the likelihood.
The R function runs as expected. I can compile the R function, and it also runs as expected (same outcomes, faster).
When I try to compile the nimble model that uses the nimble function, I get an error:
Error: Failed to create the shared library.
The end of the compileNimble output with a failure message:
/usr/lib/R/etc/Makeconf:172: recipe for target 'P_6_modelcode_MID_5_nfCode.o' failed
P_6_modelcode_MID_5_nfCode.cpp: In member function ‘virtual void p_L5_UID_50::simulate(const ind
#nimblefunction
state.transition<- nimbleFunction(
run = function(records = integer(0),
beta0 = double(0),
agem=integer(1),
Nage_lookup=integer(0),
car_age=double(1),
age_lookup=integer(1)) {
p <- nimNumeric(records)
gam <-nimMatrix(value = 0,nrow = records,ncol =Nage_lookup )
for (i in 1:records) {
for (k in 1:agem[i]) {
gam[i,k]<-beta0 + car_age[age_lookup[k]]
}
p[i] <- 1-exp(-sum(exp(gam[i,1:agem[i]])))
}
returnType(double(1))
return(p[1:records])
})
Cstate.transition <- compileNimble(state.transition,showCompilerOutput = TRUE) #runs and compiles okay
#nimblemodel
modelcode <- nimbleCode({
prec ~ dgamma(0.01, 0.01)
beta0 ~ T(dnorm(-6,3),-9,-1)
for (i in 1:Tage) {car_age[i] ~ dnorm(0,prec) }
p[1:records]<-state.transition(records=records, beta0=beta0,agem=agem[1:records],Nage_lookup=Nage_lookup, car_age=car_age[1:Tage], age_lookup = age_lookup[1:Nage_lookup])
for (i in 1:records) {
pos[i] ~ dbern(p[i])
}
})
modelout <- nimbleModel(code= modelcode, constants = nimConsts, data = nimData,inits = nimInits) #runs okay, checks out
mcmcConf <- configureMCMC(modelout)#runs okay
mcmc <- buildMCMC(mcmcConf)#runs okay
Cmodel <- compileNimble(modelout,showCompilerOutput = TRUE)# this is where it breaks.
#####################################################################
Already suggested by Perry de Valpine, to just test a simple example, I was able to write and compile a simple nimble function:
hw <- nimbleFunction(run = function(){print("hello world")})
chw <- compileNimble(hw, showCompilerOutput = TRUE)
I have also previously successfully used a nimble function within a simple logistic regression model.
printErrors() from a nimbleMCMC call is maybe more informative:
P_5_modelcode_MID_5_nfCode.cpp: In member function ‘virtual void p_L5_UID_50::simulate(const indexedNodeInfo&) const’:
P_5_modelcode_MID_5_nfCode.cpp:851:80: error: invalid initialization of reference of type ‘NimArr<1, int>&’ from expression of type ‘NimArr<1, double>’
Interm_106 = rcFun_5(20572, Interm_102, Interm_103, 132, Interm_104, Interm_105);
^
P_5_modelcode_MID_5_nfCode.cpp:769:20: note: in passing argument 3 of ‘NimArr<1, double> rcFun_5(int, double, NimArr<1, int>&, int, NimArr<1, double>&, NimArr<1, int>&)’
NimArr<1, double> rcFun_5 ( int ARG1_records_, double ARG2_beta0_, NimArr<1, int> & ARG3_agem_, int ARG4_Nage_lookup_, NimArr<1, double> & ARG5_car_age_, NimArr<1, int> & ARG6_age_lookup_ ) {
^
At global scope:
cc1plus: warning: unrecognized command line option ‘-Wno-ignored-attributes’
cc1plus: warning: unrecognized command line option ‘-Wno-misleading-indentation’
make: *** [P_5_modelcode_MID_5_nfCode.o] Error 1