no output from print statements in transformed parameters when initialization fails
Nobody has claimed this yet.
- Dominant language
- R
- Stars
- 1.1k
- Forks
- 266
- Avg merge
- 2h 56m
- Merged PRs (30d)
- 1
Description
Summary:
Print statements in the transformed parameters block produce no output when initialization fails.
Description:
If initialization fails (in this case, due to NaN being assigned to a constrained transformed parameter) then print statements in the transformed parameters block before the error do not produce any output. This appears similar to #416 and #577, except in this case it's a print statement rather than a reject statement getting lost. As noted, this makes print-debugging complex models extremely difficult in exactly the case where it is most needed. It sounds like those earlier issues were fixed in version 2.18.2, but that is the version I'm running.
Reproducible Steps:
init_test <- 'parameters {
real a;
}
transformed parameters {
real<lower=0> x;
print("Is this thing on?");
x = a * 0.0 / 0.0;
}
model {
a ~ normal(0,1);
}'
test <- stan(model_code = init_test, chains = 1, iter = 10)
Current Output:
The "rejecting initial value" error is repeated a large number of times. The print statement output never appears.
SAMPLING FOR MODEL 'init_test' NOW (CHAIN 1).
Chain 1: Rejecting initial value:
Chain 1: Error evaluating the log probability at the initial value.
Chain 1: Exception: model2e9c309a15f6_init_test_namespace::write_array: x is nan, but must be greater than or equal to 0 (in 'model2e9c309a15f6_init_test' at line 6)
Chain 1:
Chain 1: Initialization between (-2, 2) failed after 100 attempts.
Chain 1: Try specifying initial values, reducing ranges of constrained values, or reparameterizing the model.
[1] "Error in sampler$call_sampler(args_list[[i]]) : Initialization failed."
[1] "error occurred during calling the sampler; sampling not done"
Expected Output:
The print message "Is this thing on?" should appear somewhere in the output. This works as expected if the divide-by-zero that produces the NaN is removed.
RStan Version:
2.18.2
R Version:
3.5.2
Operating System:
Windows 7 x64 (build 7601) Service Pack 1
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 by running the supplied R reproducer with RStan and compare initialization output when the NaN-producing assignment is present versus removed. Trace the initialization and transformed-parameter output path to determine why the print message is lost; done means "Is this thing on?" appears even when initialization fails.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- r
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100