Skip to content

Clean up sample loop, pass discard_sample keyword as kwarg to step/step_warmup#194

Merged
penelopeysm merged 7 commits into
mainfrom
py/discard
Jan 28, 2026
Merged

Clean up sample loop, pass discard_sample keyword as kwarg to step/step_warmup#194
penelopeysm merged 7 commits into
mainfrom
py/discard

Conversation

@penelopeysm
Copy link
Copy Markdown
Member

@penelopeysm penelopeysm commented Jan 28, 2026

This PR:

  1. Fixes Num_warmup / discard_initial / thinning error (?!) #196.

  2. Fixes Pass information through to step / step_warmup about whether a step will be discarded #185.

  3. Abstracts step_warmup and step into a single function, so that this pattern doesn't have to be repeated a few times inside sample().

if i < num_warmup
   step_warmup(...)
else
   step(...)
end
  1. Same with saving samples and invoking the callback. Those two things should only ever be called in tandem and if there isn't a single function for them, it just makes it too easy to accidentally do one but not the other. Also this code is just cleaner.

@github-actions
Copy link
Copy Markdown
Contributor

AbstractMCMC.jl documentation for PR #194 is available at:
https://TuringLang.github.io/AbstractMCMC.jl/previews/PR194/

@penelopeysm penelopeysm marked this pull request as ready for review January 28, 2026 13:30
@penelopeysm penelopeysm merged commit ea9f901 into main Jan 28, 2026
15 checks passed
@penelopeysm penelopeysm deleted the py/discard branch January 28, 2026 15:02
@codecov
Copy link
Copy Markdown

codecov Bot commented Jan 28, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 0.00%. Comparing base (a346c51) to head (8e7457d).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@     Coverage Diff     @@
##   main   #194   +/-   ##
===========================
===========================

☔ 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.

penelopeysm added a commit to TuringLang/Turing.jl that referenced this pull request Jan 28, 2026
Closes #2639

Quoting from the changelog:

> Avoid reevaluating the model on MCMC iterations where the transition
is not saved to the chain (e.g. in initial burn-in, or when using
thinning).
> Also avoid each component sampler of Gibbs unnecessarily evaluating
the model once per iteration.

This makes use of the `discard_sample` keyword argument to `step` /
`step_warmup` TuringLang/AbstractMCMC.jl#194

Note that this is still type stable as the value of the `discard_sample`
kwarg can be constant propagated (I've checked this with code_warntype
etc).
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.

Num_warmup / discard_initial / thinning error (?!) Pass information through to step / step_warmup about whether a step will be discarded

1 participant