pymc-devs / pymc-experimental

https://pymc-experimental.readthedocs.io
Other
72 stars 46 forks source link

new `pymc` version breaks import of `pymc_experimental` #317

Closed RZachLamberty closed 3 months ago

RZachLamberty commented 3 months ago

if you install pymc==5.11 and pymc-experimental==0.0.17, changes to the pymc.distributions.distributrionmodule make it impossible to importpymc_experimental`:

import pymc_experimental

will result in

ImportError: cannot import name '_moment' from 'pymc.distributions.distribution' (xxx/lib/python3.10/site-packages/pymc/distributions/distribution.py)

----> 1 import pymc_experimental
File xxx/lib/python3.10/site-packages/pymc_experimental/__init__.py:26
     23         handler = logging.StreamHandler()
     24         _log.addHandler(handler)
---> 26 from pymc_experimental import distributions, gp, statespace, utils
     27 from pymc_experimental.inference.fit import fit
     28 from pymc_experimental.model.marginal_model import MarginalModel
File xxx/lib/python3.10/site-packages/pymc_experimental/distributions/__init__.py:28
     26 from pymc_experimental.distributions.histogram_utils import histogram_approximation
     27 from pymc_experimental.distributions.multivariate import R2D2M2CP
---> 28 from pymc_experimental.distributions.timeseries import DiscreteMarkovChain
     30 __all__ = [
     31     "BetaNegativeBinomial",
     32     "DiscreteMarkovChain",
   (...)
     39     "Maxwell",
     40 ]
File xxx/lib/python3.10/site-packages/pymc_experimental/distributions/timeseries.py:9
      7 import pytensor.tensor as pt
      8 from pymc.distributions.dist_math import check_parameters
----> 9 from pymc.distributions.distribution import (
     10     Distribution,
     11     SymbolicRandomVariable,
     12     _moment,
     13     moment,
     14 )
     15 from pymc.distributions.shape_utils import (
     16     _change_dist_size,
     17     change_dist_size,
     18     get_support_shape_1d,
     19 )
     20 from pymc.logprob.abstract import _logprob
ricardoV94 commented 3 months ago

Thanks for flagging, we failed to deprecate softly in https://github.com/pymc-devs/pymc/pull/7166

@aerubanov do you happen to have the time to fix things on this end?

aerubanov commented 3 months ago

@ricardoV94 yeah, will take a look today

ricardoV94 commented 3 months ago

It's still useful to update pymc-experimental not to depend on the deprecated methods, as the tests will start to fail anyway

rklees commented 3 months ago

Has this problem already been fixed? I installed the latest version of pymc-experimental this morning and when running a python program I get the same error message as the topic starter.

ricardoV94 commented 3 months ago

No it hasn't been fixed. You can install an older version of PyMC in the meantime

ricardoV94 commented 3 months ago

Should work fine with https://github.com/pymc-devs/pymc/releases/tag/v5.10.4

rklees commented 3 months ago

I confirm that in my case pymc version 5.10.4 solves the problem.

zaxtax commented 3 months ago

I am still getting the following error when trying to import pymc-experimental on the newest pymc

    219         new_size = tuple(new_size) + tuple(old_size)
    221     return DiscreteMarkovChain.rv_op(*dist.owner.inputs[:-1], size=new_size, n_lags=op.n_lags)
--> 224 @_moment.register(DiscreteMarkovChainRV)
    225 def discrete_mc_moment(op, rv, P, steps, init_dist, state_rng):
    226     init_dist_moment = moment(init_dist)
    227     n_lags = op.n_lags

AttributeError: 'function' object has no attribute 'register'
ricardoV94 commented 3 months ago

Yeah the simple function wrapper doesnt' cut it haha.

Anyway the fix here is easy, uses of _moment should be replaced by _support_point

ricardoV94 commented 3 months ago

Closed via #320