Skip to content

Conversation

@atheendre130505
Copy link

@atheendre130505 atheendre130505 commented Nov 4, 2025

Description

This PR implements validation to check idata dimensions and coordinates consistency before sampling begins, addressing issue #7891.

Problem

Previously, sampling would fail with unclear error messages when idata had inconsistent dims/coords with the model. This made debugging difficult.

Solution

Added early validation that:

  • Checks dims/coords in idata before sampling starts
  • Provides clear, actionable error messages for mismatches
  • Prevents confusing failures deep in the sampling process

Testing

  • All existing tests pass locally
  • Manual testing confirms expected error behavior for dimension mismatches

Related Issue

Fixes #7891


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

…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
@atheendre130505
Copy link
Author

pre-commit.ci autofix

2 similar comments
@atheendre130505
Copy link
Author

pre-commit.ci autofix

@atheendre130505
Copy link
Author

pre-commit.ci autofix

@atheendre130505 atheendre130505 force-pushed the dims-coords-validate-7891 branch from 7a188b8 to 75cbed0 Compare November 4, 2025 15:01
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