Skip to content

Allow nonnumeric observations in model checks - #1546

Open
shravanngoswamii wants to merge 1 commit into
mainfrom
sg/check-nonnumeric-observations
Open

shravanngoswamii wants to merge 1 commit into
mainfrom
sg/check-nonnumeric-observations

Conversation

@shravanngoswamii

@shravanngoswamii shravanngoswamii commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

Valid observations need not be numeric.

Custom isnan methods still apply.

using DynamicPPL, Distributions

struct SymbolChoice <: DiscreteUnivariateDistribution end
Base.eltype(::Type{SymbolChoice}) = Symbol
Distributions.loglikelihood(::SymbolChoice, x::Symbol) =
    x in (:left, :right) ? -log(2) : -Inf

@model function choice(y)
    x ~ Normal()
    y ~ SymbolChoice()
end

check_model(choice(:right))

Closes #1545

@codecov

codecov Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.12%. Comparing base (702b8c0) to head (714543f).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1546   +/-   ##
=======================================
  Coverage   85.12%   85.12%           
=======================================
  Files          52       52           
  Lines        4671     4671           
=======================================
  Hits         3976     3976           
  Misses        695      695           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions

Copy link
Copy Markdown
Contributor

DynamicPPL.jl documentation for PR #1546 is available at:
https://TuringLang.github.io/DynamicPPL.jl/previews/PR1546/

@github-actions

Copy link
Copy Markdown
Contributor

Benchmarks

Performance Ratio: gradient time divided by log-density time.

For very small models these ratios are noisy across runs and machines; raw primal and gradient timings are more reliable. The benchmarks are aimed at DynamicPPL developers and mainly catch obvious allocation or type-stability regressions. See benchmark notes for details.

Primal times: main 702b8c0, PR 714543f

================================================================================================================================
                                                                     primal                            gradient                 
                                                             ----------------------  -------------------------------------------
Model                                         dim    linked        main          PR     FwdDiff    RvsDiff    Mooncake    Enzyme
--------------------------------------------------------------------------------------------------------------------------------
Simple assume observe*                          1     false     5.37 ns     4.17 ns       10.45    1215.18       10.85      9.66
Simple assume observe*                          1      true     5.37 ns     4.17 ns       10.61    1256.96       10.57     10.17
Smorgasbord                                   201     false     5.33 μs     4.19 μs      101.19     137.18        5.80      1.28
Smorgasbord                                   201      true     6.33 μs     4.98 μs       97.77     159.24        5.94      1.48
Smorgasbord fixed                             100     false     2.77 μs     2.15 μs       67.91     153.18        6.26      1.29
Smorgasbord fixed                             100      true     3.17 μs      2.5 μs       70.44     172.21        6.53      1.46
NamedTuple-field LHS variable*                  1     false     5.37 ns     4.17 ns       10.70    1317.94       10.69     10.30
NamedTuple-field LHS variable*                  1      true     5.38 ns     4.18 ns       10.64    1338.96       10.74     10.46
MvNormal argument-supplied observation*         1     false     88.6 ns     69.8 ns        2.22     545.40        2.88      2.23
MvNormal argument-supplied observation*         1      true     82.8 ns     66.4 ns        2.04     552.12        3.28      2.14
Loop univariate 1k                           1000     false     15.7 μs     12.2 μs     1368.82     353.88        3.46      0.88
Loop univariate 1k                           1000      true     18.3 μs     14.1 μs     1646.84     302.97        3.20      0.81
Multivariate 1k                              1000     false     1.15 μs    939.0 ns     2660.86     561.02        1.96      3.10
Multivariate 1k                              1000      true     1.23 μs    920.0 ns     3913.46     553.11        1.64      3.29
Loop univariate 10k                         10000     false    151.0 μs    117.0 μs    21179.81     450.38        3.58      0.80
Loop univariate 10k                         10000      true    176.0 μs    138.0 μs    20178.74     386.31        3.13      0.74
Multivariate 10k                            10000     false     9.88 μs     9.15 μs    55596.87     593.82        1.57      2.71
Multivariate 10k                            10000      true     10.8 μs     8.42 μs    53783.19     708.53        1.52      2.54
Dynamic                                       err     false     1.52 μs      1.2 μs         err      52.43       14.75      4.87
Dynamic                                        10      true     1.96 μs     1.54 μs        1.79      72.22       11.40      6.79
Submodel*                                       1     false      5.4 ns     4.17 ns       10.46    1671.62       11.12     10.13
Submodel*                                       1      true     5.41 ns     4.18 ns       10.65    1676.20       11.12      8.82
LDA                                             6      true     4.09 μs     3.25 μs        1.54      13.40       43.11     48.53
================================================================================================================================
Environment
Julia Version 1.13.4
Commit c1ac32ab733 (2026-11-13 17:30 UTC)
Build Info:
  Official https://julialang.org release
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 4 × AMD EPYC 9V74 80-Core Processor
  WORD_SIZE: 64
  LLVM: libLLVM-20.1.8 (ORCJIT, znver4)
  GC: Built with stock GC
Threads: 1 default, 1 interactive, 1 GC (on 4 virtual cores)

@shravanngoswamii
shravanngoswamii marked this pull request as ready for review November 20, 2026 15:03

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

check_model throws MethodError: no method matching isnan(::Symbol) for an observed value that isn't a number

1 participant