Skip to content

Improve error message for initialization failures with troubleshootin… #2637

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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 @@ -168,7 +168,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/usage/troubleshooting/#initial-parameters for common causes and solutions. If the issue persists, please open an issue at https://github.com/TuringLang/Turing.jl/issues",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we set up a more robust URI for this link, e.g. via https://turinglang.org/docs/uri/initial-parameters? This URI redirects to the corresponding docs link, and would never change if we restructure the docs.

Quarto supports this via redirects: https://quarto.org/docs/websites/website-navigation.html#redirects

Cc @shravanngoswamii

Copy link
Member

@shravanngoswamii shravanngoswamii Aug 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, let me add a redirects template in docs repo so we can easily create permanent redirects for docs.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

)
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 @@ -276,6 +276,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