Stan now (mostly) working on RStudio Cloud

#22

The number of kids who don’t know R or Stan but do know enough about probability / statistics / computation to have any interest in and appreciation for what Stan is doing is a very small set. But for them you presumably just want HTML that has the plots but hides the code.

#23

One possible audience is people who don’t know statistics but who could think this is cool. People such as Alan Edelman.

#24

I love this and I’m happy with Aki’s knitr-like .R file. I have just 2 concerns:

  1. The session takes a long time to load. Is that because the .rds and .html files are so big, in which case should we remove them from the saved session?

  2. If load time is proportional to file sizes, then this is a concern if we’d like to put in several models in the same session. Perhaps we should talk with JJ about him giving us some number of separate sessions: one for the regression model, one for the golf example, etc etc. This is all good publicity for Rstudio, so I don’t see why he’d say no to this request.

  3. The other concern is compilation time. Yes, I realize this conflicts with item 1 above. But, seeing the online version makes me worry that, for new users especially, compilation time is a barrier, as it makes it difficult to play around with models.

#25

I don’t think it has to do with file sizes in projects; see https://community.rstudio.com/t/performance-issues/14019 . So, we should continue to precompile the examples.

#26

Here is the afore mentioned blog post: https://andrewgelman.com/2018/10/12/stan-on-the-web-for-free-thanks-to-rstudio/

1 Like
#27

I’ve succesfully complied two simpler models, but the following and other models with similar complexity fail to compile

writeLines(readLines("binomb.stan"))
data {
  int<lower=0> N;
  int<lower=0> y;
}
parameters {
  real alpha;
}
transformed parameters {
  real theta;
  theta = inv_logit(alpha);
}
model {
  alpha ~ normal(0,1.5);
  y ~ binomial_logit(N,alpha);
}
d_bin <- list(N = 100, y = 70)
fit_bin <- stan(file = 'binomb.stan', data = d_bin)
#28

I am guessing that one should compile when the server is under less load.

#29

but

so it’s not particularily useful as is. Have you asked RStudio what is the price for more resources when running a course to avoid problems like this?

#30

It is in alpha so they are not yet selling it. For a workshop, the person in charge should compile the models in advance when everyone else is asleep. But I will ask RStudio if they will install a version of clang++ that supports ThinLTO and maybe we can compile a few more models within the resource limits.

#31

It’s difficult to pre-compile those models that students write or modify during the course…

#32

This binomial model compiles for me on Saturday, although RStudio seems open to adding a better compiler.

#33

This is excellent news and is really a great step in terms of encouraging the adoption of Stan. Up until now I’ve been reluctant to run tutorial sessions on Stan because of the difficulties of getting it installed on our University machines, but this changes everything.

After playing around with my own copy of the project and one thing I’m noticing is that compilation is really finicky. Often it’ll work on the first attempt, but subsequent attempts will give a bunch of clang errors. Sometimes, restarting R (using Session -> Restart R) will work, but other times it will just refuse to work. Is there anything that can be done about this, or is it just a limitation of the present implementation?

#34

I think it depends on the load that happens to be present at that moment. We are trying to improve it a little bit. It is always possible to serialize a compiled model if you specify auto_write = TRUE in the call to sampling or rstan_options(auto_write = TRUE) at the outset. I was able to compile almost 500 examples just by waiting until late at night Eastern time.

#35

I was encouraged to try out the RStudio Cloud implementation of Stan through the Statistical Rethinking course using my MacBook Pro. I installed the rethinking package (+dependencies) and updated a few of the existing packages (not sure if supposed to do that). The rethinking code works fine; however, when I try to run the examples (as recommended) I get the following:

library(rstan)
options(mc.cores = parallel::detectCores())
rstan_options(auto_write = TRUE)
?stan_demo()
fit1 <- stan_demo(68)
stan_demo(model = character(68),
method = c(“sampling”))

chose model 68 when prompted

> “N” <-

+ 8

> “sigma_y” <-

+ c(15,10,16,11,9,11,10,18)

> “y” <-

+ c(28,8,-3,7,-1,1,18,12)

Error in compileCode(f, code, language = language, verbose = verbose) :

Compilation ERROR, function(s)/method(s) not created! clang version 5.0.0-3~16.04.1 (tags/RELEASE_500/final)

Target: x86_64-pc-linux-gnu

Thread model: posix

InstalledDir: /usr/bin

Found candidate GCC installation: /usr/bin/…/lib/gcc/x86_64-linux-gnu/5

Found candidate GCC installation: /usr/bin/…/lib/gcc/x86_64-linux-gnu/5.4.0

Found candidate GCC installation: /usr/bin/…/lib/gcc/x86_64-linux-gnu/6

