From e8e8e3232714321f3654e7d147f7a20d174d901a Mon Sep 17 00:00:00 2001 From: Penelope Yong Date: Sat, 26 Oct 2024 20:32:10 +0100 Subject: [PATCH 1/4] Remove check on Julia>1.2 --- test/mcmc/Inference.jl | 106 ++++++++++++++++++++--------------------- 1 file changed, 51 insertions(+), 55 deletions(-) diff --git a/test/mcmc/Inference.jl b/test/mcmc/Inference.jl index a92f9c763f..87c7d7244e 100644 --- a/test/mcmc/Inference.jl +++ b/test/mcmc/Inference.jl @@ -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) From 9d44dd98d527fd1f68c6657f77178fa473b00c16 Mon Sep 17 00:00:00 2001 From: Penelope Yong Date: Thu, 24 Oct 2024 12:14:05 +0100 Subject: [PATCH 2/4] Upgrade julia-actions/cache to v2 --- .github/workflows/Tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/Tests.yml b/.github/workflows/Tests.yml index 7ef2ad36fc..6d0abc6470 100644 --- a/.github/workflows/Tests.yml +++ b/.github/workflows/Tests.yml @@ -85,7 +85,7 @@ jobs: with: version: '${{ matrix.version }}' arch: ${{ matrix.arch }} - - uses: julia-actions/cache@v1 + - 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 From 4a27bd05fcff9029ba5e928c22ae8430a8391c00 Mon Sep 17 00:00:00 2001 From: Penelope Yong Date: Thu, 24 Oct 2024 12:13:57 +0100 Subject: [PATCH 3/4] Refactor CI matrix to make intent clearer --- .github/workflows/Tests.yml | 85 +++++++++++++++++++------------------ 1 file changed, 44 insertions(+), 41 deletions(-) diff --git a/.github/workflows/Tests.yml b/.github/workflows/Tests.yml index 6d0abc6470..1e7769c65f 100644 --- a/.github/workflows/Tests.yml +++ b/.github/workflows/Tests.yml @@ -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 @@ -35,63 +35,66 @@ 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 - arch: x86 - - os: windows-latest + runner: + # Default + - version: '1' + os: ubuntu-latest + arch: x64 num_threads: 1 - - os: macOS-latest + # x86 + - version: '1' + os: ubuntu-latest + arch: x86 num_threads: 1 - # It's sufficient to test x86 with only Julia 1.10 and 1 thread. - - arch: x86 - version: '1' - - arch: x86 + # 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 + # 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 }} + 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 From 7ea9808e9eae0c333c161a52189cfdf5741bd961 Mon Sep 17 00:00:00 2001 From: Penelope Yong Date: Sun, 27 Oct 2024 00:26:20 +0100 Subject: [PATCH 4/4] Reinsert 1.11/2 threads combination --- .github/workflows/Tests.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/Tests.yml b/.github/workflows/Tests.yml index 1e7769c65f..eb631c16f8 100644 --- a/.github/workflows/Tests.yml +++ b/.github/workflows/Tests.yml @@ -66,6 +66,11 @@ jobs: os: ubuntu-latest arch: x64 num_threads: 1 + # Minimum supported Julia version, multithreaded + - version: 'min' + os: ubuntu-latest + arch: x64 + num_threads: 2 # Pre-release Julia version - version: 'pre' os: ubuntu-latest