From 145a52b514dc3d842abbe20b0625bda59ecb2d85 Mon Sep 17 00:00:00 2001 From: Penelope Yong Date: Mon, 3 Nov 2025 09:47:34 +0000 Subject: [PATCH 1/5] Implement AbstractMCMC.getstats --- src/AdvancedMH.jl | 3 +++ src/MALA.jl | 3 +++ src/RobustAdaptiveMetropolis.jl | 11 ++++++++++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/AdvancedMH.jl b/src/AdvancedMH.jl index a3d2ece..1df8b31 100644 --- a/src/AdvancedMH.jl +++ b/src/AdvancedMH.jl @@ -146,6 +146,9 @@ end function AbstractMCMC.getparams(t::Transition) return t.params end +function AbstractMCMC.getstats(t::Transition) + return (accepted=t.accepted,) +end # TODO (sunxd): remove `DensityModel` in favor of `AbstractMCMC.LogDensityModel` function AbstractMCMC.setparams!!(model::DensityModelOrLogDensityModel, t::Transition, params) diff --git a/src/MALA.jl b/src/MALA.jl index 527f338..f95da67 100644 --- a/src/MALA.jl +++ b/src/MALA.jl @@ -23,6 +23,9 @@ logdensity(model::DensityModelOrLogDensityModel, t::GradientTransition) = t.lp function AbstractMCMC.getparams(t::GradientTransition) return t.params end +function AbstractMCMC.getstats(t::GradientTransition) + return (accepted=t.accepted,) +end function AbstractMCMC.setparams!!(model::DensityModelOrLogDensityModel, t::GradientTransition, params) lp, gradient = logdensity_and_gradient(model, params) diff --git a/src/RobustAdaptiveMetropolis.jl b/src/RobustAdaptiveMetropolis.jl index c84fcc0..c174f7b 100644 --- a/src/RobustAdaptiveMetropolis.jl +++ b/src/RobustAdaptiveMetropolis.jl @@ -116,9 +116,18 @@ end AbstractMCMC.getparams(state::RobustAdaptiveMetropolisState) = state.x function AbstractMCMC.setparams!!(state::RobustAdaptiveMetropolisState, x) return RobustAdaptiveMetropolisState( - x, state.logprob, state.S, state.logα, state.η, state.iteration, state.isaccept + x, + state.logprob, + state.S, + state.logα, + state.η, + state.iteration, + state.isaccept, ) end +function AbstractMCMC.getstats(state::RobustAdaptiveMetropolisState) + return (logα = state.logα, η = state.η, accepted = state.isaccept) +end function ram_step_inner( rng::Random.AbstractRNG, From 6bba949a7c8fa4d9879eb8d57f8e760b9feffcaa Mon Sep 17 00:00:00 2001 From: Penelope Yong Date: Mon, 3 Nov 2025 09:48:45 +0000 Subject: [PATCH 2/5] Add tests --- test/runtests.jl | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/runtests.jl b/test/runtests.jl index 76a1631..b40a852 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -53,6 +53,15 @@ include("util.jl") end end + @testset "AbstractMCMC.getstats" begin + t1, _ = AbstractMCMC.step(Random.default_rng(), model, StaticMH([Normal(0, 1), Normal(0, 1)])) + t2, _ = AbstractMCMC.step(Random.default_rng(), model, MALA(x -> MvNormal(x, I)); initial_params=ones(2)) + for t in [t1, t2] + stats = AbstractMCMC.getstats(t) + @test stats == (accepted = t.accepted,) + end + end + @testset "StaticMH" begin # Set up our sampler with initial parameters. spl1 = StaticMH([Normal(0,1), Normal(0, 1)]) From dd794d7338e7d3436994b071b39cf7a8c5cc6e52 Mon Sep 17 00:00:00 2001 From: Penelope Yong Date: Mon, 3 Nov 2025 09:50:01 +0000 Subject: [PATCH 3/5] Bump compat etc --- Project.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Project.toml b/Project.toml index ceafac7..93315ed 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "AdvancedMH" uuid = "5b7e9947-ddc0-4b3f-9b55-0d8042f74170" -version = "0.8.8" +version = "0.8.9" [deps] AbstractMCMC = "80f14c24-f653-4e6a-9b94-39d6b0f70001" @@ -24,7 +24,7 @@ AdvancedMHMCMCChainsExt = "MCMCChains" AdvancedMHStructArraysExt = "StructArrays" [compat] -AbstractMCMC = "5.6" +AbstractMCMC = "5.9" DiffResults = "1" Distributions = "0.25" DocStringExtensions = "0.9" From 8e0a7629a634f753254c2612c62e274e97551df7 Mon Sep 17 00:00:00 2001 From: Penelope Yong Date: Mon, 3 Nov 2025 09:52:12 +0000 Subject: [PATCH 4/5] Disable JuliaPre workflow --- .github/workflows/JuliaPre.yml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/JuliaPre.yml b/.github/workflows/JuliaPre.yml index 6c005bf..e762ad4 100644 --- a/.github/workflows/JuliaPre.yml +++ b/.github/workflows/JuliaPre.yml @@ -1,10 +1,12 @@ name: JuliaPre on: - push: - branches: - - main - pull_request: + workflow_dispatch: + # Disabled for now because there is no available prerelease of Julia. + # push: + # branches: + # - main + # pull_request: # needed to allow julia-actions/cache to delete old caches that it has created permissions: From c6c6a48ccc05c0d86c2ec5cfea39727ec9d1fd50 Mon Sep 17 00:00:00 2001 From: Penelope Yong Date: Mon, 3 Nov 2025 09:52:56 +0000 Subject: [PATCH 5/5] Add testing on 1.10 (lts) --- .github/workflows/CI.yml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 3723993..57af74f 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -17,19 +17,18 @@ jobs: # Current stable version - version: '1' os: ubuntu-latest - arch: x64 + # LTS + - version: 'lts' + os: ubuntu-latest # Minimum supported version - version: 'min' os: ubuntu-latest - arch: x64 # Windows - version: '1' os: windows-latest - arch: x64 # macOS - version: '1' os: macos-latest - arch: aarch64 steps: - uses: actions/checkout@v4 @@ -37,7 +36,6 @@ jobs: - uses: julia-actions/setup-julia@v2 with: version: ${{ matrix.runner.version }} - arch: ${{ matrix.runner.arch }} - uses: julia-actions/cache@v2