refactor(mcmc): extract store_nuts_diagnostics_if_present helper#142
Merged
Conversation
The NUTS per-iteration diagnostics store in run_mcmc_chain's sampling-phase block nested a dynamic_cast, a null check, and a six-argument store call inline. Move it to a file-local helper so the main loop reads as one call. Per the design-review critique this stays a chain_runner-local helper: no DiagnosticsBase::store_into (that would invert the algorithm/storage layering bgmCompare relies on), and the reserve/convert ladders stay explicit. Behavior-preserving: same guard, same dynamic_cast, same stored fields. Verified bitwise: NUTS GGM raw draws AND the stored NUTS diagnostics (tree depth, divergent, energy, accept prob, ...) are digest-identical pre/post (edge-sel + no-edge); adaptive-Metropolis draws unaffected. identical(main, branch) == TRUE.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #142 +/- ##
==========================================
- Coverage 87.68% 87.66% -0.03%
==========================================
Files 87 87
Lines 12863 12862 -1
==========================================
- Hits 11279 11275 -4
- Misses 1584 1587 +3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
# Conflicts: # src/mcmc/execution/chain_runner.cpp
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
The NUTS per-iteration diagnostics store in
run_mcmc_chain's sampling-phase block nested adynamic_cast, a null check, and a six-argumentstore_nuts_diagnosticscall inline. Moved it to a file-localstore_nuts_diagnostics_if_presenthelper so the loop reads as one call.Per the design-review critique this stays a
chain_runner-local helper: noDiagnosticsBase::store_into(that would invert the algorithm/storage layering bgmCompare relies on), and thereserve/convertladders stay explicit (R parses exact keys/dims).Why this is safe
Same guard, same
dynamic_cast, same stored fields in the same order.Verified bitwise: NUTS GGM raw draws and the stored NUTS diagnostics (tree depth, divergent, non-reversible, energy, accept prob) are digest-identical pre/post (edge-sel + no-edge); adaptive-Metropolis draws unaffected.
identical(main, branch) == TRUE. Harnesses:dev/bitwise_ggm_nuts.R,dev/bitwise_nuts_diag.R.