From 740c960d4374e5a044efc7869feeeab27f8d9e20 Mon Sep 17 00:00:00 2001 From: Penelope Yong Date: Mon, 24 Nov 2025 19:03:12 +0000 Subject: [PATCH 1/3] make MCMCThreads respect check_model --- src/mcmc/abstractmcmc.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/src/mcmc/abstractmcmc.jl b/src/mcmc/abstractmcmc.jl index 0f2092576..aeba71be2 100644 --- a/src/mcmc/abstractmcmc.jl +++ b/src/mcmc/abstractmcmc.jl @@ -131,6 +131,7 @@ function AbstractMCMC.sample( N, n_chains; chain_type, + check_model=false, # no need to check again initial_params=map(_convert_initial_params, initial_params), kwargs..., ) From 244e53bf7a8253c3e56d2fadb083c308b6372576 Mon Sep 17 00:00:00 2001 From: Penelope Yong Date: Mon, 24 Nov 2025 19:04:16 +0000 Subject: [PATCH 2/3] Changelog --- HISTORY.md | 4 ++++ Project.toml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/HISTORY.md b/HISTORY.md index 515b624cc..bb7902ba9 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,3 +1,7 @@ +# 0.41.4 + +Fixed a bug where the `check_model=false` keyword argument would not be respected when sampling with multiple threads or cores. + # 0.41.3 Fixed NUTS not correctly specifying the number of adaptation steps when calling `AdvancedHMC.initialize!` (this bug led to mass matrix adaptation not actually happening). diff --git a/Project.toml b/Project.toml index cdeb59a16..8b73f7ab9 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "Turing" uuid = "fce5fe82-541a-59a6-adf8-730c64b5f9a0" -version = "0.41.3" +version = "0.41.4" [deps] ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b" From 7a64206176532ba3052b7c55e259594c3949ccaa Mon Sep 17 00:00:00 2001 From: Penelope Yong Date: Mon, 24 Nov 2025 19:12:38 +0000 Subject: [PATCH 3/3] Add a test --- test/mcmc/abstractmcmc.jl | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/mcmc/abstractmcmc.jl b/test/mcmc/abstractmcmc.jl index 6f4b47613..957d33acf 100644 --- a/test/mcmc/abstractmcmc.jl +++ b/test/mcmc/abstractmcmc.jl @@ -6,6 +6,23 @@ using Random: AbstractRNG using Test: @test, @testset, @test_throws using Turing +@testset "Disabling check_model" begin + # Set up a model for which check_model errors. + @model f() = x ~ Normal() + model = f() + Turing.Inference._check_model(::typeof(model)) = error("nope") + # Make sure that default sampling does throw the error. + @test_throws "nope" sample(model, NUTS(), 100) + @test_throws "nope" sample(model, NUTS(), MCMCThreads(), 100, 2) + @test_throws "nope" sample(model, NUTS(), MCMCSerial(), 100, 2) + @test_throws "nope" sample(model, NUTS(), MCMCDistributed(), 100, 2) + # Now disable the check and make sure sampling works. + @test sample(model, NUTS(), 100; check_model=false) isa Any + @test sample(model, NUTS(), MCMCThreads(), 100, 2; check_model=false) isa Any + @test sample(model, NUTS(), MCMCSerial(), 100, 2; check_model=false) isa Any + @test sample(model, NUTS(), MCMCDistributed(), 100, 2; check_model=false) isa Any +end + @testset "Initial parameters" begin # Dummy algorithm that just returns initial value and does not perform any sampling abstract type OnlyInit <: AbstractMCMC.AbstractSampler end