Error running Stan on AWS

Hi all,

I’m trying to run Stan models on Amazon Web Services. This is my first attempt at cloud computing so I know next to nothing about how it works.

I followed these instructions (How to run RStudio on AWS in under 3 minutes for free | by Jonas Schröder | Towards Data Science) to use Louis Aslett’s RStudio AMIs, as discussed in this thread (Run rstan on AWS). So far so good, but when I try to fit a simple Stan model I get an error.

The model:

# Simulate data
mu <- 2
sig <- 0.5
N <- 4000
y <- rnorm(N,mu,sig)

# Fit Stan model to estimate mean and std. dev.

model_code <- '
data {
  int<lower=0> N;
  vector[N] y;

parameters {
 real mu;
 real<lower=0> sig;

model {
  y ~ normal(mu,sig);

input_data <- list(N=N,y=y)
fit <- stan(model_code = model_code, data = input_data)

The error:

Error in context_eval(join(src), private$context, serialize) : 
  TypeError: Object #<Object> has no method 'imul'

Any assistance much appreciated!

it looks like a similar symptom (& some suggested fixes to try) was mentioned a few months ago in this thread: Problem compiling STAN program (via brms) on HPC

If that doesn’t work, here’s one strategy to go about debugging it:

  • distill the failing program down to a minimal example (your code looks pretty minimal)
  • confirm you can get the minimal example to run locally in your own development environment, without the extra layers of complexity from running it inside AWS EC2
  • or alternatively, if you can get the minimal example to fail in the same way locally in your own development environment, maybe that hints there’s a flaw in the script
  • try to figure out what the differences are (if any) between your local dev environment and the remote AWS dev environment inside the AMI virtual machine image you are running (operating system type & version, R version, Stan version, C++ compiler version, CPU architecture (amd64? arm64?).

Another debugging tactic is “try to run it locally with the exact configuration you are trying to use remotely, and see if you can reproduce the exact fault”. It looks like you are running RStudio inside amazon EC2 service using amazon’s proprietary AMI virtual machine image format. I don’t think there is a way to run an AMI virtual machine locally, but apparently it is possible to export some AMI images to vmware virtual machine images which you may then be able to run locally using vmware player software. This probably isn’t a useful direction to explore, as the issue is almost certainly related to the configuration of software inside the virtual machine image, not anything to do with amazon’s EC2 platform.

A different workflow, that would make it much easier to run things locally with the exact same software versions that are used remotely, would be to switch to using docker container images to bundle stan, R, c++ compilers, etc, rather than bundling them into AMI virtual machine images, as mentioned briefly by mbjospeh:

A downside of doing this would be the additional learning curve of getting some familiarity with docker. This container-image based workflow is used by many software development teams as one piece of the puzzle in managing software dependencies to ensure that the versions of software that are developed and tested locally in development environments are the exact same versions that gets deployed (to AWS or wherever) and run.

Thanks @rfc, I’ve gone the way of learning some docker as you suggested.

1 Like