From 04682e150b82f2b25dc8b0726a831d89378a978b Mon Sep 17 00:00:00 2001 From: Penelope Yong Date: Thu, 26 Mar 2026 21:59:59 +0000 Subject: [PATCH] Fix thread safety of debug raw value accumulator (#1337) Copy `acc.f` in `Base.copy` for VNTAccumulator/TSVNTAccumulator so that mutable state (e.g. `repeated_vns::Set{VarName}`) is not shared across threads. Co-Authored-By: Claude Opus 4.6 (1M context) --- HISTORY.md | 5 +++++ Project.toml | 2 +- src/accumulators/vnt.jl | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 5b4c37b30..ecec98217 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,3 +1,8 @@ +# 0.40.16 + +Fixed `Base.copy` for `VNTAccumulator` and `TSVNTAccumulator` to also copy the `acc.f` field, not just `acc.values`. +This makes sure that the accumulator is thread-safe if `acc.f` contains some mutable state. + # 0.40.15 DynamicPPL now allows you to set the type that log-probabilities are initialised with, using the `DynamicPPL.set_logprob_type!` function. diff --git a/Project.toml b/Project.toml index c794203dd..d01c1fcc0 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "DynamicPPL" uuid = "366bfd00-2699-11ea-058f-f148b4cae6d8" -version = "0.40.15" +version = "0.40.16" [deps] ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b" diff --git a/src/accumulators/vnt.jl b/src/accumulators/vnt.jl index 8e9a56666..f9e144104 100644 --- a/src/accumulators/vnt.jl +++ b/src/accumulators/vnt.jl @@ -59,7 +59,7 @@ end for acc_type in (:VNTAccumulator, :TSVNTAccumulator) @eval begin function Base.copy(acc::$acc_type{AccName}) where {AccName} - return $acc_type{AccName}(acc.f, copy(acc.values)) + return $acc_type{AccName}(copy(acc.f), copy(acc.values)) end accumulator_name(::$acc_type{AccName}) where {AccName} = AccName