Compile error when calling the function stan_model in an R Jupyter notebook
Nobody has claimed this yet.
- Dominant language
- R
- Stars
- 1.1k
- Forks
- 266
- Avg merge
- 2h 56m
- Merged PRs (30d)
- 1
Description
Summary:
I get a compile error when calling the function stan_model in an R Jupyter notebook. When running the same code from the terminal no error occurs.
Description:
I'm trying to run the following toy model in rstan:
# In R:
# Load necessary libraries and set up multi-core processing for Stan
options(warn=-1, message =-1)
library(dplyr); library(ggplot2); library(rstan); library(reshape2)
rstan_options(auto_write = TRUE)
options(mc.cores = parallel::detectCores())
# In R, or you could save the contents of the string in a file with .stan file type
dgp_string <- "
functions {
/**
* Return draws from a linear regression with data matrix X,
* coefficients beta, and student-t noise with degrees of freedom nu
* and scale sigma.
*
* @param X Data matrix (N x P)
* @param beta Coefficient vector (P x 1)
* @param nu Residual distribution degrees of freedom.
* @param sigma Residual distribution scale.
* @return Return an N-vector of draws from the model.
*/
vector dgp_rng(matrix X, vector beta, real nu, real sigma) {
vector[rows(X)] y; // define the output vector to be as long as the number of rows in X
// Now fill it in
for (n in 1:rows(X))
y[n] <- student_t_rng(nu, X[n] * beta, sigma);
return y;
}
}
data {
// If we were estimating a model, we'd define the data inputs here
}
parameters {
// ... and the parameters we want to estimate would go in here
}
model {
// This is where the probability model we want to estimate would go
}
"
# Generate a matrix of random numbers, and values for beta, nu and sigma
set.seed(42) # Set the random number generator seed so that we get the same parameters
N <- 1000 # Number of observations
P <- 10 # Number of covariates
X <- matrix(rnorm(N*P), N, P) # generate an N*P covariate matrix of random data
nu <- 5 # Set degrees of freedom
sigma <- 5 # And scale parameter
beta <- rnorm(10) # Generate some random coefficients that we'll try to recover
# Make sure the first element of beta is positive as in our chosen DGP
beta[1] <- abs(beta[1])
# Compile the script
compiled_function <- stan_model(model_code = dgp_string) # you could use file = "path/to/yourfile.stan" if you have saved it as so
Current Output:
If applicable, any relevant output from RStan.
I get the following error message:
(...)
Error in compileCode(f, code, language = language, verbose = verbose): Compilation ERROR, function(s)/method(s) not created! **********************************************************************
* Please run brazil-build rather than make. Your build might not work
* correctly without running brazil-build.
**********************************************************************
cc1plus: error: unrecognized command line option "-mbmi-mavx"
make: *** [file3bf5713249a.o] Error 1
Traceback:
1. stan_model(model_code = dgp_string)
2. cxxfunctionplus(signature(), body = paste(" return Rcpp::wrap(\"",
. model_name, "\");", sep = ""), includes = inc, plugin = "rstan",
. save_dso = save_dso | auto_write, module_name = paste("stan_fit4",
. model_cppname, "_mod", sep = ""), verbose = verbose)
3. cxxfunction(sig = sig, body = body, plugin = plugin, includes = includes,
. settings = settings, ..., verbose = verbose)
4. compileCode(f, code, language = language, verbose = verbose)
5. stop(paste("Compilation ERROR, function(s)/method(s) not created!",
. paste(errmsg, collapse = "\n")))
RStan and R version:
sessionInfo()
R version 3.3.2 (2016-10-31)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Amazon Linux Bare Metal release 2012.03
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] reshape2_1.4.2 rstan_2.12.1 StanHeaders_2.12.0-1
[4] ggplot2_2.2.0 dplyr_0.5.0
loaded via a namespace (and not attached):
[1] Rcpp_0.12.8 magrittr_1.5 munsell_0.4.3 uuid_0.1-2
[5] colorspace_1.3-1 R6_2.2.0 stringr_1.1.0 plyr_1.8.4
[9] tools_3.3.2 parallel_3.3.2 grid_3.3.2 gtable_0.2.0
[13] DBI_0.5-1 lazyeval_0.2.0 assertthat_0.1 digest_0.6.10
[17] tibble_1.2 crayon_1.3.2 gridExtra_2.2.1 IRdisplay_0.4.4
[21] repr_0.10 IRkernel_0.7.1 inline_0.3.14 evaluate_0.10
[25] pbdZMQ_0.2-4 stringi_1.1.2 scales_0.4.1 stats4_3.3.2
[29] jsonlite_1.1
Operating System:
cat /etc/redhat-release
Red Hat Enterprise Linux Server release 5.3 (Tikanga)
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the stan_model call in the R Jupyter notebook and from the terminal, using the reported RStan versions and compiler error for -mbmi-mavx. Inspect the compileCode path and RStan build configuration; done means the notebook compilation succeeds without the unrecognized compiler option, or the incompatibility is clearly documented.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- jupyter, r
- Domain
- build-system, compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100