Skip to content

Fix DEMetropolis stats type mismatch in population sampler output#8172

Open
SanketMeghale wants to merge 3 commits into
pymc-devs:v5from
SanketMeghale:fix-8169-demetropolis-stats
Open

Fix DEMetropolis stats type mismatch in population sampler output#8172
SanketMeghale wants to merge 3 commits into
pymc-devs:v5from
SanketMeghale:fix-8169-demetropolis-stats

Conversation

@SanketMeghale
Copy link
Copy Markdown

@SanketMeghale SanketMeghale commented Mar 6, 2026

Description

This PR fixes a stats contract violation in DEMetropolis that can break population sampling output handling and trigger CI failures like:

  • ValueError: setting an array element with a sequence

Root cause:

  • DEMetropolis.stats_dtypes_shapes declares scalar stats (tune: bool, scaling: float64),
  • but DEMetropolis.astep was emitting:
    • tune as str | None
    • scaling as a NumPy array

This mismatch can propagate into downstream stats packing/trace handling and fail tests in tests/sampling/test_population.py.

Fix

In DEMetropolis.astep stats payload:

  • "tune": self.tune is not None (bool)
  • "scaling": float(np.mean(self.scaling)) (scalar float)

This restores consistency with stats_dtypes_shapes and aligns behavior with DEMetropolisZ (which already reports scalar scaling).

Fixes #8169

Testing

Targeted population sampler checks:

$env:PYTENSOR_FLAGS='cxx='
.\.venv\Scripts\python.exe -m pytest tests/sampling/test_population.py -k "checks_population_size or demcmc_warning_on_small_populations or nonparallelized_chains_are_random or parallelized_chains_are_random" -q

Observed result relevant to this PR:

  • The original ValueError: setting an array element with a sequence is no longer reproduced.
  • test_checks_population_size: pass
  • test_demcmc_warning_on_small_populations: pass

@read-the-docs-community
Copy link
Copy Markdown

Documentation build overview

📚 pymc | 🛠️ Build #31689837 | 📁 Comparing 86b2554 against latest (c9cd0c8)


🔍 Preview build

Show files changed (2 files in total): 📝 2 modified | ➕ 0 added | ➖ 0 deleted
File Status
glossary.html 📝 modified
_modules/pymc/step_methods/metropolis.html 📝 modified

@ricardoV94
Copy link
Copy Markdown
Member

You have unrelated commit here

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.

2 participants