nimble-dev / nimble

The base NIMBLE package for R
http://R-nimble.org
BSD 3-Clause "New" or "Revised" License
156 stars 23 forks source link

`nimbleHMC()` error: "must set `buildDerivs = TRUE` when building model" when the model is created using `readBUGSmodel()` #1397

Closed pehkawn closed 4 months ago

pehkawn commented 8 months ago

According to the Nimble user guide, automatic differentiation (AD) is needed when using HMC (nimbleHMC::nimbleHMC()).

When building a model using nimbleModel(), AD can be enabled by setting the function argument buildDerivs = TRUE. However, when building the model using readBUGSmodel(), there's seemingly no option for enabling AD.

Consequentially, I get the error message:

Error: must set buildDerivs = TRUE when building model

when running nimbleHMC() on my BUGS model.

~I was therefore wondering if there's another way of enabling AD, when reading in a BUGS model file?~

As a feature suggestion, it would be an improvement if buildDerivs were to be added to available options in either nimbleHMC() or readBUGSmodel().


[Edit:]

I just realized I can enable AD for all models by setting nimbleOptions(buildModelDerivs = TRUE). However, I do not know the implications of having AD globally enabled. Still, it would be a nice feature to enable AD for the model only.

danielturek commented 8 months ago

@perrydv It seems reasonable to add this buildDerivs argument to readBUGSmodel.

I'd be happy to make this quick change, but let me know what you think.

paciorek commented 8 months ago

@danielturek @perrydv looks like we never resolved this. I'm going to add the argument to readBUGSmodel unless there are objections.

danielturek commented 8 months ago

@paciorek Agreed, thank you.