ADproxyModel with CAR prior

76 views
Skip to first unread message

Dusit Ngoprasert

unread,
Jul 9, 2025, 11:04:09 PMJul 9
to nimble-users
Dear all,

I am an ecologist beginning to use NIMBLE on a high-performance computing (HPC) system running Ubuntu. My code runs fine on a Windows PC, but I encounter an error related to CAR and automatic differentiation (AD) when running it on the HPC.

I’m using R version 4.3.1 with NIMBLE 1.3.0, and my model includes a CAR prior and a modified "barker" sampler. The R script is attached.

I have tried to search but didn't get any solutions.

> printErrors()
using C++ compiler: ‘x86_64-conda-linux-gnu-c++ (conda-forge gcc 11.2.0-16) 11.2.0’
P_1_CAR_dot_Nmix_dot_B_MID_1_nfCode.cpp: In member function 'virtual CppAD::AD<double> lifted_CAR_calcNumIslands_oPadj_oB1to144_cB_comma_num_oB1to25_cB_cP_L9_UID_9::calculate_ADproxyModel(const indexedNodeInfo&) const':
P_1_CAR_dot_Nmix_dot_B_MID_1_nfCode.cpp:1209:110: error: invalid initialization of reference of type 'NimArr<1, double>&' from expression of type 'NimArr<1, CppAD::AD<double> >'
 1209 | (**ADproxyModel_lifted_CAR_calcNumIslands_oPadj_oB1to144_cB_comma_num_oB1to25_cB_cP)[0] = CAR_calcNumIslands(Interm_43, Interm_44);
      |                                                                                                              ^~~~~~~~~
