Skip to content

Replace assert checks in logprob.scan with explicit error handling#8095

Open
swarnaliiiiii wants to merge 1 commit intopymc-devs:mainfrom
swarnaliiiiii:fix-logprob-scan-asserts
Open

Replace assert checks in logprob.scan with explicit error handling#8095
swarnaliiiiii wants to merge 1 commit intopymc-devs:mainfrom
swarnaliiiiii:fix-logprob-scan-asserts

Conversation

@swarnaliiiiii
Copy link
Contributor

Summary

This PR replaces internal assert checks in logprob.scan with explicit, user-facing errors and adds early validation to prevent reaching those assertions.

Motivation

Users working with time series models that rely on Scan (e.g. via CustomDist) have reported hitting internal assertions during log-probability computation, resulting in uninformative AssertionErrors. This makes it difficult to understand why log-probability derivation failed.

A concrete example is discussed in the PyMC Discourse thread:
https://discourse.pymc.io/t/smooth-local-linear-trend-with-customdist/16968

What this PR does

  • Adds an early guard in logprob_scan to explicitly reject scans with multiple random outputs, which are currently unsupported.
  • Replaces internal assert statements in convert_outer_out_to_in with explicit RuntimeErrors that explain why log-probability derivation failed.

What this PR does NOT do

  • This PR does not attempt to support multi-output scans.
  • It does not change Scan semantics or PyTensor internals.
  • It does not alter any supported behavior; it only improves failure modes.

Related issue

addresses #7780

@welcome
Copy link

welcome bot commented Feb 6, 2026

Thank You Banner]
💖 Thanks for opening this pull request! 💖 The PyMC community really appreciates your time and effort to contribute to the project. Please make sure you have read our Contributing Guidelines and filled in our pull request template to the best of your ability.

@codecov
Copy link

codecov bot commented Feb 6, 2026

Codecov Report

❌ Patch coverage is 50.00000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.44%. Comparing base (11d0f1b) to head (c75500d).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
pymc/logprob/scan.py 50.00% 3 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #8095      +/-   ##
==========================================
- Coverage   90.89%   87.44%   -3.46%     
==========================================
  Files         123      123              
  Lines       19501    19526      +25     
==========================================
- Hits        17726    17074     -652     
- Misses       1775     2452     +677     
Files with missing lines Coverage Δ
pymc/logprob/scan.py 87.33% <50.00%> (-7.14%) ⬇️

... and 22 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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