Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: model.debug(fn=‘logp’) doesn’t work with Potentials #6966

Open
jonsedar opened this issue Oct 21, 2023 · 0 comments
Open

BUG: model.debug(fn=‘logp’) doesn’t work with Potentials #6966

jonsedar opened this issue Oct 21, 2023 · 0 comments
Labels

Comments

@jonsedar
Copy link
Contributor

jonsedar commented Oct 21, 2023

Describe the issue:

model.debug() errors out when I have models that contain a Potential:

ValueError: Length of {name_of_potential} cannot be determined

There seems to be something going on in https://github.com/pymc-devs/pytensor/blob/7bb18f3a3590d47132245b7868b3a4a6587a4667/pytensor/tensor/__init__.py#L59 which fails for Potentials. Possibly because this one has shape None ?

_.type
$> TensorType(float64, shape=(None,))

See more discussion here: https://discourse.pymc.io/t/possible-bug-model-debug-fn-logp-doesnt-work-with-potentials/13150/3

Reproduceable code example:

import matplotlib.pyplot as plt
import numpy as np
import pymc as pm

rng = np.random.default_rng(42)
n = 100
y_obs = rng.normal(size=n)

with pm.Model() as mdl:
    y = pm.MutableData('y', y_obs)
    
    mu = pm.Normal('mu', mu=0.0, sigma=1.0)
    sigma = pm.InverseGamma('sigma', alpha=5.0, beta=4.0)
    norm_d = pm.Normal.dist(mu=mu, sigma=sigma, size=n)
    _ = pm.Potential('pot_yhat', pm.logp(norm_d, y))

print('Random:\n')
mdl.debug(fn='random', verbose=True)

print('\n\nlogP:\n')
mdl.debug(fn='logp', verbose=True)

Error message:

ValueError: Length of pot_yhat cannot be determined

PyMC version information:

Python implementation: CPython
Python version       : 3.10.12
IPython version      : 8.16.1

pymc    : 5.9.0
pytensor: 2.17.3

Compiler    : Clang 15.0.7 
OS          : Darwin
Release     : 22.6.0
Machine     : x86_64
Processor   : i386
CPU cores   : 8
Architecture: 64bit

Context for the issue:

This could be reclassified as a 1) a feature request to allow model.debug() to work on models with Potentials, and 2) a bug to be most easily fixed by a try/catch and a user warning

@jonsedar jonsedar added the bug label Oct 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant