pymc icon indicating copy to clipboard operation
pymc copied to clipboard

Add dims/coords consistency validation before sampling (issue #7891)

Open atheendre130505 opened this issue 1 month ago • 0 comments

This commit implements validation of InferenceData dimensions and coordinates consistency before pm.sample() executes, preventing cryptic shape mismatch errors during sampling.

Changes:

  • Add pymc/model/validation.py with validation functions:

    • validate_dims_coords_consistency(): Main validation entry point
    • check_dims_exist(): Verify referenced dims exist in model.coords
    • check_shape_dims_match(): Verify variable shapes match declared dims
    • check_coord_lengths(): Verify coordinate lengths match dimension sizes
  • Integrate validation into pymc/sampling/mcmc.py:

    • Added validation call early in sample() function, before sampling setup
    • Provides clear, actionable error messages to guide users
  • Add comprehensive tests in tests/model/test_dims_coords_validation.py:

    • Test missing coord detection
    • Test shape-dims mismatch detection
    • Test coordinate length validation
    • Test MutableData, observed data, and Deterministic variables
    • Test edge cases and complex models

Fixes #7891

Description

Related Issue

  • [ ] Closes #
  • [ ] Related to #

Checklist

Type of change

  • [ ] New feature / enhancement
  • [ ] Bug fix
  • [ ] Documentation
  • [ ] Maintenance
  • [ ] Other (please specify):

📚 Documentation preview 📚: https://pymc--7943.org.readthedocs.build/en/7943/

atheendre130505 avatar Nov 02 '25 07:11 atheendre130505