stan-dev / rstan

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

"double free or corruption (out)" error on using previously working code using dordlogit function in "rethinking" library (Rstan 2.21.2) #977

Open sidhun opened 2 years ago

sidhun commented 2 years ago

Summary:

"double free or corruption (out)" error on using previously working code using dordlogit function in "rethinking" library (Rstan 2.21.2)

Description:

In trying to use the dordlogit function from the rethinking package (version 2.13), I’m getting an error after reinstalling Rstan to a more recent version (2.21.2, GitRev: 2e1f913d3ca3). The code used to run fine previously.

Reproducible Steps:

To reproduce it, please use (code essentially from McElreath, R. Statistical Rethinking, 2nd Edition, New York: CRC Press, 2020, p. 385, just slightly adapted):

library(rethinking)
library(rstan)
data(Trolley)
d <- Trolley

## R code 12.16
m12.4 <- ulam(
    alist(
        R ~ dordlogit( 0 , cutpoints ),
        cutpoints ~ dnorm( 0 , 1.5 )
    ) , data=list( R=d$response ), chains=1 )

Current Output:

source("~/test.r") Loading required package: rstan Loading required package: StanHeaders Loading required package: ggplot2 rstan (Version 2.21.2, GitRev: 2e1f913d3ca3) For execution on a local, multicore CPU with excess RAM we recommend calling options(mc.cores = parallel::detectCores()). To avoid recompilation of unchanged Stan programs, we recommend calling rstan_options(auto_write = TRUE) Loading required package: parallel rethinking (Version 2.13)

Attaching package: 'rethinking'

The following object is masked from 'package:stats':

rstudent

Error in open.connection(con, open = mode) : Could not resolve host: github.com

SAMPLING FOR MODEL 'fbca4c7b48ba5e5074b8d9463e3ca10c' NOW (CHAIN 1). Chain 1: Chain 1: Gradient evaluation took 0.004117 seconds Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 41.17 seconds. Chain 1: Adjust your expectations accordingly! Chain 1: Chain 1: double free or corruption (out) Aborted (core dumped)

Rstan version:

rstan (Version 2.21.2, GitRev: 2e1f913d3ca3)

Rethinking version

2.13

R Version:

R version 4.1.1 (2021-08-10)

Operating System:

Ubuntu 20.04.3 LTS

The code used to run despite the github.com connection error, which does not seem to be relevant here.

Thank you.

samuelVJrobinson commented 2 years ago

I'm getting a very similar problem when running a hierarchical beta-binomial. The problems don't occur when I model the successes/failures as separate negative binomial models.

epkanol commented 2 years ago

Leaving a note here for a future googler:

I had a similar issue, but already in the first ulam section in the book (R code 9.14, p. 280 in the 2nd ed.) Was using:

OS: Ubuntu 20.4
R version 4.1.3
stan version 2.21.3
gcc version 10.3.0 (Ubuntu 10.3.0-1ubuntu1~20.04)
rethinking version 2.13

But I managed to solve the issue by reinstalling the needed toolchain:

install.packages("devtools")
devtools::install_github("stan-dev/cmdstanr")
cmdstanr::install_cmdstan()
install.packages(c("coda","mvtnorm","loo","dagitty"))
devtools::install_github("rmcelreath/rethinking")

After doing this, the problem disappeared (for now...)