Skip to content

BUG: Sampling fails because 'numpy.random._generator.Generator' object has no attribute 'spawn' #7605

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

Closed
cluhmann opened this issue Dec 4, 2024 · 1 comment · Fixed by #7607
Labels
bug dependencies Pull requests that update a dependency file

Comments

@cluhmann
Copy link
Member

cluhmann commented Dec 4, 2024

Describe the issue:

PyMC now relies on the spawn() method from numpy.random._generator.Generator. But this is a relatively recent addition to numpy (added in v1.25). So we need to set a lower limit on the numpy dependency.

Reproduceable code example:

import pymc as pm

with pm.Model() as model:
    a = pm.Normal("a")
    obs = pm.Normal("obs", a, 1, observed=[1,2])
    idata = pm.sample()

Error message:

```shell --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) Input In [7], in () 7 a = pm.Normal("a") 8 obs = pm.Normal("obs", a, 1, observed=[1,2]) ----> 9 idata = pm.sample() 11 print(az.summary(idata)) File ~/mambaforge/envs/pymc/lib/python3.10/site-packages/pymc/sampling/mcmc.py:733, in sample(draws, tune, chains, cores, random _seed, progressbar, progressbar_theme, step, var_names, nuts_sampler, initvals, init, jitter_max_retries, n_init, trace, discard _tuned_samples, compute_convergence_checks, keep_warning_stat, return_inferencedata, idata_kwargs, nuts_sampler_kwargs, callback , mp_ctx, blas_cores, model, compile_kwargs, **kwargs) 731 if random_seed == -1: 732 random_seed = None --> 733 rngs = get_random_generator(random_seed).spawn(chains) 734 random_seed_list = [rng.integers(2**30) for rng in rngs] 736 if not discard_tuned_samples and not return_inferencedata: AttributeError: 'numpy.random._generator.Generator' object has no attribute 'spawn' ```

PyMC version information:

# packages in environment at /home/xian/mambaforge/envs/pymc: # # Name Version Build Channel numpy 1.24.2 py310h8deb116_0 conda-forge pymc 5.19.0 hd8ed1ab_0 conda-forge pymc-base 5.19.0 pyhd8ed1ab_0 conda-forge pytensor 2.26.4 py310ha549d7f_0 conda-forge pytensor-base 2.26.4 py310h89e8f5a_0 conda-forge
@cluhmann cluhmann added the bug label Dec 4, 2024
@ricardoV94 ricardoV94 added the dependencies Pull requests that update a dependency file label Dec 4, 2024
@nataziel
Copy link
Contributor

nataziel commented Dec 5, 2024

This was true as of 5.18, I ran into the problem last week and didn't think to file a report sorry! From this commit: 4ea1406

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug dependencies Pull requests that update a dependency file
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants