Skip to content

Eagerly clean rv shape references introduced by maybe_resize#8302

Merged
ricardoV94 merged 1 commit into
pymc-devs:mainfrom
ricardoV94:nested_customdist_bug
May 18, 2026
Merged

Eagerly clean rv shape references introduced by maybe_resize#8302
ricardoV94 merged 1 commit into
pymc-devs:mainfrom
ricardoV94:nested_customdist_bug

Conversation

@ricardoV94
Copy link
Copy Markdown
Member

@ricardoV94 ricardoV94 commented May 17, 2026

Closes #8301

Size arguments don't make it into regular logprob expressions, so we monkey patch that with maybe_resize in #8105

Otherwise it's fine for arguments to include shape(rv) in their arguments, PyTensor conditional_logprob will replace those with references to the shape(value) before the logprob function is invoked. TruncatedRV however can refer the shape of a variable that is not in the graph (the generating untruncated dist) and introduce that in a way that conditional_logprob wouldn't clean.

This PR is not the ultimate answer to this question. First the current check could be said to be too eager, RV in the graph just inside the shape argument are plausible fine. Or we could always try to call resolve_shape before failing. Still seems like a good place to do this for now, we can iterate later if it is not good enough.

The new helpers have long been needed and reinvented in multiple places, so it's good to have them regardless.

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

read-the-docs-community Bot commented May 17, 2026

Documentation build overview

📚 pymc | 🛠️ Build #32735813 | 📁 Comparing 5faa634 against latest (a65e8b6)

  🔍 Preview build  

4 files changed
± glossary.html
± contributing/jupyter_style.html
± _modules/pymc/pytensorf.html
± _modules/pymc/distributions/shape_utils.html

@codecov
Copy link
Copy Markdown

codecov Bot commented May 17, 2026

Codecov Report

❌ Patch coverage is 90.90909% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 91.77%. Comparing base (169e901) to head (5faa634).

Files with missing lines Patch % Lines
pymc/pytensorf.py 87.50% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #8302      +/-   ##
==========================================
- Coverage   91.78%   91.77%   -0.01%     
==========================================
  Files         125      125              
  Lines       20428    20437       +9     
==========================================
+ Hits        18749    18757       +8     
- Misses       1679     1680       +1     
Files with missing lines Coverage Δ
pymc/distributions/shape_utils.py 92.38% <100.00%> (+0.07%) ⬆️
pymc/pytensorf.py 88.44% <87.50%> (-0.05%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ricardoV94 ricardoV94 requested a review from maresb May 17, 2026 20:42
@ricardoV94
Copy link
Copy Markdown
Member Author

@maresb can you check if this fixes the actual issue you had and not just the MWE?

@maresb
Copy link
Copy Markdown
Contributor

maresb commented May 17, 2026

Wow, thanks so much!!!

Will check in the morning.

@ricardoV94 ricardoV94 force-pushed the nested_customdist_bug branch from 44d6a1a to 5faa634 Compare May 18, 2026 11:28
Copy link
Copy Markdown
Contributor

@maresb maresb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks so much @ricardoV94! Confirmed that this resolves also my non-minimal example.

@ricardoV94 ricardoV94 merged commit 88dc395 into pymc-devs:main May 18, 2026
42 checks passed
@ricardoV94 ricardoV94 deleted the nested_customdist_bug branch May 18, 2026 20:59
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.

Bug: nested SymbolicRandomVariable inside CustomDist.logp raises 'Random variables detected in the logp graph'

2 participants