Skip to content

Commit 3077a5e

Browse files
authored
Make CI + tests more efficient (#749)
* Disable CI fail-fast * Separate tests into two groups * Suppress unneeded output in test logs * Cancel CI on subsequent pushes to same PR * Surely we don't need the double loop * Add comment about tests * Don't suppress output from debug_utils test
1 parent 5c8fc59 commit 3077a5e

File tree

5 files changed

+84
-26
lines changed

5 files changed

+84
-26
lines changed

.github/workflows/CI.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,17 @@ permissions:
1717
actions: write
1818
contents: read
1919

20+
# Cancel existing tests on the same PR if a new commit is added to a pull request
21+
concurrency:
22+
group: ${{ github.workflow }}-${{ github.ref || github.run_id }}
23+
cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}
24+
2025
jobs:
2126
test:
2227
runs-on: ${{ matrix.runner.os }}
2328
strategy:
29+
fail-fast: false
30+
2431
matrix:
2532
runner:
2633
# Current stable version
@@ -58,6 +65,9 @@ jobs:
5865
os: macos-latest
5966
arch: aarch64
6067
num_threads: 2
68+
test_group:
69+
- Group1
70+
- Group2
6171

6272
steps:
6373
- uses: actions/checkout@v4
@@ -73,6 +83,7 @@ jobs:
7383

7484
- uses: julia-actions/julia-runtest@v1
7585
env:
86+
GROUP: ${{ matrix.test_group }}
7687
JULIA_NUM_THREADS: ${{ matrix.runner.num_threads }}
7788

7889
- uses: julia-actions/julia-processcoverage@v1

test/debug_utils.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@
199199
@test retype <: Tuple
200200

201201
# Just make sure the following is runnable.
202-
@test (DynamicPPL.DebugUtils.model_warntype(model); true)
202+
@test DynamicPPL.DebugUtils.model_warntype(model) isa Any
203203
end
204204
end
205205
end

test/lkj.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ _lkj_atol = 0.05
2222
model = lkj_prior_demo()
2323
# `SampleFromPrior` will sample in constrained space.
2424
@testset "SampleFromPrior" begin
25-
samples = sample(model, SampleFromPrior(), 1_000)
25+
samples = sample(model, SampleFromPrior(), 1_000; progress=false)
2626
@test mean(map(Base.Fix2(getindex, Colon()), samples)) target_mean atol =
2727
_lkj_atol
2828
end
2929

3030
# `SampleFromUniform` will sample in unconstrained space.
3131
@testset "SampleFromUniform" begin
32-
samples = sample(model, SampleFromUniform(), 1_000)
32+
samples = sample(model, SampleFromUniform(), 1_000; progress=false)
3333
@test mean(map(Base.Fix2(getindex, Colon()), samples)) target_mean atol =
3434
_lkj_atol
3535
end
@@ -39,7 +39,7 @@ end
3939
model = lkj_chol_prior_demo(uplo)
4040
# `SampleFromPrior` will sample in unconstrained space.
4141
@testset "SampleFromPrior" begin
42-
samples = sample(model, SampleFromPrior(), 1_000)
42+
samples = sample(model, SampleFromPrior(), 1_000; progress=false)
4343
# Build correlation matrix from factor
4444
corr_matrices = map(samples) do s
4545
M = reshape(s.metadata.vals, (2, 2))
@@ -50,7 +50,7 @@ end
5050

5151
# `SampleFromUniform` will sample in unconstrained space.
5252
@testset "SampleFromUniform" begin
53-
samples = sample(model, SampleFromUniform(), 1_000)
53+
samples = sample(model, SampleFromUniform(), 1_000; progress=false)
5454
# Build correlation matrix from factor
5555
corr_matrices = map(samples) do s
5656
M = reshape(s.metadata.vals, (2, 2))

test/runtests.jl

Lines changed: 54 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,16 @@ using OrderedCollections: OrderedSet
3535

3636
using DynamicPPL: getargs_dottilde, getargs_tilde, Selector
3737

38+
const GROUP = get(ENV, "GROUP", "All")
3839
Random.seed!(100)
3940

4041
include("test_util.jl")
4142

