Skip to content

Commit

Permalink
Deduplicate packages loading in tests (#1548)
Browse files Browse the repository at this point in the history
* Refactor splitdir

* Use dirname instead of basename

* Finish

* Refactor

* Add two

* Few more

* Uncomment runtests again

* Fix typo

* Remove imports

* Clean up

* Remove more using occurrences
  • Loading branch information
rikhuijzer committed Feb 22, 2021
1 parent 1cd12d1 commit 24d3731
Show file tree
Hide file tree
Showing 24 changed files with 37 additions and 160 deletions.
6 changes: 0 additions & 6 deletions test/contrib/inference/dynamichmc.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
using Turing, Test
import Random

dir = splitdir(splitdir(pathof(Turing))[1])[1]
include(dir*"/test/test_utils/AllUtils.jl")

@stage_testset "dynamichmc" "dynamichmc.jl" begin
import DynamicHMC
Random.seed!(100)
Expand Down
8 changes: 0 additions & 8 deletions test/contrib/inference/sghmc.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
using Turing
using LinearAlgebra
using Random
using Test

dir = splitdir(splitdir(pathof(Turing))[1])[1]
include(dir*"/test/test_utils/AllUtils.jl")

@testset "sghmc.jl" begin
@numerical_testset "sghmc inference" begin
Random.seed!(125)
Expand Down
14 changes: 0 additions & 14 deletions test/core/ad.jl
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
using ForwardDiff, Distributions, FiniteDifferences, Tracker, Random, LinearAlgebra
using PDMats, Zygote
using Turing: Turing, invlink, link, SampleFromPrior,
TrackerAD, ZygoteAD
using DynamicPPL: getval
using Turing.Core: TuringDenseMvNormal, TuringDiagMvNormal
using ForwardDiff: Dual
using StatsFuns: binomlogpdf, logsumexp
using Test, LinearAlgebra
const FDM = FiniteDifferences

dir = splitdir(splitdir(pathof(Turing))[1])[1]
include(dir*"/test/test_utils/AllUtils.jl")

@testset "ad.jl" begin
@turing_testset "adr" begin
ad_test_f = gdemo_default
Expand Down
9 changes: 0 additions & 9 deletions test/inference/AdvancedSMC.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
using Turing, Random, Test
using Turing.Inference: getspace
using AdvancedPS: ResampleWithESSThreshold, resample_systematic, resample_multinomial

using Random

dir = splitdir(splitdir(pathof(Turing))[1])[1]
include(dir*"/test/test_utils/AllUtils.jl")

@testset "SMC" begin
@turing_testset "constructor" begin
s = SMC()
Expand Down
9 changes: 0 additions & 9 deletions test/inference/Inference.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
using Turing, Random, Test
using DynamicPPL: getlogp
import MCMCChains

using Random

dir = splitdir(splitdir(pathof(Turing))[1])[1]
include(dir*"/test/test_utils/AllUtils.jl")

@testset "io.jl" begin
# Only test threading if 1.3+.
if VERSION > v"1.2"
Expand Down
7 changes: 1 addition & 6 deletions test/inference/emcee.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using Turing, Random, Test
import Turing.Inference
import AdvancedMH

dir = splitdir(splitdir(pathof(Turing))[1])[1]
include(dir*"/test/test_utils/AllUtils.jl")

@testset "emcee.jl" begin
@testset "gdemo" begin
Expand All @@ -18,4 +13,4 @@ include(dir*"/test/test_utils/AllUtils.jl")
chain = sample(gdemo_default, spl, n_samples)
check_gdemo(chain)
end
end
end
5 changes: 0 additions & 5 deletions test/inference/ess.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
using Turing, Random, Test

dir = splitdir(splitdir(pathof(Turing))[1])[1]
include(dir*"/test/test_utils/AllUtils.jl")

@testset "ESS" begin
@model demo(x) = begin
m ~ Normal()
Expand Down
9 changes: 0 additions & 9 deletions test/inference/gibbs.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
using Random, Turing, Test
import AbstractMCMC
import MCMCChains
import Turing.Inference
using Turing.RandomMeasures

dir = splitdir(splitdir(pathof(Turing))[1])[1]
include(dir*"/test/test_utils/AllUtils.jl")

@testset "gibbs.jl" begin
@turing_testset "gibbs constructor" begin
N = 500
Expand Down
8 changes: 0 additions & 8 deletions test/inference/gibbs_conditional.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
using Random, Turing, Test
using StatsFuns
using Clustering

dir = splitdir(splitdir(pathof(Turing))[1])[1]
include(dir*"/test/test_utils/AllUtils.jl")


@turing_testset "gibbs conditionals" begin
Random.seed!(100)

Expand Down
10 changes: 0 additions & 10 deletions test/inference/hmc.jl
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
using Turing, Random, Test
using Turing: Sampler, NUTS
using MCMCChains: Chains
using StatsFuns: logistic

using LinearAlgebra

dir = splitdir(splitdir(pathof(Turing))[1])[1]
include(dir*"/test/test_utils/AllUtils.jl")

@testset "hmc.jl" begin
@numerical_testset "constrained bounded" begin
# Set a seed
Expand Down
9 changes: 0 additions & 9 deletions test/inference/is.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
using Turing
using StatsFuns

using Random
using Test

dir = splitdir(splitdir(pathof(Turing))[1])[1]
include(dir*"/test/test_utils/AllUtils.jl")

@turing_testset "is.jl" begin
function reference(n)
as = Vector{Float64}(undef, n)
Expand Down
7 changes: 0 additions & 7 deletions test/inference/mh.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
using Turing, Random, Test
import Turing.Inference
import AdvancedMH

dir = splitdir(splitdir(pathof(Turing))[1])[1]
include(dir*"/test/test_utils/AllUtils.jl")

@testset "mh.jl" begin
@turing_testset "mh constructor" begin
Random.seed!(0)
Expand Down
2 changes: 0 additions & 2 deletions test/inference/utilities.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using Random

@testset "predict" begin
Random.seed!(100)

Expand Down
13 changes: 1 addition & 12 deletions test/modes/ModeEstimation.jl
Original file line number Diff line number Diff line change
@@ -1,15 +1,4 @@
using Turing
using Optim
using Test
using StatsBase
using NamedArrays
using ReverseDiff
using Random
using LinearAlgebra
using Zygote

dir = splitdir(splitdir(pathof(Turing))[1])[1]
include(dir*"/test/test_utils/AllUtils.jl")


@testset "ModeEstimation.jl" begin
@testset "MLE" begin
Expand Down
40 changes: 35 additions & 5 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,16 +1,46 @@
##########################################
# Master file for running all test cases #
##########################################
using Zygote, ReverseDiff, Memoization, Turing
using AbstractMCMC
using AdvancedMH
using Clustering
using Distributions
using DistributionsAD
using FiniteDifferences
using ForwardDiff
using MCMCChains
using Memoization
using NamedArrays
using Optim
using PDMats
using ReverseDiff
using SpecialFunctions
using StatsBase
using StatsFuns
using Tracker
using Turing
using Turing.Inference
using Turing.RandomMeasures
using Zygote

using LinearAlgebra
using Pkg
using Random
using Test

using AdvancedPS: ResampleWithESSThreshold, resample_systematic, resample_multinomial
using AdvancedVI: TruncatedADAGrad, DecayedADAGrad, apply!
using Distributions: Binomial, logpdf
using DynamicPPL: getval, getlogp
using ForwardDiff: Dual
using MCMCChains: Chains
using StatsFuns: binomlogpdf, logistic, logsumexp
using Turing: BinomialLogit, ForwardDiffAD, Sampler, SampleFromPrior, NUTS, TrackerAD,
Variational, ZygoteAD, getspace, gradient_logp
using Turing.Core: TuringDenseMvNormal, TuringDiagMvNormal
using Turing.Variational: TruncatedADAGrad, DecayedADAGrad, AdvancedVI

setprogress!(false)

include("test_utils/AllUtils.jl")

# Begin testing.
@testset "Turing" begin
@testset "core" begin
include("core/ad.jl")
Expand Down
8 changes: 0 additions & 8 deletions test/stdlib/RandomMeasures.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
using Turing
using Turing.RandomMeasures
using Test
using Random

dir = splitdir(splitdir(pathof(Turing))[1])[1]
include(dir*"/test/test_utils/AllUtils.jl")

@testset "RandomMeasures.jl" begin
@testset "Infinite Mixture Model" begin
@model infiniteGMM(x) = begin
Expand Down
8 changes: 0 additions & 8 deletions test/stdlib/distributions.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
using Turing, Random, Test
using Turing: BinomialLogit, NUTS
using Distributions: Binomial, logpdf
using StatsFuns: logistic

dir = splitdir(splitdir(pathof(Turing))[1])[1]
include(dir*"/test/test_utils/AllUtils.jl")

@testset "distributions.jl" begin
@turing_testset "distributions functions" begin
ns = 10
Expand Down
2 changes: 0 additions & 2 deletions test/test_utils/AllUtils.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using Turing, Random, Test

# Import utility functions and reused models.
include("staging.jl")
include("numerical_tests.jl")
Expand Down
3 changes: 0 additions & 3 deletions test/test_utils/ad_utils.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
using Turing: gradient_logp, ForwardDiffAD
using Test

"""
test_reverse_mode_ad(forward, f, ȳ, x...; rtol=1e-6, atol=1e-6)
Expand Down
2 changes: 0 additions & 2 deletions test/test_utils/random_measure_utils.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using SpecialFunctions

function compute_log_joint(observations, partition, tau0, tau1, sigma, theta)
n = length(observations)
k = length(partition)
Expand Down
2 changes: 0 additions & 2 deletions test/test_utils/testing_functions.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using Turing

GKernel(var) = (x) -> Normal(x, sqrt.(var))

function randr(vi::Turing.VarInfo,
Expand Down
5 changes: 0 additions & 5 deletions test/utilities/stan-interface.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
using Turing, Random, Test

dir = splitdir(splitdir(pathof(Turing))[1])[1]
include(dir*"/test/test_utils/AllUtils.jl")

@stage_testset "stan" "stan-interface.jl" begin
using CmdStan

Expand Down
8 changes: 0 additions & 8 deletions test/variational/advi.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
using DistributionsAD

using Turing, Random, Test, LinearAlgebra
using Turing: Variational
using Turing.Variational: TruncatedADAGrad, DecayedADAGrad, AdvancedVI

include("../test_utils/AllUtils.jl")

@testset "advi.jl" begin
@turing_testset "advi constructor" begin
Random.seed!(0)
Expand Down
3 changes: 0 additions & 3 deletions test/variational/optimisers.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
using Random, Test, LinearAlgebra, ForwardDiff
using AdvancedVI: TruncatedADAGrad, DecayedADAGrad, apply!

function test_opt(ADPack, opt)
θ = randn(10, 10)
θ_fit = randn(10, 10)
Expand Down

0 comments on commit 24d3731

Please sign in to comment.