Skip to content

BUG: Using a length-only coord causes it to be volatile #7376

Closed
@JasonTam

Description

@JasonTam

Describe the issue:

When a variable is defined with a coord, it's considered volatile. Then sample_posterior_predictive does not transfer the node over.
I believe the volatility condition that's met is

or ( # SharedVariables, except RandomState/Generators
isinstance(node, SharedVariable)
and not isinstance(node, RandomStateSharedVariable | RandomGeneratorSharedVariable)
and not shared_value_matches(node)
)

The coord is intended to be immutable, but after #7047, coords always mutable

Somewhat related:

Reproduceable code example:

import pymc as pm

y_obs = [0] * 3
with pm.Model() as m:
    m.add_coord("coord0", length=1)
    x = pm.Data("x", [0] * 3)
    b = pm.Normal("b", dims="coord0")  # Causes `b` to be volatile
    # b = pm.Normal("b", shape=1)      # Works as expected (`b` is transferred)
    y = pm.Normal("y", b[0] * x, observed=y_obs)
    idata = pm.sample()
    
    pm.sample_posterior_predictive(trace=idata, var_names='y')

Error message:

Sampling: [b, y]

PyMC version information:

5.15.1

Context for the issue:

Cannot use sample_posterior_predictive as intended

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