Skip to content

Enable keyword arguments for particle methods#2660

Merged
penelopeysm merged 7 commits into
mainfrom
py/smc-kwargs
Jan 25, 2026
Merged

Enable keyword arguments for particle methods#2660
penelopeysm merged 7 commits into
mainfrom
py/smc-kwargs

Conversation

@penelopeysm

@penelopeysm penelopeysm commented Aug 18, 2025

Copy link
Copy Markdown
Member

Note

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

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.

Comment thread src/mcmc/particle_mcmc.jl Outdated
@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
Copy Markdown
Contributor

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

Comment thread Project.toml Outdated
Comment thread test/Project.toml Outdated
@penelopeysm penelopeysm requested a review from mhauru December 12, 2025 17:40
@codecov

codecov Bot commented Dec 12, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.11765% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 86.94%. Comparing base (8762fa3) to head (3831744).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/mcmc/particle_mcmc.jl 94.11% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2660      +/-   ##
==========================================
+ Coverage   86.65%   86.94%   +0.29%     
==========================================
  Files          20       20              
  Lines        1259     1264       +5     
==========================================
+ Hits         1091     1099       +8     
+ Misses        168      165       -3     

☔ 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

yebai commented Dec 15, 2025

Copy link
Copy Markdown
Member

@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
@penelopeysm penelopeysm removed the request for review from mhauru January 17, 2026 22:02
@penelopeysm penelopeysm merged commit 751ae1d into main Jan 25, 2026
28 of 29 checks passed
@penelopeysm penelopeysm deleted the py/smc-kwargs branch January 25, 2026 18:29
@penelopeysm

Copy link
Copy Markdown
Member Author

Merging this so that we can work on other SMC/PG bugs.

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

2 participants