Skip to content

Confusing error when sampling from empty model #918

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
penelopeysm opened this issue May 13, 2025 · 3 comments
Open

Confusing error when sampling from empty model #918

penelopeysm opened this issue May 13, 2025 · 3 comments

Comments

@penelopeysm
Copy link
Member

julia> using Turing

julia> @model function f(x)
           x ~ Normal()
       end
f (generic function with 2 methods)

julia> sample(f(1.0), NUTS(), 100)
Sampling 100%|██████████████████████████████████████████| Time: 0:00:00
ERROR: ArgumentError: reducing over an empty collection is not allowed; consider supplying `init` to the reducer
[...]

I think check_model() should probably error if the model is empty.

@mhauru
Copy link
Member

mhauru commented May 14, 2025

Or maybe VarInfo should be able to handle this without erroring, return a chain with one dimension being zero? I don't see a reason why we should ban likelihood-only models, even if they are a bit silly. Might come around as a special case in some system of models someone is developing or somesuch.

@penelopeysm
Copy link
Member Author

DynamicPPL is actually quite fine with it, it's getparams that errors so in that case this would be a Turing bug. Happy to move it, I opened it here because if it was check_model it would be here.

@penelopeysm
Copy link
Member Author

We might run into this though

julia> m = Array{Float64}(undef, 0, 0, 0)
0×0×0 Array{Float64, 3}

julia> Chains(m, [])
ERROR: StackOverflowError:
Stacktrace:
     [1] Chains(::Array{Float64, 3}, ::Vector{Any}; kwargs::@Kwargs{})
       @ MCMCChains ~/.julia/packages/MCMCChains/RIFg4/src/chains.jl:24
     [2] Chains(::Array{Float64, 3}, ::Vector{Any})
       @ MCMCChains ~/.julia/packages/MCMCChains/RIFg4/src/chains.jl:18
--- the above 2 lines are repeated 26655 more times ---
 [53313] Chains(::Array{Float64, 3}, ::Vector{Any}; kwargs::@Kwargs{})
       @ MCMCChains ~/.julia/packages/MCMCChains/RIFg4/src/chains.jl:24

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

No branches or pull requests

2 participants