Skip to content

Take exactly num_warmup warm-up steps when resuming from initial_state - #221

Merged
sunxd3 merged 2 commits into
TuringLang:mainfrom
thevolatilebit:fix-resumed-warmup
Oct 17, 2026
Merged

sunxd3 merged 2 commits into
TuringLang:mainfrom
thevolatilebit:fix-resumed-warmup

Conversation

@thevolatilebit

Copy link
Copy Markdown
Contributor

Fixes #220.

A chain resumed from initial_state has no initialisation step: its first call already takes a transition. mcmcsample still counted that call as step 0, so resumed chains took num_warmup + 1 warm-up transitions, including one when num_warmup = 0. The num_warmup = 0 case dates from #194 (v5.13.0). #220 has the details and a reproducer.

Change

  • _step_or_step_warmup takes a resumed::Bool and calls step_warmup while nsteps + resumed <= num_warmup.
  • Both single-chain mcmcsample methods (fixed N and isdone) set resumed = initial_state !== nothing. The ensemble methods go through them, so they need no change.
  • Fresh chains are unchanged: one initial step, then num_warmup warm-up steps, as discussed in num_warmup off by one error #195.
  • nsteps itself is unchanged, so progress reporting, discard_initial and thinning behave as before.
  • Samplers whose step_warmup is the default step see no change at all. Samplers that adapt in step_warmup, such as AdvancedMH.RobustAdaptiveMetropolis, no longer adapt once more on resume.

Tests

  • New testset "Warm-up when resuming from initial_state" in test/sample.jl. Its sampler's state counts warm-up and regular transitions.
  • It covers num_warmup ∈ {0, 1, 3} × discard_initial ∈ {0, 2}, and checks fresh chains plus resumed chains through both the fixed-N and isdone methods.
  • On main all 12 resumed assertions fail; with this change they pass.
  • Locally (Julia 1.12, 2 threads), sample.jl, chains.jl, stepper.jl and logdensityproblems.jl pass, 328/328. I couldn't run the callback tests offline (they need OnlineStats and TensorBoardLogger).
  • Formatted with JuliaFormatter 1.0.62, blue style.

Docs and version

  • docs/src/api.md: initial_state is now described as going to the first step_warmup call (or step if num_warmup == 0), with no initialisation step.
  • Version bump to 5.17.1, with a HISTORY.md entry.

🤖 Generated with Claude Code

…tate`

A chain resumed from `initial_state` has no initialisation step, but
`mcmcsample` counted its first transition as step 0, so it took
`num_warmup + 1` warm-up transitions, one even with `num_warmup = 0`.
Pass a `resumed` flag to `_step_or_step_warmup` and shift the warm-up
comparison by one for resumed chains. `nsteps` itself is unchanged, so
progress reporting, discarding and thinning behave as before.

Fixes TuringLang#220

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sunxd3

sunxd3 commented Oct 16, 2026 •

Copy link
Copy Markdown
Member

@thevolatilebit thanks! this looks good. You are welcome to mark it ready when you're ready!

@thevolatilebit
thevolatilebit marked this pull request as ready for review October 17, 2026 00:06
@codecov

codecov Bot commented Oct 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 0.00%. Comparing base (05b45f9) to head (7537251).

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

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

@thevolatilebit

Copy link
Copy Markdown
Contributor Author

@thevolatilebit thanks! this looks good. You are welcome to mark it ready when you're ready!

Thank you! I have marked it ready. Let me know if any further action is needed from my side!

@sunxd3
sunxd3 merged commit 0ae8f8f into TuringLang:main Oct 17, 2026
17 checks passed
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.

Chains resumed from initial_state take num_warmup + 1 warm-up steps

2 participants