# 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 <- '
y ~ normal(mu,sig);
input_data <- list(N=N,y=y)
fit <- stan(model_code = model_code, data = input_data)
Error in context_eval(join(src), private$context, serialize) :
TypeError: Object #<Object> has no method 'imul'
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.