Found candidate GCC installation: /usr/bin/…/lib/gcc/x86_64-linux-gnu/6.0.0

Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/5

Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/5.4.0

Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6

Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6.0.0

Selected GCC installation: /usr/bin/…/lib/gcc/x86_64-linux-gnu/5.4.0

Candidate multilib: .;@m64

Selected multilib: .;@m64

“/usr/lib/llvm-5.0/bin/clang” -cc1 -triple x86_64-pc-linux-gnu -emit-llvm-bc -flto=thin -flto-unit -disable-free -

In addition: Warning message:

In system(cmd, intern = !verbose) :

running command ‘/opt/R/3.5.2/lib/R/bin/R CMD SHLIB file11165b009b1.cpp 2> file11165b009b1.cpp.err.txt’ had status 1

Error in sink(type = “output”) : invalid connection

Any thoughts? Is it OK to update/add packages or should one stick to what is provided?

#36

I got a similar error message and I think it’s due to the current RAM/memory limit (1GB) in RStudio Cloud.

#37

I have a simmilar error now on iPad pro with google chrome.
My device RAM is 4GB.

Why dosen’t work?

#38

It is not related to the RAM on your machine; it is related to the 1GB RAM limit imposed by RStudio Cloud. I think Stan 2.18.x is not going to work with those restrictions and I will have to downgrade everything to Stan 2.17.x.

1 Like
#39

Oh, I had misunderstand. Thank you. I wil try it!

#40

Thanks everyone.

#41

Not sure if you were planning on fixing this, but I note that there has been an update since I last posted. Nevertheless, I still have problems when trying to run the demos:

> fit1 <- stan_demo(68)

Do you want to download the example models?

1: Download to include directory of the rstan package
2: Download to the temporary directory
3: Do not download

Selection: 2
trying URL ‘https://github.com/stan-dev/example-models/archive/master.zip
downloaded 27.8 MB

“N” <-

  • 8

“sigma_y” <-

  • c(15,10,16,11,9,11,10,18)

“y” <-

  • c(28,8,-3,7,-1,1,18,12)
    Error in compileCode(f, code, language = language, verbose = verbose) :
    Compilation ERROR, function(s)/method(s) not created! /usr/bin/ld.gold: error: filecab2dc710.o:1:3: invalid character
    /usr/bin/ld.gold: error: filecab2dc710.o:1:3: syntax error, unexpected $end
    /usr/bin/ld.gold: error: filecab2dc710.o: not an object or archive
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    make: *** [filecab2dc710.so] Error 1
    In addition: Warning message:
    In system(cmd, intern = !verbose) :
    running command ‘/opt/R/3.5.2/lib/R/bin/R CMD SHLIB filecab2dc710.cpp 2> filecab2dc710.cpp.err.txt’ had status 1
    Error in sink(type = “output”) : invalid connection

fit1 <- stan_demo(1)

“score1” <-

  • c(0.446, 0.334, -0.233, -0.304, -0.256, 0.515, -0.652, 0.271, -0.556,
  • 0.955, 0.307, -0.434, -0.272, -0.404, 0.415, 0.39, -0.755, 0. … [TRUNCATED]

“party” <-

  • c(1, 1, 0, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1,
  • 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1,
  • 1, 0, 1, 0, 1, 1, 0 … [TRUNCATED]

“x” <-

  • c(0.62073, 0.50803, 0.38243, 0.29769, 0.32751, 0.53766, 0.20003, 0.52211,
  • 0.31267, 0.64143, 0.69113, 0.4386, 0.30166, 0.25836, 0.51547, … [TRUNCATED]

“N” <-

  • 357
    Error in compileCode(f, code, language = language, verbose = verbose) :
    Compilation ERROR, function(s)/method(s) not created! clang: error: unable to execute command: Killed
    clang: error: clang frontend command failed due to signal (use -v to see invocation)
    clang version 5.0.0-3~16.04.1 (tags/RELEASE_500/final)
    Target: x86_64-pc-linux-gnu
    Thread model: posix
    InstalledDir: /usr/bin
    clang: note: diagnostic msg: PLEASE submit a bug report to http://llvm.org/bugs/ and include the crash backtrace, preprocessed source, and associated run script.
    clang: note: diagnostic msg:

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang: note: diagnostic msg: /tmp/fileca40943554-1385b3.cpp
clang: note: diagnostic msg: /tmp/fileca40943554-1385b3.sh
clang: note: diagnostic msg:


make: *** [fileca40943554.o] Error 254
In addition: Warning message:
In system(cmd, intern = !verbose) :
running command ‘/opt/R/3.5.2/lib/R/bin/R CMD SHLIB fileca40943554.cpp 2> fileca40943554.cpp.err.txt’ had status 1
Error in sink(type = “output”) : invalid connection