Skip to content

Conversation

penelopeysm
Copy link
Member

@penelopeysm penelopeysm commented Aug 18, 2025

Note

This PR requires some changes to AdvancedPS. TuringLang/AdvancedPS.jl#118

It also needs the following Libtask patch: TuringLang/Libtask.jl#198

Until both are merged CI is likely to fail.

This PR allows models with keyword arguments to be run with SMC / PG.

Example:

julia> using Turing

julia> @model function m(y; n=0)
           x ~ Normal(n)
           y ~ Normal(x)
       end
m (generic function with 2 methods)

julia> mean(sample(m(5.0), PG(20), 1000))
[...]
ERROR: Models with keyword arguments need special treatment to be used with particle methods. Please run:

    using Libtask; Libtask.@might_produce(m)

before sampling from this model with particle methods.

Stacktrace:
[...]

julia> using Libtask; Libtask.@might_produce(m)

julia> mean(sample(m(5.0), PG(20), 1000))
[...]
Mean
  parameters      mean
      Symbol   Float64

           x    2.4155

Closes #2007.

)
printstyled(
ctx,
" using Libtask; Libtask.@might_produce($(model.f))";
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would be open to re-exporting this, or something similar, from Turing. However I think it's not hugely important.

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.

SMC samplers no longer support usage of keyword arguments in models
1 participant