TuringLang / DynamicPPL.jl

Implementation of domain-specific language (DSL) for dynamic probabilistic programming
https://turinglang.org/DynamicPPL.jl/
MIT License
164 stars 29 forks source link

Fix type inference of `eltype(vi, spl)` (Turing#2151) #568

Closed devmotion closed 9 months ago

devmotion commented 10 months ago

Fixes the error in https://github.com/TuringLang/Turing.jl/issues/2151 on Julia 1.10 for me:

using Turing, ReverseDiff, LinearAlgebra

# build data
t = 1:0.05:8
σ = 0.3
y = @. rand(sin(t) + Normal(0, σ))

@model function state_space(y, TT, ::Type{T}=Float64) where {T}
    # Priors 
    α ~ Normal(y[1], 0.001)
    τ ~ Exponential(1)
    η ~ filldist(Normal(0, 1), TT-1)
    σ ~ Exponential(1)

    # create latent variable
    x = Vector{T}(undef, TT)

    x[1] = α

    for t in 2:TT
        x[t] = x[t-1] + η[t-1] * τ
    end

    # measurement model
    y ~ MvNormal(x, σ^2 * I)

    return x
end

n_iter = 1500
model = state_space(y, length(t))
chns = sample(model, NUTS(n_iter * 2, 0.8; adtype = AutoReverseDiff(true)), n_iter);

cc @sjwild

torfjelde commented 9 months ago

This looks good to me, but there's something weird happening with the tests; looking into this.

@devmotion Could you bump patch version?

github-actions[bot] commented 9 months ago

Pull Request Test Coverage Report for Build 7583034714


Totals Coverage Status
Change from base Build 7506113239: -0.5%
Covered Lines: 2329
Relevant Lines: 2936

💛 - Coveralls
codecov[bot] commented 9 months ago

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Comparison is base (c6e3b6b) 79.64% compared to head (4ff8324) 84.28%. Report is 1 commits behind head on master.

Files Patch % Lines
src/abstract_varinfo.jl 75.00% 1 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #568 +/- ## ========================================== + Coverage 79.64% 84.28% +4.63% ========================================== Files 26 26 Lines 2938 3175 +237 ========================================== + Hits 2340 2676 +336 + Misses 598 499 -99 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

coveralls commented 9 months ago

Pull Request Test Coverage Report for Build 7628589803


Changes Missing Coverage Covered Lines Changed/Added Lines %
src/abstract_varinfo.jl 3 4 75.0%
<!-- Total: 4 5 80.0% -->
Files with Coverage Reduction New Missed Lines %
src/model.jl 1 87.88%
src/simple_varinfo.jl 5 79.64%
src/varinfo.jl 6 85.6%
src/threadsafe.jl 13 44.23%
<!-- Total: 25 -->
Totals Coverage Status
Change from base Build 7615074409: 0.02%
Covered Lines: 2677
Relevant Lines: 3163

💛 - Coveralls
devmotion commented 9 months ago

I think TuringLang/Turing.jl/pull/2156 will fix the test issues.

devmotion commented 9 months ago

@torfjelde The PR is ready for another round of review 🙂