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" 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..., ) 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