Closed weefuzzy closed 8 months ago
Yes, I'd done something silly: if I correct to matrix[4,4] Rho;
(not [2,2]
) the error goes away. Hopefully that helps narrow it down.
Declaring matrix[2,2] Rho;
instead of [4,4]
should result in
Exception: matrix assign columns: assigning variable Rho (2) and right hand side columns (4) must match in size
The error about serializer storage capacity means the size check during assignment is skipped for some reason and the mistake is not caught until copying the data to the output (which had reserved space for a 2-by-2 matrix in accordance with the declaration)
This may be a problem in an older version of Stan. Are you using the latest RStan?
Do you have optimizations enabled? With optimizations the following model throws the "capacity exceeded" error:
generated quantities {
matrix[2,2] Rho = lkj_corr_rng(4, 1.0);
}
Optimizations are experimental but even so I don't think they should throw internal errors.
Thanks!
Are you using the latest RStan?
> rstan::stan_version()
[1] "2.32.2"
The current version is 2.34? I'll try upgrading, after checking the effect of optimization.
Do you have optimizations enabled?
I think so – the invocation of stan is coming via the rethinking package's ulam
function, which claims that it passes O1
by default. I'll try with explicit settings and see if it changes.
O0
and Oexperimental
I get Exception: matrix assign columns:...
O1
I get capacity exceeded
Correction to version given above. Both rstan
and StanHeaders
are 2.32.5, which seems to be the latest on CRAN
A more minimal and self-contained reproduction. tl;dr in O1
only, I get the internal error. Other flags correctly hint at what I did wrong:
stanmodelcode <- "
parameters{
cholesky_factor_corr[4] L_Rho;
}
model{
L_Rho ~ lkj_corr_cholesky( 4 );
}
generated quantities{
matrix[2,2] Rho;
Rho = multiply_lower_tri_self_transpose(L_Rho);
}
"
print("Running with O0")
stan(model_code=stanmodelcode,data=list(), iter=2, chains=1,stanc_options=list("O0"))
print("Running with Oexperimental")
stan(model_code=stanmodelcode,data=list(), iter=2, chains=1,stanc_options=list("Oexperimental"))
print("Running with O1")
stan(model_code=stanmodelcode,data=list(), iter=2, chains=1,stanc_options=list("O1"))
Sounds like this is another example of https://github.com/stan-dev/stanc3/issues/1295.
One of the optimizations we currently have enabled prevents initializing a variable in Stan if it is immediately assigned to. However, this breaks the way we do bounds checking on containers. Just one of the reasons we recommend running the model at O0
(even if only for a handful of iterations) before setting O1
.
Thank you for reporting!
Summary:
Running a model produces the error above and also says:
Description:
Running the model code quoted below, which is generated code produced via https://github.com/rmcelreath/rethinking gives the error above.
I'm just in the process of learning, so (a) may well have done something silly (b) can't provide good answers for why the code is the way it is. I'm just reporting here because the error message asked me to.
Reproducible Steps:
Raw Data: https://github.com/rmcelreath/rethinking/blob/master/data/bangladesh.csv
Data to model:
Code
Current Output:
Each chain does:
Expected Output:
Additional Information:
The
/var/...
folder with the generated code also contains some chunky csv files (7.2MB each; one per chain?) that may contain more detailed output. Can u/l somewhere if that's helpful.Current Version:
v2.34.0