42-
@testset "DynamicPPL.jl" begin
43-
@testset "interface" begin
43+
@testset verbose = true "DynamicPPL.jl" begin
44+
# The tests are split into two groups so that CI can run in parallel. The
45+
# groups are chosen to make both groups take roughly the same amount of
46+
# time, but beyond that there is no particular reason for the split.
47+
if GROUP == "All" || GROUP == "Group1"
4448
include("utils.jl")
4549
include("compiler.jl")
4650
include("varnamedvector.jl")
@@ -50,15 +54,60 @@ include("test_util.jl")
5054
include("sampler.jl")
5155
include("independence.jl")
5256
include("distribution_wrappers.jl")
53-
include("contexts.jl")
54-
include("context_implementations.jl")
5557
include("logdensityfunction.jl")
5658
include("linking.jl")
57-
include("threadsafe.jl")
5859
include("serialization.jl")
5960
include("pointwise_logdensities.jl")
6061
include("lkj.jl")
62+
end
63+
64+
if GROUP == "All" || GROUP == "Group2"
65+
include("contexts.jl")
66+
include("context_implementations.jl")
67+
include("threadsafe.jl")
6168
include("debug_utils.jl")
69+
@testset "compat" begin
70+
include(joinpath("compat", "ad.jl"))
71+
end
72+
@testset "extensions" begin
73+
include("ext/DynamicPPLMCMCChainsExt.jl")
74+
include("ext/DynamicPPLJETExt.jl")
75+
end
76+
@testset "ad" begin
77+
include("ext/DynamicPPLForwardDiffExt.jl")
78+
include("ext/DynamicPPLMooncakeExt.jl")
79+
include("ad.jl")
80+
end
81+
@testset "prob and logprob macro" begin
82+
@test_throws ErrorException prob"..."
83+
@test_throws ErrorException logprob"..."
84+
end
85+
@testset "doctests" begin
86+
DocMeta.setdocmeta!(
87+
DynamicPPL,
88+
:DocTestSetup,
89+
:(using DynamicPPL, Distributions);
90+
recursive=true,
91+
)
92+
doctestfilters = [
93+
# Older versions will show "0 element Array" instead of "Type[]".
94+
r"(Any\[\]|0-element Array{.+,[0-9]+})",
95+
# Older versions will show "Array{...,1}" instead of "Vector{...}".
96+
r"(Array{.+,\s?1}|Vector{.+})",
97+
# Older versions will show "Array{...,2}" instead of "Matrix{...}".
98+
r"(Array{.+,\s?2}|Matrix{.+})",
99+
# Errors from macros sometimes result in `LoadError: LoadError:`
100+
# rather than `LoadError:`, depending on Julia version.
101+
r"ERROR: (LoadError:\s)+",
102+
# Older versions do not have `;;]` but instead just `]` at end of the line
103+
# => need to treat `;;]` and `]` as the same, i.e. ignore them if at the end of a line
104+
r"(;;){0,1}\]$"m,
105+
# Ignore the source of a warning in the doctest output, since this is dependent on host.
106+
# This is a line that starts with "└ @ " and ends with the line number.
107+
r"└ @ .+:[0-9]+",
108+
]
109+
doctest(DynamicPPL; manual=false, doctestfilters=doctestfilters)
110+
end
62111
end
63112

64113
@testset "compat" begin

test/sampler.jl

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,20 @@
3434

3535
@testset "init" begin
3636
@testset "$(model.f)" for model in DynamicPPL.TestUtils.DEMO_MODELS
37-
@testset "$(model.f)" for model in DynamicPPL.TestUtils.DEMO_MODELS
38-
N = 1000
39-
chain_init = sample(model, SampleFromUniform(), N; progress=false)
40-
41-
for vn in keys(first(chain_init))
42-
if AbstractPPL.subsumes(@varname(s), vn)
43-
# `s ~ InverseGamma(2, 3)` and its unconstrained value will be sampled from Unif[-2,2].
44-
dist = InverseGamma(2, 3)
45-
b = DynamicPPL.link_transform(dist)
46-
@test mean(mean(b(vi[vn])) for vi in chain_init) 0 atol = 0.11
47-
elseif AbstractPPL.subsumes(@varname(m), vn)
48-
# `m ~ Normal(0, sqrt(s))` and its constrained value is the same.
49-
@test mean(mean(vi[vn]) for vi in chain_init) 0 atol = 0.11
50-
else
51-
error("Unknown variable name: $vn")
52-
end
37+
N = 1000
38+
chain_init = sample(model, SampleFromUniform(), N; progress=false)
39+
40+
for vn in keys(first(chain_init))
41+
if AbstractPPL.subsumes(@varname(s), vn)
42+
# `s ~ InverseGamma(2, 3)` and its unconstrained value will be sampled from Unif[-2,2].
43+
dist = InverseGamma(2, 3)
44+
b = DynamicPPL.link_transform(dist)
45+
@test mean(mean(b(vi[vn])) for vi in chain_init) 0 atol = 0.11
46+
elseif AbstractPPL.subsumes(@varname(m), vn)
47+
# `m ~ Normal(0, sqrt(s))` and its constrained value is the same.
48+
@test mean(mean(vi[vn]) for vi in chain_init) 0 atol = 0.11
49+
else
50+
error("Unknown variable name: $vn")
5351
end
5452
end
5553
end

0 commit comments

Comments
 (0)