Skip to content

BUG: sample returning a different size in pymc 5.7.0 #6840

@oscarbenjamin

Description

@oscarbenjamin

Describe the issue:

With pymc == 5.6.1 I get:

In [2]: import pymc
WARNING (pytensor.tensor.blas): Using NumPy C-API based implementation for BLAS functions.

In [3]: with pymc.Model():
   ...:     pymc.Bernoulli('X', p=0.2)
   ...:     samps = pymc.sample(draws=3, chains=1, return_inferencedata=False)
   ...: 
Only 3 samples in chain.
Sequential sampling (1 chains in 1 job)
BinaryGibbsMetropolis: [X]
Sampling 1 chain for 1_000 tune and 3 draw iterations (1_000 + 3 draws total) took 0 seconds.rgences]
The number of samples is too small to check convergence reliably.

In [4]: samps[:]['X'].shape
Out[4]: (3,)

However with pymc==5.7.0 I get:

In [1]: import pymc
WARNING (pytensor.tensor.blas): Using NumPy C-API based implementation for BLAS functions.

In [2]: with pymc.Model():
   ...:     pymc.Bernoulli('X', p=0.2)
   ...:     samps = pymc.sample(draws=3, chains=1, return_inferencedata=False)
   ...: 
Only 3 samples in chain.
Sequential sampling (1 chains in 1 job)
BinaryGibbsMetropolis: [X]
Sampling 1 chain for 0 tune and 1_003 draw iterations (0 + 1_003 draws total) took 0 seconds.rgences]
Only one chain was sampled, this makes it impossible to run some convergence checks

In [3]: samps[:]['X'].shape
Out[3]: (1003,)

So the shape of the generated output has changed.

Reproduceable code example:

import pymc
with pymc.Model():
    pymc.Bernoulli('X', p=0.2)
    samps = pymc.sample(draws=3, chains=1, return_inferencedata=False)
print(samps[:]['X'].shape)

Error message:

No response

PyMC version information:

5.7.0

Context for the issue:

This is just coming up in SymPy CI. From a SymPy VCS checkout this is reproduced with:

$ pytest sympy/stats/sampling/tests/test_sample_finite_rv.py -k test_sample_pymc
...
            with pymc.Model():
                if do_sample_pymc(self):
                    samps = pymc.sample(draws=prod(size), chains=1, compute_convergence_checks=False,
                            progressbar=False, random_seed=seed, return_inferencedata=False)[:]['X']
>                   samps = samps.reshape(size)
E                   ValueError: cannot reshape array of size 1003 into shape (1,3)

sympy/stats/rv.py:1639: ValueError

The code in question is here:
https://github.com/sympy/sympy/blob/e8ffcf40a6148235667ed75b811bdc1f953466e9/sympy/stats/rv.py#L1635-L1639

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions