Model compilation problems

56 views
Skip to first unread message

Alison Ketz

unread,
Apr 15, 2019, 4:36:21 PM4/15/19
to nimble-users
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

Perry de Valpine

unread,
Apr 15, 2019, 5:15:18 PM4/15/19
to Alison Ketz, nimble-users
Hi Alison,

Please try changing "agem = integer(1)" to "agem = double(1)", and the same for age_lookup, in the state.transition arguments.  All numbers in models are represented by double precision, even if they only make sense as integers. For scalars, this shouldn't matter (but you change integer(0) to double(0) as well), but for vectors it will matter.  The last error message you provided points in this direction.  I am not sure why it would work on one system and not on another, but please let us know if this fixes the problem.

-Perry


--
You received this message because you are subscribed to the Google Groups "nimble-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nimble-users...@googlegroups.com.
To post to this group, send email to nimble...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nimble-users/1018dc87-311e-433d-a616-a13b82800328%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Alison Ketz

unread,
Apr 15, 2019, 5:27:40 PM4/15/19
to nimble-users
Hi Perry,

It worked! I changed all nimbleFunction() argument types to doubles, retaining scalar, vector, and matrix specs. 
The model and mcmc compiled and were able to run.

Thanks so much for you help in sleuthing this one.

--Alison


To unsubscribe from this group and stop receiving emails from it, send an email to nimble...@googlegroups.com.

Perry de Valpine

unread,
Apr 15, 2019, 5:29:02 PM4/15/19
to nimble-users
Great!

To unsubscribe from this group and stop receiving emails from it, send an email to nimble-users...@googlegroups.com.

To post to this group, send email to nimble...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages