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: constant_data is missing from idata when sampling with nutpie #74

Open
Y0dler opened this issue Sep 25, 2023 · 2 comments
Open

BUG: constant_data is missing from idata when sampling with nutpie #74

Y0dler opened this issue Sep 25, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@Y0dler
Copy link

Y0dler commented Sep 25, 2023

Describe the issue:

I recently encountered an issue when trying to add constant data to some of my models.
When sampling with nuts_sampler="pymc", idata contains a group denominated as constant_data where x and y from this toy example are stored. Unfortunately, when using nutpie, the constant data is nowhere to be found.
Is this actually a bug or is there something wrong with my definitions? Or are pm.ConstantData() and such perhaps just not supported when using nutpie?
Any help would be much appreciated.

Reproduceable code example:

import numpy as np
import pymc as pm
import pytensor.tensor as pt

x = np.array([1,2,3,4])
y = np.array([100, 190, 310, 405])

with pm.Model() as pmodel:
    # add data to the pmodel as ConstantData
    pm.ConstantData("x", x)
    pm.ConstantData("y", y)

    var = pm.Normal("var", 100, 5)
    
    # likelihood
    pm.Normal("L", mu=y, sigma=0.1, observed=y)
    # posterior
    pst = x * var
    pst = pm.Deterministic("posterior", pst)
    # sampling
    idata = pm.sample(nuts_sampler="nutpie", tune=50, draws=50)

print(idata)

Error message:

Output of print(idata):

Inference data with groups:
	> posterior
	> sample_stats

Warmup iterations saved (warmup_*).

PyMC version information:

PyMC v5.8.1 (pypi)
nutpie v0.9.1 (pypi)
PyTensor v2.16.2 (pypi)

Context for the issue:

No response

@Y0dler Y0dler added the bug Something isn't working label Sep 25, 2023
@welcome
Copy link

welcome bot commented Sep 25, 2023

Welcome Banner
🎉 Welcome to PyMC! 🎉 We're really excited to have your input into the project! 💖

If you haven't done so already, please make sure you check out our Contributing Guidelines and Code of Conduct.

@michaelosthege
Copy link
Member

michaelosthege commented Sep 25, 2023

Might be because this information is not even passed to _trace_to_arviz here?

https://github.com/pymc-devs/nutpie/blob/2938d5a0f04a8797792d1f7746f8a24de250db82/python/nutpie/sample.py#L250C25-L250C25

We should probably adopt from here: https://github.com/pymc-devs/mcbackend/blob/96e4248d1d1d1be8b73b28d702bb1a3012ef98f6/mcbackend/core.py#L265

These pieces are all already implemented in the McBackend code. For example a find_data function: https://github.com/pymc-devs/pymc/blob/15fbf0e2f0892b556c8b59446347dd4691a476e6/pymc/backends/mcbackend.py#L44

@aseyboldt @ferrine do I see it correctly that the solution here is to change this line to pass return_raw_trace=True and do the conversion to InferenceData in PyMC codebase?

@ricardoV94 ricardoV94 transferred this issue from pymc-devs/pymc Oct 3, 2023
Y0dler added a commit to Y0dler/pymc that referenced this issue Oct 6, 2023
Y0dler added a commit to Y0dler/pymc that referenced this issue Oct 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants