nimble-dev / nimble

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

Invalid parameter name 'int' #1335

Closed famuvie closed 9 months ago

famuvie commented 1 year ago

Dear all,

Similarly to #1219, using int as a parameter name (after intercept) leads to a compilation error, which is not straightforward to track back to the source of the problem.

library(nimble)
#> nimble version 0.13.0 is loaded.
#> For more information on NIMBLE and a User Manual,
#> please visit https://R-nimble.org.
#> 
#> Note for advanced users who have written their own MCMC samplers:
#>   As of version 0.13.0, NIMBLE's protocol for handling posterior
#>   predictive nodes has changed in a way that could affect user-defined
#>   samplers in some situations. Please see Section 15.5.1 of the User Manual.
#> 
#> Attaching package: 'nimble'
#> The following object is masked from 'package:stats':
#> 
#>     simulate
code <- nimbleCode({
  int ~ dexp(1) 
})
rModel <- nimbleModel(code)
#> Defining model
#> Building model
#> Running calculate on model
#>   [Note] Any error reports that follow may simply reflect missing values in model variables.
#> Checking model sizes and dimensions
#>   [Note] This model is not fully initialized. This is not an error.
#>          To see which variables are not initialized, use model$initializeInfo().
#>          For more information on model initialization, see help(modelInitialization).
cModel <- compileNimble(rModel)
#> Compiling
#>   [Note] This may take a minute.
#>   [Note] Use 'showCompilerOutput = TRUE' to see C++ compilation details.
#> Error: Failed to create the shared library. Run 'printErrors()' to see the compilation errors.
printErrors()
#> using C++ compiler: ‘g++ (Ubuntu 11.3.0-1ubuntu1~22.04.1) 11.3.0’
#> using C++11
#> In file included from P_1_code_MID_1.cpp:7:
#> P_1_code_MID_1.h:24:23: error: expected unqualified-id before ‘int’
#>    24 |   NimArr<1, double> * int;
#>       |                       ^~~
#> P_1_code_MID_1.cpp: In constructor ‘code_MID_1::code_MID_1()’:
#> P_1_code_MID_1.cpp:48:22: error: expected primary-expression before ‘int’
#>    48 | namedObjects["int"]=&int;
#>       |                      ^~~
#> P_1_code_MID_1.cpp: In member function ‘void code_MID_1::pointAtAll(code_MID_1_MV_UID_1*, int)’:
#> P_1_code_MID_1.cpp:52:4: error: expected unqualified-id before ‘=’ token
#>    52 | int=&(values__->int_Vec[i__]);
#>       |    ^
#> make: *** [/usr/lib/R/etc/Makeconf:200: P_1_code_MID_1.o] Error 1

Created on 2023-07-27 with reprex v2.0.2

Perhaps some detection of invalid node names with a more informative error message would be useful?

Best. ƒacu.-

paciorek commented 1 year ago

One thought here is that we detect a set of names that we know will cause C++ name conflicts - presumably int, double , etc. and check during the C++ code generation phase.

paciorek commented 11 months ago

I'm proceeding to insert a check early in modelDef creation in branch fix_1335.

In addition to checking C++ keywords, Values and NimArr cause problems but not various other keywords from nimble's C++ or Eigen. There may be others that are problems.