stan-dev / rstan

RStan, the R interface to Stan
https://mc-stan.org
1.03k stars 264 forks source link

segfault on very simple program #836

Open CdeMills opened 4 years ago

CdeMills commented 4 years ago

Summary:

fit <- stan(file = 'schools.stan', data = schools_dat) from the RStan tutorial results in failure

Description:

caught segfault address 0x3c580e7ca670, cause 'memory not mapped'

Traceback: 1: context_eval(join(src), private$context, serialize) 2: get_str_output(context_eval(join(src), private$context, serialize)) 3: evaluate_js(src, serialize = TRUE) 4: get_json_output(evaluate_js(src, serialize = TRUE)) 5: ctx$call("stanc", model_name, paste(model_code, collapse = "\n")) 6: doTryCatch(return(expr), name, parentenv, handler) 7: tryCatchOne(expr, names, parentenv, handlers[[1L]]) 8: tryCatchList(expr, classes, parentenv, handlers) 9: tryCatch(expr, error = function(e) { call <- conditionCall(e) if (!is.null(call)) { if (identical(call[[1L]], quote(doTryCatch))) call <- sys.call(-4L) dcall <- deparse(call)[1L] prefix <- paste("Error in", dcall, ": ") LONG <- 75L sm <- strsplit(conditionMessage(e), "\n")[[1L]] w <- 14L + nchar(dcall, type = "w") + nchar(sm[1L], type = "w") if (is.na(w)) w <- 14L + nchar(dcall, type = "b") + nchar(sm[1L], type = "b") if (w > LONG) prefix <- paste0(prefix, "\n ") } else prefix <- "Error : " msg <- paste0(prefix, conditionMessage(e), "\n") .Internal(seterrmessage(msg[1L])) if (!silent && isTRUE(getOption("show.error.messages"))) { cat(msg, file = outFile) .Internal(printDeferredWarnings()) } invisible(structure(msg, class = "try-error", condition = e))}) 10: try(ctx$call("stanc", model_name, paste(model_code, collapse = "\n")), silent = TRUE) 11: stanc_beta(model_code, model_name, isystem) 12: doTryCatch(return(expr), name, parentenv, handler) 13: tryCatchOne(expr, names, parentenv, handlers[[1L]]) 14: tryCatchList(expr, classes, parentenv, handlers) 15: tryCatch(expr, error = function(e) { call <- conditionCall(e) if (!is.null(call)) { if (identical(call[[1L]], quote(doTryCatch))) call <- sys.call(-4L) dcall <- deparse(call)[1L] prefix <- paste("Error in", dcall, ": ") LONG <- 75L sm <- strsplit(conditionMessage(e), "\n")[[1L]] w <- 14L + nchar(dcall, type = "w") + nchar(sm[1L], type = "w") if (is.na(w)) w <- 14L + nchar(dcall, type = "b") + nchar(sm[1L], type = "b") if (w > LONG) prefix <- paste0(prefix, "\n ") } else prefix <- "Error : " msg <- paste0(prefix, conditionMessage(e), "\n") .Internal(seterrmessage(msg[1L])) if (!silent && isTRUE(getOption("show.error.messages"))) { cat(msg, file = outFile) .Internal(printDeferredWarnings()) } invisible(structure(msg, class = "try-error", condition = e))}) 16: try(stanc_beta(model_code, model_name, isystem)) 17: stanc(file = file, model_code = model_code, model_name = model_name, verbose = verbose, obfuscate_model_name = obfuscate_model_name, allow_undefined = allow_undefined, isystem = isystem) 18: stan_model(file, model_name = model_name, model_code = model_code, stanc_ret = NULL, boost_lib = boost_lib, eigen_lib = eigen_lib, save_dso = save_dso, verbose = verbose) 19: stan(file = "schools.stan", data = schools_dat)

Reproducible Steps:

fit <- stan(file = 'schools.stan', data = schools_dat) shools_dat and schools.stan initialised as instructed

Current Output:

Segfault

Expected Output:

as explained in tutorial

RStan Version:

The version of RStan you are running (e.g., from packageVersion("rstan")) 2.21.2

R Version:

The version of R you are running (e.g., from R.version.string) R version 4.0.2 (2020-06-22)

Operating System:

CentOS-8 on a x86_64 machine I took libnghttp2-devel-1.41 and nodejs-12.18.3 from Fedora32 and recompiled them using the rpm build system. This way everything is supposed to be coherent (same compiler, ...)

Any idea ? Thanks Pascal Dupuis

jgabry commented 4 years ago

Hmm, @bgoodri could this be related to the inline package issue? Or do you see any issues with the OS configuration described?

bgoodri commented 4 years ago

