Skip to content

refactor(mcmc): extract store_nuts_diagnostics_if_present helper#142

Merged
MaartenMarsman merged 2 commits into
mainfrom
refactor/diagnostics-store-helper
Jun 4, 2026
Merged

refactor(mcmc): extract store_nuts_diagnostics_if_present helper#142
MaartenMarsman merged 2 commits into
mainfrom
refactor/diagnostics-store-helper

Conversation

@MaartenMarsman

Copy link
Copy Markdown
Collaborator

What

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_nuts_diagnostics call inline. Moved it to a file-local store_nuts_diagnostics_if_present helper so the 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 (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.

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

codecov Bot commented Jun 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.66%. Comparing base (0408b64) to head (d938ef0).

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

# Conflicts:
#	src/mcmc/execution/chain_runner.cpp
@MaartenMarsman MaartenMarsman merged commit bab7ca2 into main Jun 4, 2026
9 of 10 checks passed
@MaartenMarsman MaartenMarsman deleted the refactor/diagnostics-store-helper branch June 4, 2026 20:55
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