Skip to content

Commit ac93c30

Browse files
AoifeHughesAoifeHughesgithub-actions[bot]mhauru
authored
Improve error message for initialization failures with troubleshootin… (#2637)
* Improve error message for initialization failures with troubleshooting link * Refactor error message for initialization failures to remove redundant information and enhance clarity * fc * simplier * Update test/mcmc/hmc.jl Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * updated error uri * Update test/mcmc/hmc.jl Co-authored-by: Markus Hauru <[email protected]> --------- Co-authored-by: AoifeHughes <[email protected]> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Markus Hauru <[email protected]>
1 parent 4862ad6 commit ac93c30

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/mcmc/hmc.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ function find_initial_params(
170170

171171
# if we failed to find valid initial parameters, error
172172
return error(
173-
"failed to find valid initial parameters in $(max_attempts) tries. This may indicate an error with the model or AD backend; please open an issue at https://github.com/TuringLang/Turing.jl/issues",
173+
"failed to find valid initial parameters in $(max_attempts) tries. See https://turinglang.org/docs/uri/initial-parameters for common causes and solutions. If the issue persists, please open an issue at https://github.com/TuringLang/Turing.jl/issues",
174174
)
175175
end
176176

test/mcmc/hmc.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,20 @@ using Turing
259259
@test Turing.Inference.getstepsize(spl, hmc_state) isa Float64
260260
end
261261
end
262+
263+
@testset "improved error message for initialization failures" begin
264+
# Model that always fails to initialize
265+
@model function failing_model()
266+
x ~ Normal()
267+
@addlogprob! -Inf
268+
end
269+
270+
# Test that error message includes troubleshooting link
271+
@test_throws ErrorException sample(failing_model(), NUTS(), 10; progress=false)
272+
@test_throws "https://turinglang.org/docs/uri/initial-parameters" sample(
273+
failing_model(), NUTS(), 10; progress=false
274+
)
275+
end
262276
end
263277

264278
end

0 commit comments

Comments
 (0)