I'm going to guess that Rcpp needs to be installed from source using the same compiler.

CdeMills commented 4 years ago

Hello again, R is a standard package (R-4.0.2-1.el8.x86_64) in CentOS-8, and Rcpp was installed from inside R under some path in the user main directory, obtained by putting R_LIBS_USER = ${HOME}/usr/lib/R/%p-library/%v in ~/.Renviron. Rcpp is 1.0.5, which is exactly the same version as as one available from RCRAN. So basically everything was generated from the same compiler, gcc version 8.3.1 20191121

Regards Pascal

jgabry commented 4 years ago

@bgoodri any other ideas? Sounds like Rcpp was installed from source using the same compiler.

bgoodri commented 4 years ago

This one happens when calling the functions in v8. So, first doing rstan_options(javascript = FALSE) will probably allow the model to go through, but does not address the problem(s) with V8 that will need to get fixed for 2.25.x.

On Fri, Sep 4, 2020 at 3:35 PM Jonah Gabry notifications@github.com wrote:

@bgoodri https://github.com/bgoodri any other ideas? Sounds like Rcpp was installed from source using the same compiler.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/stan-dev/rstan/issues/836#issuecomment-687341860, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAZ2XKQA2O6XOSNLPRAAC3TSEE6RNANCNFSM4QJUMXMA .

jgabry commented 4 years ago

Ok thanks

bnicenboim commented 3 years ago

is there a workaround? I've tried with rstan_options(javascript = FALSE) and it's still not working.

bgoodri commented 3 years ago

And you still get an error from V8?

On Thu, Sep 17, 2020 at 5:00 AM Bruno Nicenboim notifications@github.com wrote:

is there a workaround? I've tried with rstan_options(javascript = FALSE) and it's still not working.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/stan-dev/rstan/issues/836#issuecomment-694098139, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAZ2XKVZDHNIJVKAI4LKTCDSGHFZFANCNFSM4QJUMXMA .

bnicenboim commented 3 years ago

ok, so now

bnicenboim commented 3 years ago

it might be related to this https://discourse.mc-stan.org/t/object-with-null-pointer-in-rstudio/12239

bgoodri commented 3 years ago

I would guess that might be due to cached stanfit objects or .rds files with stan_model's in them that were created by a previous version of RStan.

On Thu, Sep 17, 2020 at 9:35 AM Bruno Nicenboim notifications@github.com wrote:

it might be related to this https://discourse.mc-stan.org/t/object-with-null-pointer-in-rstudio/12239

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/stan-dev/rstan/issues/836#issuecomment-694239082, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAZ2XKV5MCCY7HP44D2P3XTSGIGDRANCNFSM4QJUMXMA .

bnicenboim commented 3 years ago

I deleted all the rds files and I've also tried without caching the objects, and this still happens. It wasn't happening before, with R 3.6 or something, Ubuntu 18.04, and rstan 2.21.1. I've changed too many things, so I have no idea what's the culprit.

And by the way, this is regardless of rstudio, it also happens in command line R when I try to compile a bookdown.

bgoodri commented 3 years ago

Does it happen when you try to run the Stan related code from the bookdown chunks in a regular R session?

On Thu, Sep 17, 2020 at 9:49 AM Bruno Nicenboim notifications@github.com wrote:

I deleted all the rds files and I've also tried without caching the objects, and this still happens. It wasn't happening before, with R 3.6 or something, Ubuntu 18.04, and rstan 2.21.1. I've changed too many things, so I have no idea what's the culprit.

And by the way, this is regardless of rstudio, it also happens in command line R when I try to compile a bookdown.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/stan-dev/rstan/issues/836#issuecomment-694248389, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAZ2XKVZFWURIHK4E7WLWQTSGIHYJANCNFSM4QJUMXMA .

bnicenboim commented 3 years ago

No, and by the way, brms objects work fine inside the bookdown.

bgoodri commented 3 years ago

So, it is something specific to bookdown and Stan programs that are not generated by brms?

On Thu, Sep 17, 2020 at 10:03 AM Bruno Nicenboim notifications@github.com wrote:

No, and by the way, brms objects work fine inside the bookdown.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/stan-dev/rstan/issues/836#issuecomment-694257645, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAZ2XKQULLPLEDNBWQNOBZDSGIJKZANCNFSM4QJUMXMA .

bnicenboim commented 3 years ago

I've checked now, and I have the same problem when I use Rstudio, or when I run render_book either from Rstudio or the command line.

bnicenboim commented 3 years ago

but this is not segfault anymore. I guess I should open a new issue and properly document when it happens.

bnicenboim commented 3 years ago

Ok, it's the strangest thing, I've opened it here #854. It also happens from the command line.