Skip to content

Commit

Permalink
Test with Tapir
Browse files Browse the repository at this point in the history
  • Loading branch information
mhauru committed Jul 17, 2024
1 parent 29a1342 commit bb1bcef
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 12 deletions.
2 changes: 2 additions & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3"
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
StatsFuns = "4c63d2b9-4356-54db-8cca-17b64c39e42c"
Tapir = "07d77754-e150-4737-8c94-cd238a1fb45b"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
TimerOutputs = "a759f4b9-e2f1-59dc-863e-4aeb61b1ea8f"
Tracker = "9f7883ad-71c0-57eb-9f7f-b5c9e6d3789c"
Expand Down Expand Up @@ -67,6 +68,7 @@ SpecialFunctions = "0.10.3, 1, 2"
StableRNGs = "1"
StatsBase = "0.33, 0.34"
StatsFuns = "0.9.5, 1"
Tapir = "0.2.24"
TimerOutputs = "0.5"
Tracker = "0.2.11"
Zygote = "0.5.4, 0.6"
Expand Down
4 changes: 3 additions & 1 deletion test/mcmc/Inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module InferenceTests

using ..Models: gdemo_d, gdemo_default
using ..NumericalTests: check_gdemo, check_numerical
using ..ADUtils: adbackends
using Distributions: Bernoulli, Beta, InverseGamma, Normal
using Distributions: sample
import DynamicPPL
Expand All @@ -11,10 +12,11 @@ using LinearAlgebra: I
import MCMCChains
import Random
import ReverseDiff
import Tapir
using Test: @test, @test_throws, @testset
using Turing

@testset "Testing inference.jl with $adbackend" for adbackend in (AutoForwardDiff(; chunksize=0), AutoReverseDiff(; compile=false))
@testset "Testing inference.jl with $adbackend" for adbackend in adbackends
# Only test threading if 1.3+.
if VERSION > v"1.2"
@testset "threaded sampling" begin
Expand Down
5 changes: 3 additions & 2 deletions test/mcmc/abstractmcmc.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module AbstractMCMCTests

using ..ADUtils: adbackends
using AdvancedMH: AdvancedMH
using Distributions: sample
using Distributions.FillArrays: Zeros
Expand All @@ -11,6 +12,7 @@ using LogDensityProblemsAD: LogDensityProblemsAD
using Random: Random
using ReverseDiff: ReverseDiff
using StableRNGs: StableRNG
import Tapir
using Test: @test, @test_throws, @testset
using Turing
using Turing.Inference: AdvancedHMC
Expand Down Expand Up @@ -112,8 +114,7 @@ end

@testset "External samplers" begin
@testset "AdvancedHMC.jl" begin
# Try a few different AD backends.
@testset "adtype=$adtype" for adtype in [AutoForwardDiff(), AutoReverseDiff()]
@testset "adtype=$adtype" for adtype in adbackends
@testset "$(model.f)" for model in DynamicPPL.TestUtils.DEMO_MODELS
# Need some functionality to initialize the sampler.
# TODO: Remove this once the constructors in the respective packages become "lazy".
Expand Down
6 changes: 3 additions & 3 deletions test/mcmc/gibbs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ module GibbsTests

using ..Models: MoGtest_default, gdemo, gdemo_default
using ..NumericalTests: check_MoGtest_default, check_gdemo, check_numerical
using ..ADUtils: adbackends
using Distributions: InverseGamma, Normal
using Distributions: sample
using ForwardDiff: ForwardDiff
using Random: Random
using ReverseDiff: ReverseDiff
import Tapir
using Test: @test, @testset
using Turing
using Turing: Inference
using Turing.RandomMeasures: ChineseRestaurantProcess, DirichletProcess

@testset "Testing gibbs.jl with $adbackend" for adbackend in (
AutoForwardDiff(; chunksize=0), AutoReverseDiff(; compile=false)
)
@testset "Testing gibbs.jl with $adbackend" for adbackend in adbackends
@testset "gibbs constructor" begin
N = 500
s1 = Gibbs(HMC(0.1, 5, :s, :m; adtype=adbackend))
Expand Down
6 changes: 3 additions & 3 deletions test/mcmc/gibbs_conditional.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module GibbsConditionalTests

using ..Models: gdemo, gdemo_default
using ..NumericalTests: check_gdemo, check_numerical
using ..ADUtils: adbackends
using Clustering: Clustering
using Distributions: Categorical, InverseGamma, Normal, sample
using ForwardDiff: ForwardDiff
Expand All @@ -11,12 +12,11 @@ using ReverseDiff: ReverseDiff
using StableRNGs: StableRNG
using StatsBase: counts
using StatsFuns: StatsFuns
import Tapir
using Test: @test, @testset
using Turing

@testset "Testing gibbs conditionals.jl with $adbackend" for adbackend in (
AutoForwardDiff(; chunksize=0), AutoReverseDiff(; compile=false)
)
@testset "Testing gibbs conditionals.jl with $adbackend" for adbackend in adbackends
Random.seed!(1000)
rng = StableRNG(123)

Expand Down
4 changes: 3 additions & 1 deletion test/mcmc/hmc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module HMCTests
using ..Models: gdemo_default
#using ..Models: gdemo
using ..NumericalTests: check_gdemo, check_numerical
using ..ADUtils: adbackends
using Distributions: Bernoulli, Beta, Categorical, Dirichlet, Normal, Wishart, sample
import DynamicPPL
using DynamicPPL: Sampler
Expand All @@ -13,10 +14,11 @@ using LinearAlgebra: I, dot, vec
import Random
using StableRNGs: StableRNG
using StatsFuns: logistic
import Tapir
using Test: @test, @test_logs, @testset
using Turing

@testset "Testing hmc.jl with $adbackend" for adbackend in (AutoForwardDiff(; chunksize=0), AutoReverseDiff(; compile=false))
@testset "Testing hmc.jl with $adbackend" for adbackend in adbackend
# Set a seed
rng = StableRNG(123)
@testset "constrained bounded" begin
Expand Down
6 changes: 4 additions & 2 deletions test/mcmc/sghmc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@ module SGHMCTests

using ..Models: gdemo_default
using ..NumericalTests: check_gdemo
using ..ADUtils: adbackends
using Distributions: sample
import ForwardDiff
using LinearAlgebra: dot
import ReverseDiff
using StableRNGs: StableRNG
import Tapir
using Test: @test, @testset
using Turing

@testset "Testing sghmc.jl with $adbackend" for adbackend in (AutoForwardDiff(; chunksize=0), AutoReverseDiff(; compile=false))
@testset "Testing sghmc.jl with $adbackend" for adbackend in adbackends
@testset "sghmc constructor" begin
alg = SGHMC(; learning_rate=0.01, momentum_decay=0.1, adtype=adbackend)
@test alg isa SGHMC
Expand All @@ -36,7 +38,7 @@ using Turing
end
end

@testset "Testing sgld.jl with $adbackend" for adbackend in (AutoForwardDiff(; chunksize=0), AutoReverseDiff(; compile=false))
@testset "Testing sgld.jl with $adbackend" for adbackend in adbackends
@testset "sgld constructor" begin
alg = SGLD(; stepsize=PolynomialStepsize(0.25), adtype=adbackend)
@test alg isa SGLD
Expand Down
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Turing

include(pkgdir(Turing) * "/test/test_utils/models.jl")
include(pkgdir(Turing) * "/test/test_utils/numerical_tests.jl")
include(pkgdir(Turing) * "/test/test_utils/ad_utils.jl")

Turing.setprogress!(false)

Expand Down

0 comments on commit bb1bcef

Please sign in to comment.