Skip to content

Commit b10a00a

Browse files
Merge pull request #915 from stan-dev/using-stanc-updates
Update section on stanc for new --color flag, warning formatting
2 parents 34e1d94 + fa7e3dd commit b10a00a

File tree

1 file changed

+81
-71
lines changed

1 file changed

+81
-71
lines changed

src/stan-users-guide/using-stanc.qmd

Lines changed: 81 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ The stanc3 options are:
8888
- `--warn-uninitialized` - Emit warnings about uninitialized variables
8989
to stderr. Currently an experimental feature.
9090

91+
- `--color` - Control whether errors and warnings are emitted with colored
92+
styling on terminals that support it. Valid values are `auto` (the default),
93+
`always`, `never`. Can also be controlled by the `STANC_COLOR` environment variable.
9194

9295
The compiler also provides a number of debug options which are
9396
primarily of interest to stanc3 developers; use the `--help`
@@ -108,17 +111,17 @@ in two situations
108111

109112
1. A completely blank Stan program will produce the following warning message
110113
```
111-
Warning: Empty file 'empty.stan' detected;
112-
this is a valid stan model but likely unintended!
114+
Warning in 'empty.stan', line 1, column 0 to line 2, column 0:
115+
Empty model detected; this is a valid Stan model but likely unintended!
113116
```
114117
2. The use of any [deprecated
115118
features](https://mc-stan.org/docs/reference-manual/deprecations.html)
116119
will lead to warnings which will look as follows
117120
```
118-
Warning in 'deprecated.stan', line 2, column 0: Comments beginning with # are
119-
deprecated and this syntax will be removed in Stan 2.32.0. Use // to
120-
begin line comments; this can be done automatically using stanc
121-
--auto-format
121+
Warning in 'deprecated.stan', line 2, column 10 to column 17:
122+
lkj_cov is deprecated and will be removed in Stan 3.0. Use lkj_corr with
123+
an independent lognormal distribution on the scales, see:
124+
https://mc-stan.org/docs/reference-manual/deprecations.html#lkj_cov-distribution
122125
```
123126
A single Stan program can produce many warnings during compilation.
124127

@@ -148,7 +151,7 @@ There are five kinds of errors emitted by stanc3
148151
look like the following.
149152

150153
```
151-
Syntax error in 'char.stan', line 2, column 6, lexing error:
154+
Syntax error in 'char.stan', line 2, column 7 to column 8, lexing error:
152155
-------------------------------------------------
153156
1: data {
154157
2: int $ome_variable;
@@ -166,10 +169,10 @@ There are five kinds of errors emitted by stanc3
166169
Syntax error in './incl.stan', line 1, column 0, included from
167170
'./incl.stan', line 1, column 0, included from
168171
'incl.stan', line 1, column 0, include error:
169-
-------------------------------------------------
170-
1: #include <incl.stan>
171-
^
172-
-------------------------------------------------
172+
-------------------------------------------------
173+
1: #include <incl.stan>
174+
^
175+
-------------------------------------------------
173176
File incl.stan recursively included itself.
174177
```
175178
@@ -178,15 +181,15 @@ There are five kinds of errors emitted by stanc3
178181
put a size on a type like vector, as in the following, this raises a parsing
179182
(structural) error in the compiler.
180183
```
181-
Syntax error in vec.stan', line 3, column 10 to column 11, parsing error:
182-
-------------------------------------------------
183-
1: data {
184-
2: int<lower=0> N;
185-
3: vector x;
186-
^
187-
4: }
188-
-------------------------------------------------
189-
"[" expression "]" expected for vector size.
184+
Syntax error in 'vec.stan', line 3, column 10 to column 11, parsing error:
185+
-------------------------------------------------
186+
1: data {
187+
2: int<lower=0> N;
188+
3: vector x;
189+
^
190+
4: }
191+
-------------------------------------------------
192+
Ill-formed type. Expected "[" expression "]" for vector size.
190193
```
191194
192195
3. Semantic errors (also known as type errors) occur when a program is structured
@@ -196,14 +199,17 @@ There are five kinds of errors emitted by stanc3
196199
variable defined as an integer.
197200
```
198201
Semantic error in 'type.stan', line 2, column 3 to column 15:
199-
-------------------------------------------------
200-
1: transformed data {
201-
2: int x = 1.5;
202-
^
203-
3: }
204-
-------------------------------------------------
205-
Ill-typed arguments supplied to assignment operator =: lhs has
206-
type int and rhs has type real
202+
-------------------------------------------------
203+
1: transformed data {
204+
2: int x = 1.5;
205+
^
206+
3: }
207+
-------------------------------------------------
208+
Ill-typed arguments supplied to assignment operator =:
209+
The left hand side has type
210+
int
211+
and the right hand side has type
212+
real
207213
```
208214
4. The compiler will raise an error for use of any [removed
209215
features](https://mc-stan.org/docs/reference-manual/removals.html)
@@ -218,7 +224,6 @@ There are five kinds of errors emitted by stanc3
218224
never happen," and we apologize if they do.
219225
220226
221-
222227
## Pedantic mode
223228
224229
Pedantic mode is a compilation option built into Stanc3 that warns you about
@@ -243,13 +248,15 @@ model {
243248
When pedantic mode is turned on, the compiler will produce the following warnings.
244249

245250
```
246-
Warning:
247-
The parameter sigma has no priors.
248-
Warning at 'ped-mode-ex1.stan', line 10, column 14 to column 16:
249-
The variable mu may not have been assigned a value before its use.
250-
Warning at 'ped-mode-ex1.stan', line 10, column 18 to column 23:
251-
A normal distribution is given parameter sigma as a scale parameter
252-
(argument 2), but sigma was not constrained to be strictly positive.
251+
Warning in 'ped-mode-ex1.stan', line 6, column 2 to column 13:
252+
The parameter sigma has no priors. This means either no prior is
253+
provided, or the prior(s) depend on data variables. In the later case,
254+
this may be a false positive.
255+
Warning in 'ped-mode-ex1.stan', line 10, column 13 to column 15:
256+
The variable mu may not have been assigned a value before its use.
257+
Warning in 'ped-mode-ex1.stan', line 10, column 17 to column 22:
258+
A normal distribution is given parameter sigma as a scale parameter
259+
(argument 2), but sigma was not constrained to be strictly positive.
253260
```
254261

255262
Here are the kinds of issues that pedantic mode will find (which are described
@@ -305,7 +312,7 @@ The parameter of `poisson` should be strictly positive, but `unb_p` is not const
305312
Pedantic mode produces the following warning.
306313

307314
```
308-
Warning at 'ex-dist-args.stan', line 6, column 14 to column 19:
315+
Warning in 'ex-dist-args.stan', line 6, column 14 to column 19:
309316
A poisson distribution is given parameter unb_p as a rate parameter
310317
(argument 1), but unb_p was not constrained to be strictly positive.
311318
```
@@ -342,7 +349,7 @@ model {
342349
Pedantic mode produces the following warning.
343350

344351
```
345-
Warning at 'uniform-warn.stan', line 6, column 2 to column 20:
352+
Warning in 'uniform-warn.stan', line 6, column 2 to column 20:
346353
Parameter a is given a uniform distribution. The uniform distribution is
347354
not recommended, for two reasons: (a) Except when there are logical or
348355
physical constraints, it is very unusual for you to be sure that a
@@ -392,8 +399,8 @@ model {
392399
Pedantic mode produces the following warning.
393400

394401
```
395-
Warning:
396-
The parameter b was declared but was not used in the density calculation.
402+
Warning in 'unused.stan', line 3, column 2 to column 9:
403+
The parameter b was declared but was not used in the density calculation.
397404
```
398405

399406

@@ -423,12 +430,14 @@ The constants `-100` and `100` suggest that `x` is not unit scaled.
423430
Pedantic mode produces the following warning.
424431

425432
```
426-
Warning at 'constants-warn.stan', line 6, column 14 to column 17:
427-
Argument -100 suggests there may be parameters that are not unit scale;
428-
consider rescaling with a multiplier (see manual section 22.12).
429-
Warning at 'constants-warn.stan', line 6, column 19 to column 22:
430-
Argument 100 suggests there may be parameters that are not unit scale;
431-
consider rescaling with a multiplier (see manual section 22.12).
433+
Warning in 'constants-warn.stan', line 6, column 13 to column 17:
434+
Argument -100 suggests there may be parameters that are not unit scale;
435+
consider rescaling with a multiplier, see:
436+
https://mc-stan.org/docs/stan-users-guide/efficiency-tuning.html#standardizing-predictors
437+
Warning in 'constants-warn.stan', line 6, column 19 to column 22:
438+
Argument 100 suggests there may be parameters that are not unit scale;
439+
consider rescaling with a multiplier, see:
440+
https://mc-stan.org/docs/stan-users-guide/efficiency-tuning.html#standardizing-predictors
432441
```
433442

434443

@@ -472,9 +481,9 @@ The `if` and `for` statements are control flow that depend (indirectly) on the v
472481
Pedantic mode produces the following warning.
473482

474483
```
475-
Warning at 'param-dep-cf-warn.stan', line 11, column 2 to line 16, column 3:
484+
Warning in 'param-dep-cf-warn.stan', line 11, column 2 to line 16, column 3:
476485
A control flow statement depends on parameter(s): a.
477-
Warning at 'param-dep-cf-warn.stan', line 19, column 2 to line 21, column 3:
486+
Warning in 'param-dep-cf-warn.stan', line 19, column 2 to line 21, column 3:
478487
A control flow statement depends on parameter(s): a.
479488
```
480489

@@ -506,7 +515,7 @@ model {
506515
Pedantic mode produces the following warning.
507516

508517
```
509-
Warning at 'multi-tildes.stan', line 9, column 2 to column 19:
518+
Warning in 'multi-tildes.stan', line 9, column 2 to column 19:
510519
The parameter a is on the left-hand side of more than one tildes
511520
statement.
512521
```
@@ -554,10 +563,13 @@ One prior is found for `a` and for `b`, while `c` only has a factor that touches
554563
Pedantic mode produces the following warning.
555564

556565
```
557-
Warning:
558-
The parameter c has no priors.
559-
Warning:
560-
The parameter d has 2 priors.
566+
Warning in 'priors.stan', line 7, column 2 to column 9:
567+
The parameter c has no priors. This means either no prior is provided, or
568+
the prior(s) depend on data variables. In the later case, this may be a
569+
false positive.
570+
Warning in 'priors.stan', line 8, column 2 to column 9:
571+
The parameter d has 2 priors.
572+
561573
```
562574

563575

@@ -584,7 +596,7 @@ Since `x` is only assigned in one of the branches of the `if` statement, it migh
584596
Pedantic mode produces the following warning.
585597

586598
```
587-
Warning at 'uninit-warn.stan', line 7, column 8 to column 9:
599+
Warning in 'uninit-warn.stan', line 7, column 8 to column 9:
588600
The variable x may not have been assigned a value before its use.
589601
```
590602

@@ -611,16 +623,16 @@ model {
611623
Pedantic mode produces the following warning.
612624

613625
```
614-
Warning:
615-
Your Stan program has a parameter c with a lower and upper bound in its
616-
declaration. These hard constraints are not recommended, for two reasons:
617-
(a) Except when there are logical or physical constraints, it is very
618-
unusual for you to be sure that a parameter will fall inside a specified
619-
range, and (b) The infinite gradient induced by a hard constraint can cause
620-
difficulties for Stan's sampling algorithm. As a consequence, we recommend
621-
soft constraints rather than hard constraints; for example, instead of
622-
constraining an elasticity parameter to fall between 0, and 1, leave it
623-
unconstrained and give it a normal(0.5, 0.5) prior distribution.
626+
Warning in 'hard-constraint.stan', line 4, column 2 to column 31:
627+
Your Stan program has a parameter c with a lower and upper bound in its
628+
declaration. These hard constraints are not recommended, for two reasons:
629+
(a) Except when there are logical or physical constraints, it is very
630+
unusual for you to be sure that a parameter will fall inside a specified
631+
range, and (b) The infinite gradient induced by a hard constraint can
632+
cause difficulties for Stan's sampling algorithm. As a consequence, we
633+
recommend soft constraints rather than hard constraints; for example,
634+
instead of constraining an elasticity parameter to fall between 0, and 1,
635+
leave it unconstrained and give it a normal(0.5,0.5) prior distribution.
624636
```
625637

626638
### Nonlinear transformations {-}
@@ -641,19 +653,17 @@ parameters {
641653
model {
642654
log(y) ~ normal(0,1);
643655
}
644-
645656
```
646657

647658
Pedantic mode produces the following warning.
648659

649660
```
650-
Warning:
661+
Warning in 'jacobian.stan', line 5, column 2 to column 23:
651662
Left-hand side of distribution statement (~) may contain a non-linear
652-
transform of a parameter or local variable. If it does, you need
653-
to include a target += statement with the log absolute determinant
654-
of the Jacobian of the transform. You could also consider defining
655-
a transformed parameter and using jacobian += in the transformed
656-
parameters block.
663+
transform of a parameter or local variable. If it does, you need to
664+
include a target += statement with the log absolute determinant of the
665+
Jacobian of the transform. You could also consider defining a transformed
666+
parameter and using jacobian += in the transformed parameters block.
657667
```
658668

659669
### Pedantic mode limitations {-}

0 commit comments

Comments
 (0)