Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/mcmc/hmc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ function find_initial_params(

# if we failed to find valid initial parameters, error
return error(
"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",
"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",
)
end

Expand Down
14 changes: 14 additions & 0 deletions test/mcmc/hmc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,20 @@ using Turing
@test Turing.Inference.getstepsize(spl, hmc_state) isa Float64
end
end

@testset "improved error message for initialization failures" begin
# Model that always fails to initialize
@model function failing_model()
x ~ Normal()
@addlogprob! -Inf
end

# Test that error message includes troubleshooting link
@test_throws ErrorException sample(failing_model(), NUTS(), 10; progress=false)
@test_throws "https://turinglang.org/docs/usage/troubleshooting/#initial-parameters" sample(
failing_model(), NUTS(), 10; progress=false
)
end
end

end
Loading