rstan:::rstudio_stanc() update syntax or add message in the error for Stan version
Nobody has claimed this yet.
- Dominant language
- R
- Stars
- 1.1k
- Forks
- 266
- Avg merge
- 2h 56m
- Merged PRs (30d)
- 1
Description
Summary:
RStudio calls rstan:::rstudio_stanc() to check the syntax of Stan files, which relies on the version coinciding with rstan, which can lag Stan versions, and its new syntax, for necessary development reasons. This can lead to RStudio / rstan:::rstudio_stanc() throwing an error for syntactically correct Stan code if compiled under the latest version (using, for example, the package interface cmdstanr).
E.g., reduce_sum type syntax not currently recognized.
It is not intuitive that RStudio would not be agnostic to the package interface when we have multiple interfaces for different Stan versions. Would it make sense to either a) include in the error message from rstan:::rstudio_stanc() the version of Stan used for syntax checking or b) have this RStudio-specific function check syntax against the latest Stan, but flag what may not compile with rstan's current implementation?
Reproducible Steps:
From the Stan User Guide, now in version 2.24:
functions {
real partial_sum(int[] y_slice,
int start, int end,
vector x,
vector beta) {
return bernoulli_logit_lpmf(y_slice | beta[1] + beta[2] * x[start:end]);
}
}
data {
int N;
int y[N];
vector[N] x;
}
parameters {
vector[2] beta;
}
model {
int grainsize = 1;
beta ~ std_normal();
target += reduce_sum(partial_sum, y,
grainsize,
x, beta);
}
Current Output:
RStudio (Version 1.3.1070)'s syntax checking produces this error:
> rstan:::rstudio_stanc("test.stan")
SYNTAX ERROR, MESSAGE(S) FROM PARSER:
Variable "partial_sum" does not exist.
error in 'model1d1918bc1980_test' at line 20, column 34
-------------------------------------------------
18: int grainsize = 1;
19: beta ~ std_normal();
20: target += reduce_sum(partial_sum, y,
^
21: grainsize,
-------------------------------------------------
Error in stanc(filename, allow_undefined = TRUE) :
failed to parse Stan model 'test' due to the above error.
Expected Output:
See the suggestion above.
RStan Version:
2.21.2
R Version:
4.02
Operating System:
OSX Catalina
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the rstan:::rstudio_stanc() entry point and reproduce the failure using test.stan and the reduce_sum example from the Stan User Guide. Compare the reported RStan 2.21.2 behavior with the requested alternatives, and consider the work complete when syntax-version behavior is clearly communicated or the compatibility check is defined and covered.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- r
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100