-
Notifications
You must be signed in to change notification settings - Fork 226
Gibbs test | Fix dynamic model test in Gibbs sampler suite #2579
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
base: main
Are you sure you want to change the base?
Conversation
…ce sampling validation
Leave this as a draft for a teeny bit, I need to properly test and fully understand how julia tests work so I'm not breaking what I think I understand - no need for any reviews yet. |
This should address: #2402 when completed. |
As discussed on Slack, feel free to change the base branch of this to |
Results from my local testing: Test Summary: | Pass Total Time
Turing | 2613 2613 19m50.9s
Aqua | 0 0.1s
AD | 0 0.0s
essential | 0 0.0s
samplers (without AD) | 0 0.0s
inference with samplers | 2613 2613 19m50.8s
GibbsContext | 868 868 27.7s
type stability | 868 868 27.7s
Invalid Gibbs constructor | 8 8 0.1s
Sampler call order | 1 1 53.9s
Equivalence of RepeatSampler and repeating Sampler | 1 1 4.5s
Gibbs warmup | 8 8 2.3s
Testing gibbs.jl | 1727 1727 18m19.3s
Gibbs constructors | 13 13 19.7s
Gibbs inference | 22 22 6m06.7s
transitions | 0 2.1s
dynamic model with analytical posterior | 5 5 8.4s
dynamic model with ESS | 6 6 33.4s
dynamic model with dot tilde | 0 11.3s
Demo model | 1564 1564 8m32.2s
multiple varnames | 20 20 1.5s
non-identity varnames | 2 2 9.2s
submodels | 2 2 11.3s
CSMC + ESS | 42 42 38.9s
CSMC + ESS (usage of implicit varname) | 42 42 51.8s
externalsampler | 8 8 28.2s
linking changes dimension | 1 1 4.5s
variational algorithms | 0 0.0s
mode estimation | 0 0.0s
variational optimisers | 0 0.0s
stdlib | 0 0.0s
utilities | 0 0.0s
───────────────────────────────────────────────────────────
Time Allocations
─────────────── ───────────────
Total measured: 1191s 534GiB
Section ncalls time %tot alloc %tot
───────────────────────────────────────────────────────────
inference 1 1191s 100.0% 534GiB 100.0%
mcmc/gibbs.jl 1 1191s 100.0% 534GiB 100.0%
─────────────────────────────────────────────────────────── Testing Turing tests passed |
test/mcmc/gibbs.jl
Outdated
# When b=1: two parameters θ₁, θ₂ where we observe their sum | ||
@model function dynamic_bernoulli_normal(y_obs=2.0) | ||
b ~ Bernoulli(0.3) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter v1.0.62] reported by reviewdog 🐶
test/mcmc/gibbs.jl
Outdated
b ~ Bernoulli(0.3) | ||
|
||
if b == 0 | ||
θ = Vector{Float64}(undef, 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter v1.0.62] reported by reviewdog 🐶
θ = Vector{Float64}(undef, 1) | |
θ = Vector{Float64}(undef, 1) |
test/mcmc/gibbs.jl
Outdated
StableRNG(42), model, Gibbs(:b => MH(), :θ => HMC(0.1, 10)), 1000; | ||
discard_initial=500 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter v1.0.62] reported by reviewdog 🐶
StableRNG(42), model, Gibbs(:b => MH(), :θ => HMC(0.1, 10)), 1000; | |
discard_initial=500 | |
StableRNG(42), | |
model, | |
Gibbs(:b => MH(), :θ => HMC(0.1, 10)), | |
1000; | |
discard_initial=500, |
test/mcmc/gibbs.jl
Outdated
# Issue ref: https://github.com/TuringLang/Turing.jl/issues/2402 | ||
@test isapprox(mean(num_ms), 8.6087; atol=0.8) | ||
@test isapprox(std(num_ms), 1.8865; atol=0.03) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter v1.0.62] reported by reviewdog 🐶
test/mcmc/gibbs.jl
Outdated
|
||
# Test that sampling completes without error | ||
@test size(chn, 1) == 1000 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter v1.0.62] reported by reviewdog 🐶
test/mcmc/gibbs.jl
Outdated
b_samples = chn[:b] | ||
unique_b_values = unique(skipmissing(b_samples)) | ||
@test length(unique_b_values) >= 1 # At least one value should be sampled | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter v1.0.62] reported by reviewdog 🐶
test/mcmc/gibbs.jl
Outdated
@test all(isfinite, theta1_samples) # All samples should be finite | ||
@test std(theta1_samples) > 0.1 # Should show some variation | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter v1.0.62] reported by reviewdog 🐶
test/mcmc/gibbs.jl
Outdated
# θ[2] should have some missing values (when b=0) and some non-missing (when b=1) | ||
n_missing_theta2 = sum(ismissing.(theta2_samples)) | ||
n_present_theta2 = sum(.!ismissing.(theta2_samples)) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter v1.0.62] reported by reviewdog 🐶
Turing.jl documentation for PR #2579 is available at: |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2579 +/- ##
=======================================
Coverage 85.86% 85.86%
=======================================
Files 24 24
Lines 1429 1429
=======================================
Hits 1227 1227
Misses 202 202 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Pull Request Test Coverage Report for Build 15464256226Details
💛 - Coveralls |
There was a problem hiding this 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 improves the dynamic model test in the Gibbs sampler suite by replacing slow, less informative tests with a fast, analytically tractable dynamic_bernoulli_normal model and updating model signature syntax to the new standards.
- Updates model function parameter syntax across several test files
- Refactors multi-line expressions for clarity and consistency in optimisation and MCMC files
- Introduces a new dynamic model test that validates dimension changes and ensures sampler robustness
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
File | Description |
---|---|
test/skipped/vec_assume_mat.jl | Updated model function signature to new parameter syntax |
test/optimisation/Optimisation.jl | Reformatted multi-line expression for setting child context |
test/mcmc/hmc.jl | Adjusted formatting and signature updates in several models |
test/mcmc/gibbs.jl | Introduced dynamic_bernoulli_normal model and updated test logic |
test/mcmc/Inference.jl | Updated model function signatures to new syntax |
src/mcmc/external_sampler.jl | Adjusted function parameter handling in sampler construction |
The existing dynamic model test was problematic:
Here I've changed this with:
a new dynamic_bernoulli_normal model that: