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: Several distributions fail in Python 3.13 due to deprecated class property support #7551

Open
thomasaarholt opened this issue Oct 28, 2024 · 1 comment
Labels

Comments

@thomasaarholt
Copy link
Contributor

thomasaarholt commented Oct 28, 2024

Describe the issue:

Python 3.13 breaks backward compatibility on chaining classmethods and property decorators, citing that it was a flawed approach. See the first bullet point here, and another article here going in to workarounds.

The pattern used in pymc, which is now failing, is this from distribution.py:

class SymbolicRandomVariable(MeasurableOp, OpFromGraph):
    ...

    @_class_or_instancemethod
    @property
    def ndims_params(cls_or_self) -> Sequence[int] | None:

This pattern occurs 5 times in the codebase, all in distribution.py.

Reproduceable code example:

import pymc as pm

with pm.Model() as model:
    pm.ExGaussian("foo", mu=1, sigma=2, nu=5)

Error message:

WARNING (pytensor.tensor.blas): Using NumPy C-API based implementation for BLAS functions.
Traceback (most recent call last):
  File "/Users/thomas/repos/pymc-typed-distributions/run.py", line 4, in <module>
    x = pm.ExGaussian("foo", mu=1, sigma=2, nu=5)
  File "/Users/thomas/repos/pymc-typed-distributions/.venv/lib/python3.13/site-packages/pymc/distributions/distribution.py", line 508, in __new__
    rv_out = cls.dist(*args, **kwargs)
  File "/Users/thomas/repos/pymc-typed-distributions/.venv/lib/python3.13/site-packages/pymc/distributions/continuous.py", line 2945, in dist
    return super().dist([mu, sigma, nu], **kwargs)
           ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/thomas/repos/pymc-typed-distributions/.venv/lib/python3.13/site-packages/pymc/distributions/distribution.py", line 577, in dist
    rv_out = cls.rv_op(*dist_params, size=create_size, **kwargs)
  File "/Users/thomas/repos/pymc-typed-distributions/.venv/lib/python3.13/site-packages/pymc/distributions/continuous.py", line 2862, in rv_op
    size = implicit_size_from_params(mu, sigma, nu, ndims_params=cls.ndims_params)
  File "/Users/thomas/repos/pymc-typed-distributions/.venv/lib/python3.13/site-packages/pymc/distributions/shape_utils.py", line 464, in implicit_size_from_params
    for param, ndim in zip(params, ndims_params):
                       ~~~^^^^^^^^^^^^^^^^^^^^^^

PyMC version information:

pymc 5.17.0, installed via uv/pip

Context for the issue:

No response

@ricardoV94
Copy link
Member

We actually had another approach (duplicated code?) in that PR so we can go with the alternative approach.

Thanks for signaling

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

2 participants