refactor(mcmc): resolve sampler_type once via resolve_sampler_spec#141
Merged
Conversation
config.sampler_type was string-compared at four sites: create_sampler (factory),
the learn_sd flag for the warmup schedule, and the has_nuts_diag/has_am_diag
reservation flags. Add resolve_sampler_spec(string) -> SamplerSpec{kind, learn_sd,
nuts_diag, am_diag} as the single string decode; create_sampler now switches on
the SamplerKind enum and the runner reads the spec fields.
Per the design-review critique this is a free function, not a field on the
thread-shared const SamplerConfig. bgmCompare, target_acceptance, and
initial_step_size are untouched (create_sampler has no callers outside this TU).
Behavior-preserving: same factory choice, same flags; no RNG/math change.
Verified bitwise: adaptive-Metropolis GGM, NUTS GGM, and adaptive-Metropolis
mixed-MRF raw draws digest-identical pre/post. identical(main, branch) == TRUE.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #141 +/- ##
==========================================
- Coverage 87.73% 87.70% -0.03%
==========================================
Files 87 87
Lines 12853 12859 +6
==========================================
+ Hits 11276 11278 +2
- Misses 1577 1581 +4 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
config.sampler_typewas string-compared at four sites:create_sampler(the factory), thelearn_sdflag for theWarmupSchedule, and thehas_nuts_diag/has_am_diagreservation flags. Adding a sampler meant editing each.Adds
resolve_sampler_spec(string) -> SamplerSpec{kind, learn_sd, nuts_diag, am_diag}as the single place that decodes the string.create_samplernow switches on theSamplerKindenum;run_mcmc_chain/run_mcmc_samplerread the spec fields.Per the design-review critique, this is a free function — not a field on the thread-shared const
SamplerConfig.bgmCompare,target_acceptance, andinitial_step_sizeare untouched;create_samplerhas no callers outside this translation unit, so the signature change is contained.Why this is safe
Pure control-flow plumbing: same factory choice, same three flags, no RNG or math change.
Verified bitwise: adaptive-Metropolis GGM, NUTS GGM, and adaptive-Metropolis mixed-MRF raw draws are digest-identical pre/post.
identical(main, branch) == TRUE. Harnesses:dev/bitwise_ggm_mh_primitive.R,dev/bitwise_ggm_nuts.R,dev/bitwise_mixed_logdet_ratio.R.