Skip to content

Commit

Permalink
Various CI improvements (#2375)
Browse files Browse the repository at this point in the history
* Remove check on Julia>1.2

* Upgrade julia-actions/cache to v2

* Refactor CI matrix to make intent clearer

* Reinsert 1.11/2 threads combination
  • Loading branch information
penelopeysm authored Oct 29, 2024
1 parent 42189fd commit d2ea94a
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 96 deletions.
90 changes: 49 additions & 41 deletions .github/workflows/Tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ on:
jobs:
test:
# Use matrix.test.name here to avoid it taking up the entire window width
name: test ${{matrix.test.name}} (${{ matrix.os }}, ${{ matrix.version }}, ${{ matrix.arch }}, ${{ matrix.num_threads }})
runs-on: ${{ matrix.os }}
continue-on-error: ${{ matrix.version == 'nightly' }}
name: test ${{matrix.test.name}} (${{ matrix.runner.os }}, ${{ matrix.runner.version }}, ${{ matrix.runner.arch }}, ${{ matrix.runner.num_threads }})
runs-on: ${{ matrix.runner.os }}
continue-on-error: ${{ matrix.runner.version == 'pre' }}

strategy:
fail-fast: false
Expand All @@ -35,63 +35,71 @@ jobs:
args: "mcmc/ess.jl"
- name: "everything else"
args: "--skip essential/ad.jl mcmc/gibbs.jl mcmc/hmc.jl mcmc/abstractmcmc.jl mcmc/Inference.jl experimental/gibbs.jl mcmc/ess.jl"
version:
- '1.10'
- '1'
os:
- ubuntu-latest
- windows-latest
- macOS-latest
arch:
- x64
- x86
num_threads:
- 1
- 2
exclude:
# With Windows and macOS, only run x64, 2 threads. We just want to see
# some combination work on OSes other than Ubuntu.
- os: windows-latest
version: '1'
- os: macOS-latest
version: '1'
- os: windows-latest
arch: x86
- os: macOS-latest
runner:
# Default
- version: '1'
os: ubuntu-latest
arch: x64
num_threads: 1
# x86
- version: '1'
os: ubuntu-latest
arch: x86
- os: windows-latest
num_threads: 1
- os: macOS-latest
# Multithreaded
- version: '1'
os: ubuntu-latest
arch: x64
num_threads: 2
# Windows
- version: '1'
os: windows-latest
arch: x64
num_threads: 1
# macOS
- version: '1'
os: macos-latest
arch: x64
num_threads: 1
# Minimum supported Julia version
- version: 'min'
os: ubuntu-latest
arch: x64
num_threads: 1
# It's sufficient to test x86 with only Julia 1.10 and 1 thread.
- arch: x86
version: '1'
- arch: x86
# Minimum supported Julia version, multithreaded
- version: 'min'
os: ubuntu-latest
arch: x64
num_threads: 2
# Pre-release Julia version
- version: 'pre'
os: ubuntu-latest
arch: x64
num_threads: 1

steps:
- name: Print matrix variables
run: |
echo "OS: ${{ matrix.os }}"
echo "Architecture: ${{ matrix.arch }}"
echo "Julia version: ${{ matrix.version }}"
echo "Number of threads: ${{ matrix.num_threads }}"
echo "OS: ${{ matrix.runner.os }}"
echo "Architecture: ${{ matrix.runner.arch }}"
echo "Julia version: ${{ matrix.runner.version }}"
echo "Number of threads: ${{ matrix.runner.num_threads }}"
echo "Test arguments: ${{ matrix.test.args }}"
- name: (De)activate coverage analysis
run: echo "COVERAGE=${{ matrix.version == '1' && matrix.os == 'ubuntu-latest' && matrix.num_threads == 2 }}" >> "$GITHUB_ENV"
run: echo "COVERAGE=${{ matrix.runner.version == '1' && matrix.runner.os == 'ubuntu-latest' && matrix.runner.num_threads == 2 }}" >> "$GITHUB_ENV"
shell: bash
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v2
with:
version: '${{ matrix.version }}'
arch: ${{ matrix.arch }}
- uses: julia-actions/cache@v1
version: '${{ matrix.runner.version }}'
arch: ${{ matrix.runner.arch }}
- uses: julia-actions/cache@v2
- uses: julia-actions/julia-buildpkg@v1
# TODO: Use julia-actions/julia-runtest when test_args are supported
# Custom calls of Pkg.test tend to miss features such as e.g. adjustments for CompatHelper PRs
# Ref https://github.com/julia-actions/julia-runtest/pull/73
- name: Call Pkg.test
run: julia --color=yes --inline=yes --depwarn=yes --check-bounds=yes --threads=${{ matrix.num_threads }} --project=@. -e 'import Pkg; Pkg.test(; coverage=parse(Bool, ENV["COVERAGE"]), test_args=ARGS)' -- ${{ matrix.test.args }}
run: julia --color=yes --inline=yes --depwarn=yes --check-bounds=yes --threads=${{ matrix.runner.num_threads }} --project=@. -e 'import Pkg; Pkg.test(; coverage=parse(Bool, ENV["COVERAGE"]), test_args=ARGS)' -- ${{ matrix.test.args }}
- uses: julia-actions/julia-processcoverage@v1
if: ${{ env.COVERAGE }}
- uses: codecov/codecov-action@v4
Expand Down
106 changes: 51 additions & 55 deletions test/mcmc/Inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,70 +17,66 @@ using Test: @test, @test_throws, @testset
using Turing

@testset "Testing inference.jl with $adbackend" for adbackend in ADUtils.adbackends
# Only test threading if 1.3+.
if VERSION > v"1.2"
@testset "threaded sampling" begin
# Test that chains with the same seed will sample identically.
@testset "rng" begin
model = gdemo_default

# multithreaded sampling with PG causes segfaults on Julia 1.5.4
# https://github.com/TuringLang/Turing.jl/issues/1571
samplers = @static if VERSION <= v"1.5.3" || VERSION >= v"1.6.0"
(
HMC(0.1, 7; adtype=adbackend),
PG(10),
IS(),
MH(),
Gibbs(PG(3, :s), HMC(0.4, 8, :m; adtype=adbackend)),
Gibbs(HMC(0.1, 5, :s; adtype=adbackend), ESS(:m)),
)
else
(
HMC(0.1, 7; adtype=adbackend),
IS(),
MH(),
Gibbs(HMC(0.1, 5, :s; adtype=adbackend), ESS(:m)),
)
end
for sampler in samplers
Random.seed!(5)
chain1 = sample(model, sampler, MCMCThreads(), 1000, 4)
@testset "threaded sampling" begin
# Test that chains with the same seed will sample identically.
@testset "rng" begin
model = gdemo_default

# multithreaded sampling with PG causes segfaults on Julia 1.5.4
# https://github.com/TuringLang/Turing.jl/issues/1571
samplers = @static if VERSION <= v"1.5.3" || VERSION >= v"1.6.0"
(
HMC(0.1, 7; adtype=adbackend),
PG(10),
IS(),
MH(),
Gibbs(PG(3, :s), HMC(0.4, 8, :m; adtype=adbackend)),
Gibbs(HMC(0.1, 5, :s; adtype=adbackend), ESS(:m)),
)
else
(
HMC(0.1, 7; adtype=adbackend),
IS(),
MH(),
Gibbs(HMC(0.1, 5, :s; adtype=adbackend), ESS(:m)),
)
end
for sampler in samplers
Random.seed!(5)
chain1 = sample(model, sampler, MCMCThreads(), 1000, 4)

Random.seed!(5)
chain2 = sample(model, sampler, MCMCThreads(), 1000, 4)
Random.seed!(5)
chain2 = sample(model, sampler, MCMCThreads(), 1000, 4)

@test chain1.value == chain2.value
end
@test chain1.value == chain2.value
end

# Should also be stable with am explicit RNG
seed = 5
rng = Random.MersenneTwister(seed)
for sampler in samplers
Random.seed!(rng, seed)
chain1 = sample(rng, model, sampler, MCMCThreads(), 1000, 4)
# Should also be stable with am explicit RNG
seed = 5
rng = Random.MersenneTwister(seed)
for sampler in samplers
Random.seed!(rng, seed)
chain1 = sample(rng, model, sampler, MCMCThreads(), 1000, 4)

Random.seed!(rng, seed)
chain2 = sample(rng, model, sampler, MCMCThreads(), 1000, 4)
Random.seed!(rng, seed)
chain2 = sample(rng, model, sampler, MCMCThreads(), 1000, 4)

@test chain1.value == chain2.value
end
@test chain1.value == chain2.value
end
end

# Smoke test for default sample call.
Random.seed!(100)
chain = sample(
gdemo_default, HMC(0.1, 7; adtype=adbackend), MCMCThreads(), 1000, 4
)
check_gdemo(chain)
# Smoke test for default sample call.
Random.seed!(100)
chain = sample(gdemo_default, HMC(0.1, 7; adtype=adbackend), MCMCThreads(), 1000, 4)
check_gdemo(chain)

# run sampler: progress logging should be disabled and
# it should return a Chains object
sampler = Sampler(HMC(0.1, 7; adtype=adbackend), gdemo_default)
chains = sample(gdemo_default, sampler, MCMCThreads(), 1000, 4)
@test chains isa MCMCChains.Chains
end
# run sampler: progress logging should be disabled and
# it should return a Chains object
sampler = Sampler(HMC(0.1, 7; adtype=adbackend), gdemo_default)
chains = sample(gdemo_default, sampler, MCMCThreads(), 1000, 4)
@test chains isa MCMCChains.Chains
end

@testset "chain save/resume" begin
Random.seed!(1234)

Expand Down

0 comments on commit d2ea94a

Please sign in to comment.