P_1_CAR_dot_Nmix_dot_B_MID_1_nfCode.cpp:1070:50: note: in passing argument 1 of 'double CAR_calcNumIslands(NimArr<1, double>&, NimArr<1, double>&)'
 1070 | double  CAR_calcNumIslands ( NimArr<1, double> & ARG1_adj_, NimArr<1, double> & ARG2_num_ )  {
      |                              ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~
P_1_CAR_dot_Nmix_dot_B_MID_1_nfCode.cpp: In member function 'virtual CppAD::AD<double> rho_L9_UID_10::calculate_ADproxyModel(const indexedNodeInfo&) const':
P_1_CAR_dot_Nmix_dot_B_MID_1_nfCode.cpp:1468:54: error: invalid initialization of reference of type 'NimArr<1, double>&' from expression of type 'NimArr<1, CppAD::AD<double> >'
 1468 | (**ADproxyModel_logProb_rho)[0] = nimArr_dcar_normal(Interm_74, Interm_75, Interm_76, Interm_77, Interm_78, Interm_79, 1, 1);
      |                                                      ^~~~~~~~~
In file included from /bimo/anaconda3/envs/r-nimble-gcc11/lib/R/library/nimble/include/nimble/predefinedNimbleLists.h:12,
                 from /bimo/anaconda3/envs/r-nimble-gcc11/lib/R/library/nimble/include/nimble/nimbleCppAD.h:41,
                 from P_1_CAR_dot_Nmix_dot_B_MID_1_nfCode.cpp:7:
/bimo/anaconda3/envs/r-nimble-gcc11/lib/R/library/nimble/include/nimble/nimDists.h:63:46: note: in passing argument 1 of 'double nimArr_dcar_normal(NimArr<1, double>&, NimArr<1, double>&, NimArr<1, double>&, NimArr<1, double>&, double, int, int, int)'
   63 | double nimArr_dcar_normal(NimArr<1, double> &x, NimArr<1, double> &adj, NimArr<1, double> &wgts, NimArr<1, double> &num, double tau, int c, int zero_mean, int give_log);
      |                           ~~~~~~~~~~~~~~~~~~~^
make: *** [/bimo/anaconda3/envs/r-nimble-gcc11/lib/R/etc/Makeconf:200: P_1_CAR_dot_Nmix_dot_B_MID_1_nfCode.o] Error 1

Thank you in advance for your help.

Sincerely,
Dusit
R_code_for2edited.R

Dusit Ngoprasert

unread,
Jul 16, 2025, 2:46:39 AMJul 16
to nimble-users
I found the solution.

Chris Paciorek

unread,
Jul 16, 2025, 11:24:01 AMJul 16
to Dusit Ngoprasert, nimble-users
hi Dusit, I'm glad you were able to figure it out -- sorry we didn't get a chance to respond to your post.

For anyone reading this in the future can you say briefly what the problem/solution was?

-chris

--
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 view this discussion visit https://groups.google.com/d/msgid/nimble-users/c692e9e0-2ef5-4f98-92e4-fd39b997651fn%40googlegroups.com.

Dusit Ngoprasert

unread,
Jul 16, 2025, 11:35:22 PMJul 16
to nimble-users

Dear Chris,

Sorry, I was rushing to get it done yesterday. I believe the main issue was an incompatibility between Nimble and R. I reinstalled R version 4.4.3, which works on my PC. Both the older version (4.3.1) and the newer version (4.5.1) seemed to cause problems. 

I also reinstalled Nimble (v1.3.0) along with all the other necessary packages. However, some R packages—like MCMCvis and mcmcOutput—had to be installed directly through the R console (they couldn't be installed via Ubuntu). In particular, installing MCMCvis took quite a bit of time, possibly due to incompatibility among its dependencies. After reinstalling everything with compatible versions, the model ran fine.

But, I’m still unable to set up parallel processing with Nimble on Ubuntu with doParallel package.

Best,
Dusit

Chris Paciorek

unread,
Jul 25, 2025, 1:27:13 PMJul 25
to Dusit Ngoprasert, nimble-users
Hi Dusit,

Sorry about the slow response; I was travelling.

NIMBLE should work with recent versions of R. We haven't had any other similar reports. But if you can tell us the combination of the R version, NIMBLE version, and operating system that seemed to have a problem (and the error message you got, ideally), we could try to reproduce the issue with the code file you provided.

As far as doParallel with NIMBLE under Ubuntu, if you can provide a reproducible example, I will try to see if I can reproduce the issue. I assume you've seen our example of doing parallel MCMC in R and are following the guidance there.

-chris


Dusit Ngoprasert

unread,
Aug 17, 2025, 1:36:55 PMAug 17
to nimble-users
Dear Chris,
I have been unable to access the r-nimble.org website for a few days already. Is there any problem with the website? 
Best regards,
Dusit

Perry de Valpine

unread,
Aug 17, 2025, 1:58:55 PMAug 17
to Dusit Ngoprasert, nimble-users
Yes, our web-site has been caught up in problems beyond our control (with our web hosting organization) for 2-3 weeks now. We are working on replacing it. Thanks for the report.


Dusit Ngoprasert

unread,
Aug 17, 2025, 11:28:38 PMAug 17
to Perry de Valpine, nimble-users

Thanks for your information. 

I am looking for an example of doing parallel MCMC in R, according to Chris's suggestion. Is there any off-line document that you can share? 

Your help would be greatly appreciated.

Dusit

-- 
ดุสิต งอประเสริฐ
Dusit Ngoprasert

Conservation Ecology Program,
School of Bioresources and Technology,
King Mongkut’s University of Technology Thonburi (Bangkhuntien campus)
Address: 49 Thakham, Bangkhuntien, Bangkok, 10150 Thailand
Tel: +66 81 710 4734
Email: ndu...@gmail.com; dusi...@kmutt.ac.th
website: https://cons-ecol-kmutt.weebly.com/

"You cannot hope to build a better world without improving the individuals. 
To that end, each of us must work for our own improvement", Marie Curie

Chris Paciorek

unread,
Aug 18, 2025, 12:36:04 AMAug 18
to Dusit Ngoprasert, Perry de Valpine, nimble-users
Hi Dusit,

We have a temporary location for the NIMBLE website set up while we get the regular site back up. Please go here for the parallelization example: https://nimble-dev.github.io/site/examples/parallelizing_NIMBLE.html.

-chris

Dusit Ngoprasert

unread,
Aug 18, 2025, 2:28:54 AMAug 18
to paci...@stat.berkeley.edu, Perry de Valpine, nimble-users

Dear Chris,

Thank you so much.

Best regards,

Dusit

Marc Kery

unread,
Aug 19, 2025, 9:05:36 AMAug 19
to nimble-users, 'Perry de Valpine' via hmecology: Hierarchical Modeling in Ecology
Dear all,
We are currently working on a 2nd edition of the BPA book from back in 2012, which will be entitled 'Bayesian population analysis using NIMBLE and JAGS'. As part of that project, we have translated into NIMBLE all the BPA code of the 1st edition. You can download it here: https://www.vogelwarte.ch/en/research/population-biology/book-bpa/
Since default NIMBLE output is extremely basic, we are very grateful to Ken Kellner who wrote for us an R function called 'nimbleSummary'. It produces output with very similar format as when you run JAGS by 'jagsUI'. This function is contained in the beta version of our 'BPAbook' R package, which you can also download along with the 'BPA with NIMBLE' code.
Best regards  --- Marc & Michael

Reply all
Reply to author
Forward
0 new messages