AttributeError: 'function' object has no attribute 'register'

Hi, I’m using a Windows 11 64-bit machine with Anaconda. I followed the official bap3.yml to build my environment.
The I begin to use the pymc_experimental.GenExtreme to build a model, but encountered an AttributeError: ‘function’ object has no attribute ‘register’. My code is this:

import arviz as az
import matplotlib.pyplot as plt
import numpy as np
import pymc as pm
import pymc_experimental.distributions as pmx
import pytensor.tensor as pt

from arviz.plots import plot_utils as azpu

with pm.Model() as model1:
    miu = pm.Normal("miu", mu=10, sigma=5)
    sigma = pm.HalfNormal("sigma", sigma=10)
    ksi = pm.TruncatedNormal("ksi", mu=0, sigma=0.2, lower=-0.6, upper=0.6)
    
    # Estimation
    gev = pmx.GenExtreme("gev", mu=miu, sigma=sigma, xi=ksi, observed=new_data.max_load)
    # Return level
    z_p = pm.Deterministic("z_p", μ - σ / ksi * (1 - (-np.log(1 - p)) ** (-ksi)))

And the error is this:

AttributeError                            Traceback (most recent call last)
Cell In[3], line 5
      3 import numpy as np
      4 import pymc as pm
----> 5 import pymc_experimental.distributions as pmx
      6 import pytensor.tensor as pt
      8 from arviz.plots import plot_utils as azpu

File d:\anaconda3\envs\pymc5\Lib\site-packages\pymc_experimental\__init__.py:26
     23         handler = logging.StreamHandler()
     24         _log.addHandler(handler)
---> 26 from pymc_experimental import distributions, gp, utils
     27 from pymc_experimental.inference.fit import fit
     28 from pymc_experimental.marginal_model import MarginalModel

File d:\anaconda3\envs\pymc5\Lib\site-packages\pymc_experimental\distributions\__init__.py:24
     22 from pymc_experimental.distributions.histogram_utils import histogram_approximation
     23 from pymc_experimental.distributions.multivariate import R2D2M2CP
---> 24 from pymc_experimental.distributions.timeseries import DiscreteMarkovChain
     26 __all__ = [
     27     "DiscreteMarkovChain",
     28     "GeneralizedPoisson",
   (...)
     31     "histogram_approximation",
     32 ]

File d:\anaconda3\envs\pymc5\Lib\site-packages\pymc_experimental\distributions\timeseries.py:225
    220         new_size = tuple(new_size) + tuple(old_size)
    222     return DiscreteMarkovChain.rv_op(*dist.owner.inputs[:-1], size=new_size, n_lags=op.n_lags)
--> 225 @_moment.register(DiscreteMarkovChainRV)
    226 def discrete_mc_moment(op, rv, P, steps, init_dist, state_rng):
    227     init_dist_moment = moment(init_dist)
    228     n_lags = op.n_lags

AttributeError: 'function' object has no attribute 'register'

Thanks in advance for your help.

bap3.yml pins pymc to 5.8.0, but there’s no associated pin on pymc-experimental, which is what I think is leading to this error. I’d just update everything to the latest versions if I were you – I’d rather deal with potential problems that would bring by learning the latest syntax (I can’t think of any major user-facing changing since then though).

If you’re not keen to do that, you need to pin pymc-experimental to whatever was out around version 5.8.0. That version was released September last year. Just checking the experimental releases, you can try 0.0.11 or 0.0.12. But again, I still recommend always going to the latest version.

cc @aloctavodia

As @jessegrabowski said, installing the last version of pymc-experimental is probably a good idea. I don’t think you will face a major syntax problem using a new PyMC version. If you do, you can open an issue here Issues · aloctavodia/BAP3 · GitHub

Many Thanks to your reply!
I solved this problem and update the dependencies by using the yml document here: pymc/conda-envs/windows-environment-dev.yml at main · pymc-devs/pymc · GitHub

1 Like