Skip to content

Add FAQ section to improve user guidance #608

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 7 commits into
base: main
Choose a base branch
from
Open

Add FAQ section to improve user guidance #608

wants to merge 7 commits into from

Conversation

AoifeHughes
Copy link
Contributor

@AoifeHughes AoifeHughes commented Jun 3, 2025

This pull request adds a new FAQ section to the Turing.jl website and updates the navigation menu to include a link to the FAQ page. The FAQ section provides answers to common questions about using Turing.jl, covering topics such as random variables, implementing samplers, parallelism, debugging, syntax differences, automatic differentiation backends, and performance issues.

Website Navigation Update:

  • _quarto.yml: Added a new link to the FAQ page in the website's navigation menu.

FAQ Section Addition:

  • faq/index.qmd: Created a new FAQ page with detailed answers to common questions about Turing.jl. Topics include variable treatment, sampler implementation, parallelism, type stability, debugging, syntax differences, automatic differentiation backends, and performance debugging.

Relevant Issues:

@AoifeHughes AoifeHughes requested a review from Copilot June 3, 2025 12:01
@AoifeHughes AoifeHughes added the enhancement New feature or request label Jun 3, 2025
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds a new FAQ section to the Turing.jl website and updates the navigation menu to include a link to it.

  • Added a “FAQ” entry in the site navigation
  • Created faq/index.qmd with a set of common Q&A on using Turing.jl

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
_quarto.yml Inserted a navigation entry for the FAQ
faq/index.qmd Added FAQ page with detailed user guidance
Comments suppressed due to low confidence (1)

_quarto.yml:27

  • Indentation of the new navigation entry does not match the surrounding items and could break the YAML. Align the - href: faq/ and its text: line with the other menu entries.
- href: faq/

Copy link
Contributor

github-actions bot commented Jun 3, 2025

Preview the changes: https://turinglang.org/docs/pr-previews/608
Please avoid using the search feature and navigation bar in PR previews!

@AoifeHughes AoifeHughes marked this pull request as ready for review June 4, 2025 08:49
@AoifeHughes AoifeHughes self-assigned this Jun 4, 2025
@AoifeHughes AoifeHughes requested a review from penelopeysm June 4, 2025 08:52
Copy link
Member

@penelopeysm penelopeysm left a comment

Choose a reason for hiding this comment

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

This is a nice start, I think there are a few places where it's necessary to go into more detail, which I've commented on.

General comment for the entire PR: for the URLs, you can use the meta variables defined in _quarto.yml, i.e. [text]({{< meta usage-automatic-differentiation >}}) to avoid hardcoding relative paths (useful if you want to move pages around, which has happened a couple of times).

AoifeHughes and others added 6 commits June 17, 2025 10:11
Co-authored-by: Penelope Yong <penelopeysm@gmail.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Penelope Yong <penelopeysm@gmail.com>
@AoifeHughes
Copy link
Contributor Author

I think I've addressed the comments @penelopeysm

@AoifeHughes AoifeHughes requested a review from penelopeysm July 2, 2025 10:50
Copy link
Member

@penelopeysm penelopeysm left a comment

Choose a reason for hiding this comment

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

Looking good! Thanks for expanding on the points here. A few more comments, which hopefully aren't too complicated to deal with.

Comment on lines +62 to +66
@model function f(x)
Threads.@threads for i in eachindex(x)
x[i] ~ Normal() # UNSAFE: Assume statements in threads can crash!
end
end
Copy link
Member

@penelopeysm penelopeysm Jul 3, 2025

Choose a reason for hiding this comment

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

In this model, x is observed so it's fine. 'assume' means that it's a random parameter, so for example something like this:

Suggested change
@model function f(x)
Threads.@threads for i in eachindex(x)
x[i] ~ Normal() # UNSAFE: Assume statements in threads can crash!
end
end
@model function f(y)
x = Vector{Float64}(undef, length(y))
Threads.@threads for i in eachindex(y)
x[i] ~ Normal() # UNSAFE: `assume` statements in @threads can crash!
y[i] ~ Normal(x[i]) # `observe` statements are okay
end
end

- **Multithreaded sampling**: Use `MCMCThreads()` to run one chain per thread
- **Distributed sampling**: Use `MCMCDistributed()` for distributed computing

See the [Core Functionality guide](../core-functionality/#sampling-multiple-chains) for examples.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
See the [Core Functionality guide](../core-functionality/#sampling-multiple-chains) for examples.
See the [Core Functionality guide]({{< meta core-functionality >}}/#sampling-multiple-chains) for examples.

The key insight is that `filldist` creates a single distribution (not N independent distributions), which is why you cannot condition on individual elements. The distinction is not just about what appears on the LHS of `~`, but whether you're dealing with separate distributions (`.~` with univariate) or a single distribution over multiple values (`~` with multivariate or `filldist`).

To understand more about how Turing determines whether a variable is treated as random or observed, see:
- [Core Functionality](../core-functionality/) - basic explanation of the `~` notation and conditioning
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
- [Core Functionality](../core-functionality/) - basic explanation of the `~` notation and conditioning
- [Core Functionality]({{< meta core-functionality >}}) - basic explanation of the `~` notation and conditioning


For debugging both statistical and syntactical issues:
- [Troubleshooting Guide]({{< meta usage-troubleshooting >}}) - common errors and their solutions
- For more advanced debugging, DynamicPPL provides `DynamicPPL.DebugUtils` for inspecting model internals
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
- For more advanced debugging, DynamicPPL provides `DynamicPPL.DebugUtils` for inspecting model internals
- For more advanced debugging, DynamicPPL provides [the `DynamicPPL.DebugUtils` module](https://turinglang.org/DynamicPPL.jl/stable/api/#Debugging-Utilities) for inspecting model internals

Friendly link


Key syntactic differences include:

- **Parameter blocks**: Stan requires explicit `data`, `parameters`, `transformed parameters`, and `model` blocks. In Turing, everything is defined within the `@model` macro
Copy link
Member

@penelopeysm penelopeysm Jul 3, 2025

Choose a reason for hiding this comment

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

Suggested change
- **Parameter blocks**: Stan requires explicit `data`, `parameters`, `transformed parameters`, and `model` blocks. In Turing, everything is defined within the `@model` macro
- **Parameter blocks**: Stan requires explicit `data`, `parameters`, and `model` blocks. In Turing, everything is defined within the `@model` macro

transformed parameters isn't mandatory

# Turing
@model function my_model(y)
mu ~ Normal(0, 1)
sigma ~ truncated(Normal(0, 1), 0, Inf)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
sigma ~ truncated(Normal(0, 1), 0, Inf)
sigma ~ truncated(Normal(0, 1); lower=0)

truncated(d, 0, Inf) causes issues with AD (https://turinglang.org/docs/usage/troubleshooting/#nan-gradient has an illustration of this).

Comment on lines +104 to +111
parameters {
real mu;
real<lower=0> sigma;
}
model {
y ~ normal(mu, sigma);
}
```
Copy link
Member

@penelopeysm penelopeysm Jul 3, 2025

Choose a reason for hiding this comment

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

So I'm not a super duper expert on Stan, but I think that these parameters don't have priors assigned and thus have completely flat priors (i.e. the prior probability is always 1 for any value of mu and any value of sigma > 0). That would make this not equivalent to the Turing model which has non-flat priors. I think you would need to specify mu ~ normal(0, 1); and sigma ~ normal(0, 1); if you want to include a prior probability that is equivalent to the Turing model below it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants