Skip to content

Conversation

@atheendre130505
Copy link

@atheendre130505 atheendre130505 commented Nov 2, 2025

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/

…vs#7891)

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 pymc-devs#7891
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Check idata dims/coords for consistency before sampling begins

1 participant