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 This is merged

This PR also lacks tests; some should be added. Tests added.

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))
Sampling 100%|███████████████████████████████████████████████████████████████████| Time: 0:00:05
Mean

  parameters      mean
      Symbol   Float64

           x    2.7182



julia> mean(sample(m(5.0; n=10.0), PG(20), 1000))
Sampling 100%|███████████████████████████████████████████████████████████████████| Time: 0:00:04
Mean

  parameters      mean
      Symbol   Float64

           x    7.4854

Closes #2007.

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

@penelopeysm penelopeysm Aug 19, 2025

Choose a reason for hiding this comment

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

I think we could/should reexport Libtask.@might_produce or something similar from Turing, to make it easier?

@penelopeysm penelopeysm force-pushed the py/smc-kwargs branch 5 times, most recently from 6dd26db to c94c5fa Compare December 12, 2025 17:25
@penelopeysm penelopeysm marked this pull request as ready for review December 12, 2025 17:25
@github-actions
Copy link
Contributor

Turing.jl documentation for PR #2660 is available at:
https://TuringLang.github.io/Turing.jl/previews/PR2660/

Comment on lines +90 to +91
[sources]
AdvancedPS = {url = "https://github.com/TuringLang/AdvancedPS.jl", rev = "py/kwargs"}
Copy link
Member Author

Choose a reason for hiding this comment

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

This will have to be removed pending release of TuringLang/AdvancedPS.jl#118

Comment on lines +81 to +82
[sources]
AdvancedPS = {url = "https://github.com/TuringLang/AdvancedPS.jl", rev = "py/kwargs"}
Copy link
Member Author

Choose a reason for hiding this comment

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

Likewise

@penelopeysm penelopeysm requested a review from mhauru December 12, 2025 17:40
@codecov
Copy link

codecov bot commented Dec 12, 2025

Codecov Report

❌ Patch coverage is 94.11765% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 55.75%. Comparing base (4dc7ad0) to head (f533de2).

Files with missing lines Patch % Lines
src/mcmc/particle_mcmc.jl 94.11% 1 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (4dc7ad0) and HEAD (f533de2). Click for more details.

HEAD has 6 uploads less than BASE
Flag BASE (4dc7ad0) HEAD (f533de2)
24 18
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #2660       +/-   ##
===========================================
- Coverage   86.51%   55.75%   -30.77%     
===========================================
  Files          20       20               
  Lines        1261     1259        -2     
===========================================
- Hits         1091      702      -389     
- Misses        170      557      +387     

☔ View full report in Codecov by Sentry.
📢 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.

@yebai
Copy link
Member

yebai commented Dec 15, 2025

@mhauru @sunxd3 this should be ready now that TuringLang/AdvancedPS.jl#118 is released.

@yebai yebai requested a review from sunxd3 December 15, 2025 14:02
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

3 participants