From 5ba7673042917c13196038893843be236d67cf69 Mon Sep 17 00:00:00 2001 From: Arpan Chakraborty Date: Mon, 4 May 2026 08:11:53 +0530 Subject: [PATCH 1/7] =?UTF-8?q?feat:=20warn=20on=20=C2=B1Inf=20values=20in?= =?UTF-8?q?=20check=5Fmodel=20observe=20statements?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/debug_utils.jl | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/debug_utils.jl b/src/debug_utils.jl index 7c0be506b..2355e6723 100644 --- a/src/debug_utils.jl +++ b/src/debug_utils.jl @@ -71,7 +71,15 @@ Check if `x` is `NaN`, or contains any `NaN` values. _has_nans(x::NamedTuple) = any(_has_nans, x) _has_nans(x::AbstractArray) = any(_has_nans, x) _has_nans(x) = isnan(x) -_has_nans(::Missing) = false +""" + _has_infs(x) + +Check if `x` is `Inf` or `-Inf`, or contains any such values. +""" +_has_infs(x::NamedTuple) = any(_has_infs, x) +_has_infs(x::AbstractArray) = any(_has_infs, x) +_has_infs(x) = isinf(x) +_has_infs(::Missing) = false function DynamicPPL.accumulate_assume!!( acc::DebugAccumulator, val, tval, logjac, vn::VarName, right::Distribution, template @@ -98,12 +106,13 @@ function DynamicPPL.accumulate_observe!!( @warn full_msg failed = true end - # Check for NaN's as well - if _has_nans(val) + # Check for Inf values, but only warn if the logpdf at that value is -Inf + # (i.e., Inf is not in the support of the distribution) + if _has_infs(val) && isinf(logpdf(right, val)) msg = - "Encountered a NaN value on the left-hand side of an" * + "Encountered an infinite value on the left-hand side of an" * " observe statement; this may indicate that your data" * - " contain NaN values." + " contain Inf or -Inf values." @warn msg failed = true end From 1bad7c8c45059745559f5176b6697e668e0469ea Mon Sep 17 00:00:00 2001 From: Arpan Chakraborty Date: Mon, 4 May 2026 08:40:45 +0530 Subject: [PATCH 2/7] fix: add missing _has_nans(::Missing) = false --- src/debug_utils.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/src/debug_utils.jl b/src/debug_utils.jl index 2355e6723..50e692a41 100644 --- a/src/debug_utils.jl +++ b/src/debug_utils.jl @@ -71,6 +71,7 @@ Check if `x` is `NaN`, or contains any `NaN` values. _has_nans(x::NamedTuple) = any(_has_nans, x) _has_nans(x::AbstractArray) = any(_has_nans, x) _has_nans(x) = isnan(x) +_has_nans(::Missing) = false """ _has_infs(x) From e61b9ed368f701dd21f2e0e39e7aacb9755c78d0 Mon Sep 17 00:00:00 2001 From: Arpan Chakraborty Date: Mon, 4 May 2026 08:56:54 +0530 Subject: [PATCH 3/7] fix: restore NaN check in accumulate_observe!! --- src/debug_utils.jl | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/debug_utils.jl b/src/debug_utils.jl index 50e692a41..83af97fae 100644 --- a/src/debug_utils.jl +++ b/src/debug_utils.jl @@ -107,6 +107,15 @@ function DynamicPPL.accumulate_observe!!( @warn full_msg failed = true end + # Check for NaN's as well + if _has_nans(val) + msg = + "Encountered a NaN value on the left-hand side of an" * + " observe statement; this may indicate that your data" * + " contain NaN values." + @warn msg + failed = true + end # Check for Inf values, but only warn if the logpdf at that value is -Inf # (i.e., Inf is not in the support of the distribution) if _has_infs(val) && isinf(logpdf(right, val)) From 07a014b5be07a2603eb73bc883117945f92d5cf5 Mon Sep 17 00:00:00 2001 From: Arpan Chakraborty Date: Mon, 4 May 2026 09:19:59 +0530 Subject: [PATCH 4/7] =?UTF-8?q?test:=20add=20tests=20for=20=C2=B1Inf=20war?= =?UTF-8?q?ning=20in=20check=5Fmodel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/debug_utils.jl | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/debug_utils.jl b/test/debug_utils.jl index 551cf0323..6e3faf402 100644 --- a/test/debug_utils.jl +++ b/test/debug_utils.jl @@ -122,6 +122,22 @@ end @test_throws ErrorException check_model(m; error_on_failure=true) end + @testset "Inf in data" begin + @model function demo_inf_in_data(x) + a ~ Normal() + for i in eachindex(x) + x[i] ~ Normal(a) + end + end + m = demo_inf_in_data([1.0, Inf]) + @test_throws ErrorException check_model(m; error_on_failure=true) + m2 = demo_inf_in_data([1.0, -Inf]) + @test_throws ErrorException check_model(m2; error_on_failure=true) + # Finite data should pass + m3 = demo_inf_in_data([1.0, 2.0]) + @test check_model(m3; error_on_failure=true) + end + @testset "incorrect use of condition" begin @testset "missing in multivariate" begin @model function demo_missing_in_multivariate(x) From a43d7f6800b327e40c98874d5bef508c7f4dfaf7 Mon Sep 17 00:00:00 2001 From: Arpan Chakraborty Date: Tue, 5 May 2026 07:40:30 +0530 Subject: [PATCH 5/7] style: fix formatting after upstream merge --- src/abstract_varinfo.jl | 10 ++++++---- test/compiler.jl | 14 ++++++++------ 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/abstract_varinfo.jl b/src/abstract_varinfo.jl index 0b1c250b9..dfc02f659 100644 --- a/src/abstract_varinfo.jl +++ b/src/abstract_varinfo.jl @@ -219,10 +219,12 @@ function setlogp!!(vi::AbstractVarInfo, logp::NamedTuple{names}) where {names} end function setlogp!!(vi::AbstractVarInfo, logp::Number) - return error(""" - `setlogp!!(vi::AbstractVarInfo, logp::Number)` is no longer supported. Use - `setloglikelihood!!`, `setlogjac!!`, and/or `setlogprior!!` instead. - """) + return error( + """ + `setlogp!!(vi::AbstractVarInfo, logp::Number)` is no longer supported. Use + `setloglikelihood!!`, `setlogjac!!`, and/or `setlogprior!!` instead. + """ + ) end """ diff --git a/test/compiler.jl b/test/compiler.jl index 3d34594cc..18a631ba6 100644 --- a/test/compiler.jl +++ b/test/compiler.jl @@ -372,12 +372,14 @@ end x .~ [Normal(), Normal()] return x end - expected_error = ArgumentError(""" - As of v0.35, DynamicPPL does not allow arrays of distributions in `.~`. \ - Please use `product_distribution` instead, or write a loop if necessary. \ - See https://github.com/TuringLang/DynamicPPL.jl/releases/tag/v0.35.0 for more \ - details.\ - """) + expected_error = ArgumentError( + """ +As of v0.35, DynamicPPL does not allow arrays of distributions in `.~`. \ +Please use `product_distribution` instead, or write a loop if necessary. \ +See https://github.com/TuringLang/DynamicPPL.jl/releases/tag/v0.35.0 for more \ +details.\ +""" + ) @test_throws expected_error (vector_dot_tilde()(); true) end From 26c7a3b81b2e8ccddaf4743e41cf7e3f67c831bc Mon Sep 17 00:00:00 2001 From: Arpan Chakraborty Date: Wed, 6 May 2026 08:46:48 +0530 Subject: [PATCH 6/7] =?UTF-8?q?docs:=20update=20DebugAccumulator=20docstri?= =?UTF-8?q?ng=20to=20mention=20=C2=B1Inf=20check?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/debug_utils.jl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/debug_utils.jl b/src/debug_utils.jl index 83af97fae..8174b2e83 100644 --- a/src/debug_utils.jl +++ b/src/debug_utils.jl @@ -14,8 +14,9 @@ export check_model, has_static_constraints An accumulator which checks calls at each tilde-statement for potential errors. -Right now this accumulator only checks for `NaN` values on the left-hand side of observe -statements, and partially `missing` values on the left-hand side of observe statements. +Right now this accumulator checks for `NaN` and `±Inf` values on the left-hand +side of observe statements, and partially `missing` values on the left-hand side of observe statements. + Other checks in `check_model` are accomplished via different accumulators. """ @@ -149,6 +150,7 @@ needed. - Repeated usage of the same or overlapping VarNames - `NaN` on the left-hand side of observe statements +- `±Inf` on the left-hand side of observe statements (when the value is not in the support of the distribution) - (if `fail_if_discrete` is set) Usage of discrete distributions From 0474577a15f720b8fb7453586774f45b9604e9d4 Mon Sep 17 00:00:00 2001 From: Arpan Chakraborty Date: Wed, 6 May 2026 08:50:11 +0530 Subject: [PATCH 7/7] style: fix line wrapping in DebugAccumulator docstring --- src/debug_utils.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/debug_utils.jl b/src/debug_utils.jl index 8174b2e83..1097bac6f 100644 --- a/src/debug_utils.jl +++ b/src/debug_utils.jl @@ -15,7 +15,8 @@ export check_model, has_static_constraints An accumulator which checks calls at each tilde-statement for potential errors. Right now this accumulator checks for `NaN` and `±Inf` values on the left-hand -side of observe statements, and partially `missing` values on the left-hand side of observe statements. +side of observe statements, and partially `missing` values on the left-hand side +of observe statements. Other checks in `check_model` are accomplished via different accumulators.