Skip to content

refactor(mcmc): resolve sampler_type once via resolve_sampler_spec#141

Merged
MaartenMarsman merged 1 commit into
mainfrom
refactor/sampler-spec-descriptor
Jun 4, 2026
Merged

refactor(mcmc): resolve sampler_type once via resolve_sampler_spec#141
MaartenMarsman merged 1 commit into
mainfrom
refactor/sampler-spec-descriptor

Conversation

@MaartenMarsman

Copy link
Copy Markdown
Collaborator

What

config.sampler_type was string-compared at four sites: create_sampler (the factory), the learn_sd flag for the WarmupSchedule, and the has_nuts_diag/has_am_diag reservation 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_sampler now switches on the SamplerKind enum; run_mcmc_chain/run_mcmc_sampler read 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 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.

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

codecov Bot commented Jun 4, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 89.47368% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.70%. Comparing base (e85bd6c) to head (3b37d9c).

Files with missing lines Patch % Lines
src/mcmc/execution/chain_runner.cpp 89.47% 2 Missing ⚠️
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.
📢 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.

@MaartenMarsman MaartenMarsman merged commit 0408b64 into main Jun 4, 2026
9 of 10 checks passed
@MaartenMarsman MaartenMarsman deleted the refactor/sampler-spec-descriptor branch June 4, 2026 20:32
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.

1 participant