Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ulam: failure when using start parameter when using cmdstanr #328

Open
ramanshah opened this issue Aug 27, 2021 · 4 comments
Open

ulam: failure when using start parameter when using cmdstanr #328

ramanshah opened this issue Aug 27, 2021 · 4 comments
Assignees
Labels

Comments

@ramanshah
Copy link

Hi! I'm learning a ton from studying Statistical Rethinking in self-study with a couple data scientist friends. Thank you so much!

I ran into the following issue using ulam while working through Chapter 9: estimating the models using cmdstanr appears to fail when I include a start parameter. Here's a hopefully reproducible example:

> library(rethinking)
> set_ulam_cmdstan(TRUE)
> N <- 100
> set.seed(909)
> height <- rnorm(N, 10, 2)
> leg_prop <- runif(N, 0.4, 0.5)
> leg_left <- leg_prop * height + rnorm(N, 0, 0.2)
> leg_right <- leg_prop * height + rnorm(N, 0, 0.2)
> d <- list(height=height, leg_left=leg_left, leg_right=leg_right)
> 
> m9h3 <- ulam(
+   alist(
+     height ~ dnorm(mu, sigma),
+     mu <- a + bl * leg_left + br * leg_right,
+     a ~ dnorm(10, 100),
+     bl ~ dnorm(2, 10),
+     br ~ dnorm(2, 10),
+     sigma ~ dexp(1)
+   ), data=d, chains=4, cores=4
+ )
Compiling Stan program...
[...]
All 4 chains finished successfully.
Mean chain execution time: 2.9 seconds.
Total execution time: 3.2 seconds.
> precis(m9h3)
      mean   sd 5.5% 94.5% n_eff Rhat4
a     1.30 0.30 0.82  1.78  1171     1
bl    0.95 0.28 0.50  1.41   774     1
br    0.98 0.29 0.51  1.43   772     1
sigma 0.67 0.05 0.60  0.75  1243     1
> m9h3_start <- ulam(
+   alist(
+     height ~ dnorm(mu, sigma),
+     mu <- a + bl * leg_left + br * leg_right,
+     a ~ dnorm(10, 100),
+     bl ~ dnorm(2, 10),
+     br ~ dnorm(2, 10),
+     sigma ~ dexp(1)
+   ), data=d, chains=4, cores=4, start=list(a=10, bl=0, br=0.1, sigma=1)
+ )
Error in dyn.load(libLFile) : 
  unable to load shared object '/var/folders/_8/0q_m6cvn03xg4x7f5fcfjxym0000gn/T//RtmpDon0LA/filefba57ddd2bd5.so':
  dlopen(/var/folders/_8/0q_m6cvn03xg4x7f5fcfjxym0000gn/T//RtmpDon0LA/filefba57ddd2bd5.so, 6): Symbol not found: __ZN5rstan8stan_fitC1EP7SEXPRECi
  Referenced from: /var/folders/_8/0q_m6cvn03xg4x7f5fcfjxym0000gn/T//RtmpDon0LA/filefba57ddd2bd5.so
  Expected in: flat namespace
 in /var/folders/_8/0q_m6cvn03xg4x7f5fcfjxym0000gn/T//RtmpDon0LA/filefba57ddd2bd5.so
Error in sink(type = "output") : invalid connection

I've tried various permutations of options, and this failure seems to happen when the start parameter is included.

I haven't been able to try this with rstan because I haven't been able to get a functioning installation of it.

Thanks much for your insight!

@rmcelreath
Copy link
Owner

Thanks. cmdstanr support is still incomplete, because the API wasn't stable when I added it. I should check that things are stable now and fix this. Much appreciated.

@rmcelreath rmcelreath added the bug label Aug 28, 2021
@rmcelreath rmcelreath self-assigned this Aug 28, 2021
@ramanshah
Copy link
Author

Makes sense. Thank you so much!!

@jhoupt
Copy link

jhoupt commented Mar 30, 2024

Just ran into this (or closely related) issue. It looks like the ulam-function code checks for cmstanr but does not when start parameters are included (lines 1477-1489 compared to 1446-1476). The error I had related to it looking for rstan (failed to load namespace) which I do not have installed. I would guess that the error is not too common if people have rstan installed, it is just not running cmdstan. This may be related to issue #428 because I found it when trying to sort out that exact problem.

@harper357
Copy link

@jhoupt I am running into this error too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants